Esempio 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);
  }
Esempio n. 2
0
 /**
  * Hook to compute the menu location if the focus widget is a tree widget.
  *
  * @param tree the tree widget that has the focus
  * @return a widget relative position of the menu to pop up or <code>null</code> if now position
  *     inside the widget can be computed
  */
 protected Point computeMenuLocation(Tree tree) {
   TreeItem[] items = tree.getSelection();
   Rectangle clientArea = tree.getClientArea();
   switch (items.length) {
     case 0:
       return null;
     case 1:
       Rectangle bounds = items[0].getBounds();
       Rectangle intersect = clientArea.intersection(bounds);
       if (intersect != null && intersect.height == bounds.height) {
         return new Point(
             Math.max(0, bounds.x + getAvarageCharWith(tree) * CHAR_INDENT),
             bounds.y + bounds.height);
       } else {
         return null;
       }
     default:
       Rectangle[] rectangles = new Rectangle[items.length];
       for (int i = 0; i < rectangles.length; i++) {
         rectangles[i] = items[i].getBounds();
       }
       Point cursorLocation = tree.getDisplay().getCursorLocation();
       Point result =
           findBestLocation(
               getIncludedPositions(rectangles, clientArea), tree.toControl(cursorLocation));
       if (result != null) result.x = result.x + getAvarageCharWith(tree) * CHAR_INDENT;
       return result;
   }
 }
 private void refreshProposalSize() {
   if (contentProposalAdapter != null) {
     Rectangle maxSize =
         new Rectangle(0, 0, MAX_WIDTH_PROPOSAL_STYLED_TEXT, MAX_HEIGHT_PROPOSAL_STYLED_TEXT);
     Rectangle boundsStyledText = StyledTextHandler.this.getStyledText().getBounds();
     Rectangle intersect = boundsStyledText.intersection(maxSize);
     Point sizeProposal = new Point(intersect.width, intersect.height);
     contentProposalAdapter.setPopupSize(sizeProposal);
   }
 }
Esempio n. 4
0
 private Point[] getIncludedPositions(Rectangle[] rectangles, Rectangle widgetBounds) {
   List result = new ArrayList();
   for (int i = 0; i < rectangles.length; i++) {
     Rectangle rectangle = rectangles[i];
     Rectangle intersect = widgetBounds.intersection(rectangle);
     if (intersect != null && intersect.height == rectangle.height) {
       result.add(new Point(intersect.x, intersect.y + intersect.height));
     }
   }
   return (Point[]) result.toArray(new Point[result.size()]);
 }
Esempio n. 5
0
  /** Moves the target control on top of the dummy control. */
  public void layout() {
    if (getTargetControl() == null) {
      return;
    }

    // Compute the unclipped bounds of the target in display coordinates
    Rectangle displayBounds = Geometry.toDisplay(control.getParent(), control.getBounds());

    // Clip the bounds of the target so that it doesn't go outside the dummy control's parent
    Rectangle clippingRegion = DragUtil.getDisplayBounds(control.getParent());
    displayBounds = displayBounds.intersection(clippingRegion);

    // Compute the bounds of the target, in the local coordinate system of its parent
    Rectangle targetBounds = Geometry.toControl(getTargetControl().getParent(), displayBounds);

    // Move the target
    getTargetControl().setBounds(targetBounds);
  }
Esempio n. 6
0
  /* Paint function */
  private void paint(GC gc) {
    Rectangle clientRect = getClientArea(); // Canvas' painting area
    if (sourceImage != null) {
      Rectangle imageRect = SWTUtil.inverseTransformRect(transform, clientRect);
      int gap = 2; // find a better start point to render
      imageRect.x -= gap;
      imageRect.y -= gap;
      imageRect.width += 2 * gap;
      imageRect.height += 2 * gap;

      Rectangle imageBound = sourceImage.getBounds();
      imageRect = imageRect.intersection(imageBound);
      Rectangle destRect = SWTUtil.transformRect(transform, imageRect);

      if (screenImage != null) screenImage.dispose();
      screenImage = new Image(getDisplay(), clientRect.width, clientRect.height);
      GC newGC = new GC(screenImage);
      newGC.setClipping(clientRect);
      newGC.drawImage(
          sourceImage,
          imageRect.x,
          imageRect.y,
          imageRect.width,
          imageRect.height,
          destRect.x,
          destRect.y,
          destRect.width,
          destRect.height);
      newGC.dispose();

      gc.drawImage(screenImage, 0, 0);
    } else {
      gc.setClipping(clientRect);
      gc.fillRectangle(clientRect);
      initScrollBars();
    }
  }