Exemplo n.º 1
0
  private static void paintImage(GC gc, Point size) {
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.fillRectangle(0, 0, size.x, size.y);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
    gc.fillRoundRectangle(0, 0, size.x - 1, size.y - 1, 10, 10);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.drawRoundRectangle(0, 0, size.x - 1, size.y - 1, 10, 10);
    gc.drawText(gc.getFont().getFontData()[0].toString(), 10, 10, true);
  }
Exemplo n.º 2
0
  /** Draw the item {@inheritDoc} */
  @Override
  public void paintControl(final PaintEvent e) {
    final Display display = getDisplay();
    final GC gc = e.gc;
    final Rectangle bounds = getBounds();

    last_alarm_state = item.getSeverity();
    gc.setBackground(color_provider.getColor(last_alarm_state));
    gc.fillRoundRectangle(0, 0, bounds.width, bounds.height, 10, 10);

    gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_BORDER));
    gc.drawRoundRectangle(0, 0, bounds.width - 1, bounds.height - 1, 10, 10);

    // Draw Text
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    final String label = item.getName();
    final Point extend = gc.textExtent(label);
    gc.drawString(label, (bounds.width - extend.x) / 2, (bounds.height - extend.y) / 2, true);
  }
Exemplo n.º 3
0
  private static void paintImage2(GC gc, Point size, int f) {
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.fillRectangle(0, 0, size.x, size.y);

    // Scale line width, corner roundness, and font size.
    // Caveat: line width expands in all directions, so the origin also has to move.

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
    gc.fillRoundRectangle(f / 2, f / 2, size.x - f, size.y - f, 10 * f, 10 * f);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.setLineWidth(f);
    gc.drawRoundRectangle(f / 2, f / 2, size.x - f, size.y - f, 10 * f, 10 * f);
    FontData fontData = gc.getFont().getFontData()[0];
    fontData.setHeight(fontData.getHeight() * f);
    Font font = new Font(gc.getDevice(), fontData);
    try {
      gc.setFont(font);
      gc.drawText(fontData.toString(), 10 * f, 10 * f, true);
    } finally {
      font.dispose();
    }
  }
Exemplo n.º 4
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);
      }
    }
  }
