public static void paintTextDecoration(Graphics g, Rectangle rect, int textDecoration) { if ((textDecoration & TextDecorationMeta.UNDERLINE) != 0) { g.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1); } if ((textDecoration & TextDecorationMeta.OVERLINE) != 0) { g.drawLine(rect.x, rect.y + 1, rect.x + rect.width - 1, rect.y + 1); } if ((textDecoration & TextDecorationMeta.LINETHROUGH) != 0) { g.drawLine(rect.x, rect.y + rect.height / 2, rect.x + rect.width - 1, rect.y + rect.height / 2); } }
public void paintFigure(Graphics g, Rectangle rect) { int centerX = rect.x + rect.width / 2; int centerY = rect.y + rect.height / 2; // we always draw it as a square. int width = Math.min(rect.width, rect.height); int innerWidth = width * 4 / 5; int left = centerX - innerWidth / 2; int top = centerY - innerWidth / 2; BorderUtil.drawBorder(g, left, top, innerWidth, innerWidth, 2, true); if (isChecked()) { g.pushState(); Display display = Display.getCurrent(); g.setForegroundColor(display.getSystemColor(SWT.COLOR_BLACK)); g.drawLine(left + 3, top + 2, left + innerWidth - 3, top + innerWidth - 4); g.drawLine(left + 2, top + 2, left + innerWidth - 3, top + innerWidth - 3); g.drawLine(left + innerWidth - 4, top + 2, left + 2, top + innerWidth - 4); g.drawLine(left + innerWidth - 3, top + 2, left + 2, top + innerWidth - 3); g.popState(); } }
@Override public void paint(IFigure figure, Graphics graphics, Insets insets) { Rectangle paintRectangle = getPaintRectangle(figure, insets); graphics.drawLine(paintRectangle.getTopLeft(), paintRectangle .getTopRight()); } }
@Override public void paint(IFigure figure, Graphics graphics, Insets insets) { Rectangle paintRectangle = getPaintRectangle(figure, insets); graphics.drawLine(paintRectangle.getTopLeft(), paintRectangle.getTopRight()); } }
@Override public void paint(IFigure figure, Graphics graphics, Insets insets) { Rectangle paintRectangle = getPaintRectangle(figure, insets); graphics.drawLine(paintRectangle.getTopLeft(), paintRectangle .getTopRight()); } }
public void paint(Graphics graphics) { graphics.fillRectangle(getBounds()); super.paint(graphics); boolean isFirst = false; for (Iterator i = getChildren().iterator(); i.hasNext();) { Figure figure = (Figure) i.next(); if (isFirst) { isFirst = false; } else { Rectangle r = figure.getBounds(); graphics.drawLine(r.x, r.y + 1, r.x + r.width, r.y + 1); } } } };
private static void drawHorizontalPart(Graphics g, int arrawLength, int borderThick, Rectangle rect) { int left = rect.x; int top = rect.y; int width = Math.min(arrawLength, rect.width / 2); int height = Math.min(arrawLength, rect.height); Rectangle borderRect = new Rectangle(left, top, width, height); BorderUtil.drawBorder(g, borderRect, borderThick, false); g.setForegroundColor(ColorConstants.black); int decoratorHeight = (height - borderThick * 2) / 2; int length = decoratorHeight / 2 + 1; int leftX = rect.x + (width + length) / 2 - 1; int bottomY = rect.y + (height - length) / 2 - 1; for (int i = 0; i < length; i++) { g.drawLine(leftX - i, bottomY + i, leftX - i, bottomY - i + decoratorHeight); } left = rect.x + rect.width - width; borderRect = new Rectangle(left, top, width, height); BorderUtil.drawBorder(g, borderRect, borderThick, false); leftX = left + (width - length) / 2; g.setForegroundColor(ColorConstants.black); for (int i = 0; i < length; i++) { g.drawLine(leftX + i, bottomY + i, leftX + i, bottomY - i + decoratorHeight); } }
private static void drawVerticalPart(Graphics g, int arrawLength, int borderThick, Rectangle rect) { int left = rect.x; int top = rect.y; int width = Math.min(arrawLength, rect.width); int height = Math.min(arrawLength, rect.height / 2); Rectangle borderRect = new Rectangle(left, top, width, height); BorderUtil.drawBorder(g, borderRect, borderThick, false); g.setForegroundColor(ColorConstants.black); int decoratorWidth = (width - borderThick * 2) / 2; int length = decoratorWidth / 2 + 1; int leftX = rect.x + (width - decoratorWidth) / 2 - 1; int bottomY = rect.y + (height + length) / 2 - 1; for (int i = 0; i < length; i++) { g.drawLine(leftX + i, bottomY - i, leftX - i + decoratorWidth, bottomY - i); } top = rect.y + rect.height - height; borderRect = new Rectangle(left, top, width, height); BorderUtil.drawBorder(g, borderRect, borderThick, false); int topY = top + (height - length) / 2; g.setForegroundColor(ColorConstants.black); for (int i = 0; i < length; i++) { g.drawLine(leftX + i, topY + i, leftX - i + decoratorWidth, topY + i); } }
g.drawLine(frag._x, frag._y + frag.getHeight() - 1, frag._x + frag.getWidth(), frag._y + frag.getHeight() - 1); g.drawLine(frag._x, frag._y, frag._x + frag.getWidth(), frag._y); g.drawLine(frag._x, frag._y + frag.getHeight() / 2, frag._x + frag.getWidth(), frag._y + frag.getHeight() / 2); g.drawLine(frag._x, frag._y + frag.getAscent(), frag._x + frag.getWidth(), frag._y + frag.getAscent());
protected void paintFigure(Graphics graphics) { super.paintFigure(graphics); graphics.setFont(getFont()); // TODO (cs) this lookup to find " :" is a hack // that's specialized for element and type label text // we need to make the TopLevelComponent use two labels in this case // String string = getText(); int index = string.indexOf(" :"); if (index != -1) { string = string.substring(0, index); } // end hack Point p = getTextLocation(); Dimension textSize = FigureUtilities.getTextExtents(string, getFont()); int textWidth = textSize.width; int textHeight = textSize.height; int descent = graphics.getFontMetrics().getDescent(); int lineY = bounds.y + p.y + textHeight - descent + 1; int lineX = bounds.x + p.x; graphics.drawLine(lineX, lineY, lineX + textWidth, lineY); } }
private void paintLeftEdge(Graphics graphics, RGB[] rgbs, String style, Rectangle rect, Rectangle innerRect) { int x = rect.x; int topY = rect.y; int bottomY = rect.bottom() - 1; int width = innerRect.x - rect.x; if (ICSSPropertyID.VAL_DOTTED.equals(style)) { drawDottedBorder(graphics, rgbs, ICSSStyle.LEFT, rect, width); } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { drawDashedBorder(graphics, rgbs, ICSSStyle.LEFT, rect, width); } else { double yTopRate = ((double) (innerRect.y - rect.y)) / width; double yBottomRate = ((double) (rect.bottom() - innerRect.bottom())) / width; graphics.pushState(); for (int i = 0; i < width; i++) { Color color = new Color(Display.getCurrent(), rgbs[rgbs.length * i / width]); graphics.setForegroundColor(color); graphics.drawLine(x + i, topY + (int) (i * yTopRate), x + i, bottomY - (int) (i * yBottomRate)); color.dispose(); } graphics.popState(); } }
private void paintTopEdge(Graphics graphics, RGB[] rgbs, String style, Rectangle rect, Rectangle innerRect) { int leftX = rect.x; int rightX = rect.right() - 1; int y = rect.y; int width = innerRect.y - rect.y; if (ICSSPropertyID.VAL_DOTTED.equals(style)) { drawDottedBorder(graphics, rgbs, ICSSStyle.TOP, rect, width); } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { drawDashedBorder(graphics, rgbs, ICSSStyle.TOP, rect, width); } else { double xLeftRate = ((double) (innerRect.x - rect.x)) / width; double xRightRate = ((double) (rect.right() - innerRect.right())) / width; graphics.pushState(); for (int i = 0; i < width; i++) { Color color = new Color(Display.getCurrent(), rgbs[rgbs.length * i / width]); graphics.setForegroundColor(color); graphics.drawLine((int) (leftX + i * xLeftRate), y + i, (int) (rightX - i * xRightRate), y + i); color.dispose(); } graphics.popState(); } }
/** * draw a mask to a rectangle * * @param Graphics * @param Rectangle * @param Color */ public static void maskRectangle(Graphics g, Rectangle rect, Color color) { // set default if one not provided if (color == null) { color = ColorConstants.blue; } // get old information and keep them int lineStyle = g.getLineStyle(); Color foregroundColor = g.getForegroundColor(); g.setLineStyle(SWT.LINE_SOLID); g.setForegroundColor(color); for (int i = 0, n = rect.height; i < n; i++, i++) { for (int j = 0, m = rect.width; j < m; j++, j++) { g.drawLine(rect.x + j, rect.y + i, rect.x + j, rect.y + i); } } // restore to the old state g.setLineStyle(lineStyle); g.setForegroundColor(foregroundColor); }
private void paintBottomEdge(Graphics graphics, RGB[] rgbs, String style, Rectangle rect, Rectangle innerRect) { int leftX = rect.x; int rightX = rect.right() - 1; int y = rect.bottom() - 1; int width = rect.bottom() - innerRect.bottom(); if (ICSSPropertyID.VAL_DOTTED.equals(style)) { drawDottedBorder(graphics, rgbs, ICSSStyle.BOTTOM, rect, width); } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { drawDashedBorder(graphics, rgbs, ICSSStyle.BOTTOM, rect, width); } else { double xLeftRate = ((double) (innerRect.x - rect.x)) / width; double xRightRate = ((double) (rect.right() - innerRect.right())) / width; graphics.pushState(); for (int i = 0; i < width; i++) { Color color = new Color(Display.getCurrent(), rgbs[rgbs.length * i / width]); graphics.setForegroundColor(color); graphics.drawLine(leftX + (int) (i * xLeftRate), y - i, rightX - (int) (i * xRightRate), y - i); color.dispose(); } graphics.popState(); } }
private void paintRightEdge(Graphics graphics, RGB[] rgbs, String style, Rectangle rect, Rectangle innerRect) { int x = rect.right() - 1; int topY = rect.y; int bottomY = rect.bottom() - 1; int width = rect.right() - innerRect.right(); if (ICSSPropertyID.VAL_DOTTED.equals(style)) { drawDottedBorder(graphics, rgbs, ICSSStyle.RIGHT, rect, width); } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { drawDashedBorder(graphics, rgbs, ICSSStyle.RIGHT, rect, width); } else { graphics.pushState(); for (int i = 0; i < width; i++) { double yTopRate = ((double) (innerRect.y - rect.y)) / width; double yBottomRate = ((double) (rect.bottom() - innerRect .bottom())) / width; Color color = new Color(Display.getCurrent(), rgbs[rgbs.length * i / width]); graphics.setForegroundColor(color); graphics.drawLine(x - i, topY + (int) (i * yTopRate), x - i, bottomY - (int) (i * yBottomRate)); color.dispose(); } graphics.popState(); } }
int topY = top + (height - length) / 2 + 1; for (int i = 0; i < length; i++) { g.drawLine(leftX + i, topY + i, leftX - i + decoratorWidth, topY + i);