コード例 #1
0
  private void processNewFile(DataBean bean) {
    try {
      locker.acquire();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    playback.addFile((String) bean.getGuiParameters().get(GuiParameters.FILENAME));
    String colourScheme = getPreferenceColourMapChoice();

    SWTGridEntry entry =
        new SWTGridEntry(
            (String) bean.getGuiParameters().get(GuiParameters.FILENAME),
            bean.getData().get(0),
            canvas,
            colourScheme,
            getPreferenceAutoContrastLo(),
            getPreferenceAutoContrastHi());
    Integer xPos = (Integer) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDXPOS);
    Integer yPos = (Integer) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDYPOS);
    if (xPos != null && yPos != null) imageGrid.addEntry(entry, xPos, yPos);
    else imageGrid.addEntry(entry);
    imageGrid.setThumbnailSize(getPreferenceImageSize());
    locker.release();
    if (liveActive) playback.moveToLast();
  }
コード例 #2
0
    /**
     * Returns a list of all legal parameter values for {@link ShowPlotViewHandler}. The key is the
     * display name and the value is the parameter value to {@link
     * ShowPlotViewHandler#VIEW_NAME_PARAM}.
     *
     * <p>The list of legal values is made up of the following sources:
     *
     * <ul>
     *   <li>All of the Plot Views that have been activated and registered themselves
     *       PlotWindowManager
     *   <li>All views in the view registry whose ID starts with {@link IPlotWindowManager#ID}
     *   <li>All the view references whose primary ID is {@link
     *       IPlotWindowManager#PLOT_VIEW_MULTIPLE_ID}
     *   <li>All Gui Names from {@link PlotService#getGuiNames()}. These are suffixed with {@link
     *       ShowPlotViewHandler#IN_PLOT_SERVER_SUFFIX}
     *   <li>A <code>null</code> value for a option to open a new unique view name.
     * </ul>
     */
    @Override
    public Map<String, String> getParameterValues() {
      PlotWindowManager manager = PlotWindowManager.getPrivateManager();

      String[] views = manager.getAllPossibleViews(null, false);
      Set<String> guiNamesWithData = Collections.emptySet();
      try {
        String[] names = PlotServerProvider.getPlotServer().getGuiNames();
        if (names != null) guiNamesWithData = new HashSet<String>(Arrays.asList(names));
      } catch (Exception e) {
        // non-fatal, just means no IN_PLOT_SERVER_SUFFIX next to view name, still shouldn't happen
        logger.debug("Failed to get list of Gui Names from Plot Server", e);
      }
      Map<String, String> values = new HashMap<String, String>();
      for (String view : views) {
        String viewDisplay = view;

        DATA_BLOCK:
        if (guiNamesWithData.contains(view)) {
          try {
            DataBean db = PlotServerProvider.getPlotServer().getData(view);
            if (db == null || db.getData() == null || db.getData().isEmpty()) break DATA_BLOCK;
            viewDisplay = view + IN_PLOT_SERVER_SUFFIX;
          } catch (Exception ne) {
            break DATA_BLOCK;
          }
        }
        values.put(viewDisplay, view);
      }
      // null is a legal argument, means open a new view
      values.put(NEW_PLOT_VIEW, null);
      return values;
    }
コード例 #3
0
  private void processNewGrid(DataBean bean) {
    final Integer[] gridDims = (Integer[]) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDSIZE);

    if (gridDims != null && gridDims.length > 0) {
      try {
        locker.acquire();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      canvas
          .getDisplay()
          .asyncExec(
              new Runnable() {
                @Override
                public void run() {
                  imageGrid.dispose();
                  if (gridDims.length == 1)
                    imageGrid =
                        new PlotServerSWTImageGrid(gridDims[0], gridDims[0], canvas, plotViewName);
                  else
                    imageGrid =
                        new PlotServerSWTImageGrid(gridDims[1], gridDims[0], canvas, plotViewName);
                  imageGrid.setThumbnailSize(getPreferenceImageSize());
                  locker.release();
                  canvas.redraw();
                }
              });
    }
    cleanUpOnServer();
  }
コード例 #4
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();
                }
              });
    }
  }
