⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swtgraphics2d.java

📁 JFreeChart它主要是用来制作各种各样的图表
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @param height  the height.     */    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);    }    /**     * Returns the current clip.     *     * @return The current clip.     */    public Shape getClip() {        return SWTUtils.toAwtRectangle(this.gc.getClipping());    }    /**     * Sets the clip region.     *     * @param clip  the clip.     */    public void setClip(Shape clip) {        if (clip == null) {            return;        }        Path clipPath = toSwtPath(clip);        this.gc.setClipping(clipPath);        clipPath.dispose();    }    /**     * Sets the clip region to the specified rectangle.     *     * @param x  the x-coordinate.     * @param y  the y-coordinate.     * @param width  the width.     * @param height  the height.     */    public void setClip(int x, int y, int width, int height) {        this.gc.setClipping(x, y, width, height);    }    /**     * Returns the current transform.     *     * @return The current transform.     */    public AffineTransform getTransform() {        Transform swtTransform = new Transform(this.gc.getDevice());        this.gc.getTransform(swtTransform);        AffineTransform awtTransform = toAwtTransform(swtTransform);        swtTransform.dispose();        return awtTransform;    }    /**     * Sets the current transform.     *     * @param t  the transform.     */    public void setTransform(AffineTransform t) {        Transform transform = getSwtTransformFromPool(t);        this.gc.setTransform(transform);    }    /**     * Concatenates the specified transform to the existing transform.     *     * @param t  the transform.     */    public void transform(AffineTransform t) {        Transform swtTransform = new Transform(this.gc.getDevice());        this.gc.getTransform(swtTransform);        swtTransform.multiply(getSwtTransformFromPool(t));        this.gc.setTransform(swtTransform);        swtTransform.dispose();    }    /**     * Applies a translation.     *     * @param x  the translation along the x-axis.     * @param y  the translation along the y-axis.     */    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();    }    /**     * Applies a translation.     *     * @param tx  the translation along the x-axis.     * @param ty  the translation along the y-axis.     */    public void translate(double tx, double ty) {        translate((int) tx, (int) ty);    }    /**     * Applies a rotation transform.     *     * @param theta  the angle of rotation.     */    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();    }    /**     * Not implemented - see {@link Graphics2D#rotate(double, double, double)}.     *     * @see java.awt.Graphics2D#rotate(double, double, double)     */    public void rotate(double theta, double x, double y) {        // TODO Auto-generated method stub    }    /**     * Applies a scale transform.     *     * @param scaleX  the scale factor along the x-axis.     * @param scaleY  the scale factor along the y-axis.     */    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();    }    /**     * Applies a shear transform.     *     * @param shearX  the x-factor.     * @param shearY  the y-factor.     */    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);    }    /**     * Not implemented - see {@link Graphics#fillPolygon(int[], int[], int)}.     *     * @param xPoints  the x-coordinates.     * @param yPoints  the y-coordinates.     * @param npoints  the number of points.     */    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)     */    public void setFont(Font font) {        org.eclipse.swt.graphics.Font swtFont = getSwtFontFromPool(font);        this.gc.setFont(swtFont);    }    /**     * Returns the font metrics.     *     * @param font the font.     *     * @return The font metrics.     */    public FontMetrics getFontMetrics(Font font) {        return SWTUtils.DUMMY_PANEL.getFontMetrics(font);    }    /**     * Returns the font render context.     *     * @return The font render context.     */    public FontRenderContext getFontRenderContext() {        FontRenderContext fontRenderContext = new FontRenderContext(                new AffineTransform(), true, true);        return fontRenderContext;    }    /**     * Not implemented - see {@link Graphics2D#drawGlyphVector(GlyphVector,     * float, float)}.     */    public void drawGlyphVector(GlyphVector g, float x, float y) {        // TODO Auto-generated method stub    }    /**     * Draws a string on the receiver. note that     * to be consistent with the awt method,     * the y has to be modified with the ascent of the font.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -