📄 swtgraphics2d.java
字号:
swtDashes[i] = (int) dashes[i]; } this.gc.setLineDash(swtDashes); } } else { throw new RuntimeException( "Can only handle 'Basic Stroke' at present."); } } /* (non-Javadoc) * @see java.awt.Graphics2D#clip(java.awt.Shape) */ public void clip(Shape s) { Path path = toSwtPath(s); this.gc.setClipping(path); path.dispose(); } /* (non-Javadoc) * @see java.awt.Graphics#getClipBounds() */ public Rectangle getClipBounds() { org.eclipse.swt.graphics.Rectangle clip = this.gc.getClipping(); return new Rectangle(clip.x, clip.y, clip.width, clip.height); } /* (non-Javadoc) * @see java.awt.Graphics#clipRect(int, int, int, int) */ public void clipRect(int x, int y, int width, int height) { org.eclipse.swt.graphics.Rectangle clip = this.gc.getClipping(); clip.intersects(x, y, width, height); this.gc.setClipping(clip); } /* (non-Javadoc) * @see java.awt.Graphics#getClip() */ public Shape getClip() { return SWTUtils.toAwtRectangle(this.gc.getClipping()); } /* (non-Javadoc) * @see java.awt.Graphics#setClip(java.awt.Shape) */ public void setClip(Shape clip) { if (clip == null) return; Path clipPath = toSwtPath(clip); this.gc.setClipping(clipPath); clipPath.dispose(); } /* (non-Javadoc) * @see java.awt.Graphics#setClip(int, int, int, int) */ public void setClip(int x, int y, int width, int height) { this.gc.setClipping(x, y, width, height); } /* (non-Javadoc) * @see java.awt.Graphics2D#getTransform() */ public AffineTransform getTransform() { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); AffineTransform awtTransform = toAwtTransform(swtTransform); swtTransform.dispose(); return awtTransform; } /* (non-Javadoc) * @see java.awt.Graphics2D#setTransform(java.awt.geom.AffineTransform) */ public void setTransform(AffineTransform Tx) { this.gc.setTransform(toSwtTransform(Tx)); } /* (non-Javadoc) * @see java.awt.Graphics2D#transform(java.awt.geom.AffineTransform) */ public void transform(AffineTransform Tx) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); Transform swtMatrix = toSwtTransform(Tx); swtTransform.multiply(swtMatrix); this.gc.setTransform(swtTransform); swtMatrix.dispose(); swtTransform.dispose(); } /* (non-Javadoc) * @see java.awt.Graphics2D#translate(int, int) */ public void translate(int x, int y) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.translate(x, y); this.gc.setTransform(swtTransform); swtTransform.dispose(); } /* (non-Javadoc) * @see java.awt.Graphics2D#translate(double, double) */ public void translate(double tx, double ty) { translate((int) tx, (int) ty); } /* (non-Javadoc) * @see java.awt.Graphics2D#rotate(double) */ public void rotate(double theta) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.rotate( (float) (theta * 180 / Math.PI)); this.gc.setTransform(swtTransform); swtTransform.dispose(); } /* (non-Javadoc) * @see java.awt.Graphics2D#rotate(double, double, double) */ public void rotate(double theta, double x, double y) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.Graphics2D#scale(double, double) */ public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); } /* (non-Javadoc) * @see java.awt.Graphics2D#shear(double, double) */ public void shear(double shearX, double shearY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); Transform shear = new Transform(this.gc.getDevice(), 1f, (float) shearX, (float) shearY, 1f, 0, 0); swtTransform.multiply(shear); this.gc.setTransform(swtTransform); swtTransform.dispose(); } /** * Draws the outline of the specified shape using the current stroke and * paint settings. * * @param shape the shape (<code>null</code> not permitted). * * @see #getPaint() * @see #getStroke() * @see #fill(Shape) */ public void draw(Shape shape) { Path path = toSwtPath(shape); this.gc.drawPath(path); path.dispose(); } /** * Draws a line from (x1, y1) to (x2, y2) using the current stroke * and paint settings. * * @param x1 the x-coordinate for the starting point. * @param y1 the y-coordinate for the starting point. * @param x2 the x-coordinate for the ending point. * @param y2 the y-coordinate for the ending point. * * @see #draw(Shape) */ public void drawLine(int x1, int y1, int x2, int y2) { this.gc.drawLine(x1, y1, x2, y2); } /** * Draws the outline of the polygon specified by the given points, using * the current paint and stroke settings. * * @param xPoints the x-coordinates. * @param yPoints the y-coordinates. * @param npoints the number of points in the polygon. * * @see #draw(Shape) */ public void drawPolygon(int [] xPoints, int [] yPoints, int npoints) { drawPolyline(xPoints, yPoints, npoints); if (npoints > 1) { this.gc.drawLine(xPoints[npoints-1], yPoints[npoints-1], xPoints[0], yPoints[0]); } } /** * Draws a sequence of connected lines specified by the given points, using * the current paint and stroke settings. * * @param xPoints the x-coordinates. * @param yPoints the y-coordinates. * @param npoints the number of points in the polygon. * * @see #draw(Shape) */ public void drawPolyline(int [] xPoints, int [] yPoints, int npoints) { if (npoints > 1) { int x0 = xPoints[0]; int y0 = yPoints[0]; int x1 = 0, y1 = 0; for (int i = 1; i < npoints; i++) { x1 = xPoints[i]; y1 = yPoints[i]; this.gc.drawLine(x0, y0, x1, y1); x0 = x1; y0 = y1; } } } /** * Draws an oval that fits within the specified rectangular region. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the frame width. * @param height the frame height. * * @see #fillOval(int, int, int, int) * @see #draw(Shape) */ public void drawOval(int x, int y, int width, int height) { this.gc.drawOval(x, y, width - 1, height - 1); } /** * Draws an arc that is part of an ellipse that fits within the specified * framing rectangle. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the frame width. * @param height the frame height. * @param arcStart the arc starting point, in degrees. * @param arcAngle the extent of the arc. * * @see #fillArc(int, int, int, int, int, int) */ public void drawArc(int x, int y, int width, int height, int arcStart, int arcAngle) { this.gc.drawArc(x, y, width - 1, height - 1, arcStart, arcAngle); } /** * Draws a rectangle with rounded corners that fits within the specified * framing rectangle. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the frame width. * @param height the frame height. * @param arcWidth the width of the arc defining the roundedness of the * rectangle's corners. * @param arcHeight the height of the arc defining the roundedness of the * rectangle's corners. * * @see #fillRoundRect(int, int, int, int, int, int) */ public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { this.gc.drawRoundRectangle(x, y, width - 1, height - 1, arcWidth, arcHeight); } /** * Fills the specified shape using the current paint. * * @param shape the shape (<code>null</code> not permitted). * * @see #getPaint() * @see #draw(Shape) */ public void fill(Shape shape) { Path path = toSwtPath(shape); // Note that for consistency with the AWT implementation, it is // necessary to switch temporarily the foreground and background // colours switchColors(); this.gc.fillPath(path); switchColors(); path.dispose(); } /** * Fill a rectangle area on the swt graphic composite. * The <code>fillRectangle</code> method of the <code>GC</code> * class uses the background color so we must switch colors. * @see java.awt.Graphics#fillRect(int, int, int, int) */ public void fillRect(int x, int y, int width, int height) { this.switchColors(); this.gc.fillRectangle(x, y, width, height); this.switchColors(); } /** * Fills the specified rectangle with the current background colour. * * @param x the x-coordinate for the rectangle. * @param y the y-coordinate for the rectangle. * @param width the width. * @param height the height. * * @see #fillRect(int, int, int, int) */ public void clearRect(int x, int y, int width, int height) { Paint saved = getPaint(); setPaint(getBackground()); fillRect(x, y, width, height); setPaint(saved); } /* (non-Javadoc) * @see java.awt.Graphics#fillPolygon(int[], int[], int) */ public void fillPolygon(int [] xPoints, int [] yPoints, int npoints) { // TODO Auto-generated method stub } /** * Draws a rectangle with rounded corners that fits within the specified * framing rectangle. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the frame width. * @param height the frame height. * @param arcWidth the width of the arc defining the roundedness of the * rectangle's corners. * @param arcHeight the height of the arc defining the roundedness of the * rectangle's corners. * * @see #drawRoundRect(int, int, int, int, int, int) */ public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { switchColors(); this.gc.fillRoundRectangle(x, y, width - 1, height - 1, arcWidth, arcHeight); switchColors(); } /** * Fills an oval that fits within the specified rectangular region. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the frame width. * @param height the frame height. * * @see #drawOval(int, int, int, int) * @see #fill(Shape) */ public void fillOval(int x, int y, int width, int height) { switchColors(); this.gc.fillOval(x, y, width - 1, height - 1); switchColors(); } /** * Fills an arc that is part of an ellipse that fits within the specified * framing rectangle. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the frame width. * @param height the frame height. * @param arcStart the arc starting point, in degrees. * @param arcAngle the extent of the arc. * * @see #drawArc(int, int, int, int, int, int) */ public void fillArc(int x, int y, int width, int height, int arcStart, int arcAngle) { switchColors(); this.gc.fillArc(x, y, width - 1, height - 1, arcStart, arcAngle); switchColors(); } /** * Returns the font in form of an awt font created * with the parameters of the font of the swt graphic * composite. * @see java.awt.Graphics#getFont() */ public Font getFont() { // retrieve the swt font description in an os indept way FontData[] fontData = this.gc.getFont().getFontData(); // create a new awt font with the appropiate data return SWTUtils.toAwtFont(this.gc.getDevice(), fontData[0], true); } /** * Set the font swt graphic composite from the specified * awt font. Be careful that the newly created swt font * must be disposed separately. * @see java.awt.Graphics#setFont(java.awt.Font) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -