Ejemplo n.º 1
0
  @Override
  protected Control createControl(Composite parent) {
    // TODO Auto-generated method stub

    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = 0;
    composite.setLayout(layout);

    scale = new Scale(composite, SWT.HORIZONTAL);
    scale.setSize(200, 30);
    scale.setMinimum(0);
    scale.setMaximum(10);
    scale.addSelectionListener(
        new SelectionListener() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            // TODO Auto-generated method stub
            System.out.println("scale: " + scale.getSelection());
            LevelHighlightingEvent event = new LevelHighlightingEvent();
            event.setHierarchyLevel(scale.getSelection());

            EventPublisher.trigger(event);
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub

          }
        });

    return composite;
  }
Ejemplo n.º 2
0
    public Setting(Composite comp, String title) {
      final Composite settingComp = new Composite(comp, SWT.BORDER);
      settingComp.setLayout(new FillLayout(SWT.VERTICAL));

      final RowLayout infoLayout = new RowLayout();
      infoLayout.center = true;

      final Composite infoComp = new Composite(settingComp, SWT.NONE);
      infoComp.setLayout(infoLayout);

      final Label settingLabel = new Label(infoComp, SWT.CENTER);
      settingLabel.setText(title);

      settingValue = new Text(infoComp, SWT.BORDER | SWT.SINGLE);
      settingValue.setText("000");

      settingScale = new Scale(settingComp, SWT.BORDER);
      settingScale.setSize(200, 64);
      settingScale.setMaximum(50);
      settingScale.addListener(
          SWT.Selection,
          new Listener() {
            @Override
            public void handleEvent(Event e) {
              settingValue.setText("" + settingScale.getSelection());
            }
          });
    }
Ejemplo n.º 3
0
 private void setLoggingInfo(LoggingInfo loggingInfo) {
   logCategoryCombo.select(loggingInfo.getCategorySelection());
   logLevelScale.setMaximum(LoggingInfo.getLoggingLevelRange(loggingInfo.getCategoryExt()) - 1);
   logLevelScale.setSelection(loggingInfo.getLevelScaleSelection());
   logLevelDesc.setText(PLUS_PREFIX + loggingInfo.getLevelLabelText());
   layout(true, true);
 }
Ejemplo n.º 4
0
 protected boolean handleScaleSelection(Scale scale) {
   int min = scale.getMinimum();
   double portion = (scale.getSelection() - min) * 1.0d / (scale.getMaximum() - min);
   boolean selectionChanged = internalSetSelection(portion, false);
   refresh();
   return selectionChanged;
 }
  public void testRenderParent() throws IOException {
    Scale scale = new Scale(shell, SWT.NONE);

    lca.renderInitialization(scale);

    Message message = Fixture.getProtocolMessage();
    CreateOperation operation = message.findCreateOperation(scale);
    assertEquals(WidgetUtil.getId(scale.getParent()), operation.getParent());
  }
  public void testRenderPageIncrement() throws IOException {
    Scale scale = new Scale(shell, SWT.NONE);

    scale.setPageIncrement(20);
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertEquals(new Integer(20), message.findSetProperty(scale, "pageIncrement"));
  }
  public void testRenderMaxmum() throws IOException {
    Scale scale = new Scale(shell, SWT.NONE);

    scale.setMaximum(10);
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertEquals(new Integer(10), message.findSetProperty(scale, "maximum"));
  }
Ejemplo n.º 8
0
  @Override
  public void initialize() {
    super.initialize();

    if (!dynamicEnabled) {
      return;
    }

    Scale scale = getScale();
    scale.addSelectionListener(selectionListener);
  }
  public void testRenderAddSelectionListener() throws Exception {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);
    Fixture.preserveWidgets();

    scale.addSelectionListener(new SelectionAdapter() {});
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertEquals(Boolean.TRUE, message.findListenProperty(scale, "selection"));
  }
Ejemplo n.º 10
0
  public void testRenderPageIncrementUnchanged() throws IOException {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);

    scale.setPageIncrement(20);
    Fixture.preserveWidgets();
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(scale, "pageIncrement"));
  }
Ejemplo n.º 11
0
  public void testRenderSelectionListenerUnchanged() throws Exception {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);
    Fixture.preserveWidgets();

    scale.addSelectionListener(new SelectionAdapter() {});
    Fixture.preserveWidgets();
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findListenOperation(scale, "selection"));
  }
