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); }
/** * Convert an AWT Shape to an SWT Path. * * @param shape * @return the SWT Path or <code>null</code> if <code>shape == null</code> */ private Path convertToPath(Shape shape) { if (shape == null) { return null; } Path path = new Path(_gc.getDevice()); PathIterator iter = shape.getPathIterator(null); float[] coords = new float[6]; while (!iter.isDone()) { int op = iter.currentSegment(coords); switch (op) { case PathIterator.SEG_MOVETO: path.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: path.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: path.close(); break; } iter.next(); } return path; }
public void translate(double tx, double ty) { if (_transform == null) { _transform = new Transform(_gc.getDevice()); } _transform.translate((int) tx, (int) ty); _gc.setTransform(_transform); if (_clippingArea != null) { AffineTransform t = new AffineTransform(); t.translate(-tx, -ty); _clippingArea.transform(t); } }
// @see // org.gudy.azureus2.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, org.gudy.azureus2.ui.swt.views.table.TableCellSWT) public void cellPaint(GC gc, TableCellSWT cell) { VuzeActivitiesEntry entry = (VuzeActivitiesEntry) cell.getDataSource(); if (entry == null) { return; } TableRow row = cell.getTableRow(); if (row == null) { return; } String text = (String) row.getData("text"); if (text != null && text.length() > 0) { if (font == null) { FontData[] fontData = gc.getFont().getFontData(); fontData[0].setStyle(SWT.BOLD); font = new Font(gc.getDevice(), fontData); } gc.setFont(font); Rectangle bounds = getDrawBounds(cell); GCStringPrinter sp = new GCStringPrinter(gc, text, bounds, true, true, SWT.WRAP | SWT.CENTER); sp.calculateMetrics(); if (sp.hasHitUrl()) { URLInfo[] hitUrlInfo = sp.getHitUrlInfo(); for (int i = 0; i < hitUrlInfo.length; i++) { URLInfo info = hitUrlInfo[i]; // handle fake row when showing in column editor info.urlUnderline = cell.getTableRow() == null || cell.getTableRow().isSelected(); if (info.urlUnderline) { info.urlColor = null; } else { info.urlColor = colorLinkNormal; } } int[] mouseOfs = cell.getMouseOffset(); if (mouseOfs != null) { Rectangle realBounds = cell.getBounds(); URLInfo hitUrl = sp.getHitUrl(mouseOfs[0] + realBounds.x, mouseOfs[1] + realBounds.y); if (hitUrl != null) { hitUrl.urlColor = colorLinkHover; } } } sp.printString(); } }
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(); } }
public void setColor(java.awt.Color color) { if (color.equals(_awt_color)) { return; } Color col = new Color(_gc.getDevice(), color.getRed(), color.getGreen(), color.getBlue()); _gc.setForeground(col); _gc.setBackground(col); _gc.setAlpha(color.getAlpha()); if (_color != null) { _color.dispose(); } _color = col; _awt_color = color; }
public void drawImage(FSImage image, int x, int y) { Image img = ((SWTFSImage) image).getImage(); if (img == null) { int width = image.getWidth(); int height = image.getHeight(); Color oldBG = _gc.getBackground(); Color oldFG = _gc.getForeground(); _gc.setBackground(_gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); _gc.setForeground(_gc.getDevice().getSystemColor(SWT.COLOR_BLACK)); _gc.fillRectangle(x, y, width, height); _gc.drawRectangle(x, y, width, height); _gc.drawLine(x, y, x + width - 1, y + height - 1); _gc.drawLine(x, y + height - 1, x + width - 1, y); _gc.setBackground(oldBG); _gc.setForeground(oldFG); } else { Rectangle bounds = img.getBounds(); _gc.drawImage( img, 0, 0, bounds.width, bounds.height, x, y, image.getWidth(), image.getHeight()); } }