/**
   * Manually paints the checked or unchecked symbol. This provides a fast replacement for the
   * variant that paints the images defined in this class.
   *
   * <p>The reason for this is that painting manually is 2-3 times faster than painting the image -
   * which is very notable if you have a completely filled table! (see example!)
   *
   * @param gc The GC to use when dawing
   * @param rect The cell ara where the symbol should be painted into.
   * @param checked Wether the symbol should be the checked or unchecked
   * @param bgColor The background color of the cell.
   * @param fillColor The color of the box drawn (with of without checked mark). Used when a click
   *     indication is desired.
   */
  protected void drawCheckedSymbol(
      GC gc, Rectangle rect, boolean checked, Color bgColor, Color fillColor) {
    // clear background:
    gc.setBackground(bgColor);
    gc.fillRectangle(rect);

    // paint rectangle:
    Rectangle bound = getAlignedLocation(rect, IMAGE_CHECKED);

    gc.setForeground(BORDER_LIGHT);
    gc.drawLine(bound.x, bound.y, bound.x + bound.width, bound.y);
    gc.drawLine(bound.x, bound.y, bound.x, bound.y + bound.height);
    gc.setForeground(BORDER_DARK);
    gc.drawLine(
        bound.x + bound.width, bound.y + 1, bound.x + bound.width, bound.y + bound.height - 1);
    gc.drawLine(bound.x, bound.y + bound.height, bound.x + bound.width, bound.y + bound.height);

    if (!bgColor.equals(fillColor)) {
      gc.setBackground(fillColor);
      gc.fillRectangle(bound.x + 1, bound.y + 1, bound.width - 1, bound.height - 1);
    }

    if (checked) // draw a check symbol:
    drawCheckSymbol(gc, bound);
  }
  /**
   * paint progress bar
   *
   * @param paintEvent paint event
   */
  private void paint(PaintEvent paintEvent) {
    GC gc;
    Rectangle bounds;
    int x, y, w, h;

    gc = paintEvent.gc;
    bounds = getBounds();
    x = 0;
    y = 0;
    w = bounds.width;
    h = bounds.height;

    // shadow
    gc.setForeground(colorNormalShadow);
    gc.drawRectangle(x + 0, y + 0, w - 2, h - 2);

    gc.setForeground(colorHighlightShadow);
    gc.drawLine(x + 1, y + 1, x + w - 3, y + 1);
    gc.drawLine(x + 1, y + 2, x + 1, y + h - 3);
    gc.drawLine(x + 0, y + h - 1, x + w - 1, y + h - 1);
    gc.drawLine(x + w - 1, y + 0, x + w - 1, y + h - 2);

    // draw bar
    gc.setBackground(colorBar);
    gc.fillRectangle(x + 2, y + 2, w - 4, h - 4);
    gc.setBackground(colorBarSet);
    gc.fillRectangle(x + 2, y + 2, (int) ((double) (w - 4) * value), h - 4);

    // draw percentage text
    gc.setForeground(colorBlack);
    gc.drawString(text, (w - textSize.x) / 2, (h - textSize.y) / 2, true);
  }
  public void paint(
      GC gc,
      boolean hover,
      Hashtable resourceTable,
      boolean selected,
      SelectionData selData,
      Rectangle repaintRegion) {
    Image image = getImage(resourceTable);
    int iwidth = 0;
    int iheight = 0;
    if (image != null) {
      Rectangle rect = image.getBounds();
      iwidth = rect.width + (isSelectable() ? 2 : 0);
      iheight = rect.height + (isSelectable() ? 2 : 0);
    } else return;
    Rectangle bounds = getBounds();
    int ix = bounds.x + (isSelectable() ? 1 : 0);
    int iy = bounds.y + (isSelectable() ? 1 : 0);

    if (selData != null) {
      int leftOffset = selData.getLeftOffset(bounds.height);
      int rightOffset = selData.getRightOffset(bounds.height);
      boolean firstRow = selData.isFirstSelectionRow(bounds.y, bounds.height);
      boolean lastRow = selData.isLastSelectionRow(bounds.y, bounds.height);
      boolean selectedRow = selData.isSelectedRow(bounds.y, bounds.height);
      if (selectedRow) {
        if ((firstRow && leftOffset > ix) || (lastRow && rightOffset < ix + iwidth / 2)) {
          drawClipImage(gc, image, ix, iy, repaintRegion);
        } else {
          Color savedBg = gc.getBackground();
          gc.setBackground(selData.bg);
          int sx = ix;
          int sy = iy;
          if (repaintRegion != null) {
            sx -= repaintRegion.x;
            sy -= repaintRegion.y;
          }
          gc.fillRectangle(sx, sy, iwidth, iheight);
          Image selImage = getSelectedImage(resourceTable, selData);
          gc.drawImage(selImage, sx, sy);
          gc.setBackground(savedBg);
        }
      } else drawClipImage(gc, image, ix, iy, repaintRegion);
    } else drawClipImage(gc, image, ix, iy, repaintRegion);
    if (selected) {
      int fx = bounds.x;
      int fy = bounds.y;
      if (repaintRegion != null) {
        fx -= repaintRegion.x;
        fy -= repaintRegion.y;
      }
      Color fg = gc.getForeground();
      gc.setForeground(gc.getBackground());
      // Clean up to avoid canceling out XOR if it is already
      // selected.
      gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
      gc.setForeground(fg);
      gc.drawFocus(fx, fy, bounds.width, bounds.height);
    }
  }
Example #4
0
  private void drawBackground(GC gc) {
    Rectangle bounds = mShell.getBounds();
    if (!getMaximized()) {
      Color borderColor = null;
      if (Display.getDefault().getActiveShell() == mShell)
        borderColor = AbstractShellPainter.outerBorderNonMaximized;
      else borderColor = AbstractShellPainter.outerBorderNonMaximized_Inactive;
      gc.setBackground(borderColor);

      gc.fillRectangle(0, 0, bounds.width, bounds.height);

      gc.setBackground(bgColor);
      gc.fillRectangle(1, 1, bounds.width - 2, bounds.height - 2);

      // draw pretty borders, only bottoms, the top borders (as the menubar needs to connect for the
      // big button to work)
      // are drawn in a similar fashion in the RibbonTabFolder

      gc.setForeground(borderColor);
      // bottom left
      gc.drawLine(1, bounds.height - 4, 1, bounds.height - 4);
      gc.drawLine(1, bounds.height - 3, 2, bounds.height - 3);
      gc.drawLine(2, bounds.height - 2, 3, bounds.height - 2);

      // bottom right
      gc.drawLine(bounds.width - 4, bounds.height - 2, bounds.width - 3, bounds.height - 2);
      gc.drawLine(bounds.width - 3, bounds.height - 3, bounds.width - 2, bounds.height - 3);
      gc.drawLine(bounds.width - 2, bounds.height - 4, bounds.width - 2, bounds.height - 4);
    } else {
      gc.setBackground(bgColor);
      gc.fillRectangle(bounds);
    }
  }
Example #5
0
 /** @param gc */
 private void paintRanges(GC gc, Rectangle bounds) {
   // draw a rectangle for each range
   gc.setAlpha(200);
   for (RangeAnnotation a : items) {
     if (a == selectedAnnotation) {
       continue;
     }
     if (a.isDisposed()) continue;
     int visualLow = toVisualValue(a.getOffset()) + bounds.x;
     int visualHigh = toVisualValue(a.getLength()) + visualLow;
     if (visualLow < bounds.x + HANDLE_SIZE) {
       visualLow = bounds.x + HANDLE_SIZE;
     }
     if (visualHigh > bounds.x + bounds.width - HANDLE_SIZE) {
       visualHigh = bounds.x + bounds.width - HANDLE_SIZE;
     }
     Color fg = a.getForeground();
     if (a == selectedAnnotation) {
       fg = gc.getDevice().getSystemColor(SWT.COLOR_WHITE);
     }
     if (fg == null) {
       fg = getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
     }
     Color bg = a.getBackground();
     if (bg == null) {
       bg = getDisplay().getSystemColor(SWT.COLOR_GRAY);
     }
     gc.setForeground(fg);
     gc.setBackground(bg);
     gc.fillRectangle(visualLow, bounds.y, visualHigh - visualLow, bounds.height - 1);
     gc.drawRectangle(visualLow, bounds.y, visualHigh - visualLow - 1, bounds.height - 1);
   }
   // paint the selected annotation
   if (selectedAnnotation != null) {
     RangeAnnotation a = selectedAnnotation;
     if (a.isDisposed()) return;
     int visualLow = toVisualValue(a.getOffset()) + bounds.x;
     int visualHigh = toVisualValue(a.getLength()) + visualLow;
     if (visualLow < bounds.x + HANDLE_SIZE) {
       visualLow = bounds.x + HANDLE_SIZE;
     }
     if (visualHigh > bounds.x + bounds.width - HANDLE_SIZE) {
       visualHigh = bounds.x + bounds.width - HANDLE_SIZE;
     }
     Color fg = gc.getDevice().getSystemColor(SWT.COLOR_WHITE);
     if (fg == null) {
       fg = getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
     }
     Color bg = a.getBackground();
     if (bg == null) {
       bg = getDisplay().getSystemColor(SWT.COLOR_GRAY);
     }
     gc.setForeground(fg);
     gc.setBackground(bg);
     gc.fillRectangle(visualLow, bounds.y, visualHigh - visualLow, bounds.height - 1);
     gc.drawRectangle(visualLow, bounds.y, visualHigh - visualLow - 1, bounds.height - 1);
   }
 }