コード例 #5
0
  @SuppressWarnings("unchecked")
  @Override
  public void update(Object source, Object changeCode) {
    if (stopLoading) return;

    if (source == ImageExplorerView.FOLDER_UPDATE_MARKER) { // Folder Update
      if (changeCode instanceof List<?>) {
        playback.clearPlayback();
        btnPlay
            .getDisplay()
            .asyncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    resetPlaying(false);
                    if (isLive) {
                      playback.setDelay(50);
                      playback.setStepping(1);
                      playback.start();
                      btnPlay.setSelection(true);
                      btnPlay.setImage(imgStill);
                      execSvc.execute(playback);
                      if (!monActive)
                        CommandExecutor.executeCommand(
                            getViewSite(),
                            "uk.ac.diamond.scisoft.analysis.rcp.MontorDirectoryAction");
                      cmbDirectoryLocation.setText(currentDir);
                      isLive = false;
                    }
                  }
                });
        filesToLoad = (List<String>) changeCode;
        processClientLocalUpdate();
      }
    } else {
      if (source instanceof RMIPlotServer && changeCode instanceof String) {
        String viewName = (String) changeCode;
        if (!viewName.startsWith("Image Explorer")) return;
        RMIPlotServer server = (RMIPlotServer) source;
        try {
          String[] names = server.getGuiNames();
          final DataBean bean = server.getData(names[0]);
          // when imagegrid size is set it means we need to reset the grid
          if (bean != null && bean.getGuiParameters().get(GuiParameters.IMAGEGRIDSIZE) != null) {
            Display.getDefault()
                .syncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        Integer[] gridDim =
                            (Integer[]) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDSIZE);
                        if (imageGrid != null) imageGrid.dispose();
                        imageGrid =
                            new PlotServerSWTImageGrid(
                                gridDim[0], gridDim[1], canvas, plotViewName);
                        imageGrid.setThumbnailSize(getPreferenceImageSize());
                      }
                    });
          }
          if (bean != null) {
            if (bean.getData().isEmpty()) {
              // We try to load the data from the filename if data not in the databean
              String filename = (String) bean.getGuiParameters().get(GuiParameters.FILENAME);
              if (filename == null) return;
              List<DatasetWithAxisInformation> data = new ArrayList<>();
              DatasetWithAxisInformation dwai = new DatasetWithAxisInformation();
              IDataHolder holder = LoaderFactory.getData(filename);
              IDataset loadedData = holder.getDataset(0);
              dwai.setData(loadedData);
              data.add(dwai);
              bean.setData(data);
            }
            processUpdate(bean);
          } else {
            throw new Exception("Databean is null. This image grid use is not supported.");
          }
        } catch (Exception e) {
          logger.error("Error updating data from server: ", e);
        }
      }
    }
  }
コード例 #6
0
  private void processUpdate(DataBean bean) {
    if (bean == null) return;
    if (bean.getGuiParameters() == null) return;
    UUID id = (UUID) bean.getGuiParameters().get(GuiParameters.PLOTID);
    if (id == null || plotID.compareTo(id) != 0) { // filter out own beans
      if (guiBean == null) guiBean = bean.getGuiParameters().copy(); // cache a local copy
      else guiBean.merge(bean.getGuiParameters()); // or merge it

      if (bean.getGuiParameters().containsKey(GuiParameters.FILEOPERATION)) return;

      if (bean.getGuiParameters().containsKey(GuiParameters.PLOTMODE)) {
        GuiPlotMode plotMode = (GuiPlotMode) bean.getGuiParameters().get(GuiParameters.PLOTMODE);
        if (plotMode.equals(GuiPlotMode.IMGEXPL)) {
          if (bean.getGuiParameters().containsKey(GuiParameters.FILENAME)) {
            if (filesToLoad == null) filesToLoad = new ArrayList<String>();
            filesToLoad.add((String) bean.getGuiParameters().get(GuiParameters.FILENAME));
            processNewFile(bean);
          } else if (bean.getGuiParameters().containsKey(GuiParameters.IMAGEGRIDSIZE)) {
            if (filesToLoad == null) filesToLoad = new ArrayList<String>();
            else filesToLoad.clear();
            btnPlay
                .getDisplay()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        resetPlaying(true);
                      }
                    });
            processNewGrid(bean);
          }
        }
      } else if (bean.getGuiParameters().containsKey(GuiParameters.IMAGEGRIDLIVEVIEW)) {
        String directory = (String) bean.getGuiParameters().get(GuiParameters.IMAGEGRIDLIVEVIEW);
        spawnLoadJob(directory);
        currentDir = directory;
        isLive = true;
        liveActive = true;
      }
    }
  }