Ejemplo n.º 12
0
  @Override
  public void dispose() {
    super.dispose();

    if (!dynamicEnabled) {
      return;
    }

    Scale scale = getScale();
    if (!scale.isDisposed()) {
      scale.removeSelectionListener(selectionListener);
    }
  }
  /** TODO summary sentence for apply ... */
  public void apply() {
    RasterSymbolizer symbolizer = (RasterSymbolizer) getContent();
    StyleBuilder styleBuilder = getStyleBuilder();

    double opacity = ((double) opacityScale.getSelection()) / 100;
    symbolizer.setOpacity(styleBuilder.literalExpression(opacity));
  }
  private void setStylingElements(RasterSymbolizer symbolizer) {
    double number = SLDs.rasterOpacity(symbolizer);
    int opacity = (new Double(number * 100)).intValue();

    opacityScale.setSelection(opacity);
    opacityText.setText(Integer.toString(opacity) + "%"); // $NON-NLS-1$
    opacityText.pack(true);
  }
Ejemplo n.º 15
0
 private void testPreserveControlProperties(Scale scale) {
   // bound
   Rectangle rectangle = new Rectangle(10, 10, 10, 10);
   scale.setBounds(rectangle);
   Fixture.preserveWidgets();
   IWidgetAdapter adapter = WidgetUtil.getAdapter(scale);
   assertEquals(rectangle, adapter.getPreserved(Props.BOUNDS));
   Fixture.clearPreserved();
   // enabled
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.TRUE, adapter.getPreserved(Props.ENABLED));
   Fixture.clearPreserved();
   scale.setEnabled(false);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.FALSE, adapter.getPreserved(Props.ENABLED));
   Fixture.clearPreserved();
   scale.setEnabled(true);
   // visible
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.TRUE, adapter.getPreserved(Props.VISIBLE));
   Fixture.clearPreserved();
   scale.setVisible(false);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.FALSE, adapter.getPreserved(Props.VISIBLE));
   Fixture.clearPreserved();
   // menu
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(null, adapter.getPreserved(Props.MENU));
   Fixture.clearPreserved();
   Menu menu = new Menu(scale);
   MenuItem item = new MenuItem(menu, SWT.NONE);
   item.setText("1 Item");
   scale.setMenu(menu);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(menu, adapter.getPreserved(Props.MENU));
   Fixture.clearPreserved();
   // foreground background font
   Color background = Graphics.getColor(122, 33, 203);
   scale.setBackground(background);
   Color foreground = Graphics.getColor(211, 178, 211);
   scale.setForeground(foreground);
   Font font = Graphics.getFont("font", 12, SWT.BOLD);
   scale.setFont(font);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(background, adapter.getPreserved(Props.BACKGROUND));
   assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND));
   assertEquals(font, adapter.getPreserved(Props.FONT));
   Fixture.clearPreserved();
 }
Ejemplo n.º 16
0
 private void resetPlaying(boolean reset) {
   playback.stop();
   if (reset) playback.clearPlayback();
   btnPlay.setSelection(false);
   btnPlay.setImage(imgPlay);
   sldProgress.setSelection(0);
   curPosition = -1;
 }
Ejemplo n.º 17
0
 public void addListener() {
   settingScale.addListener(
       SWT.Selection,
       new Listener() {
         @Override
         public void handleEvent(Event arg0) {}
       });
 }
Ejemplo n.º 18
0
 protected void configureControl(Control control) {
   if (control instanceof Scale) {
     Scale scale = (Scale) control;
     scale.setMinimum(0);
     scale.setMaximum(10000);
     scale.setSelection(0);
     return;
   } else if (control instanceof FigureCanvas) {
     FigureCanvas fc = (FigureCanvas) control;
     fc.setScrollBarVisibility(FigureCanvas.NEVER);
     fc.getLightweightSystem().setEventDispatcher(new SliderEventDispatcher());
     fc.setViewport(createViewport(fc));
     IFigure contents = createContents(fc);
     fc.setContents(contents);
     createSlotFigure(contents);
     createBlockFigure(contents);
   }
 }