Example #6
0
  private void drawTile(GC gc, Rectangle bounds, Tile tile, boolean highlight) {
    if (tile == null || tile.equals(Tile.NONE)) return;

    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    int s = Math.min(w, h);
    int n = Math.max(s / 12, 1);
    int x1 = x;
    int x2 = x1 + n;
    int x3 = x + s - n;
    int x4 = x + s;
    int y1 = y;
    int y2 = y1 + n;
    int y3 = y + s - n;
    int y4 = y + s;

    int[] p1 = new int[] {x1, y1, x4, y1, x3, y2, x2, y2, x2, y3, x1, y4};
    int[] p2 = new int[] {x4, y4, x1, y4, x2, y3, x3, y3, x3, y2, x4, y1};

    gc.setBackground(tileFill);
    gc.fillRectangle(x, y, w, h);
    gc.setBackground(highlight ? tileLightHighlight : tileLight);
    gc.fillPolygon(p1);
    gc.setBackground(highlight ? tileDarkHighlight : tileDark);
    gc.fillPolygon(p2);

    if (tile.isWild()) {
      if (!bounds.contains(mousex, mousey)) {
        return;
      }
    }

    Font font = new Font(null, tileFont, s / 2 + 1, SWT.BOLD);
    String string = Character.toString(tile.getLetter()).toUpperCase();
    gc.setFont(font);
    Point extent = gc.stringExtent(string);
    int sx = x + w / 2 - extent.x / 2 - n; // n * 2; //w / 2 - extent.x / 2 - s/8;
    int sy = y + h / 2 - extent.y / 2;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();

    font = new Font(null, tileFont, s / 5, SWT.BOLD);
    string = Integer.toString(game.getTileValues().getValue(tile));
    gc.setFont(font);
    extent = gc.stringExtent(string);
    sx = x + w - n - extent.x - 1;
    sy = y + h - n - extent.y;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();
  }
  /** @param e */
  protected void drawTitleBackground(PaintEvent e) {

    Rectangle bounds = getClientArea();
    Point tsize = null;
    Point labelSize = null;
    int twidth = bounds.width - marginWidth - marginWidth;
    if (label != null) {
      labelSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    }
    if (labelSize != null) {
      twidth -= labelSize.x + 4;
    }
    int tvmargin = 4;
    int theight = getHeight();
    if (tsize != null) {
      theight += Math.max(theight, tsize.y);
    }
    if (labelSize != null) {
      theight = Math.max(theight, labelSize.y);
    }
    theight += tvmargin + tvmargin;
    int midpoint = (theight * 66) / 100;
    int rem = theight - midpoint;
    GC gc = e.gc;
    gc.setForeground(bg);
    gc.setBackground(gbg);
    gc.fillGradientRectangle(
        marginWidth,
        marginHeight,
        bounds.width - 1 - marginWidth - marginWidth,
        midpoint - 1,
        true);
    gc.setForeground(gbg);
    gc.setBackground(getBackground());
    gc.fillGradientRectangle(
        marginWidth,
        marginHeight + midpoint - 1,
        bounds.width - 1 - marginWidth - marginWidth,
        rem - 1,
        true);
    gc.setForeground(border);
    gc.drawLine(marginWidth, marginHeight + 2, marginWidth, marginHeight + theight - 1);
    gc.drawLine(marginWidth, marginHeight + 2, marginWidth + 2, marginHeight);
    gc.drawLine(marginWidth + 2, marginHeight, bounds.width - marginWidth - 3, marginHeight);
    gc.drawLine(
        bounds.width - marginWidth - 3,
        marginHeight,
        bounds.width - marginWidth - 1,
        marginHeight + 2);
    gc.drawLine(
        bounds.width - marginWidth - 1,
        marginHeight + 2,
        bounds.width - marginWidth - 1,
        marginHeight + theight - 1);
  }
  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);
  }
