Ejemplo n.º 1
0
 public void op(Display display, Object target, IProgressMonitor monitor)
         throws Exception {
     ILayer layer = (ILayer) target;
     IMap map = layer.getMap();
     Layer view = map.getLayerFactory().createLayer(layer.findGeoResource(FeatureSource.class));
     view.getStyleBlackboard().put(ProjectBlackboardConstants.LAYER__DATA_QUERY, layer.getFilter());
     AddLayerCommand command = new AddLayerCommand(view);
     map.sendCommandASync(command);
 }
  /**
   * Vitalus: Refreshes map image from buffered images of renderers with or without labels cache
   * painting.
   *
   * @param paintLabels
   */
  void refreshImage(boolean paintLabels) throws RenderException {
    if (getContext().getMapDisplay() == null) {
      // we've been disposed lets bail
      return;
    }
    synchronized (getContext()) {
      Graphics2D g = null;
      try {
        BufferedImage current = getContext().getImage();

        // create a copy of the image to draw into

        BufferedImage copy =
            new BufferedImage(current.getWidth(), current.getHeight(), current.getType());

        g = (Graphics2D) copy.getGraphics();

        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
        g.setRenderingHint(
            RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
        g.setRenderingHint(
            RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
        g.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        g.setRenderingHint(
            RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

        IMap map = getContext().getMap();
        Object object = map.getBlackboard().get(ProjectBlackboardConstants.MAP__BACKGROUND_COLOR);
        if (object == null) {
          IPreferenceStore store = ProjectPlugin.getPlugin().getPreferenceStore();
          RGB background = PreferenceConverter.getColor(store, PreferenceConstants.P_BACKGROUND);
          map.getBlackboard()
              .put(
                  ProjectBlackboardConstants.MAP__BACKGROUND_COLOR,
                  new Color(background.red, background.green, background.blue));
          object = map.getBlackboard().get(ProjectBlackboardConstants.MAP__BACKGROUND_COLOR);
        }
        g.setBackground((Color) object);
        g.clearRect(0, 0, copy.getWidth(), copy.getHeight());

        SortedSet<RenderExecutor> executors;
        synchronized (renderExecutors) {
          executors = new TreeSet<RenderExecutor>(comparator);
          executors.addAll(getRenderExecutors());
        }
        ILabelPainter cache = getContext().getLabelPainter();

        RENDERERS:
        for (RenderExecutor executor : executors) {

          if (!executor.getContext().isVisible()) {
            if (paintLabels && !(executor.getContext().getLayer() instanceof SelectionLayer)) {
              // disable layer from label cache
              cache.disableLayer(executor.getContext().getLayer().getID().toString());
            }
            continue RENDERERS;
          }

          if (executor.getState() == NEVER
              || executor.getState() == STARTING
              || executor.getState() == RENDER_REQUEST) {
            continue RENDERERS;
          }
          if (isFullAlphaUsed(executor)) {
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
          } else {
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
          }
          g.drawRenderedImage(executor.getContext().getImage(), IDENTITY);
        }
        if (paintLabels) {
          RenderingHints hints =
              new RenderingHints(
                  RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setRenderingHints(hints);
          Dimension displaySize = getContext().getMapDisplay().getDisplaySize();
          try {
            cache.end(g, new Rectangle(displaySize));
          } catch (Throwable t) {
            ProjectPlugin.trace(CompositeRenderContextImpl.class, "painting labels failed", t);
          }
        }

        // update the context with the new image
        ((RenderContextImpl) getContext()).setImage(copy);

      } catch (IllegalStateException e) {
        stopRendering();
        //                e.printStackTrace();
        return;
      } finally {
        if (g != null) g.dispose();
      }
    }
  }