Ejemplo n.º 19
0
 public void enable(boolean enable) {
   if (logCategoryCombo != null) {
     logCategoryCombo.setEnabled(enable);
   }
   if (logLevelScale != null) {
     logLevelScale.setEnabled(enable);
   }
   // set default log category and corresponding level
   if (enable && Utils.isNotEmpty(this.project)) {
     setDefaultLoggingInfoSelection(this.project, supportedFeatureEnum);
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see net.refractions.udig.style.sld.SLDEditorPart#createPartControl(org.eclipse.swt.widgets.Composite)
   */
  protected Control createPartControl(Composite parent) {
    myparent = parent;
    RowLayout layout = new RowLayout();
    myparent.setLayout(layout);
    layout.pack = false;
    layout.wrap = true;
    layout.type = SWT.HORIZONTAL;

    /* Border Opacity */
    Group borderOpacityArea = new Group(myparent, SWT.NONE);
    borderOpacityArea.setLayout(new GridLayout(2, false));
    borderOpacityArea.setText("Raster Opacity"); // $NON-NLS-1$

    opacityScale = new Scale(borderOpacityArea, SWT.HORIZONTAL);
    opacityScale.setMinimum(0);
    opacityScale.setMaximum(100);
    opacityScale.setPageIncrement(10);
    opacityScale.setBounds(0, 0, 10, SWT.DEFAULT);
    opacityScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            opacityText.setText(String.valueOf(opacityScale.getSelection()) + "%"); // $NON-NLS-1$
            opacityText.pack(true);
          }
        });
    opacityScale.addSelectionListener(this);

    opacityText = new Text(borderOpacityArea, SWT.BORDER | SWT.READ_ONLY);
    opacityText.pack(true);

    return parent;
  }
Ejemplo n.º 21
0
 org.eclipse.swt.widgets.Scale makeWidget(
     Composite comp, Dimension major, IFigureConstructionEnv env) {
   int swtConstant = 0;
   switch (major) {
     case X:
       swtConstant = SWT.HORIZONTAL;
       break;
     case Y:
       swtConstant = SWT.VERTICAL;
       break;
   }
   org.eclipse.swt.widgets.Scale result = new org.eclipse.swt.widgets.Scale(comp, swtConstant);
   result.setSelection(selected.getValue());
   result.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           doCallback();
         }
       });
   return result;
 }
Ejemplo n.º 22
0
  /** {@inheritDoc} */
  public Map<IPreferenceGroup, Object> eventFired() {
    Sensitivity sensitivity = Sensitivity.fromOrd(slider.getSelection());

    Map<IPreferenceGroup, Object> preferenceControlMap = new HashMap<IPreferenceGroup, Object>();
    preferenceControlMap.put(PreferenceId.SamplingRate.SLIDER_ID, sensitivity);

    // get the actual selected divider mode button and set the specific id
    if (timeframeModeButton.getSelection()) {
      preferenceControlMap.put(
          PreferenceId.SamplingRate.DIVIDER_ID, PreferenceId.SamplingRate.TIMEFRAME_DIVIDER_ID);
    }

    return preferenceControlMap;
  }
Ejemplo n.º 23
0
 private void testSelectionEvent(final Scale scale) {
   final StringBuilder log = new StringBuilder();
   SelectionListener selectionListener =
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
           assertEquals(scale, event.getSource());
           assertEquals(null, event.item);
           assertEquals(SWT.NONE, event.detail);
           assertEquals(0, event.x);
           assertEquals(0, event.y);
           assertEquals(0, event.width);
           assertEquals(0, event.height);
           assertEquals(true, event.doit);
           log.append("widgetSelected");
         }
       };
   scale.addSelectionListener(selectionListener);
   String scaleId = WidgetUtil.getId(scale);
   Fixture.fakeRequestParam(JSConst.EVENT_WIDGET_SELECTED, scaleId);
   Fixture.readDataAndProcessAction(scale);
   assertEquals("widgetSelected", log.toString());
 }
Ejemplo n.º 24
0
  private void processClientLocalUpdate() {
    DataBean bean = new DataBean();
    int gridDim = (int) Math.ceil(Math.sqrt(filesToLoad.size()));
    if (imageGrid != null) imageGrid.dispose();

    imageGrid = new PlotServerSWTImageGrid(gridDim, gridDim, canvas, plotViewName);
    imageGrid.setThumbnailSize(getPreferenceImageSize());
    Iterator<String> iter = filesToLoad.iterator();
    while (iter.hasNext()) {
      String filename = iter.next();
      try {
        IDataHolder holder = LoaderFactory.getData(filename);
        IDataset data = holder.getDataset(0);
        List<DatasetWithAxisInformation> datalist = new ArrayList<DatasetWithAxisInformation>();
        DatasetWithAxisInformation d = new DatasetWithAxisInformation();
        if (data != null) {
          d.setData(data);
          datalist.add(d);
          bean.setData(datalist);
        }
      } catch (Exception e) {
        logger.error("Error loading data with filename " + filename, e);
      }
      bean.putGuiParameter(GuiParameters.FILENAME, filename);
      processNewFile(bean);
    }
    if (liveActive) {
      sldProgress
          .getDisplay()
          .asyncExec(
              new Runnable() {
                @Override
                public void run() {
                  playback.moveToLast();
                }
              });
    }
  }