Example #9
0
 private void markPoint(double x, double y, String label, Color fg, Color bg, GC gc) {
   gc.setForeground(black);
   gc.setBackground(bg);
   gc.fillOval((int) x - 3, (int) y - 3, 7, 7);
   gc.drawOval((int) x - 3, (int) y - 3, 6, 6);
   gc.setForeground(fg);
   gc.setBackground(white);
   if (y > 0) {
     gc.drawText(label, (int) x + 8, (int) y + 4, true);
   } else {
     gc.drawText(label, (int) x + 10, (int) y - 10, true);
   }
 }
Example #10
0
  private void drawArrow(GC gc, int x, int y, int s) {
    s += (s % 2 == 0) ? 1 : 0;
    Orientation o = arrow.o;
    int[] a;

    if (o == Orientation.VERTICAL) {
      int d = s / 4;
      int t = s / 10;
      int x3 = x + s / 2;
      int x2 = x3 - t;
      int x4 = x3 + t;
      int x1 = x3 - d;
      int x5 = x3 + d;

      int y1 = y + s / 5;
      int y3 = y + s - s / 5;
      int y2 = y3 - d;

      a =
          new int[] {
            x2, y1,
            x4, y1,
            x4, y2,
            x5, y2,
            x3, y3,
            x1, y2,
            x2, y2,
            x2, y1
          };
    } else {
      int d = s / 4;
      int t = s / 10;
      int y3 = y + s / 2;
      int y2 = y3 - t;
      int y4 = y3 + t;
      int y1 = y3 - d;
      int y5 = y3 + d;

      int x1 = x + s / 5;
      int x3 = x + s - s / 5;
      int x2 = x3 - d;

      a =
          new int[] {
            x1, y2,
            x1, y4,
            x2, y4,
            x2, y5,
            x3, y3,
            x2, y1,
            x2, y2,
            x1, y2
          };
    }

    gc.setForeground(arrowForeground);
    gc.setBackground(arrowBackground);
    gc.fillPolygon(a);
    gc.drawPolygon(a);
  }
Example #11
0
  private void drawCoordinates(IBoard b, GC gc, int xo, int yo, int size, int csize) {
    gc.setBackground(light);
    gc.setForeground(coordinateColor);
    gc.setFont(coordinateFont);

    int xs = size / b.getWidth();
    int ys = size / b.getHeight();
    int pdx = 4 + gc.stringExtent("X").x;
    int pdy = 4;

    for (int y = 0; y < b.getHeight(); y++) {
      String s = Character.toString((char) (y + 'A'));
      int x = 0;
      int px = xo + x * xs - gc.stringExtent(s).x / 2 - pdx;
      int py = yo + y * ys + ys / 2 - gc.stringExtent(s).y / 2;
      gc.drawString(s, px, py, true);
    }

    for (int x = 0; x < b.getWidth(); x++) {
      String s = Integer.toString(x + 1);
      int y = 0;
      int px = xo + x * xs + xs / 2 - gc.stringExtent(s).x / 2;
      int py = yo + y * ys - gc.stringExtent(s).y - pdy;
      gc.drawString(s, px, py, true);
    }
  }