Exemplo n.º 5
0
  /* (non-Javadoc)
   * @see org.eclipse.vtp.desktop.editors.themes.mantis.MantisComponentFrame#renderFrame(org.eclipse.swt.graphics.GC, int, int, java.util.Map)
   */
  public void renderFrame(GC gc, int renderingPhase, int options, Map<String, Object> resourceMap) {
    Font originalFont = gc.getFont();
    Color foreground = gc.getForeground();
    Color background = gc.getBackground();
    Color selectedColor = getColor(gc, resourceMap, "rust.selection.color", 82, 140, 55);
    Color elementBlue = getColor(gc, resourceMap, "rust.element.color", 207, 234, 195);
    Color elementGradBlue = getColor(gc, resourceMap, "rust.element.color.gradient", 161, 211, 137);
    Font nameFont = new Font(gc.getDevice(), "Arial", 10, SWT.NORMAL);
    gc.setFont(nameFont);
    if (upperLeft == null) {
      initializeGraphics(gc, resourceMap);
    }
    int width = lowerRight.x - upperLeft.x;
    int height = lowerRight.y - upperLeft.y;
    int mainBodyHeight = height - (uiElement.hasConnectors() ? 12 : 0);

    if (uiElement.hasConnectors()) {
      // draw inspector tray
      gc.setBackground(elementBlue);
      gc.fillRoundRectangle(upperLeft.x, upperLeft.y + 3, width - 1, height - 3, 20, 20);

      // draw inspector tray border
      if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
        gc.setForeground(selectedColor);
      }
      gc.drawRoundRectangle(upperLeft.x, upperLeft.y + 3, width - 1, height - 3, 20, 20);
    }

    // draw main body
    gc.setBackground(elementBlue);
    gc.fillRoundRectangle(upperLeft.x, upperLeft.y, width - 1, mainBodyHeight - 1, 20, 20);
    gc.setBackground(elementGradBlue);
    gc.fillRoundRectangle(
        upperLeft.x + 1,
        upperLeft.y + (mainBodyHeight / 2) - 1,
        lowerRight.x - upperLeft.x - 2,
        (mainBodyHeight / 2) + (mainBodyHeight % 2),
        20,
        20);
    //		gc.setForeground(elementBlue);
    //		gc.fillGradientRectangle(upperLeft.x + 2,
    //			upperLeft.y
    //			+ (mainBodyHeight / 3),
    //			lowerRight.x - upperLeft.x - 4,
    //			((mainBodyHeight / 3) * 2) - 5,
    //			true);
    gc.setForeground(foreground);
    gc.setBackground(background);

    // draw main body border
    if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
      gc.setForeground(selectedColor);
    }
    gc.drawRoundRectangle(upperLeft.x, upperLeft.y, width - 1, mainBodyHeight - 1, 20, 20);

    gc.setForeground(foreground);
    // draw connector hot spot
    if (uiElement.hasConnectors()) {
      gc.drawLine(lowerRight.x - 19, lowerRight.y - 8, lowerRight.x - 5, lowerRight.y - 8);
      //			gc.drawLine(lowerRight.x - 8, lowerRight.y - 15, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 10, lowerRight.y - 3, lowerRight.x - 5, lowerRight.y - 8);
    }

    // draw icon
    if ((options & Theme.RENDER_FLAG_NO_ICONS) == 0) {
      gc.drawImage(
          icon,
          upperLeft.x + 5,
          upperLeft.y + (((mainBodyHeight - 16) / 2) + ((mainBodyHeight - 16) % 2)));
    }

    // draw element name
    int curX = upperLeft.x + 25;
    int curY = upperLeft.y + 5;
    String[] parts = this.getDesignElement().getName().split(" ");
    Point stringExtent = gc.stringExtent(parts[0]);
    int ew = stringExtent.x;
    gc.drawString(parts[0], curX, curY, true);
    curX += stringExtent.x;
    for (int i = 1; i < parts.length; i++) {
      stringExtent = gc.stringExtent(" " + parts[i]);
      boolean wrapped = false;
      if (ew + stringExtent.x > 110) // wrap it
      {
        stringExtent = gc.stringExtent(parts[i]);
        ew = stringExtent.x;
        curY += 2 + stringExtent.y;
        curX = upperLeft.x + 25;
        wrapped = true;
      } else ew += stringExtent.x;
      gc.drawString((wrapped ? "" : " ") + parts[i], curX, curY, true);
      curX += stringExtent.x;
    }

    // draw decorator icons
    if ((options & Theme.RENDER_FLAG_NO_MARKERS) == 0) {
      if (uiElement.hasErrors())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_ERROR"),
            lowerRight.x - 17,
            upperLeft.y);
      else if (uiElement.hasWarnings())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_WARNING"),
            lowerRight.x - 16,
            upperLeft.y);
      else if (uiElement.hasTodo())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault().getImageRegistry().get("ICON_TASK"),
            lowerRight.x - 18,
            upperLeft.y + 2);
    }

    // resource cleanup
    if (selected) {
      gc.setForeground(foreground);
    }
    gc.setFont(originalFont);
    nameFont.dispose();
  }
  /* (non-Javadoc)
   * @see org.eclipse.vtp.desktop.editors.themes.attraction.AttractionComponentFrame#renderFrame(org.eclipse.swt.graphics.GC, int, int, java.util.Map)
   */
  public void renderFrame(GC gc, int renderingPhase, int options, Map<String, Object> resourceMap) {
    Font originalFont = gc.getFont();
    Color foreground = gc.getForeground();
    Color background = gc.getBackground();
    Color selectedColor = getColor(gc, resourceMap, "attraction.selection.color", 0, 0, 255);
    Color elementBlue = getColor(gc, resourceMap, "attraction.element.color", 201, 229, 255);
    Color elementGradBlue =
        getColor(gc, resourceMap, "attraction.element.color.gradient", 153, 206, 255);
    Font nameFont = getFont(gc, resourceMap, "attraction.element.font", "Arial", 10, SWT.NORMAL);
    gc.setFont(nameFont);

    if (upperLeft == null) {
      initializeGraphics(gc, resourceMap);
    }
    int width = lowerRight.x - upperLeft.x;
    int height = lowerRight.y - upperLeft.y;

    gc.setBackground(elementBlue);
    gc.fillRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12);
    if ((options & Theme.RENDER_FLAG_PRINTING) == 0) {
      gc.setBackground(elementGradBlue);
      gc.fillRoundRectangle(
          upperLeft.x,
          upperLeft.y + ((lowerRight.y - upperLeft.y) / 2),
          lowerRight.x - upperLeft.x,
          ((lowerRight.y - upperLeft.y) / 2),
          12,
          12);
      gc.setForeground(elementBlue);
      gc.fillGradientRectangle(
          upperLeft.x,
          upperLeft.y + ((lowerRight.y - upperLeft.y) / 3),
          lowerRight.x - upperLeft.x,
          (((lowerRight.y - upperLeft.y) / 3) * 2) - 5,
          true);
    }
    gc.setForeground(foreground);
    gc.setBackground(background);

    // draw connector hot spot
    if (uiElement.hasConnectors()) {
      gc.drawLine(lowerRight.x - 17, lowerRight.y - 10, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 8, lowerRight.y - 15, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 8, lowerRight.y - 5, lowerRight.x - 3, lowerRight.y - 10);
    }

    if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
      gc.setForeground(selectedColor);
    }
    gc.drawRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12);
    if ((options & Theme.RENDER_FLAG_NO_ICONS) == 0) {
      gc.drawImage(icon, upperLeft.x + 10, upperLeft.y + 12);
    }
    int curX = upperLeft.x + 30;
    int curY = upperLeft.y + 15;
    String[] parts = this.getDesignElement().getName().split(" ");
    Point stringExtent = gc.stringExtent(parts[0]);
    int ew = stringExtent.x;
    gc.drawString(parts[0], curX, curY, true);
    curX += stringExtent.x;
    for (int i = 1; i < parts.length; i++) {
      stringExtent = gc.stringExtent(" " + parts[i]);
      boolean wrapped = false;
      if (ew + stringExtent.x > 110) // wrap it
      {
        stringExtent = gc.stringExtent(parts[i]);
        ew = stringExtent.x;
        curY += 3 + stringExtent.y;
        curX = upperLeft.x + 30;
        wrapped = true;
      } else ew += stringExtent.x;
      gc.drawString((wrapped ? "" : " ") + parts[i], curX, curY, true);
      curX += stringExtent.x;
    }
    if (selected) {
      gc.setForeground(foreground);
    }
    gc.setFont(originalFont);
    if ((options & Theme.RENDER_FLAG_NO_MARKERS) == 0) {
      if (uiElement.hasErrors())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_ERROR"),
            lowerRight.x - 17,
            upperLeft.y);
      else if (uiElement.hasWarnings())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_WARNING"),
            lowerRight.x - 16,
            upperLeft.y);
      else if (uiElement.hasTodo())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault().getImageRegistry().get("ICON_TASK"),
            lowerRight.x - 18,
            upperLeft.y + 2);
    }
  }
 protected void highlightDifferences(GC gc) {
   // if the differencer is null then we are currently
   // in the middle of a content update, skip this paint
   // request
   if (mergeViewer.getDifferencer() == null) {
     return;
   }
   gc.setAdvanced(true);
   gc.setAntialias(SWT.ON);
   Tree tree = getTree();
   List<TreeDifference> differences = mergeViewer.getDifferencer().getLeftDifferences();
   if (mergeViewer.getLeftViewer() != this && mergeViewer.getAncestorTree() != this) {
     differences = mergeViewer.getDifferencer().getRightDifferences();
   }
   for (TreeDifference difference : differences) {
     if (differenceIsGraphical(difference)) {
       // we do not include graphical differences
       // at this time
       continue;
     }
     gc.setForeground(
         getMergeViewer()
             .getColor(
                 PlatformUI.getWorkbench().getDisplay(),
                 getMergeViewer().getStrokeColor(difference)));
     TreeItem item = getItemForDifference(difference);
     if (item == null || item.isDisposed()) {
       continue;
     }
     Rectangle highlightBounds =
         buildHighlightRectangle(
             item, difference.getIncludeChildren() && item.getExpanded(), gc, false, true);
     Rectangle itemBounds = buildHighlightRectangle(item, false, gc, false, true);
     boolean itemMatchesDifference = difference.getElement().equals(item.getData());
     if (!itemMatchesDifference && !(item.getData() instanceof EmptyElement)) {
       gc.setLineDash(new int[] {3});
       gc.setLineStyle(SWT.LINE_CUSTOM);
     } else {
       gc.setLineStyle(SWT.LINE_SOLID);
     }
     gc.drawRoundRectangle(
         highlightBounds.x,
         highlightBounds.y,
         highlightBounds.width,
         highlightBounds.height,
         5,
         5);
     if (mergeViewer.getLeftViewer() == this) {
       gc.drawLine(
           highlightBounds.x + highlightBounds.width,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x + tree.getClientArea().width,
           highlightBounds.y + (itemBounds.height / 2));
     } else {
       gc.drawLine(
           highlightBounds.x,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x,
           highlightBounds.y + (itemBounds.height / 2));
     }
     gc.setLineStyle(SWT.LINE_SOLID);
   }
 }