Exemplo n.º 1
0
  /**
   * Draws the current line highlight (over top using theme colors and alpha). If the line highlight
   * is fully opaque, then this method will not do anything and we'll fall back to using the
   * mechanism eclipse does in CursorLinePainter with a little modification.
   */
  public void paintControl(PaintEvent e) {
    // if highlight current line is disabled, don't draw!
    if (!fEnabled) {
      return;
    }
    // If there's no alpha value for the line highlight, then we need to force the bg color of the
    // whole line
    // to the rgb value!
    RGBa lineHighlight = getCurrentTheme().getLineHighlight();
    if (lineHighlight.isFullyOpaque()) {
      return;
    }

    Rectangle rect = new Rectangle(e.x, e.y, e.width, e.height);
    Rectangle lineRect = getLineRectangle(getCurrentLinePosition());
    if (lineRect == null || !lineRect.intersects(rect)) {
      return;
    }

    int previousAlpha = e.gc.getAlpha();
    Color previousBG = e.gc.getBackground();

    e.gc.setAlpha(lineHighlight.getAlpha());
    e.gc.setBackground(getColorManager().getColor(lineHighlight.toRGB()));
    // Only paint the part of lineRect that is contained in rect!
    e.gc.fillRectangle(lineRect.intersection(rect));

    // BUGFIX: need to set alpha and background color back to what they were before or it breaks
    // the painting of pair matching!
    e.gc.setAlpha(previousAlpha);
    e.gc.setBackground(previousBG);
  }
Exemplo n.º 2
0
 /*
  * Adjust the bounds so that we appear adjacent to our parent shell
  */
 protected void adjustBounds() {
   Rectangle parentBounds = getParentShell().getBounds();
   Rectangle proposedBounds;
   // Try placing the info popup to the right
   Rectangle rightProposedBounds =
       new Rectangle(
           parentBounds.x + parentBounds.width + PopupDialog.POPUP_HORIZONTALSPACING,
           parentBounds.y + PopupDialog.POPUP_VERTICALSPACING,
           parentBounds.width,
           parentBounds.height);
   rightProposedBounds = getConstrainedShellBounds(rightProposedBounds);
   // If it won't fit on the right, try the left
   if (rightProposedBounds.intersects(parentBounds)) {
     Rectangle leftProposedBounds =
         new Rectangle(
             parentBounds.x - parentBounds.width - POPUP_HORIZONTALSPACING - 1,
             parentBounds.y,
             parentBounds.width,
             parentBounds.height);
     leftProposedBounds = getConstrainedShellBounds(leftProposedBounds);
     // If it won't fit on the left, choose the proposed bounds
     // that fits the best
     if (leftProposedBounds.intersects(parentBounds)) {
       if (rightProposedBounds.x - parentBounds.x >= parentBounds.x - leftProposedBounds.x) {
         rightProposedBounds.x =
             parentBounds.x + parentBounds.width + PopupDialog.POPUP_HORIZONTALSPACING;
         proposedBounds = rightProposedBounds;
       } else {
         leftProposedBounds.width =
             parentBounds.x - POPUP_HORIZONTALSPACING - leftProposedBounds.x;
         proposedBounds = leftProposedBounds;
       }
     } else {
       // use the proposed bounds on the left
       proposedBounds = leftProposedBounds;
     }
   } else {
     // use the proposed bounds on the right
     proposedBounds = rightProposedBounds;
   }
   getShell().setBounds(proposedBounds);
 }
 public static boolean isVisible(Control c) {
   if (c.getParent() == null) return true;
   Rectangle displayRect = c.getDisplay().getBounds();
   Point loc = c.getLocation();
   loc = c.getParent().toDisplay(loc);
   Point size = c.getSize();
   if (!displayRect.intersects(loc.x, loc.y, size.x, size.y)) return false;
   if (c.getParent() == null) return true;
   Rectangle r = getVisibleRectangleInParent(c);
   return r != null;
 }