Example #12
0
 void drawItem(GC gc, boolean drawFocus) {
   int headerHeight = parent.getBandHeight();
   Display display = getDisplay();
   gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
   gc.setBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
   gc.fillGradientRectangle(x, y, width, headerHeight, true);
   if (expanded) {
     gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
     gc.drawLine(x, y + headerHeight, x, y + headerHeight + height - 1);
     gc.drawLine(x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1);
     gc.drawLine(x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight);
   }
   int drawX = x;
   if (image != null) {
     drawX += ExpandItem.TEXT_INSET;
     if (imageHeight > headerHeight) {
       gc.drawImage(image, drawX, y + headerHeight - imageHeight);
     } else {
       gc.drawImage(image, drawX, y + (headerHeight - imageHeight) / 2);
     }
     drawX += imageWidth;
   }
   if (text.length() > 0) {
     drawX += ExpandItem.TEXT_INSET;
     Point size = gc.stringExtent(text);
     gc.setForeground(parent.getForeground());
     gc.drawString(text, drawX, y + (headerHeight - size.y) / 2, true);
   }
   int chevronSize = ExpandItem.CHEVRON_SIZE;
   drawChevron(gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2);
   if (drawFocus) {
     gc.drawFocus(x + 1, y + 1, width - 2, headerHeight - 2);
   }
 }
Example #13
0
 void pairDraw(GC gc, StyledRegion sr, int start, int end) {
   if (start > text.getCharCount() || end > text.getCharCount()) return;
   if (gc != null) {
     Point left = text.getLocationAtOffset(start);
     Point right = text.getLocationAtOffset(end);
     if (sr != null) {
       if (highlightStyle == HLS_XOR) {
         int resultColor = sr.fore ^ cm.getColor(text.getBackground());
         if (text.getLineAtOffset(text.getCaretOffset()) == text.getLineAtOffset(start)
             && horzCross
             && horzCrossColor != null
             && ((StyledRegion) horzCrossColor).bback)
           resultColor = sr.fore ^ ((StyledRegion) horzCrossColor).back;
         Color color = cm.getColor(sr.bfore, resultColor);
         gc.setBackground(color);
         gc.setXORMode(true);
         gc.fillRectangle(left.x, left.y, right.x - left.x, gc.getFontMetrics().getHeight());
       } else if (highlightStyle == HLS_OUTLINE) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.drawRectangle(
             left.x, left.y, right.x - left.x - 1, gc.getFontMetrics().getHeight() - 1);
       } else if (highlightStyle == HLS_OUTLINE2) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.setLineWidth(2);
         gc.drawRectangle(
             left.x + 1, left.y + 1, right.x - left.x - 2, gc.getFontMetrics().getHeight() - 2);
       }
     }
   } else {
     text.redrawRange(start, end - start, true);
   }
 }
 public void writeValue(int ex) {
   double x = xyGraph.primaryXAxis.getPositionValue(ex, false);
   int index = (int) x;
   if (index < 0) {
     return;
   }
   Sample sample = (Sample) trace.getDataProvider().getSample(index);
   if (sample != null) {
     double y = sample.getYValue();
     int height = xyGraph.primaryYAxis.getValuePosition(y, false);
     int startX = xyGraph.primaryXAxis.getValuePosition((int) x, false);
     GC gc = new GC(canvas);
     Font font = new Font(null, "Verdana", 10, SWT.BOLD);
     gc.setFont(font);
     String value = FormatUtil.print(y, "#,###");
     Point textSize = gc.textExtent(value);
     gc.drawText(value, startX + (xAxisUnitWidth - textSize.x) / 2, height - 20, true);
     int ground = xyGraph.primaryYAxis.getValuePosition(0, false);
     gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
     gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_MAGENTA));
     gc.drawRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.fillRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.dispose();
     writedValueMode = true;
     lastWritedX = ex;
   }
 }
Example #15
0
  private void onPaint(GC gc) {
    Rectangle clientArea = getClientArea();
    gc.setClipping(clientArea);

    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
    int boxSize = 10;
    int maxCol = clientArea.width / boxSize + 1;
    int maxRow = clientArea.height / boxSize + 1;

    for (int r = 0; r < maxRow; r++) {
      for (int c = 0; c < maxCol; c++) {
        if (r % 2 == c % 2) {
          gc.fillRectangle(c * boxSize, r * boxSize, boxSize, boxSize);
        }
      }
    }

    if (image == null || image.isDisposed()) {
      return;
    }
    Rectangle imageBounds = image.getBounds();

    int x = -getHorizontalBar().getSelection();
    int y = -getVerticalBar().getSelection();

    if (clientArea.width > imageBounds.width) {
      x += (clientArea.width - imageBounds.width) / 2;
    }

    if (clientArea.height > imageBounds.height) {
      y += (clientArea.height - imageBounds.height) / 2;
    }

    gc.drawImage(image, x, y);
  }