Ejemplo n.º 25
0
 private void createScalingControls(Composite client) {
   final Scale scale = new Scale(client, SWT.NONE);
   scale.setMinimum(1);
   scale.setMaximum(100);
   scale.setSelection(50);
   scale.setPageIncrement(5);
   scale.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           int selection = scale.getSelection();
           if (selection > 50) {
             selection = selection - 50;
             scaleFactor.setText(String.valueOf(1.0d * selection));
           } else if (selection == 50) {
             scaleFactor.setText(String.valueOf(1.0d));
           } else {
             selection = 50 - selection;
             scaleFactor.setText(String.valueOf(1.0d / selection));
           }
           applyScaleFactor();
         }
       });
   GridDataFactory.fillDefaults().span(3, 0).applyTo(scale);
   Label label = kit.createLabel(client, "scale factor: ");
   GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
   scaleFactor = kit.createText(client, "1.0");
   GridDataFactory.fillDefaults().grab(true, false).applyTo(scaleFactor);
   final Button setScale = kit.createButton(client, "apply", SWT.PUSH);
   setScale.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           applyScaleFactor();
         }
       });
   GridDataFactory.fillDefaults().applyTo(setScale);
 }
Ejemplo n.º 26
0
 public void setScale(int val) {
   settingScale.setSelection(val);
   settingValue.setText("" + val);
 }
Ejemplo n.º 27
0
 @Override
 public void widgetSelected(SelectionEvent e) {
   if (e.getSource().equals(cmbDirectoryLocation)) {
     final String newDirectory =
         cmbDirectoryLocation.getItem(cmbDirectoryLocation.getSelectionIndex());
     if (newDirectory != null && newDirectory.length() > 0) {
       addToHistory();
       resetHistory();
       resetPlaying(true);
       spawnLoadJob(newDirectory);
       currentDir = newDirectory;
     }
   } else if (e.getSource().equals(btnHistoryBack)) {
     String newDir = history.get(historyPointer);
     btnHistoryForw.setEnabled(true);
     cmbDirectoryLocation.setText(newDir);
     resetPlaying(true);
     spawnLoadJob(newDir);
     historyPointer++;
     if (historyPointer >= history.size()) {
       btnHistoryBack.setEnabled(false);
       historyPointer = history.size() - 1;
     }
     if (firstBack) {
       addToHistory();
       firstBack = false;
       historyPointer++;
     }
   } else if (e.getSource().equals(btnHistoryForw)) {
     historyPointer--;
     String newDir = history.get(historyPointer);
     resetPlaying(true);
     spawnLoadJob(newDir);
     cmbDirectoryLocation.setText(newDir);
     btnHistoryBack.setEnabled(true);
     if (historyPointer <= 0) {
       btnHistoryForw.setEnabled(false);
       historyPointer = 1;
     }
   } else if (e.getSource().equals(btnPlay)) {
     if (btnPlay.getSelection()) {
       boolean isPaused = playback.isPaused();
       btnPlay.setImage(imgStill);
       playback.start();
       if (!isPaused) {
         playback.setSelection(getSelection());
         playback.setDelay(getPreferenceTimeDelay());
         playback.setStepping(getPreferencePlaybackRate());
         execSvc.execute(playback);
       }
     } else {
       playback.pause();
       btnPlay.setImage(imgPlay);
     }
   } else if (e.getSource().equals(btnStop)) {
     sldProgress.setSelection(0);
     curPosition = -1;
     btnPlay.setSelection(false);
     btnPlay.setImage(imgPlay);
     playback.stop();
   } else if (e.getSource().equals(btnRewind)) {
     sldProgress.setSelection(0);
     curPosition = -1;
     playback.rewind();
   } else if (e.getSource().equals(btnForward)) {
     sldProgress.setSelection(sldProgress.getMaximum());
     playback.forward();
   } else if (e.getSource().equals(sldProgress)) {
     int p = sldProgress.getSelection();
     if (p != curPosition) {
       playback.setPlayPos(p);
       curPosition = p;
     }
   } else if (e.getSource().equals(btnPlayLoop)) {
     playback.setAutoRewind(btnPlayLoop.getSelection());
   }
 }