Exemplo n.º 4
0
  @Override
  public void drawShadow(
      IBNAView view, ICoordinateMapper cm, GL2 gl, Rectangle clip, IResources r) {
    Rectangle lbb = BNAUtils.getLocalBoundingBox(cm, t);
    if (!clip.intersects(lbb)) {
      return;
    }

    Shape localShape = new Ellipse2D.Float(lbb.x, lbb.y, lbb.width, lbb.height);

    r.setColor(new RGB(0, 0, 0), 1f);
    BNAUtils.renderShapeFill(view, cm, gl, clip, r, localShape);
  }
  @SuppressWarnings("rawtypes")
  @Override
  public void zoom(Rectangle selection) {
    if (map == null || layer == null) {
      return;
    }
    Set<FeatureId> selected = new HashSet<FeatureId>();
    try {
      XYSeriesCollection ds = (XYSeriesCollection) getChart().getXYPlot().getDataset(2);
      XYSeries selectionSeries = ds.getSeries(0);
      selectionSeries.clear();

      EntityCollection entities = this.getChartRenderingInfo().getEntityCollection();
      Iterator iter = entities.iterator();
      while (iter.hasNext()) {
        ChartEntity entity = (ChartEntity) iter.next();
        if (entity instanceof XYItemEntity) {
          XYItemEntity item = (XYItemEntity) entity;
          if (item.getSeriesIndex() != 0) {
            continue;
          }

          java.awt.Rectangle bound = item.getArea().getBounds();
          if (selection.intersects(bound.x, bound.y, bound.width, bound.height)) {
            XYSeriesCollection dataSet = (XYSeriesCollection) item.getDataset();
            XYSeries xySeries = dataSet.getSeries(item.getSeriesIndex());
            XYDataItem xyDataItem = xySeries.getDataItem(item.getItem());
            if (xyDataItem instanceof XYDataItem2) {
              XYDataItem2 dataItem = (XYDataItem2) xyDataItem;
              selectionSeries.add(dataItem);
              selected.add(ff.featureId(dataItem.getFeature().getID()));
            }
          }
        }
      }
    } catch (Exception e) {
      // skip
    } finally {
      if (selected.size() > 0) {
        map.select(ff.id(selected), layer);
      } else {
        map.select(Filter.EXCLUDE, layer);
      }
      this.forceRedraw();
    }
  }
Exemplo n.º 6
0
  @Override
  public void draw(IBNAView view, ICoordinateMapper cm, GL2 gl, Rectangle clip, IResources r) {
    Rectangle lbb = BNAUtils.getLocalBoundingBox(cm, t);
    if (!clip.intersects(lbb)) {
      return;
    }

    Shape localShape = new Ellipse2D.Float(lbb.x, lbb.y, lbb.width, lbb.height);

    BNAUtils.renderShapeFill(t, view, cm, gl, clip, r, localShape);
    for (int count = 0; count < t.getCount(); count++) {
      int offset = count * 2 * t.getLineWidth();
      Shape edgeShape =
          new Ellipse2D.Float(
              lbb.x + offset, lbb.y + offset, lbb.width - 2 * offset, lbb.height - 2 * offset);
      BNAUtils.renderShapeEdge(t, view, cm, gl, clip, r, edgeShape);
    }
    BNAUtils.renderShapeSelected(t, view, cm, gl, clip, r, localShape);
  }
Exemplo n.º 7
0
  public Image captureImage(Control control) {
    Rectangle rectangle = control.getBounds();
    Display display = control.getDisplay();
    Image image = null;
    if (control instanceof Shell) {
      Shell shell = (Shell) control;
      shell.layout();
      Point parentLocation = control.toDisplay(0, 0);
      image = getImage(control, rectangle.width, rectangle.height, false);

      rectangle.x = parentLocation.x;
      rectangle.y = parentLocation.y;

      GC myImageGC = new GC(image);
      try {
        for (Control child : shell.getChildren()) {
          Rectangle childBounds = child.getBounds();
          // bug of SWT on Win32, child bounds is not correct in the Window is not in the ToolBar
          int x = (rectangle.width - childBounds.width) / 2;
          int y = (rectangle.height - childBounds.height) - x;
          childBounds.x = rectangle.x + x;
          childBounds.y = rectangle.y + y;
          if (!rectangle.intersects(childBounds)) continue; // Child is completely outside parent.

          Image childImage = new Image(display, child.getBounds());
          GC gc = new GC(childImage);
          child.print(gc);
          DisposeUtil.dispose(gc);
          try {
            myImageGC.drawImage(childImage, x, y);
          } finally {
            childImage.dispose();
          }
        }
      } finally {
        myImageGC.dispose();
      }
    } else {
      image = defaultCapture(control);
    }
    return image;
  }