Example #16
0
  protected void drawBottomSpace(GC gc) {
    Rectangle r = getClientArea();
    if (m_Model.getRowCount() > 0) {
      r.y =
          m_Model.getFirstRowHeight()
              + (m_Model.getFixedRowCount() - 1 + m_RowsVisible) * m_Model.getRowHeight()
              + 1;
    }

    gc.setBackground(getBackground());
    gc.fillRectangle(r);
    gc.fillRectangle(getLastColumnRight() + 2, 0, r.width, r.height);

    if (m_Model.getRowCount() > 0) {
      if (flatStyleSpecified)
        // gc.setForeground(this.getBackground());
        gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
      else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
      // Linke Schattenlinie
      gc.drawLine(0, 0, 0, r.y - 1);
    }

    if (!flatStyleSpecified) gc.setForeground(this.getBackground());
    else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WHITE));
    // Untere Abschlusslinie
    gc.drawLine(0, r.y - 1, getLastColumnRight() + 1, r.y - 1);

    // Rechte Abschlusslinie
    gc.drawLine(getLastColumnRight() + 1, 0, getLastColumnRight() + 1, r.y - 1);
  }
Example #17
0
  /**
   * Draws the rotated text.
   *
   * @param gc the graphics context
   * @param text the text
   * @param x the x coordinate
   * @param y the y coordinate
   * @param angle the angle
   */
  private void drawRotatedText(GC gc, String text, float x, float y, int angle) {

    int textWidth = gc.textExtent(text).x;
    int textHeight = gc.textExtent(text).y;

    // create image to draw text
    Image image = new Image(Display.getCurrent(), textWidth, textHeight);
    GC tmpGc = new GC(image);
    tmpGc.setForeground(getForeground());
    tmpGc.setBackground(gc.getBackground());
    tmpGc.setFont(getFont());
    tmpGc.drawText(text, 0, 0);

    // set transform to rotate
    Transform transform = new Transform(gc.getDevice());
    transform.translate(x, y);
    transform.rotate(360 - angle);
    gc.setTransform(transform);

    // draw the image on the rotated graphics context
    gc.drawImage(image, 0, 0);

    // dispose resources
    tmpGc.dispose();
    transform.dispose();
    image.dispose();
    gc.setTransform(null);
  }
  private AutoCloseable configGC(final GC gc) {
    final int lineStyle = gc.getLineStyle();
    final int alpha = gc.getAlpha();
    final int[] lineDash = gc.getLineDash();

    final Color foreground = gc.getForeground();
    final Color background = gc.getBackground();

    gc.setForeground(this.indentGuide.getColor(styledText));
    gc.setBackground(styledText.getBackground());
    gc.setAlpha(this.indentGuide.getTransparency());
    gc.setLineStyle(SWT.LINE_CUSTOM);
    gc.setLineDash(new int[] {1, 2});
    return new AutoCloseable() {

      @Override
      public void close() throws Exception {
        gc.setForeground(foreground);
        gc.setBackground(background);
        gc.setAlpha(alpha);
        gc.setLineStyle(lineStyle);
        gc.setLineDash(lineDash);
      }
    };
  }
