コード例 #1
0
  @Override
  public void init(IViewSite site, IMemento memento) throws PartInitException {
    init(site);
    String storedExtensions = "";
    if (memento != null) { // Open dir path
      this.dirPath = memento.getString("DIR");
      storedExtensions = memento.getString("FILTERS");
      if (storedExtensions == null) storedExtensions = "";
    }
    // Filter Extensions
    imgExtensions = new Action[ImageExplorerDirectoryChooseAction.LISTOFSUFFIX.length];
    MenuManager filterMenu = new MenuManager("File Filters");
    for (int i = 0; i < ImageExplorerDirectoryChooseAction.LISTOFSUFFIX.length; i++) {
      final int number = i;
      imgExtensions[i] =
          new Action("", IAction.AS_CHECK_BOX) {
            @Override
            public void run() {
              if (this.isChecked()) {
                filter.remove(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[number]);
              } else {
                filter.add(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[number]);
              }
              // reload the directory
              updateDirectory.setUser(true);
              updateDirectory.setPriority(Job.DECORATE);
              updateDirectory.schedule(1000);
            }
          };
      imgExtensions[i].setText(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i]);
      imgExtensions[i].setDescription(
          "Filter " + ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i] + " on/off");
      if (storedExtensions.contains(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i])) {
        imgExtensions[i].setChecked(false);
        filter.add(ImageExplorerDirectoryChooseAction.LISTOFSUFFIX[i]);
      } else imgExtensions[i].setChecked(true);
      filterMenu.add(imgExtensions[i]);
    }

    site.getActionBars().getMenuManager().add(filterMenu);

    // color submenus actions
    final IPaletteService pservice = PlatformUI.getWorkbench().getService(IPaletteService.class);
    final Collection<String> names = pservice.getColorSchemes();
    String schemeName = getPreferenceColourMapChoice();

    colorMenu = new MenuAction("Color");
    colorMenu.setId(getClass().getName() + colorMenu.getText());
    colorMenu.setImageDescriptor(AnalysisRCPActivator.getImageDescriptor("icons/color_wheel.png"));

    final Map<String, IAction> paletteActions = new HashMap<String, IAction>(11);
    CheckableActionGroup group = new CheckableActionGroup();
    for (final String paletteName : names) {
      final Action action =
          new Action(paletteName, IAction.AS_CHECK_BOX) {
            @Override
            public void run() {
              try {
                setPreferenceColourMapChoice(paletteName);

                IPlottingSystem<Composite> system =
                    PlottingFactory.getPlottingSystem(getPreferencePlaybackView());
                if (system != null) {
                  final Collection<ITrace> traces = system.getTraces();
                  if (traces != null)
                    for (ITrace trace : traces) {
                      if (trace instanceof IPaletteTrace) {
                        IPaletteTrace paletteTrace = (IPaletteTrace) trace;
                        paletteTrace.setPalette(paletteName);
                      }
                    }
                }

              } catch (Exception ne) {
                logger.error("Cannot create palette data!", ne);
              }
            }
          };
      action.setId(paletteName);
      group.add(action);
      colorMenu.add(action);
      action.setChecked(paletteName.equals(schemeName));
      paletteActions.put(paletteName, action);
    }
    colorMenu.setToolTipText("Histogram");
    site.getActionBars().getMenuManager().add(colorMenu);

    // ImageExplorer preferences
    final Action openPreferences =
        new Action("Image Explorer Preferences...") {
          @Override
          public void run() {
            PreferenceDialog pref =
                PreferencesUtil.createPreferenceDialogOn(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    ImageExplorerPreferencePage.ID,
                    null,
                    null);
            if (pref != null) pref.open();
          }
        };
    site.getActionBars().getMenuManager().add(openPreferences);
  }
コード例 #2
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);
                }
              }
            });
  }