Ejemplo n.º 28
0
  @Override
  public void createPartControl(Composite parent) {
    plotViewName = getViewSite().getRegisteredName();
    plotServer.addIObserver(this);
    setPartName(plotViewName);
    this.parent = parent;
    parent.setLayout(new GridLayout(1, true));

    locationRow = new Composite(parent, SWT.NONE);
    locationRow.setLayout(new GridLayout(4, false));
    {
      btnHistoryBack = new Button(locationRow, SWT.LEFT);
      btnHistoryBack.setEnabled(false);
      btnHistoryBack.setToolTipText("Go back in history");
      btnHistoryBack.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/arrow_left.png").createImage());
      btnHistoryBack.addSelectionListener(this);
      btnHistoryForw = new Button(locationRow, SWT.LEFT);
      btnHistoryForw.setEnabled(false);
      btnHistoryForw.setToolTipText("Go forward in history");
      btnHistoryForw.addSelectionListener(this);
      btnHistoryForw.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/arrow_right.png").createImage());
      lblLocation = new Label(locationRow, SWT.LEFT);
      lblLocation.setText("Location:");

      cmbDirectoryLocation = new Combo(locationRow, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
      cmbDirectoryLocation.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
      cmbDirectoryLocation.addSelectionListener(this);
    }
    locationRow.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));

    canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL);
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    compHUD = new Group(parent, SWT.NONE);
    compHUD.setLayout(new GridLayout(6, false));
    compHUD.setText("Image Playback");
    {
      btnRewind = new Button(compHUD, SWT.PUSH);
      btnRewind.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_start.png").createImage());
      btnRewind.addSelectionListener(this);
      btnRewind.setToolTipText("Rewind");
      btnPlay = new Button(compHUD, SWT.TOGGLE);
      imgPlay = AnalysisRCPActivator.getImageDescriptor("icons/control_play.png").createImage();
      imgStill = AnalysisRCPActivator.getImageDescriptor("icons/control_pause.png").createImage();
      btnPlay.setImage(imgPlay);
      btnPlay.addSelectionListener(this);
      btnPlay.setToolTipText("Play/Pause");
      btnStop = new Button(compHUD, SWT.PUSH);
      btnStop.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_stop.png").createImage());
      btnStop.addSelectionListener(this);
      btnStop.setToolTipText("Stop playback");
      btnForward = new Button(compHUD, SWT.PUSH);
      btnForward.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_end.png").createImage());
      btnForward.addSelectionListener(this);
      btnForward.setToolTipText("Forward");
      btnPlayLoop = new Button(compHUD, SWT.TOGGLE);
      btnPlayLoop.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_repeat.png").createImage());
      btnPlayLoop.setToolTipText("Playback loop (On/off)");
      btnPlayLoop.addSelectionListener(this);
      sldProgress = new Scale(compHUD, SWT.HORIZONTAL);
      sldProgress.setPageIncrement(1);
      sldProgress.addSelectionListener(this);
      sldProgress.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    }
    compHUD.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    imageGrid = new PlotServerSWTImageGrid(canvas, plotViewName);
    imageGrid.setThumbnailSize(getPreferenceImageSize());
    retainStateFromServer();

    if (dirPath != null && dirPath.length() > 0) {
      dirPath.trim();
      updateDirectory.setUser(true);
      updateDirectory.setPriority(Job.DECORATE);
      updateDirectory.schedule(1000);
      cmbDirectoryLocation.setText(dirPath);
      currentDir = dirPath;
    }
    playback =
        new ImagePlayBack(
            parent,
            getPreferencePlaybackView(),
            getViewSite().getPage(),
            sldProgress,
            getPreferenceTimeDelay(),
            getPreferencePlaybackRate());

    isDisposed = false;

    // listen to preference changes to update the Live plot play back view and colour map
    AnalysisRCPActivator.getDefault()
        .getPreferenceStore()
        .addPropertyChangeListener(
            new IPropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_PLAYBACKVIEW)) {
                  playback.setPlotView(getPreferencePlaybackView());
                }
                if (event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_COLOURMAP)
                    || event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_IMAGESIZE)) {
                  List<GridImageEntry> images = imageGrid.getListOfEntries();
                  imageGrid.setThumbnailSize(getPreferenceImageSize());
                  String colourScheme = getPreferenceColourMapChoice();
                  for (GridImageEntry entry : images) {
                    IDataset data = entry.getData();
                    SWTGridEntry gridEntry =
                        new SWTGridEntry(
                            entry.getFilename(),
                            data,
                            canvas,
                            colourScheme,
                            getPreferenceAutoContrastLo(),
                            getPreferenceAutoContrastHi());
                    imageGrid.addEntry(gridEntry, entry.getGridColumnPos(), entry.getGridRowPos());
                  }
                  // Check the colour menu accordingly
                  IAction currentColour = colorMenu.findAction(colourScheme);
                  if (currentColour != null) currentColour.setChecked(true);
                }
              }
            });
  }