Example #19
0
 private void draw(GC gc) {
   Rectangle r = getClientArea();
   gc.setBackground(color);
   gc.fillRectangle(r);
   gc.setForeground(colors.getColor(TraceColorScheme.BLACK));
   gc.drawRectangle(0, 0, r.width - 1, r.height - 1);
 }
  void resize() {
    Point size = comp.getSize();
    Image oldBackgroundImage = backgroundImage;
    backgroundImage = new Image(comp.getDisplay(), size.x, size.y);
    GC gc = new GC(backgroundImage);
    comp.getParent().drawBackground(gc, 0, 0, size.x, size.y, 0, 0);
    Color background = comp.getBackground();
    Color border = comp.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    RGB backgroundRGB = background.getRGB();
    // TODO naive and hard coded, doesn't deal with high contrast, etc.
    Color gradientTop =
        new Color(
            comp.getDisplay(),
            backgroundRGB.red + 12,
            backgroundRGB.green + 10,
            backgroundRGB.blue + 10);
    int h = size.y;
    int curveStart = 0;
    int curve_width = 5;

    int[] curve =
        new int[] {
          0, h, 1, h, 2, h - 1, 3, h - 2, 3, 2, 4, 1, 5, 0,
        };
    int[] line1 = new int[curve.length + 4];
    int index = 0;
    int x = curveStart;
    line1[index++] = x + 1;
    line1[index++] = h;
    for (int i = 0; i < curve.length / 2; i++) {
      line1[index++] = x + curve[2 * i];
      line1[index++] = curve[2 * i + 1];
    }
    line1[index++] = x + curve_width;
    line1[index++] = 0;

    int[] line2 = new int[line1.length];
    index = 0;
    for (int i = 0; i < line1.length / 2; i++) {
      line2[index] = line1[index++] - 1;
      line2[index] = line1[index++];
    }

    // custom gradient
    gc.setForeground(gradientTop);
    gc.setBackground(background);
    gc.drawLine(4, 0, size.x, 0);
    gc.drawLine(3, 1, size.x, 1);
    gc.fillGradientRectangle(2, 2, size.x - 2, size.y - 3, true);
    gc.setForeground(background);
    gc.drawLine(2, size.y - 1, size.x, size.y - 1);
    gradientTop.dispose();

    gc.setForeground(border);
    gc.drawPolyline(line2);
    gc.dispose();
    comp.setBackgroundImage(backgroundImage);
    if (oldBackgroundImage != null) oldBackgroundImage.dispose();
  }
Example #21
0
 /** @return a white flag that can be used as default. */
 private static Image createDefaultFlag() {
   Image img = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, "png/de.png").createImage();
   GC gc = new GC(img);
   gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
   gc.fillRectangle(img.getBounds());
   gc.dispose();
   return img;
 }
Example #22
0
    private void draw(GC gc) {
      Rectangle r = getClientArea();
      gc.setBackground(color);

      int y = (r.height - DX) / 2;
      int c[] = {0, y, DX, y + DX, 2 * DX, y};
      gc.fillPolygon(c);
    }
Example #23
0
 void paintCanvas(Event event) {
   canvas.setCursor(null);
   int index = list.getSelectionIndex();
   if (index == -1) return;
   GC gc = event.gc;
   Object object = objects[index];
   if (object instanceof Color) {
     if (((Color) object).isDisposed()) return;
     gc.setBackground((Color) object);
     gc.fillRectangle(canvas.getClientArea());
     return;
   }
   if (object instanceof Cursor) {
     if (((Cursor) object).isDisposed()) return;
     canvas.setCursor((Cursor) object);
     return;
   }
   if (object instanceof Font) {
     if (((Font) object).isDisposed()) return;
     gc.setFont((Font) object);
     FontData[] array = gc.getFont().getFontData();
     StringBuffer sb = new StringBuffer();
     String lf = text.getLineDelimiter();
     for (int i = 0; i < array.length; i++) {
       FontData data = array[i];
       String style = "NORMAL"; // $NON-NLS-1$
       int bits = data.getStyle();
       if (bits != 0) {
         if ((bits & SWT.BOLD) != 0) style = "BOLD "; // $NON-NLS-1$
         if ((bits & SWT.ITALIC) != 0) style += "ITALIC"; // $NON-NLS-1$
       }
       sb.append(data.getName())
           .append(" ")
           .append(data.getHeight()) // $NON-NLS-1$
           .append(" ")
           .append(style)
           .append(lf); // $NON-NLS-1$
     }
     gc.drawString(sb.toString(), 0, 0);
     return;
   }
   // NOTHING TO DRAW FOR GC
   // if (object instanceof GC) {
   // return;
   // }
   if (object instanceof Image) {
     if (((Image) object).isDisposed()) return;
     gc.drawImage((Image) object, 0, 0);
     return;
   }
   if (object instanceof Region) {
     if (((Region) object).isDisposed()) return;
     String string = ((Region) object).getBounds().toString();
     gc.drawString(string, 0, 0);
     return;
   }
 }
  @Override
  public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
    Color foregroundColor = getForeGroundColour(cell, configRegistry);
    Color backgroundColor = getBackgroundColour(cell, configRegistry);
    if (backgroundColor != null && foregroundColor != null) {
      Color originalForeground = gc.getForeground();
      Color originalBackground = gc.getBackground();

      gc.setForeground(foregroundColor);
      gc.setBackground(backgroundColor);
      gc.fillGradientRectangle(bounds.x, bounds.y, bounds.width, bounds.height, vertical);

      gc.setForeground(originalForeground);
      gc.setBackground(originalBackground);
    }

    super.paintCell(cell, gc, bounds, configRegistry);
  }
 /** @return the small {@link Image} that can be used as placeholder for missing image. */
 private static Image getMissingImage() {
   Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
   //
   GC gc = new GC(image);
   gc.setBackground(getColor(SWT.COLOR_RED));
   gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
   gc.dispose();
   //
   return image;
 }