Exemplo n.º 8
0
  protected void paint(GC gc, Display display) {
    if (bounds == null) buildCaches();

    gc.setAntialias(SWT.ON);
    gc.setTextAntialias(SWT.ON);

    int x, y, w, h;
    boolean focused = getControl().isFocusControl() || isForceFocus();
    boolean hasBackgroundAndBorder = pressed || hovered || focused;
    if (hasBackgroundAndBorder) {
      // draw control background
      gc.setBackground(getBorderBackground(display));
      gc.fillRoundRectangle(
          bounds.x, bounds.y, bounds.width, bounds.height, CORNER_SIZE, CORNER_SIZE);
    }

    if (focused) {
      // draw focused content background
      x = contentArea.x - FOCUS_BORDER;
      y = contentArea.y - FOCUS_BORDER;
      w = contentArea.width + FOCUS_BORDER * 2;
      h = contentArea.height + FOCUS_BORDER * 2;
      gc.setBackground(getRealTextBackground(display));
      gc.fillRoundRectangle(x, y, w, h, FOCUS_CORNER_SIZE, FOCUS_CORNER_SIZE);
    }

    boolean hasImage = hasImage();
    boolean hasText = hasText();
    if (hasImage) {
      Rectangle clipping = gc.getClipping();
      if (clipping == null || clipping.intersects(imgArea)) {
        // draw image
        Point imgSize = getImageSize();
        x = imgArea.x + (imgArea.width - imgSize.x) / 2;
        y = imgArea.y + (imgArea.height - imgSize.y) / 2;
        gc.setClipping(imgArea);
        gc.drawImage(image, x, y);
        gc.setClipping(clipping);
      }
    }
    if (hasText) {
      Rectangle clipping = gc.getClipping();
      if (clipping == null || clipping.intersects(textArea)) {
        // draw text
        String text = getAppliedText();
        gc.setFont(getControl().getFont());
        Point ext = gc.stringExtent(text);
        //                    if (hasImage) {
        x = textArea.x;
        //                    } else {
        //                        x = textArea.x + (textArea.width - ext.x) / 2;
        //                    }
        y = textArea.y + (textArea.height - ext.y) / 2;
        gc.setClipping(textArea);
        gc.setForeground(getRealTextForeground(display));
        gc.drawString(text, x, y, true);
        gc.setClipping(clipping);
      }
    }

    // draw arrows
    if (hasArrows() && arrowLoc != null) {
      gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
      x = arrowLoc.x + ARROW_WIDTH / 2;
      y = arrowLoc.y;
      int x1 = arrowLoc.x - 1;
      int y1 = arrowLoc.y + ARROW_HEIGHT + 1;
      int x2 = arrowLoc.x + ARROW_WIDTH;
      gc.fillPolygon(new int[] {x, y, x1, y1, x2, y1});

      y += ARROW_HEIGHT * 2 + ARROWS_SPACING + 1;
      x1 = arrowLoc.x;
      y1 += ARROWS_SPACING;
      gc.fillPolygon(new int[] {x, y, x2, y1, x1 - 1, y1});
    }

    // draw border
    if (focused) {
      x = bounds.x;
      y = bounds.y;
      w = bounds.width;
      h = bounds.height;
      if (DRAWS_FOCUS) {
        gc.drawFocus(x - MARGIN + 1, y - MARGIN + 1, w + MARGIN * 2 - 2, h + MARGIN * 2 - 2);
      } else {
        gc.setForeground(getBorderForeground(display, focused));
        gc.drawRoundRectangle(x, y, w, h, CORNER_SIZE, CORNER_SIZE);
      }
    }
  }