diff --git a/core/src/main/java/edu/umd/cs/piccolo/PNode.java b/core/src/main/java/edu/umd/cs/piccolo/PNode.java index 506e20d..c867b59 100644 --- a/core/src/main/java/edu/umd/cs/piccolo/PNode.java +++ b/core/src/main/java/edu/umd/cs/piccolo/PNode.java @@ -1454,11 +1454,11 @@ } /** - * Set the bounds of this node to the given value. These bounds are stored + * Set the bounds of this node to the given position and size. These bounds are stored * in the local coordinate system of this node. * * If the width or height is less then or equal to zero then the bound's - * emtpy bit will be set to true. + * empty bit will be set to true. * * Subclasses must call the super.setBounds() method. * diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTPath.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTPath.java index 50bae39..b0e2f29 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTPath.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/PSWTPath.java @@ -69,10 +69,6 @@ * @author Jesse Grosjean */ public class PSWTPath extends PNode { - - /** - * - */ private static final long serialVersionUID = 1L; /** @@ -92,15 +88,24 @@ private Paint strokePaint; - boolean updatingBoundsFromPath; - Shape origShape; - Shape shape; + private boolean updatingBoundsFromPath; + private Shape origShape; + private Shape shape; - PAffineTransform internalXForm; - AffineTransform inverseXForm; + private PAffineTransform internalXForm; + private AffineTransform inverseXForm; - double[] shapePts; + private double[] shapePts; + /** + * Creates a path representing the rectangle provided. + * + * @param x left of rectangle + * @param y top of rectangle + * @param width width of rectangle + * @param height height of rectangle + * @return created rectangle + */ public static PSWTPath createRectangle(final float x, final float y, final float width, final float height) { TEMP_RECTANGLE.setFrame(x, y, width, height); final PSWTPath result = new PSWTPath(TEMP_RECTANGLE); @@ -108,6 +113,17 @@ return result; } + /** + * Creates a path representing the rounded rectangle provided. + * + * @param x left of rectangle + * @param y top of rectangle + * @param width width of rectangle + * @param height height of rectangle + * @param arcWidth width of the arc at the corners + * @param arcHeight height of arc at the corners + * @return created rounded rectangle + */ public static PSWTPath createRoundRectangle(final float x, final float y, final float width, final float height, final float arcWidth, final float arcHeight) { TEMP_ROUNDRECTANGLE.setRoundRect(x, y, width, height, arcWidth, arcHeight); @@ -116,6 +132,16 @@ return result; } + /** + * Creates a path representing an ellipse that covers the rectangle + * provided. + * + * @param x left of rectangle + * @param y top of rectangle + * @param width width of rectangle + * @param height height of rectangle + * @return created ellipse + */ public static PSWTPath createEllipse(final float x, final float y, final float width, final float height) { TEMP_ELLIPSE.setFrame(x, y, width, height); final PSWTPath result = new PSWTPath(TEMP_ELLIPSE); @@ -137,6 +163,9 @@ return result; } + /** + * Creates an empty PSWTPath. + */ public PSWTPath() { strokePaint = DEFAULT_STROKE_PAINT; } @@ -149,14 +178,23 @@ // **************************************************************** // Stroke // **************************************************************** - + /** + * Returns the paint to use when drawing the stroke of the shape. + * + * @return path's stroke paint + */ public Paint getStrokePaint() { return strokePaint; } - public void setStrokeColor(final Paint aPaint) { + /** + * Sets the paint to use when drawing the stroke of the shape. + * + * @param strokeColor new stroke color + */ + public void setStrokeColor(final Paint strokeColor) { final Paint old = strokePaint; - strokePaint = aPaint; + strokePaint = strokeColor; invalidatePaint(); firePropertyChange(PPath.PROPERTY_CODE_STROKE_PAINT, PPath.PROPERTY_STROKE_PAINT, old, strokePaint); } @@ -201,6 +239,11 @@ } } + /** + * Returns true if this shape intersects the bounds provided. + * + * + */ public boolean intersects(Rectangle2D aBounds) { if (super.intersects(aBounds)) { @@ -219,6 +262,9 @@ return false; } + /** + * Recalculates the path's bounds by examining it's associated shape. + */ public void updateBoundsFromPath() { updatingBoundsFromPath = true; @@ -243,7 +289,11 @@ // **************************************************************** // Painting // **************************************************************** - + /** + * Paints the path on the context provided. + * + * @param paintContext the context onto which the path will be painted + */ protected void paint(final PPaintContext paintContext) { final Paint p = getPaint(); final SWTGraphics2D g2 = (SWTGraphics2D) paintContext.getGraphics(); @@ -254,52 +304,12 @@ if (p != null) { g2.setBackground((Color) p); - - final double lineWidth = g2.getTransformedLineWidth(); - if (shape instanceof Rectangle2D) { - g2.fillRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth); - } - else if (shape instanceof Ellipse2D) { - g2.fillOval(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth); - } - else if (shape instanceof Arc2D) { - g2.fillArc(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth, shapePts[4], shapePts[5]); - } - else if (shape instanceof RoundRectangle2D) { - g2.fillRoundRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth, shapePts[4], shapePts[5]); - } - else { - g2.fill(shape); - } + fillShape(g2); } if (strokePaint != null) { g2.setColor((Color) strokePaint); - - final double lineWidth = g2.getTransformedLineWidth(); - if (shape instanceof Rectangle2D) { - g2.drawRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth); - } - else if (shape instanceof Ellipse2D) { - g2.drawOval(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth); - } - else if (shape instanceof Arc2D) { - g2.drawArc(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth, shapePts[4], shapePts[5]); - } - else if (shape instanceof RoundRectangle2D) { - g2.drawRoundRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, - shapePts[3] - lineWidth, shapePts[4], shapePts[5]); - } - else { - g2.draw(shape); - } + drawShape(g2); } if (inverseXForm != null) { @@ -307,10 +317,61 @@ } } - public void setShape(final Shape aShape) { - shape = cloneShape(aShape); + private void drawShape(final SWTGraphics2D g2) { + final double lineWidth = g2.getTransformedLineWidth(); + if (shape instanceof Rectangle2D) { + g2.drawRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3] + - lineWidth); + } + else if (shape instanceof Ellipse2D) { + g2.drawOval(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3] + - lineWidth); + } + else if (shape instanceof Arc2D) { + g2.drawArc(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3] + - lineWidth, shapePts[4], shapePts[5]); + } + else if (shape instanceof RoundRectangle2D) { + g2.drawRoundRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, + shapePts[3] - lineWidth, shapePts[4], shapePts[5]); + } + else { + g2.draw(shape); + } + } + + private void fillShape(final SWTGraphics2D g2) { + final double lineWidth = g2.getTransformedLineWidth(); + if (shape instanceof Rectangle2D) { + g2.fillRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3] + - lineWidth); + } + else if (shape instanceof Ellipse2D) { + g2.fillOval(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3] + - lineWidth); + } + else if (shape instanceof Arc2D) { + g2.fillArc(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, shapePts[3] + - lineWidth, shapePts[4], shapePts[5]); + } + else if (shape instanceof RoundRectangle2D) { + g2.fillRoundRect(shapePts[0] + lineWidth / 2, shapePts[1] + lineWidth / 2, shapePts[2] - lineWidth, + shapePts[3] - lineWidth, shapePts[4], shapePts[5]); + } + else { + g2.fill(shape); + } + } + + /** + * Changes the underlying shape of this PSWTPath. + * + * @param newShape new associated shape of this PSWTPath + */ + public void setShape(final Shape newShape) { + shape = cloneShape(newShape); origShape = shape; - updateShapePoints(aShape); + updateShapePoints(newShape); firePropertyChange(PPath.PROPERTY_CODE_PATH, PPath.PROPERTY_PATH, null, shape); updateBoundsFromPath(); @@ -389,7 +450,7 @@ final Line2D l2 = (Line2D) aShape; return new Line2D.Double(l2.getP1(), l2.getP2()); } - else { + else { final GeneralPath aPath = new GeneralPath(); aPath.append(aShape, false); return aPath; diff --git a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java index 7c04543..e27dc87 100644 --- a/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java +++ b/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java @@ -83,24 +83,37 @@ * @author Lance Good */ public class SWTGraphics2D extends Graphics2D { - private static final boolean DEFAULT_STRING_TRANSPARENCY = true; + + /** + * The number of Graphics Contexts active as determined by called to + * incrementGCCount and decrementGCCount. + */ protected static int CACHE_COUNT = 0; + /** Map from font names to Fonts. */ protected static HashMap FONT_CACHE = new HashMap(); + /** Map from awt colors to swt colors. */ protected static HashMap COLOR_CACHE = new HashMap(); + /** Map from awt shapess to swt Paths. */ protected static HashMap SHAPE_CACHE = new HashMap(); + /** Buffer used to extract the graphics device. */ protected static BufferedImage BUFFER = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - private static Point PT = new Point(); - private static Rectangle2D RECT = new Rectangle2D.Double(); - private static Rectangle2D LINE_RECT = new Rectangle2D.Double(); + private static Point TEMP_POINT = new Point(); + private static Rectangle2D TEMP_RECT = new Rectangle2D.Double(); + private static Rectangle2D TEMP_LINE_RECT = new Rectangle2D.Double(); private static org.eclipse.swt.graphics.Rectangle SWT_RECT = new org.eclipse.swt.graphics.Rectangle(0, 0, 0, 0); + /** The Underlying GraphicsContext provided by swt. */ protected GC gc; + /** Device onto which all graphics operations will ultimately take place. */ protected Device device; + /** The current transform to apply to drawing operations. */ protected AffineTransform transform = new AffineTransform(); - private Transform swtTransform; + private final Transform swtTransform; + /** The current font to use when drawing text. */ protected org.eclipse.swt.graphics.Font curFont; + /** The current stroke width to use when drawing lines. */ protected double lineWidth = 1.0; /** @@ -123,9 +136,7 @@ // GET CLIP // ////////////////// - /** - * @see java.awt.Graphics#getClipBounds() - */ + /** {@inheritDoc} */ public Rectangle getClipBounds() { final org.eclipse.swt.graphics.Rectangle rect = gc.getClipping(); final Rectangle aRect = new Rectangle(rect.x, rect.y, rect.width, rect.height); @@ -138,10 +149,11 @@ return aRect; } + /** {@inheritDoc} */ public void clipRect(final int x, final int y, final int width, final int height) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); - SWTShapeManager.awtToSWT(RECT, SWT_RECT); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); + SWTShapeManager.awtToSWT(TEMP_RECT, SWT_RECT); org.eclipse.swt.graphics.Rectangle clip = gc.getClipping(); clip = clip.intersection(SWT_RECT); @@ -149,10 +161,11 @@ gc.setClipping(clip); } + /** {@inheritDoc} */ public void setClip(final int x, final int y, final int width, final int height) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); - SWTShapeManager.awtToSWT(RECT, SWT_RECT); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); + SWTShapeManager.awtToSWT(TEMP_RECT, SWT_RECT); gc.setClipping(SWT_RECT); } @@ -174,7 +187,7 @@ } /** - * This method isn't really supported by SWT - so will use the shape bounds + * This method isn't really supported by SWT - so will use the shape bounds. * * @param clip the desired clipping region's shape, will be simplified to * its bounds @@ -192,6 +205,7 @@ } } + /** {@inheritDoc} */ public Shape getClip() { final org.eclipse.swt.graphics.Rectangle rect = gc.getClipping(); final Rectangle2D aRect = new Rectangle2D.Double(rect.x, rect.y, rect.width, rect.height); @@ -204,10 +218,11 @@ return aRect; } - // /////////////////// - // DEVICE SPECIFIC - // /////////////////// - + /** + * Returns a dummy device configuration. + * + * @return a dummy device configuration + */ public GraphicsConfiguration getDeviceConfiguration() { return ((Graphics2D) BUFFER.getGraphics()).getDeviceConfiguration(); } @@ -216,22 +231,26 @@ // COLOR METHODS // ////////////// + /** {@inheritDoc} */ public Paint getPaint() { return getColor(); } + /** {@inheritDoc} */ public void setPaint(final Paint paint) { if (paint instanceof Color) { setColor((Color) paint); } } + /** {@inheritDoc} */ public Color getColor() { final org.eclipse.swt.graphics.Color color = gc.getForeground(); final Color awtColor = new Color(color.getRed(), color.getGreen(), color.getBlue()); return awtColor; } + /** {@inheritDoc} */ public void setColor(final Color c) { org.eclipse.swt.graphics.Color cachedColor = (org.eclipse.swt.graphics.Color) COLOR_CACHE.get(c); if (cachedColor == null) { @@ -241,10 +260,16 @@ gc.setForeground(cachedColor); } - public void setColor(final org.eclipse.swt.graphics.Color c) { - gc.setForeground(c); + /** + * Sets the foreground color to the provided swt color. + * + * @param foregroundColor new foreground color + */ + public void setColor(final org.eclipse.swt.graphics.Color foregroundColor) { + gc.setForeground(foregroundColor); } + /** {@inheritDoc} */ public void setBackground(final Color c) { org.eclipse.swt.graphics.Color cachedColor = (org.eclipse.swt.graphics.Color) COLOR_CACHE.get(c); if (cachedColor == null) { @@ -254,10 +279,16 @@ gc.setBackground(cachedColor); } - public void setBackground(final org.eclipse.swt.graphics.Color c) { - gc.setBackground(c); + /** + * Sets the background color to the provided swt color. + * + * @param backgroundColor new background color + */ + public void setBackground(final org.eclipse.swt.graphics.Color backgroundColor) { + gc.setBackground(backgroundColor); } + /** {@inheritDoc} */ public Color getBackground() { final org.eclipse.swt.graphics.Color color = gc.getBackground(); final Color awtColor = new Color(color.getRed(), color.getGreen(), color.getBlue()); @@ -268,15 +299,26 @@ // FONT METHODS // ////////////// + /** + * Returns the current swt font to use when drawing. + * + * @return current swt font + */ public org.eclipse.swt.graphics.Font getSWTFont() { return curFont; } + /** + * Returns the font metrics of the current SWT font. + * + * @return font metrics of the current SWT font + */ public org.eclipse.swt.graphics.FontMetrics getSWTFontMetrics() { gc.setFont(curFont); return gc.getFontMetrics(); } + /** {@inheritDoc} */ public Font getFont() { if (curFont != null) { int style = Font.PLAIN; @@ -299,6 +341,7 @@ } } + /** {@inheritDoc} */ public void setFont(final Font font) { final String fontString = "name=" + font.getFamily() + ";bold=" + font.isBold() + ";italic=" + font.isItalic() + ";size=" + font.getSize(); @@ -306,10 +349,17 @@ curFont = getFont(fontString); } + /** {@inheritDoc} */ public void setFont(final org.eclipse.swt.graphics.Font font) { curFont = font; } + /** + * Returns the SWT font matching the given font string. + * + * @param fontString description of the font desired + * @return matching font, or null if not found + */ public org.eclipse.swt.graphics.Font getFont(final String fontString) { org.eclipse.swt.graphics.Font cachedFont = (org.eclipse.swt.graphics.Font) FONT_CACHE.get(fontString); if (cachedFont == null) { @@ -339,15 +389,18 @@ } /** + * Deprecated since SWT now handles this. + * * @deprecated + * @return font that's been transformed by the current transform */ protected org.eclipse.swt.graphics.Font getTransformedFont() { if (curFont != null) { final FontData fontData = curFont.getFontData()[0]; int height = fontData.getHeight(); - RECT.setRect(0, 0, height, height); - SWTShapeManager.transform(RECT, transform); - height = (int) (RECT.getHeight() + 0.5); + TEMP_RECT.setRect(0, 0, height, height); + SWTShapeManager.transform(TEMP_RECT, transform); + height = (int) (TEMP_RECT.getHeight() + 0.5); final String fontString = "name=" + fontData.getName() + ";bold=" + ((fontData.getStyle() & SWT.BOLD) != 0) + ";italic=" + ((fontData.getStyle() & SWT.ITALIC) != 0) + ";size=" + height; @@ -360,46 +413,55 @@ // AFFINE TRANSFORM METHODS // ///////////////////////// + /** {@inheritDoc} */ public void translate(final int x, final int y) { transform.translate(x, y); updateSWTTransform(); } + /** {@inheritDoc} */ public void translate(final double tx, final double ty) { transform.translate(tx, ty); updateSWTTransform(); } + /** {@inheritDoc} */ public void rotate(final double theta) { transform.rotate(theta); updateSWTTransform(); } + /** {@inheritDoc} */ public void rotate(final double theta, final double x, final double y) { transform.rotate(theta, x, y); updateSWTTransform(); } + /** {@inheritDoc} */ public void scale(final double sx, final double sy) { transform.scale(sx, sy); updateSWTTransform(); } + /** {@inheritDoc} */ public void shear(final double shx, final double shy) { transform.shear(shx, shy); updateSWTTransform(); } + /** {@inheritDoc} */ public void transform(final AffineTransform Tx) { transform.concatenate(Tx); updateSWTTransform(); } + /** {@inheritDoc} */ public void setTransform(final AffineTransform Tx) { transform = (AffineTransform) Tx.clone(); updateSWTTransform(); } + /** {@inheritDoc} */ public AffineTransform getTransform() { return (AffineTransform) transform.clone(); } @@ -411,7 +473,7 @@ * Updates the SWT transform instance such that it matches AWTs counterpart. */ private void updateSWTTransform() { - double[] m = new double[6]; + final double[] m = new double[6]; transform.getMatrix(m); swtTransform.setElements((float) m[0], (float) m[1], (float) m[2], (float) m[3], (float) m[4], (float) m[5]); } @@ -423,14 +485,13 @@ * @return the corresponding path object. Must be disposed() when no longer * used. */ + private Path pathIterator2Path(final PathIterator iter) { + final float[] coords = new float[6]; - private Path pathIterator2Path(PathIterator iter) { - float[] coords = new float[6]; - - Path path = new Path(device); + final Path path = new Path(device); while (!iter.isDone()) { - int type = iter.currentSegment(coords); + final int type = iter.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: @@ -452,6 +513,8 @@ case PathIterator.SEG_CUBICTO: path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; + default: + // log this? } iter.next(); @@ -459,15 +522,12 @@ return path; } - // ///////////////////////////// - // ///////////////////////////// - // DRAWING AND FILLING METHODS - // ///////////////////////////// - + /** {@inheritDoc} */ public void clearRect(final int x, final int y, final int width, final int height) { fillRect(x, y, width, height); } + /** {@inheritDoc} */ public void draw(final Shape s) { if (s instanceof Rectangle2D) { final Rectangle2D r2 = (Rectangle2D) s; @@ -495,6 +555,7 @@ } } + /** {@inheritDoc} */ public void fill(final Shape s) { if (s instanceof Rectangle2D) { final Rectangle2D r2 = (Rectangle2D) s; @@ -522,11 +583,12 @@ } } + /** {@inheritDoc} */ public void drawPolyline(final int[] xPoints, final int[] yPoints, final int nPoints) { final int[] ptArray = new int[2 * nPoints]; for (int i = 0; i < nPoints; i++) { - PT.setLocation(xPoints[i], yPoints[i]); - transform.transform(PT, PT); + TEMP_POINT.setLocation(xPoints[i], yPoints[i]); + transform.transform(TEMP_POINT, TEMP_POINT); ptArray[2 * i] = xPoints[i]; ptArray[2 * i + 1] = yPoints[i]; } @@ -535,16 +597,18 @@ gc.drawPolyline(ptArray); } + /** {@inheritDoc} */ public void drawPolyline(final double[] pts) { final int[] intPts = SWTShapeManager.transform(pts, transform); gc.drawPolyline(intPts); } + /** {@inheritDoc} */ public void drawPolygon(final int[] xPoints, final int[] yPoints, final int nPoints) { final int[] ptArray = new int[2 * nPoints]; for (int i = 0; i < nPoints; i++) { - PT.setLocation(xPoints[i], yPoints[i]); - transform.transform(PT, PT); + TEMP_POINT.setLocation(xPoints[i], yPoints[i]); + transform.transform(TEMP_POINT, TEMP_POINT); ptArray[2 * i] = xPoints[i]; ptArray[2 * i + 1] = yPoints[i]; } @@ -552,16 +616,18 @@ gc.drawPolygon(ptArray); } + /** {@inheritDoc} */ public void fillPolygon(final double[] pts) { final int[] intPts = SWTShapeManager.transform(pts, transform); gc.fillPolygon(intPts); } + /** {@inheritDoc} */ public void fillPolygon(final int[] xPoints, final int[] yPoints, final int nPoints) { final int[] ptArray = new int[2 * nPoints]; for (int i = 0; i < nPoints; i++) { - PT.setLocation(xPoints[i], yPoints[i]); - transform.transform(PT, PT); + TEMP_POINT.setLocation(xPoints[i], yPoints[i]); + transform.transform(TEMP_POINT, TEMP_POINT); ptArray[2 * i] = xPoints[i]; ptArray[2 * i + 1] = yPoints[i]; } @@ -569,22 +635,33 @@ gc.fillPolygon(ptArray); } + /** {@inheritDoc} */ public void drawLine(final int x1, final int y1, final int x2, final int y2) { drawLine((double) x1, (double) y1, (double) x2, (double) y2); } - public void drawLine(double x1, double y1, double x2, double y2) { - PT.setLocation(x1, y1); - transform.transform(PT, PT); - x1 = (int) PT.getX(); - y1 = (int) PT.getY(); - PT.setLocation(x2, y2); - transform.transform(PT, PT); - x2 = (int) PT.getX(); - y2 = (int) PT.getY(); + /** + * Draws a line, using the current color, between the points (x1, y1) and + * (x2, y2) in this graphics context's coordinate system. + * + * @param x1 the first point's x coordinate. + * @param y1 the first point's y coordinate. + * @param x2 the second point's x coordinate. + * @param y2 the second point's y coordinate. + */ + public void drawLine(final double x1, final double y1, final double x2, final double y2) { + TEMP_POINT.setLocation(x1, y1); + transform.transform(TEMP_POINT, TEMP_POINT); + final double transformedX1 = (int) TEMP_POINT.getX(); + final double transformedY1 = (int) TEMP_POINT.getY(); + TEMP_POINT.setLocation(x2, y2); + transform.transform(TEMP_POINT, TEMP_POINT); + final double transformedX2 = (int) TEMP_POINT.getX(); + final double transformedY2 = (int) TEMP_POINT.getY(); gc.setLineWidth(getTransformedLineWidth()); - gc.drawLine((int) (x1 + 0.5), (int) (y1 + 0.5), (int) (x2 + 0.5), (int) (y2 + 0.5)); + gc.drawLine((int) (transformedX1 + 0.5), (int) (transformedY1 + 0.5), (int) (transformedX2 + 0.5), + (int) (transformedY2 + 0.5)); } // ************************************************************************** @@ -593,240 +670,538 @@ // ************************************************************************** // * + /** + * Copies the image to the specified position. + * + * @param img swt image to be copied + * @param x x component of position + * @param y y component of position + */ public void copyArea(final org.eclipse.swt.graphics.Image img, final double x, final double y) { - PT.setLocation(x, y); - transform.transform(PT, PT); + TEMP_POINT.setLocation(x, y); + transform.transform(TEMP_POINT, TEMP_POINT); - gc.copyArea(img, (int) (PT.getX() + 0.5), (int) (PT.getY() + 0.5)); + gc.copyArea(img, (int) (TEMP_POINT.getX() + 0.5), (int) (TEMP_POINT.getY() + 0.5)); } + /** {@inheritDoc} */ public void copyArea(final int x, final int y, final int width, final int height, final int dx, final int dy) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); - PT.setLocation(dx, dy); - transform.transform(PT, PT); - gc.copyArea((int) RECT.getX(), (int) RECT.getY(), (int) RECT.getWidth(), (int) RECT.getHeight(), (int) PT - .getX(), (int) PT.getY()); + TEMP_POINT.setLocation(dx, dy); + transform.transform(TEMP_POINT, TEMP_POINT); + gc.copyArea((int) TEMP_RECT.getX(), (int) TEMP_RECT.getY(), (int) TEMP_RECT.getWidth(), (int) TEMP_RECT + .getHeight(), (int) TEMP_POINT.getX(), (int) TEMP_POINT.getY()); } - public void drawString(String str, int x, int y, boolean isTransparent) { + /** + * Renders the text of the specified String, using the current text + * attribute state in the Graphics2D context. The baseline of the first + * character is at position (x, y) in the User Space. The rendering + * attributes applied include the Clip, Transform, Paint, Font and Composite + * attributes. For characters in script systems such as Hebrew and Arabic, + * the glyphs can be rendered from right to left, in which case the + * coordinate supplied is the location of the leftmost character on the + * baseline. + * + * @param str the string to be rendered + * @param x the x coordinate of the location where the String should be + * rendered + * @param y the y coordinate of the location where the String should be + * rendered + * @param isTransparent whether a background should be painted behind the + * text + */ + public void drawString(final String str, final int x, final int y, final boolean isTransparent) { gc.setTransform(swtTransform); gc.drawString(str, x, y, isTransparent); gc.setTransform(null); } + /** {@inheritDoc} */ public void drawString(final String str, final int x, final int y) { drawString(str, x, y, DEFAULT_STRING_TRANSPARENCY); } - public void drawString(String str, double x, double y) { + /** + * Renders the text of the specified String, using the current text + * attribute state in the Graphics2D context. The baseline of the first + * character is at position (x, y) in the User Space. The rendering + * attributes applied include the Clip, Transform, Paint, Font and Composite + * attributes. For characters in script systems such as Hebrew and Arabic, + * the glyphs can be rendered from right to left, in which case the + * coordinate supplied is the location of the leftmost character on the + * baseline. + * + * @param str the string to be rendered + * @param x the x coordinate of the location where the String should be + * rendered + * @param y the y coordinate of the location where the String should be + * rendered + */ + public void drawString(final String str, final double x, final double y) { drawString(str, (int) (x + 0.5), (int) (y + 0.5)); } - public void drawString(String str, double x, double y, boolean isTransparent) { + /** + * Renders the text of the specified String, using the current text + * attribute state in the Graphics2D context. The baseline of the first + * character is at position (x, y) in the User Space. The rendering + * attributes applied include the Clip, Transform, Paint, Font and Composite + * attributes. For characters in script systems such as Hebrew and Arabic, + * the glyphs can be rendered from right to left, in which case the + * coordinate supplied is the location of the leftmost character on the + * baseline. + * + * @param str the string to be rendered + * @param x the x coordinate of the location where the String should be + * rendered + * @param y the y coordinate of the location where the String should be + * rendered + * @param isTransparent whether a background should be painted behind the + * text + */ + public void drawString(final String str, final double x, final double y, final boolean isTransparent) { drawString(str, (int) (x + 0.5), (int) (y + 0.5), isTransparent); } + /** {@inheritDoc} */ public void drawString(final String str, final float x, final float y) { drawString(str, (int) (x + 0.5), (int) (y + 0.5)); } - public void drawText(final String s, final double x, final double y) { - drawString(s, (int) (x + 0.5), (int) (y + 0.5)); + /** + * Renders the text of the specified String, using the current text + * attribute state in the Graphics2D context. The baseline of the first + * character is at position (x, y) in the User Space. The rendering + * attributes applied include the Clip, Transform, Paint, Font and Composite + * attributes. For characters in script systems such as Hebrew and Arabic, + * the glyphs can be rendered from right to left, in which case the + * coordinate supplied is the location of the leftmost character on the + * baseline. + * + * @param str the string to be rendered + * @param x the x coordinate of the location where the String should be + * rendered + * @param y the y coordinate of the location where the String should be + * rendered + */ + public void drawText(final String str, final double x, final double y) { + drawString(str, (int) (x + 0.5), (int) (y + 0.5)); } - public void drawText(final String s, final double x, final double y, final int flags) { - drawText(s, (int) (x + 0.5), (int) (y + 0.5), flags); + /** + * Renders the text of the specified String, using the current text + * attribute state in the Graphics2D context. The baseline of the first + * character is at position (x, y) in the User Space. The rendering + * attributes applied include the Clip, Transform, Paint, Font and Composite + * attributes. For characters in script systems such as Hebrew and Arabic, + * the glyphs can be rendered from right to left, in which case the + * coordinate supplied is the location of the leftmost character on the + * baseline. + * + * @param str the string to be rendered + * @param x the x coordinate of the location where the String should be + * rendered + * @param y the y coordinate of the location where the String should be + * rendered + * @param flags flags to apply to the string as defined by SWT + */ + public void drawText(final String str, final double x, final double y, final int flags) { + drawText(str, (int) (x + 0.5), (int) (y + 0.5), flags); } + /** + * Renders the text of the specified String, using the current text + * attribute state in the Graphics2D context. The baseline of the first + * character is at position (x, y) in the User Space. The rendering + * attributes applied include the Clip, Transform, Paint, Font and Composite + * attributes. For characters in script systems such as Hebrew and Arabic, + * the glyphs can be rendered from right to left, in which case the + * coordinate supplied is the location of the leftmost character on the + * baseline. + * + * @param str the string to be rendered + * @param x the x coordinate of the location where the String should be + * rendered + * @param y the y coordinate of the location where the String should be + * rendered + * @param flags flags to apply to the string as defined by SWT + */ + public void drawText(final String str, final int x, final int y, final int flags) { + gc.setTransform(swtTransform); + gc.drawText(str, x, y, flags); + gc.setTransform(null); + } + + /** {@inheritDoc} */ public void drawRect(final int x, final int y, final int width, final int height) { drawRect((double) x, (double) y, (double) width, (double) height); } + /** + * Draws the outline of the specified rectangle. The left and right edges of + * the rectangle are at x and x + width. The top and bottom edges are at y + * and y + height. The rectangle is drawn using the graphics context's + * current color. + * + * @param x the x coordinate of the rectangle to be drawn. + * @param y the y coordinate of the rectangle to be drawn. + * @param width the width of the rectangle to be drawn. + * @param height the height of the rectangle to be drawn. + */ public void drawRect(final double x, final double y, final double width, final double height) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); - SWTShapeManager.awtToSWT(RECT, SWT_RECT); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); + SWTShapeManager.awtToSWT(TEMP_RECT, SWT_RECT); gc.setLineWidth(getTransformedLineWidth()); gc.drawRectangle(SWT_RECT); } + /** {@inheritDoc} */ public void fillRect(final int x, final int y, final int width, final int height) { fillRect((double) x, (double) y, (double) width, (double) height); } + /** + * Fills the specified rectangle. The left and right edges of the rectangle + * are at x and x + width - 1. The top and bottom edges are at y and y + + * height - 1. The resulting rectangle covers an area width pixels wide by + * height pixels tall. The rectangle is filled using the graphics context's + * current color. + * + * @param x the x coordinate of the rectangle to be filled. + * @param y the y coordinate of the rectangle to be filled. + * @param width the width of the rectangle to be filled. + * @param height the height of the rectangle to be filled. + */ public void fillRect(final double x, final double y, final double width, final double height) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); - SWTShapeManager.awtToSWT(RECT, SWT_RECT); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); + SWTShapeManager.awtToSWT(TEMP_RECT, SWT_RECT); gc.fillRectangle(SWT_RECT); } + /** {@inheritDoc} */ public void drawRoundRect(final int x, final int y, final int width, final int height, final int arcWidth, final int arcHeight) { drawRoundRect((double) x, (double) y, (double) width, (double) height, (double) arcWidth, (double) arcHeight); } - public void drawRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); - x = RECT.getX(); - y = RECT.getY(); - width = RECT.getWidth(); - height = RECT.getHeight(); + /** + * Draws an outlined round-cornered rectangle using this graphics context's + * current color. The left and right edges of the rectangle are at x and x + + * width, respectively. The top and bottom edges of the rectangle are at y + * and y + height. + * + * @param x the x coordinate of the rectangle to be drawn. + * @param y the y coordinate of the rectangle to be drawn. + * @param width the width of the rectangle to be drawn. + * @param height the height of the rectangle to be drawn. + * @param arcWidth the horizontal diameter of the arc at the four corners. + * @param arcHeight the vertical diameter of the arc at the four corners. + */ + public void drawRoundRect(final double x, final double y, final double width, final double height, + final double arcWidth, final double arcHeight) { + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); + final double tx = TEMP_RECT.getX(); + final double ty = TEMP_RECT.getY(); + final double twidth = TEMP_RECT.getWidth(); + final double theight = TEMP_RECT.getHeight(); - RECT.setRect(0, 0, arcWidth, arcHeight); - SWTShapeManager.transform(RECT, transform); - arcWidth = RECT.getWidth(); - arcHeight = RECT.getHeight(); + TEMP_RECT.setRect(0, 0, arcWidth, arcHeight); + SWTShapeManager.transform(TEMP_RECT, transform); + final double tarcWidth = TEMP_RECT.getWidth(); + final double tarcHeight = TEMP_RECT.getHeight(); gc.setLineWidth(getTransformedLineWidth()); - gc.drawRoundRectangle((int) (x + 0.5), (int) (y + 0.5), (int) (width + 0.5), (int) (height + 0.5), - (int) (arcWidth + 0.5), (int) (arcHeight + 0.5)); + gc.drawRoundRectangle((int) (tx + 0.5), (int) (ty + 0.5), (int) (twidth + 0.5), (int) (theight + 0.5), + (int) (tarcWidth + 0.5), (int) (tarcHeight + 0.5)); } + /** {@inheritDoc} */ public void fillRoundRect(final int x, final int y, final int width, final int height, final int arcWidth, final int arcHeight) { fillRoundRect((double) x, (double) y, (double) width, (double) height, (double) arcWidth, (double) arcHeight); } - public void fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); - x = RECT.getX(); - y = RECT.getY(); - width = RECT.getWidth(); - height = RECT.getHeight(); + /** + * Fills the specified rounded corner rectangle with the current color. The + * left and right edges of the rectangle are at x and x + width - 1, + * respectively. The top and bottom edges of the rectangle are at y and y + + * height - 1. + * + *@param x the x coordinate of the rectangle to be filled. + *@param y the y coordinate of the rectangle to be filled. + *@param width the width of the rectangle to be filled. + *@param height the height of the rectangle to be filled. + *@param arcWidth the horizontal diameter of the arc at the four corners. + *@param arcHeight the vertical diameter of the arc at the four corners. + */ + public void fillRoundRect(final double x, final double y, final double width, final double height, + final double arcWidth, final double arcHeight) { + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); + final double tx = TEMP_RECT.getX(); + final double ty = TEMP_RECT.getY(); + final double twidth = TEMP_RECT.getWidth(); + final double theight = TEMP_RECT.getHeight(); - RECT.setRect(0, 0, arcWidth, arcHeight); - SWTShapeManager.transform(RECT, transform); - arcWidth = RECT.getWidth(); - arcHeight = RECT.getHeight(); + TEMP_RECT.setRect(0, 0, arcWidth, arcHeight); + SWTShapeManager.transform(TEMP_RECT, transform); + final double tarcWidth = TEMP_RECT.getWidth(); + final double tarcHeight = TEMP_RECT.getHeight(); gc.setLineWidth(getTransformedLineWidth()); - gc.fillRoundRectangle((int) (x + 0.5), (int) (y + 0.5), (int) (width + 0.5), (int) (height + 0.5), - (int) (arcWidth + 0.5), (int) (arcHeight + 0.5)); + gc.fillRoundRectangle((int) (tx + 0.5), (int) (ty + 0.5), (int) (twidth + 0.5), (int) (theight + 0.5), + (int) (tarcWidth + 0.5), (int) (tarcHeight + 0.5)); } + /** {@inheritDoc} */ public void drawOval(final int x, final int y, final int width, final int height) { drawOval((double) x, (double) y, (double) width, (double) height); } + /** + * Draws the outline of an oval. The result is a circle or ellipse that fits + * within the rectangle specified by the x, y, width, and height arguments. + * The oval covers an area that is width + 1 pixels wide and height + 1 + * pixels tall. + * + * @param x the x coordinate of the upper left corner of the oval to be + * drawn. + * @param y the y coordinate of the upper left corner of the oval to be + * drawn. + * @param width the width of the oval to be drawn. + * @param height the height of the oval to be drawn. + */ public void drawOval(final double x, final double y, final double width, final double height) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); gc.setLineWidth(getTransformedLineWidth()); - gc.drawOval((int) (RECT.getX() + 0.5), (int) (RECT.getY() + 0.5), (int) (RECT.getWidth() + 0.5), (int) (RECT - .getHeight() + 0.5)); + gc.drawOval((int) (TEMP_RECT.getX() + 0.5), (int) (TEMP_RECT.getY() + 0.5), (int) (TEMP_RECT.getWidth() + 0.5), + (int) (TEMP_RECT.getHeight() + 0.5)); } + /** {@inheritDoc} */ public void fillOval(final int x, final int y, final int width, final int height) { fillOval((double) x, (double) y, (double) width, (double) height); } + /** + * Fills an oval bounded by the specified rectangle with the current color. + * + * @param x the x coordinate of the upper left corner of the oval to be + * filled. + * @param y the y coordinate of the upper left corner of the oval to be + * filled. + * @param width the width of the oval to be filled. + * @param height the height of the oval to be filled. + */ public void fillOval(final double x, final double y, final double width, final double height) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); - gc.fillOval((int) (RECT.getX() + 0.5), (int) (RECT.getY() + 0.5), (int) (RECT.getWidth() + 0.5), (int) (RECT - .getHeight() + 0.5)); + gc.fillOval((int) (TEMP_RECT.getX() + 0.5), (int) (TEMP_RECT.getY() + 0.5), (int) (TEMP_RECT.getWidth() + 0.5), + (int) (TEMP_RECT.getHeight() + 0.5)); } + /** {@inheritDoc} */ public void drawArc(final int x, final int y, final int width, final int height, final int startAngle, final int extent) { drawArc((double) x, (double) y, (double) width, (double) height, (double) startAngle, (double) extent); } + /** + * Draws the outline of a circular or elliptical arc covering the specified + * rectangle. + * + * The resulting arc begins at startAngle and extends for arcAngle degrees, + * using the current color. Angles are interpreted such that 0 degrees is at + * the 3 o'clock position. A positive value indicates a counter-clockwise + * rotation while a negative value indicates a clockwise rotation. + * + * The center of the arc is the center of the rectangle whose origin is (x, + * y) and whose size is specified by the width and height arguments. + * + * The resulting arc covers an area width + 1 pixels wide by height + 1 + * pixels tall. + * + * The angles are specified relative to the non-square extents of the + * bounding rectangle such that 45 degrees always falls on the line from the + * center of the ellipse to the upper right corner of the bounding + * rectangle. As a result, if the bounding rectangle is noticeably longer in + * one axis than the other, the angles to the start and end of the arc + * segment will be skewed farther along the longer axis of the bounds. + * + * @param x the x coordinate of the upper-left corner of the arc to be + * drawn. + * @param y the y coordinate of the upper-left corner of the arc to be + * drawn. + * @param width the width of the arc to be drawn. + * @param height the height of the arc to be drawn. + * @param startAngle the beginning angle. + * @param extent the angular extent of the arc, relative to the start angle. + */ public void drawArc(final double x, final double y, final double width, final double height, final double startAngle, final double extent) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); gc.setLineWidth(getTransformedLineWidth()); - gc.drawArc((int) (RECT.getX() + 0.5), (int) (RECT.getY() + 0.5), (int) (RECT.getWidth() + 0.5), (int) (RECT - .getHeight() + 0.5), (int) (startAngle + 0.5), (int) (startAngle + extent + 0.5)); + gc.drawArc((int) (TEMP_RECT.getX() + 0.5), (int) (TEMP_RECT.getY() + 0.5), (int) (TEMP_RECT.getWidth() + 0.5), + (int) (TEMP_RECT.getHeight() + 0.5), (int) (startAngle + 0.5), (int) (startAngle + extent + 0.5)); } + /** {@inheritDoc} */ public void fillArc(final int x, final int y, final int width, final int height, final int startAngle, final int extent) { drawArc((double) x, (double) y, (double) width, (double) height, (double) startAngle, (double) extent); } + /** + * Draws a filledArc with the options provided. + * + * @param x the x coordinate of the upper-left corner of the arc to be + * filled. + * @param y the y coordinate of the upper-left corner of the arc to be + * filled. + * @param width the width of the arc to be filled. + * @param height the height of the arc to be filled. + * @param startAngle the beginning angle. + * @param extent the angular extent of the arc, relative to the start angle. + */ public void fillArc(final double x, final double y, final double width, final double height, final double startAngle, final double extent) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); - gc.drawArc((int) (RECT.getX() + 0.5), (int) (RECT.getY() + 0.5), (int) (RECT.getWidth() + 0.5), (int) (RECT - .getHeight() + 0.5), (int) (startAngle + 0.5), (int) (startAngle + extent + 0.5)); + gc.drawArc((int) (TEMP_RECT.getX() + 0.5), (int) (TEMP_RECT.getY() + 0.5), (int) (TEMP_RECT.getWidth() + 0.5), + (int) (TEMP_RECT.getHeight() + 0.5), (int) (startAngle + 0.5), (int) (startAngle + extent + 0.5)); } - public void drawPath(Path p) { + /** + * Draws the provided path. + * + * @param p path to draw + */ + public void drawPath(final Path p) { gc.setTransform(swtTransform); gc.drawPath(p); gc.setTransform(null); } - public void fillPath(Path p) { + /** + * Draws a filled version of the provided path. + * + * @param p path to draw filled + */ + public void fillPath(final Path p) { gc.setTransform(swtTransform); gc.fillPath(p); gc.setTransform(null); } - // //////////////////////// - // SWT IMAGE METHODS - // //////////////////////// - + /** + * Draws the provided image at the position specified. + * + * @param image image to draw + * @param x x component of the position + * @param y y component of the position + */ public void drawImage(final org.eclipse.swt.graphics.Image image, final double x, final double y) { final org.eclipse.swt.graphics.Rectangle bounds = image.getBounds(); - RECT.setRect(x, y, bounds.width, bounds.height); - SWTShapeManager.transform(RECT, transform); - SWTShapeManager.awtToSWT(RECT, SWT_RECT); + TEMP_RECT.setRect(x, y, bounds.width, bounds.height); + SWTShapeManager.transform(TEMP_RECT, transform); + SWTShapeManager.awtToSWT(TEMP_RECT, SWT_RECT); gc.drawImage(image, 0, 0, bounds.width, bounds.height, SWT_RECT.x, SWT_RECT.y, SWT_RECT.width, SWT_RECT.height); } + /** + * Draws the source region from the image onto the destination region of the + * graphics context. Stretching if necessary. + * + * @param image image from which to copy + * @param srcX the left of the source region + * @param srcY the top of the source region + * @param srcW the width of the source region + * @param srcH the height of the source region + * @param destX the left of the destination region + * @param destY the top of the destination region + * @param destW the width of the destination region + * @param destH the height of the destination region + */ public void drawImage(final org.eclipse.swt.graphics.Image image, final int srcX, final int srcY, final int srcW, final int srcH, final double destX, final double destY, final double destW, final double destH) { - RECT.setRect(destX, destY, destW, destH); - SWTShapeManager.transform(RECT, transform); - SWTShapeManager.awtToSWT(RECT, SWT_RECT); + TEMP_RECT.setRect(destX, destY, destW, destH); + SWTShapeManager.transform(TEMP_RECT, transform); + SWTShapeManager.awtToSWT(TEMP_RECT, SWT_RECT); gc.drawImage(image, srcX, srcY, srcW, srcH, SWT_RECT.x, SWT_RECT.y, SWT_RECT.width, SWT_RECT.height); } - // //////////////////////////// - // OTHER SWT SPECIFIC METHODS - // //////////////////////////// - + /** + * Sets the line width to use when drawing shapes. + * + * @param lineWidth width of line when drawing shapes + */ public void setLineWidth(final double lineWidth) { this.lineWidth = lineWidth; } + /** + * Computes the width of the line after it passes through the current + * transform. + * + * @return resulting width of line after being transform + */ protected int getTransformedLineWidth() { - LINE_RECT.setRect(0, 0, lineWidth, lineWidth); - SWTShapeManager.transform(LINE_RECT, transform); + TEMP_LINE_RECT.setRect(0, 0, lineWidth, lineWidth); + SWTShapeManager.transform(TEMP_LINE_RECT, transform); - return (int) (Math.max(LINE_RECT.getWidth(), 1) + 0.5); + return (int) (Math.max(TEMP_LINE_RECT.getWidth(), 1) + 0.5); } + /** + * Fills a gradient rectangle of in the direction specified. + * + * @param x left of resulting rectangle + * @param y top of resulting rectangle + * @param width width of resulting rectangle + * @param height height of resulting rectangle + * @param vertical whether the gradient should be drawn vertically or + * horizontally + */ public void fillGradientRectangle(final double x, final double y, final double width, final double height, final boolean vertical) { - RECT.setRect(x, y, width, height); - SWTShapeManager.transform(RECT, transform); - SWTShapeManager.awtToSWT(RECT, SWT_RECT); + TEMP_RECT.setRect(x, y, width, height); + SWTShapeManager.transform(TEMP_RECT, transform); + SWTShapeManager.awtToSWT(TEMP_RECT, SWT_RECT); gc.fillGradientRectangle(SWT_RECT.x, SWT_RECT.y, SWT_RECT.width, SWT_RECT.height, vertical); } + /** + * @deprecated since underlying method has been deprecated + * @param xOr whether to be in xOr mode + */ public void setXORMode(final boolean xOr) { gc.setXORMode(xOr); } + /** + * Returns the advance width of the character provided in the current font. + * + * @param ch character to calculate the advance width of. + * + * @return advance width of the character in the current font + */ public int getAdvanceWidth(final char ch) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); @@ -835,6 +1210,13 @@ return width; } + /** + * Returns the width of the character provided in the current font. + * + * @param ch character to calculate the width of. + * + * @return width of the character in the current font + */ public int getCharWidth(final char ch) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); @@ -843,6 +1225,13 @@ return width; } + /** + * Returns the extent of the provided string in the current font. + * + * @param str string to calculate the extent of. + * + * @return extent of the string in the current font + */ public org.eclipse.swt.graphics.Point stringExtent(final String str) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); @@ -851,6 +1240,13 @@ return extent; } + /** + * Returns the extent of the provided text in the current font. + * + * @param str string to calculate the extent of. + * + * @return extent of the string in the current font + */ public org.eclipse.swt.graphics.Point textExtent(final String str) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); @@ -859,6 +1255,15 @@ return extent; } + /** + * Returns the extent of the provided text in the current font assuming the + * flags given. + * + * @param str string to calculate the extent of + * @param flags flags to apply to the rendered font before calculation of + * extent takes place + * @return extent of the string in the current font assuming flags provided + */ public org.eclipse.swt.graphics.Point textExtent(final String str, final int flags) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); @@ -871,64 +1276,67 @@ // CURRENTLY UNSUPPORTED METHODS // /////////////////////////////// - /** - * @see java.awt.Graphics#drawString(AttributedCharacterIterator, int, int) - */ + /** {@inheritDoc} */ public void drawString(final AttributedCharacterIterator iterator, final int x, final int y) { } - /** - * @see java.awt.Graphics2D#drawString(AttributedCharacterIterator, float, - * float) - */ + /** {@inheritDoc} */ public void drawString(final AttributedCharacterIterator iterator, final float x, final float y) { } - /** - * @see java.awt.Graphics2D#drawGlyphVector(GlyphVector, float, float) - */ + /** {@inheritDoc} */ public void drawGlyphVector(final GlyphVector g, final float x, final float y) { } /** - * @see java.awt.Graphics2D#hit(Rectangle, Shape, boolean) + * Returns whether the given rect and shape touch. If onStroke = true then + * it'll include the width of the stroke when calculating. + * + * @param rect rect to test + * @param s shape to test + * @param onStroke whether to consider the width of the stroke + * @return true if they touch */ public boolean hit(final Rectangle rect, final Shape s, final boolean onStroke) { return false; } - /** - * @see java.awt.Graphics2D#setComposite(Composite) - */ + /** {@inheritDoc} */ public void setComposite(final Composite comp) { } - /** - * @see java.awt.Graphics2D#setStroke(Stroke) - */ + /** {@inheritDoc} */ public void setStroke(final Stroke s) { } + /** {@inheritDoc} */ public void setRenderingHint(final Key hintKey, final Object hintValue) { } + /** {@inheritDoc} */ public Object getRenderingHint(final Key hintKey) { return null; } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#setRenderingHints(Map) */ public void setRenderingHints(final Map hints) { } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#addRenderingHints(Map) */ public void addRenderingHints(final Map hints) { } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#getRenderingHints() */ public RenderingHints getRenderingHints() { @@ -936,6 +1344,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#getComposite() */ public Composite getComposite() { @@ -943,6 +1353,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#getStroke() */ public Stroke getStroke() { @@ -950,6 +1362,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#getFontRenderContext() */ public FontRenderContext getFontRenderContext() { @@ -957,6 +1371,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#create() */ public Graphics create() { @@ -964,18 +1380,24 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#setPaintMode() */ public void setPaintMode() { } /** + * {@inheritDoc} + * * @see java.awt.Graphics#setXORMode(Color) */ public void setXORMode(final Color c1) { } /** + * {@inheritDoc} + * * @see java.awt.Graphics#getFontMetrics(Font) */ public FontMetrics getFontMetrics(final Font f) { @@ -983,6 +1405,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#drawImage(Image, AffineTransform, ImageObserver) */ public boolean drawImage(final Image img, final AffineTransform xform, final ImageObserver obs) { @@ -990,6 +1414,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#drawImage(BufferedImage, BufferedImageOp, int, * int) */ @@ -997,6 +1423,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#drawRenderedImage(RenderedImage, * AffineTransform) */ @@ -1004,6 +1432,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics2D#drawRenderableImage(RenderableImage, * AffineTransform) */ @@ -1011,6 +1441,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#drawImage(Image, int, int, ImageObserver) */ public boolean drawImage(final Image img, final int x, final int y, final ImageObserver observer) { @@ -1018,6 +1450,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#drawImage(Image, int, int, int, int, * ImageObserver) */ @@ -1027,6 +1461,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#drawImage(Image, int, int, Color, ImageObserver) */ public boolean drawImage(final Image img, final int x, final int y, final Color bgcolor, @@ -1035,6 +1471,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#drawImage(Image, int, int, int, int, Color, * ImageObserver) */ @@ -1044,6 +1482,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#drawImage(Image, int, int, int, int, int, int, * int, int, ImageObserver) */ @@ -1053,6 +1493,8 @@ } /** + * {@inheritDoc} + * * @see java.awt.Graphics#drawImage(Image, int, int, int, int, int, int, * int, int, Color, ImageObserver) */ @@ -1063,7 +1505,7 @@ } /** - * DO NOTHING - DISPOSED IN RENDERING CLASS + * DO NOTHING - DISPOSED IN RENDERING CLASS. */ public void dispose() { } @@ -1072,10 +1514,16 @@ // CLEAN-UP METHODS // /////////////////////////////// + /** + * Increases the number of uses of this graphics 2d object. + */ public static void incrementGCCount() { CACHE_COUNT++; } + /** + * Decreases the number of uses of this graphics 2d object. + */ public static void decrementGCCount() { CACHE_COUNT--; @@ -1088,8 +1536,8 @@ final org.eclipse.swt.graphics.Color color = (org.eclipse.swt.graphics.Color) i.next(); color.dispose(); } - for (Iterator i = SHAPE_CACHE.values().iterator(); i.hasNext();) { - Path path = (Path) i.next(); + for (final Iterator i = SHAPE_CACHE.values().iterator(); i.hasNext();) { + final Path path = (Path) i.next(); path.dispose(); } }