Example #26
0
 private void apply(GC gc, SvgGradientStop stop, boolean foreground) {
   Color c = new Color(gc.getDevice(), stop.color.red(), stop.color.green(), stop.color.blue());
   if (foreground) {
     gc.setForeground(c);
   } else {
     gc.setBackground(c);
   }
   c.dispose();
   gc.setAlpha((int) (255 * stop.opacity));
 }
Example #27
0
  private void drawBoardBorder(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    gc.setBackground(boardBorder);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);
  }
 @Override
 public void paint(Property property, GC gc, int x, int y, int width, int height)
     throws Exception {
   String text = getText(property);
   if (text != null) {
     // draw color sample
     {
       RGB rgb = ColorDialog.getRGB(text);
       if (rgb != null) {
         Color swtColor = new Color(null, rgb);
         //
         Color oldBackground = gc.getBackground();
         Color oldForeground = gc.getForeground();
         try {
           int width_c = SAMPLE_SIZE;
           int height_c = SAMPLE_SIZE;
           int x_c = x;
           int y_c = y + (height - height_c) / 2;
           // update rest bounds
           {
             int delta = SAMPLE_SIZE + SAMPLE_MARGIN;
             x += delta;
             width -= delta;
           }
           // fill
           {
             gc.setBackground(swtColor);
             gc.fillRectangle(x_c, y_c, width_c, height_c);
           }
           // draw line
           gc.setForeground(IColorConstants.gray);
           gc.drawRectangle(x_c, y_c, width_c, height_c);
         } finally {
           gc.setBackground(oldBackground);
           gc.setForeground(oldForeground);
           swtColor.dispose();
         }
       }
     }
     // draw color text
     DrawUtils.drawStringCV(gc, text, x, y, width, height);
   }
 }
  private static Image createImage(Display display, int red, int green, int blue) {
    Color color = new Color(display, red, green, blue);
    Image image = new Image(display, 10, 10);
    GC gc = new GC(image);
    gc.setBackground(color);
    gc.fillRectangle(0, 0, 10, 10);
    gc.dispose();

    return image;
  }
Example #30
0
  public void paintControl(PaintEvent e) {

    if (text == null || foreground == null) return;

    GC gc = e.gc;

    Color oldForeground = gc.getForeground(), oldBackground = gc.getBackground();
    Font oldFont = gc.getFont();
    int oldAntiAlias = gc.getTextAntialias();

    gc.setTextAntialias(SWT.ON);

    if (background != null) gc.setBackground(background);
    if (font != null) gc.setFont(font);

    int finalX = x, finalY = y;

    if (useRelativeXY) {
      Point size = shell.getSize();
      Point textExtent = gc.textExtent(text);

      if (x >= 0) finalX = x;
      else {
        finalX = size.x + x;
        finalX -= textExtent.x;
      }

      if (y >= 0) finalY = y;
      else {
        finalY = size.y + y;
        finalY -= textExtent.y;
      }
    }

    gc.setForeground(foreground);
    gc.drawText(text, finalX, finalY, background == null);

    gc.setForeground(oldForeground);
    gc.setBackground(oldBackground);
    gc.setFont(oldFont);
    gc.setTextAntialias(oldAntiAlias);
  }