Ejemplo n.º 29
0
  /** {@inheritDoc} */
  public Composite createControls(Composite parent, FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, Section.TITLE_BAR);
    section.setText("Sampling Rate");
    section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);

    GridLayout layout = new GridLayout(4, false);
    layout.marginLeft = 10;
    layout.horizontalSpacing = 10;
    composite.setLayout(layout);
    GridData gridData = new GridData(SWT.MAX, SWT.DEFAULT);
    gridData.grabExcessHorizontalSpace = true;
    composite.setLayoutData(gridData);

    final Label sliderLabel = toolkit.createLabel(composite, "no sensitivity selected", SWT.LEFT);
    GridData data = new GridData(SWT.FILL, SWT.FILL, false, false);
    data.widthHint = sliderLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    sliderLabel.setLayoutData(data);

    slider = new Scale(composite, SWT.HORIZONTAL);
    toolkit.adapt(slider, true, true);
    slider.setMinimum(0);
    slider.setMaximum(Sensitivity.values().length - 1);
    slider.setIncrement(1);
    slider.setSize(200, 10);
    slider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    slider.addSelectionListener(
        new SelectionAdapter() {
          /** {@inheritDoc} */
          @Override
          public void widgetSelected(SelectionEvent event) {
            Sensitivity sensitivity = Sensitivity.fromOrd(slider.getSelection());

            switch (sensitivity) {
              case NO_SENSITIVITY:
                sliderLabel.setText("no sensitivity selected");
                break;
              case VERY_FINE:
                sliderLabel.setText("very fine");
                break;
              case FINE:
                sliderLabel.setText("fine");
                break;
              case MEDIUM:
                sliderLabel.setText("medium");
                break;
              case COARSE:
                sliderLabel.setText("coarse");
                break;
              case VERY_COARSE:
                sliderLabel.setText("very coarse");
                break;
              default:
                break;
            }
          }
        });
    slider.setSelection(DEFAULT_SENSITIVITY.ordinal());
    slider.notifyListeners(SWT.Selection, null);

    Label modeLabel = toolkit.createLabel(composite, "Sampling Rate Mode: ", SWT.LEFT);
    modeLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    timeframeModeButton = toolkit.createButton(composite, "Timeframe dividing", SWT.RADIO);
    timeframeModeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    timeframeModeButton.setSelection(true);

    return composite;
  }
Ejemplo n.º 30
0
  /** Creates the GUI. */
  public void createGUI(Composite parent) {
    GridLayout gridLayout;
    GridData gridData;

    /** * Create principal GUI layout elements ** */
    Composite displayArea = new Composite(parent, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    displayArea.setLayout(gridLayout);

    // Creating these elements here avoids the need to instantiate the GUI elements
    // in strict layout order. The natural layout ordering is an artifact of using
    // SWT layouts, but unfortunately it is not the same order as that required to
    // instantiate all of the non-GUI application elements to satisfy referential
    // dependencies. It is possible to reorder the initialization to some extent, but
    // this can be very tedious.

    // paint canvas
    final Canvas paintCanvas =
        new Canvas(
            displayArea,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    paintCanvas.setLayoutData(gridData);
    paintCanvas.setBackground(paintColorWhite);

    // color selector frame
    final Composite colorFrame = new Composite(displayArea, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    colorFrame.setLayoutData(gridData);

    // tool settings frame
    final Composite toolSettingsFrame = new Composite(displayArea, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    toolSettingsFrame.setLayoutData(gridData);

    // status text
    final Text statusText = new Text(displayArea, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    statusText.setLayoutData(gridData);

    /** * Create the remaining application elements inside the principal GUI layout elements ** */
    // paintSurface
    paintSurface = new PaintSurface(paintCanvas, statusText, paintColorWhite);

    // finish initializing the tool data
    PaintExample.tools[PaintExample.Pencil_tool].data = new PencilTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Airbrush_tool].data =
        new AirbrushTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Line_tool].data = new LineTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.PolyLine_tool].data =
        new PolyLineTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Rectangle_tool].data =
        new RectangleTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.RoundedRectangle_tool].data =
        new RoundedRectangleTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Ellipse_tool].data =
        new EllipseTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Text_tool].data = new TextTool(toolSettings, paintSurface);

    // colorFrame
    gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    colorFrame.setLayout(gridLayout);

    // activeForegroundColorCanvas, activeBackgroundColorCanvas
    activeForegroundColorCanvas = new Canvas(colorFrame, SWT.BORDER);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeForegroundColorCanvas.setLayoutData(gridData);

    activeBackgroundColorCanvas = new Canvas(colorFrame, SWT.BORDER);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeBackgroundColorCanvas.setLayoutData(gridData);

    // paletteCanvas
    final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.heightHint = 24;
    paletteCanvas.setLayoutData(gridData);
    paletteCanvas.addListener(
        SWT.MouseDown,
        new Listener() {
          public void handleEvent(Event e) {
            Rectangle bounds = paletteCanvas.getClientArea();
            Color color = getColorAt(bounds, e.x, e.y);

            if (e.button == 1) setForegroundColor(color);
            else setBackgroundColor(color);
          }

          private Color getColorAt(Rectangle bounds, int x, int y) {
            if (bounds.height <= 1 && bounds.width <= 1) return paintColorWhite;
            final int row = (y - bounds.y) * PaintExample.numPaletteRows / bounds.height;
            final int col = (x - bounds.x) * PaintExample.numPaletteCols / bounds.width;
            return paintColors[
                Math.min(
                    Math.max(row * PaintExample.numPaletteCols + col, 0), paintColors.length - 1)];
          }
        });
    Listener refreshListener =
        new Listener() {
          public void handleEvent(Event e) {
            if (e.gc == null) return;
            Rectangle bounds = paletteCanvas.getClientArea();
            for (int row = 0; row < PaintExample.numPaletteRows; ++row)
              for (int col = 0; col < PaintExample.numPaletteCols; ++col) {
                final int x = bounds.width * col / PaintExample.numPaletteCols;
                final int y = bounds.height * row / PaintExample.numPaletteRows;
                final int width =
                    Math.max(bounds.width * (col + 1) / PaintExample.numPaletteCols - x, 1);
                final int height =
                    Math.max(bounds.height * (row + 1) / PaintExample.numPaletteRows - y, 1);
                e.gc.setBackground(paintColors[row * PaintExample.numPaletteCols + col]);
                e.gc.fillRectangle(bounds.x + x, bounds.y + y, width, height);
              }
          }
        };
    paletteCanvas.addListener(SWT.Resize, refreshListener);
    paletteCanvas.addListener(SWT.Paint, refreshListener);
    // paletteCanvas.redraw();

    // toolSettingsFrame
    gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    toolSettingsFrame.setLayout(gridLayout);

    Label label = new Label(toolSettingsFrame, SWT.NONE);
    label.setText(PaintExample.getResourceString("settings.AirbrushRadius.text"));

    final Scale airbrushRadiusScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushRadiusScale.setMinimum(5);
    airbrushRadiusScale.setMaximum(50);
    airbrushRadiusScale.setSelection(toolSettings.airbrushRadius);
    airbrushRadiusScale.setLayoutData(
        new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushRadiusScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            toolSettings.airbrushRadius = airbrushRadiusScale.getSelection();
            updateToolSettings();
          }
        });

    label = new Label(toolSettingsFrame, SWT.NONE);
    label.setText(PaintExample.getResourceString("settings.AirbrushIntensity.text"));

    final Scale airbrushIntensityScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushIntensityScale.setMinimum(1);
    airbrushIntensityScale.setMaximum(100);
    airbrushIntensityScale.setSelection(toolSettings.airbrushIntensity);
    airbrushIntensityScale.setLayoutData(
        new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushIntensityScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection();
            updateToolSettings();
          }
        });
  }