/** * 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); } }
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()); } }