Java Code Examples for java.awt.geom.GeneralPath#closePath()

The following examples show how to use java.awt.geom.GeneralPath#closePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StarTransition2D.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public Shape getShape() {
	GeneralPath p = new GeneralPath();
	double angle = Math.PI / 10;
	float r2 = 2.5f;
	double k = Math.PI * 2 / 10;
	p.moveTo((float) (Math.cos(angle)), (float) (Math.sin(angle)));
	for (int a = 0; a < 5; a++) {
		p.lineTo((float) (r2 * Math.cos(angle + k)),
				(float) (r2 * Math.sin(angle + k)));
		angle += Math.PI * 2.0 / 5.0;
		p.lineTo((float) (Math.cos(angle)), (float) (Math.sin(angle)));
	}
	p.closePath();
	return p;
}
 
Example 2
Source File: StarDust.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Shape getCurrentShape() {
    double innerSpan = this.outerSpan * (0.1f + 0.1f * outerSpan / 20);
    int POINTS = 5;
    GeneralPath result = new GeneralPath();
    for (int i = 0; i < POINTS; i++) {
        double outerAngle = this.rotation + i * 2 * Math.PI / POINTS;
        double xOuter = this.x + this.outerSpan * Math.cos(outerAngle);
        double yOuter = this.y + this.outerSpan * Math.sin(outerAngle);
        if (i == 0) {
            result.moveTo(xOuter, yOuter);
        } else {
            result.lineTo(xOuter, yOuter);
        }
        double innerAngle = outerAngle + Math.PI / POINTS;
        double xInner = this.x + innerSpan * Math.cos(innerAngle);
        double yInner = this.y + innerSpan * Math.sin(innerAngle);
        result.lineTo(xInner, yInner);
    }
    result.closePath();
    return result;
}
 
Example 3
Source File: Elixir_001_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a diagonal cross shape.
 *
 * @param l  the length of each 'arm'.
 * @param t  the thickness.
 *
 * @return A diagonal cross shape.
 */
public static Shape createDiagonalCross(float l, float t) {
    GeneralPath p0 = new GeneralPath();
    p0.moveTo(-l - t, -l + t);
    p0.lineTo(-l + t, -l - t);
    p0.lineTo(0.0f, -t * SQRT2);
    p0.lineTo(l - t, -l - t);
    p0.lineTo(l + t, -l + t);
    p0.lineTo(t * SQRT2, 0.0f);
    p0.lineTo(l + t, l - t);
    p0.lineTo(l - t, l + t);
    p0.lineTo(0.0f, t * SQRT2);
    p0.lineTo(-l + t, l + t);
    p0.lineTo(-l - t, l - t);
    p0.lineTo(-t * SQRT2, 0.0f);
    p0.closePath();
    return p0;
}
 
Example 4
Source File: TrafficLight.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public BufferedImage createYellowOnImage(final int WIDTH, final int HEIGHT) {
    final GraphicsConfiguration GFX_CONF = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    if (WIDTH <= 0 || HEIGHT <= 0) {
        return GFX_CONF.createCompatibleImage(1, 1, java.awt.Transparency.TRANSLUCENT);
    }
    final BufferedImage IMAGE = GFX_CONF.createCompatibleImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();
    final Ellipse2D LIGHT_ON = new Ellipse2D.Double(0.17346938775510204 * IMAGE_WIDTH, 0.38489208633093525 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.5 * IMAGE_HEIGHT), (0.32653061224489793f * IMAGE_WIDTH), new float[]{0.0f, 1.0f}, new Color[]{new Color(0.9960784314f, 0.8313725490f, 0.2039215686f, 1f), new Color(0.5098039216f, 0.2f, 0.0470588235f, 1f)}));
    G2.fill(LIGHT_ON);

    final GeneralPath GLOW = new GeneralPath();
    GLOW.setWindingRule(Path2D.WIND_EVEN_ODD);
    GLOW.moveTo(0.0 * IMAGE_WIDTH, 0.5035971223021583 * IMAGE_HEIGHT);
    GLOW.curveTo(0.0 * IMAGE_WIDTH, 0.6007194244604317 * IMAGE_HEIGHT, 0.22448979591836735 * IMAGE_WIDTH, 0.6798561151079137 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.6798561151079137 * IMAGE_HEIGHT);
    GLOW.curveTo(0.7755102040816326 * IMAGE_WIDTH, 0.6798561151079137 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 0.6007194244604317 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 0.5 * IMAGE_HEIGHT);
    GLOW.curveTo(0.9081632653061225 * IMAGE_WIDTH, 0.44244604316546765 * IMAGE_HEIGHT, 0.7040816326530612 * IMAGE_WIDTH, 0.3776978417266187 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.3776978417266187 * IMAGE_HEIGHT);
    GLOW.curveTo(0.2857142857142857 * IMAGE_WIDTH, 0.3776978417266187 * IMAGE_HEIGHT, 0.08163265306122448 * IMAGE_WIDTH, 0.44244604316546765 * IMAGE_HEIGHT, 0.0 * IMAGE_WIDTH, 0.5035971223021583 * IMAGE_HEIGHT);
    GLOW.closePath();
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.5 * IMAGE_HEIGHT), (0.5153061224489796f * IMAGE_WIDTH), new float[]{0.0f, 1.0f}, new Color[]{new Color(0.9960784314f, 0.8313725490f, 0.2039215686f, 1f), new Color(0.5098039216f, 0.2f, 0.0470588235f, 0f)}));
    G2.fill(GLOW);

    G2.dispose();
    return IMAGE;
}
 
Example 5
Source File: ClipPath.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Generates the clip path.
 *
 * @param dataArea  the dataArea that the plot is being draw in.
 * @param horizontalAxis  the horizontal axis.
 * @param verticalAxis  the vertical axis.
 *
 * @return The GeneralPath defining the outline
 */
public GeneralPath generateClipPath(Rectangle2D dataArea,
                                    ValueAxis horizontalAxis, 
                                    ValueAxis verticalAxis) {

    GeneralPath generalPath = new GeneralPath();
    double transX = horizontalAxis.valueToJava2D(
        this.xValue[0], dataArea, RectangleEdge.BOTTOM
    );
    double transY = verticalAxis.valueToJava2D(
        this.yValue[0], dataArea, RectangleEdge.LEFT
    );
    generalPath.moveTo((float) transX, (float) transY);
    for (int k = 0; k < this.yValue.length; k++) {
        transX = horizontalAxis.valueToJava2D(
            this.xValue[k], dataArea, RectangleEdge.BOTTOM
        );
        transY = verticalAxis.valueToJava2D(
            this.yValue[k], dataArea, RectangleEdge.LEFT
        );
        generalPath.lineTo((float) transX, (float) transY);
    }
    generalPath.closePath();

    return generalPath;

}
 
Example 6
Source File: Polygon.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draw the Polygon to the buffer of the given size.
 */
public void draw(Graphics2D g, int width, int height) {
    g.setColor(new Color(data[0], data[1], data[2], data[3]));

    GeneralPath path = new GeneralPath();
    path.moveTo(data[4] * width, data[5] * height);
    
    int polygonLength = (data.length - 4) / 2;
    for (int j = 1; j < polygonLength; j++) {
        path.lineTo(data[4 + j * 2] * width, data[5 + j * 2] * height);
    }
    path.closePath();

    g.fill(path);
}
 
Example 7
Source File: FunkyWipeTransition2D.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public Transition2DInstruction[] getInstructions(float progress,
		Dimension size) {
	Rectangle2D.Float frameRect = new Rectangle2D.Float(0, 0, size.width,
			size.height);
	Point2D p = new Point2D.Double();
	MeasuredShape path = circular ? measuredPathCyclic : measuredPathAcross;

	path.getPoint(progress * path.getOriginalDistance(), p);

	int m = circular ? 1 : 2;
	double angle = Math.PI / 2 + m * Math.PI * progress;

	float k = 10000;
	GeneralPath clip = new GeneralPath();
	clip.moveTo((float) p.getX(), (float) p.getY());
	clip.lineTo((float) (p.getX() + k * Math.cos(angle)),
			(float) (p.getY() + k * Math.sin(angle)));
	clip.lineTo(
			(float) (p.getX() + k * Math.cos(angle) + k
					* Math.cos(angle - Math.PI / 2)), (float) (p.getY() + k
					* Math.sin(angle) + k * Math.sin(angle - Math.PI / 2)));
	clip.lineTo(
			(float) (p.getX() - 100 * Math.cos(angle) + k
					* Math.cos(angle - Math.PI / 2)), (float) (p.getY() - k
					* Math.sin(angle) + k * Math.sin(angle - Math.PI / 2)));
	clip.lineTo((float) (p.getX() - k * Math.cos(angle)),
			(float) (p.getY() - k * Math.sin(angle)));
	clip.closePath();

	AffineTransform map = RectangularTransform.create(
			new Rectangle2D.Float(0, 0, 100, 100), frameRect);
	clip.transform(map);

	clip = Clipper.clipToRect(clip, frameRect);

	return new Transition2DInstruction[] {
			new ImageInstruction(true, 1, frameRect, size, null),
			new ImageInstruction(false, 1, frameRect, size, clip) };
}
 
Example 8
Source File: Chart_11_ShapeUtilities_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Creates a triangle shape that points downwards.
 *
 * @param s  the size factor (equal to half the height of the triangle).
 *
 * @return A triangle shape.
 */
public static Shape createDownTriangle(float s) {
    GeneralPath p0 = new GeneralPath();
    p0.moveTo(0.0f, s);
    p0.lineTo(s, -s);
    p0.lineTo(-s, -s);
    p0.closePath();
    return p0;
}
 
Example 9
Source File: FancyDropDownButton.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	if (mainButton != null && mainButton.getModel().isArmed() || getModel().isArmed()) {
		((Graphics2D) g).translate(1.1, 1.1);
	}
	((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	super.paintComponent(g);

	Graphics2D g2 = (Graphics2D) g.create();

	// fill background white
	g2.setColor(BACKGROUND_COLOR);
	g2.fillRect(3, 0, getWidth() - 9, getHeight() - 6);

	// draw border which complements the DropShadow
	g2.setColor(BORDER_LIGHTEST_GRAY);
	g2.drawLine(3, 0, 3, getHeight() - 6);
	g2.drawLine(getWidth() - 6, 0, getWidth() - 6, getHeight() - 6);
	g2.drawLine(3, getHeight() - 6, getWidth() - 6, getHeight() - 6);
	g2.drawLine(3, 0, getWidth() - 6, 0);

	// draw arrow
	GeneralPath arrow = new GeneralPath();
	int w, h;
	h = (int) (2 * sizeFactor);
	w = (int) (4 * sizeFactor);
	arrow.moveTo(getWidth() / 2 - w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2, getHeight() / 2 + 2 * h);
	arrow.closePath();
	if (isEnabled()) {
		g2.setColor(HOVERED_TEXTCOLOR);
	} else {
		g2.setColor(BORDER_LIGHTEST_GRAY);
	}
	g2.fill(arrow);
	g2.dispose();
}
 
Example 10
Source File: PixelToShapeConverter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Shape makePoly(int xPoints[], int yPoints[],
                       int nPoints, boolean close) {
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    if (nPoints > 0) {
        gp.moveTo(xPoints[0], yPoints[0]);
        for (int i = 1; i < nPoints; i++) {
            gp.lineTo(xPoints[i], yPoints[i]);
        }
        if (close) {
            gp.closePath();
        }
    }
    return gp;
}
 
Example 11
Source File: PointerNeedle.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
@Override
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                          Point2D rotate, double angle) {

    GeneralPath shape1 = new GeneralPath();
    GeneralPath shape2 = new GeneralPath();
    float minX = (float) plotArea.getMinX();
    float minY = (float) plotArea.getMinY();
    float maxX = (float) plotArea.getMaxX();
    float maxY = (float) plotArea.getMaxY();
    float midX = (float) (minX + (plotArea.getWidth() / 2));
    float midY = (float) (minY + (plotArea.getHeight() / 2));

    shape1.moveTo(minX, midY);
    shape1.lineTo(midX, minY);
    shape1.lineTo(maxX, midY);
    shape1.closePath();

    shape2.moveTo(minX, midY);
    shape2.lineTo(midX, maxY);
    shape2.lineTo(maxX, midY);
    shape2.closePath();

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation huston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        shape1.transform(getTransform());
        shape2.transform(getTransform());
    }

    if (getFillPaint() != null) {
        g2.setPaint(getFillPaint());
        g2.fill(shape1);
    }

    if (getHighlightPaint() != null) {
        g2.setPaint(getHighlightPaint());
        g2.fill(shape2);
    }

    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(shape1);
        g2.draw(shape2);
    }
}
 
Example 12
Source File: Level.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage create_STEPPOINTER_Image(final int WIDTH) {
    if (WIDTH <= 0) {
        return null;
    }

    final BufferedImage IMAGE = UTIL.createImage(WIDTH, WIDTH, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    G2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();

    final GeneralPath POINTER_SMALL_LEFT = new GeneralPath();
    POINTER_SMALL_LEFT.setWindingRule(Path2D.WIND_EVEN_ODD);
    POINTER_SMALL_LEFT.moveTo(IMAGE_WIDTH * 0.2850467289719626, IMAGE_HEIGHT * 0.514018691588785);
    POINTER_SMALL_LEFT.lineTo(IMAGE_WIDTH * 0.2102803738317757, IMAGE_HEIGHT * 0.5);
    POINTER_SMALL_LEFT.lineTo(IMAGE_WIDTH * 0.2850467289719626, IMAGE_HEIGHT * 0.48130841121495327);
    POINTER_SMALL_LEFT.curveTo(IMAGE_WIDTH * 0.2850467289719626, IMAGE_HEIGHT * 0.48130841121495327, IMAGE_WIDTH * 0.2803738317757009, IMAGE_HEIGHT * 0.49065420560747663, IMAGE_WIDTH * 0.2803738317757009, IMAGE_HEIGHT * 0.4953271028037383);
    POINTER_SMALL_LEFT.curveTo(IMAGE_WIDTH * 0.2803738317757009, IMAGE_HEIGHT * 0.5046728971962616, IMAGE_WIDTH * 0.2850467289719626, IMAGE_HEIGHT * 0.514018691588785, IMAGE_WIDTH * 0.2850467289719626, IMAGE_HEIGHT * 0.514018691588785);
    POINTER_SMALL_LEFT.closePath();
    final Point2D POINTER_SMALL_LEFT_START = new Point2D.Double(POINTER_SMALL_LEFT.getBounds2D().getMinX(), 0);
    final Point2D POINTER_SMALL_LEFT_STOP = new Point2D.Double(POINTER_SMALL_LEFT.getBounds2D().getMaxX(), 0);
    final float[] POINTER_SMALL_FRACTIONS = {
        0.0f,
        0.3f,
        0.59f,
        1.0f
    };
    final Color[] POINTER_SMALL_COLORS = {
        UTIL.setAlpha(getPointerColor().DARK, 180),
        UTIL.setAlpha(getPointerColor().LIGHT, 180),
        UTIL.setAlpha(getPointerColor().LIGHT, 180),
        UTIL.setAlpha(getPointerColor().DARK, 180)
    };
    final LinearGradientPaint POINTER_SMALL_LEFT_GRADIENT = new LinearGradientPaint(POINTER_SMALL_LEFT_START, POINTER_SMALL_LEFT_STOP, POINTER_SMALL_FRACTIONS, POINTER_SMALL_COLORS);
    G2.setPaint(POINTER_SMALL_LEFT_GRADIENT);
    G2.fill(POINTER_SMALL_LEFT);
    final Color STROKE_COLOR_POINTER_SMALL = UTIL.setAlpha(getPointerColor().LIGHT, 128);
    G2.setColor(STROKE_COLOR_POINTER_SMALL);
    G2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    G2.draw(POINTER_SMALL_LEFT);

    final GeneralPath POINTER_SMALL_RIGHT = new GeneralPath();
    POINTER_SMALL_RIGHT.setWindingRule(Path2D.WIND_EVEN_ODD);
    POINTER_SMALL_RIGHT.moveTo(IMAGE_WIDTH * 0.7149532710280374, IMAGE_HEIGHT * 0.514018691588785);
    POINTER_SMALL_RIGHT.lineTo(IMAGE_WIDTH * 0.7897196261682243, IMAGE_HEIGHT * 0.5);
    POINTER_SMALL_RIGHT.lineTo(IMAGE_WIDTH * 0.7149532710280374, IMAGE_HEIGHT * 0.48130841121495327);
    POINTER_SMALL_RIGHT.curveTo(IMAGE_WIDTH * 0.7149532710280374, IMAGE_HEIGHT * 0.48130841121495327, IMAGE_WIDTH * 0.719626168224299, IMAGE_HEIGHT * 0.49065420560747663, IMAGE_WIDTH * 0.719626168224299, IMAGE_HEIGHT * 0.4953271028037383);
    POINTER_SMALL_RIGHT.curveTo(IMAGE_WIDTH * 0.719626168224299, IMAGE_HEIGHT * 0.5046728971962616, IMAGE_WIDTH * 0.7149532710280374, IMAGE_HEIGHT * 0.514018691588785, IMAGE_WIDTH * 0.7149532710280374, IMAGE_HEIGHT * 0.514018691588785);
    POINTER_SMALL_RIGHT.closePath();
    final Point2D POINTER_SMALL_RIGHT_START = new Point2D.Double(POINTER_SMALL_RIGHT.getBounds2D().getMaxX(), 0);
    final Point2D POINTER_SMALL_RIGHT_STOP = new Point2D.Double(POINTER_SMALL_RIGHT.getBounds2D().getMinX(), 0);

    final LinearGradientPaint POINTER_SMALL_RIGHT_GRADIENT = new LinearGradientPaint(POINTER_SMALL_RIGHT_START, POINTER_SMALL_RIGHT_STOP, POINTER_SMALL_FRACTIONS, POINTER_SMALL_COLORS);
    G2.setPaint(POINTER_SMALL_RIGHT_GRADIENT);
    G2.fill(POINTER_SMALL_RIGHT);
    G2.setColor(STROKE_COLOR_POINTER_SMALL);
    G2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    G2.draw(POINTER_SMALL_RIGHT);

    G2.dispose();

    return IMAGE;
}
 
Example 13
Source File: PointerNeedle.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
@Override
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                          Point2D rotate, double angle) {

    GeneralPath shape1 = new GeneralPath();
    GeneralPath shape2 = new GeneralPath();
    float minX = (float) plotArea.getMinX();
    float minY = (float) plotArea.getMinY();
    float maxX = (float) plotArea.getMaxX();
    float maxY = (float) plotArea.getMaxY();
    float midX = (float) (minX + (plotArea.getWidth() / 2));
    float midY = (float) (minY + (plotArea.getHeight() / 2));

    shape1.moveTo(minX, midY);
    shape1.lineTo(midX, minY);
    shape1.lineTo(maxX, midY);
    shape1.closePath();

    shape2.moveTo(minX, midY);
    shape2.lineTo(midX, maxY);
    shape2.lineTo(maxX, midY);
    shape2.closePath();

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation huston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        shape1.transform(getTransform());
        shape2.transform(getTransform());
    }

    if (getFillPaint() != null) {
        g2.setPaint(getFillPaint());
        g2.fill(shape1);
    }

    if (getHighlightPaint() != null) {
        g2.setPaint(getHighlightPaint());
        g2.fill(shape2);
    }

    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(shape1);
        g2.draw(shape2);
    }
}
 
Example 14
Source File: Horizon.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage create_INDICATOR_Image(final int WIDTH, BufferedImage image) {
    if (WIDTH <= 0) {
        return UTIL.createImage(1, 1, Transparency.TRANSLUCENT);
    }

    if (image == null) {
        image = UTIL.createImage(WIDTH, WIDTH, Transparency.TRANSLUCENT);
    }
    final java.awt.Graphics2D G2 = image.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    final int IMAGE_WIDTH = image.getWidth();
    final int IMAGE_HEIGHT = image.getHeight();
    final Point2D LOCAL_CENTER = new Point2D.Double(IMAGE_WIDTH / 2.0, IMAGE_HEIGHT / 2.0);

    G2.setFont(new Font("Verdana", Font.PLAIN, (int) (IMAGE_WIDTH * 0.035)));
    //final java.awt.geom.Point2D TEXT_POS = new java.awt.geom.Point2D.Double(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.08878504672897196 + IMAGE_WIDTH * 0.035 / 3);

    final Line2D SCALE_MARK_SMALL = new Line2D.Double(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.08878504672897196, IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.0937850467);
    final Line2D SCALE_MARK = new Line2D.Double(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.08878504672897196, IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.1037850467);
    final Line2D SCALE_MARK_BIG = new Line2D.Double(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.08878504672897196, IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.113);
    final Stroke SMALL_STROKE = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final Stroke STROKE = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    final Stroke BIG_STROKE = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

    final int STEP = 5;
    final AffineTransform OLD_TRANSFORM = G2.getTransform();
    G2.rotate(-Math.PI / 2, LOCAL_CENTER.getX(), LOCAL_CENTER.getY());
    for (int angle = -90; angle <= 90; angle += STEP) {
        if (angle % 45 == 0 || angle == 0) {
            //G2.fill(UTIL.rotateTextAroundCenter(G2, Integer.toString(angle), (int) TEXT_POS.getX(), (int) TEXT_POS.getY(), 0));
            G2.setColor(getPointerColor().MEDIUM);
            G2.setStroke(BIG_STROKE);
            G2.draw(SCALE_MARK_BIG);
        } else if (angle % 15 == 0) {
            G2.setColor(Color.WHITE);
            G2.setStroke(STROKE);
            G2.draw(SCALE_MARK);
        } else {
            G2.setColor(Color.WHITE);
            G2.setStroke(SMALL_STROKE);
            G2.draw(SCALE_MARK_SMALL);
        }

        G2.rotate(Math.toRadians(STEP), LOCAL_CENTER.getX(), LOCAL_CENTER.getY());
    }

    G2.setTransform(OLD_TRANSFORM);
    final GeneralPath CENTER_PLANE = new GeneralPath();
    CENTER_PLANE.setWindingRule(Path2D.WIND_EVEN_ODD);
    CENTER_PLANE.moveTo(IMAGE_WIDTH * 0.4766355140186916, IMAGE_HEIGHT * 0.5);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.4766355140186916, IMAGE_HEIGHT * 0.514018691588785, IMAGE_WIDTH * 0.48598130841121495, IMAGE_HEIGHT * 0.5233644859813084, IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.5233644859813084);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.514018691588785, IMAGE_HEIGHT * 0.5233644859813084, IMAGE_WIDTH * 0.5233644859813084, IMAGE_HEIGHT * 0.514018691588785, IMAGE_WIDTH * 0.5233644859813084, IMAGE_HEIGHT * 0.5);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.5233644859813084, IMAGE_HEIGHT * 0.48598130841121495, IMAGE_WIDTH * 0.514018691588785, IMAGE_HEIGHT * 0.4766355140186916, IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.4766355140186916);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.48598130841121495, IMAGE_HEIGHT * 0.4766355140186916, IMAGE_WIDTH * 0.4766355140186916, IMAGE_HEIGHT * 0.48598130841121495, IMAGE_WIDTH * 0.4766355140186916, IMAGE_HEIGHT * 0.5);
    CENTER_PLANE.closePath();
    CENTER_PLANE.moveTo(IMAGE_WIDTH * 0.4158878504672897, IMAGE_HEIGHT * 0.5046728971962616);
    CENTER_PLANE.lineTo(IMAGE_WIDTH * 0.4158878504672897, IMAGE_HEIGHT * 0.4953271028037383);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.4158878504672897, IMAGE_HEIGHT * 0.4953271028037383, IMAGE_WIDTH * 0.4672897196261682, IMAGE_HEIGHT * 0.4953271028037383, IMAGE_WIDTH * 0.4672897196261682, IMAGE_HEIGHT * 0.4953271028037383);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.4719626168224299, IMAGE_HEIGHT * 0.48130841121495327, IMAGE_WIDTH * 0.48130841121495327, IMAGE_HEIGHT * 0.4719626168224299, IMAGE_WIDTH * 0.4953271028037383, IMAGE_HEIGHT * 0.4672897196261682);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.4953271028037383, IMAGE_HEIGHT * 0.4672897196261682, IMAGE_WIDTH * 0.4953271028037383, IMAGE_HEIGHT * 0.4158878504672897, IMAGE_WIDTH * 0.4953271028037383, IMAGE_HEIGHT * 0.4158878504672897);
    CENTER_PLANE.lineTo(IMAGE_WIDTH * 0.5046728971962616, IMAGE_HEIGHT * 0.4158878504672897);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.5046728971962616, IMAGE_HEIGHT * 0.4158878504672897, IMAGE_WIDTH * 0.5046728971962616, IMAGE_HEIGHT * 0.4672897196261682, IMAGE_WIDTH * 0.5046728971962616, IMAGE_HEIGHT * 0.4672897196261682);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.5186915887850467, IMAGE_HEIGHT * 0.4719626168224299, IMAGE_WIDTH * 0.5280373831775701, IMAGE_HEIGHT * 0.48130841121495327, IMAGE_WIDTH * 0.5327102803738317, IMAGE_HEIGHT * 0.4953271028037383);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.5327102803738317, IMAGE_HEIGHT * 0.4953271028037383, IMAGE_WIDTH * 0.5841121495327103, IMAGE_HEIGHT * 0.4953271028037383, IMAGE_WIDTH * 0.5841121495327103, IMAGE_HEIGHT * 0.4953271028037383);
    CENTER_PLANE.lineTo(IMAGE_WIDTH * 0.5841121495327103, IMAGE_HEIGHT * 0.5046728971962616);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.5841121495327103, IMAGE_HEIGHT * 0.5046728971962616, IMAGE_WIDTH * 0.5327102803738317, IMAGE_HEIGHT * 0.5046728971962616, IMAGE_WIDTH * 0.5327102803738317, IMAGE_HEIGHT * 0.5046728971962616);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.5280373831775701, IMAGE_HEIGHT * 0.5186915887850467, IMAGE_WIDTH * 0.5186915887850467, IMAGE_HEIGHT * 0.5327102803738317, IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.5327102803738317);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.48130841121495327, IMAGE_HEIGHT * 0.5327102803738317, IMAGE_WIDTH * 0.4719626168224299, IMAGE_HEIGHT * 0.5186915887850467, IMAGE_WIDTH * 0.4672897196261682, IMAGE_HEIGHT * 0.5046728971962616);
    CENTER_PLANE.curveTo(IMAGE_WIDTH * 0.4672897196261682, IMAGE_HEIGHT * 0.5046728971962616, IMAGE_WIDTH * 0.4158878504672897, IMAGE_HEIGHT * 0.5046728971962616, IMAGE_WIDTH * 0.4158878504672897, IMAGE_HEIGHT * 0.5046728971962616);
    CENTER_PLANE.closePath();
    G2.setPaint(getPointerColor().LIGHT);
    G2.fill(CENTER_PLANE);

    G2.dispose();

    return image;
}
 
Example 15
Source File: XYPointerAnnotation.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
        ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, 
        PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);
    double j2DX = domainAxis.valueToJava2D(getX(), dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(getY(), dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + Math.cos(this.angle) * this.baseRadius;
    double startY = j2DY + Math.sin(this.angle) * this.baseRadius;

    double endX = j2DX + Math.cos(this.angle) * this.tipRadius;
    double endY = j2DY + Math.sin(this.angle) * this.tipRadius;

    double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength;
    double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength;

    double arrowLeftX = arrowBaseX
            + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowLeftY = arrowBaseY
            + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    double arrowRightX = arrowBaseX
            - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightY = arrowBaseY
            - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();

    g2.setStroke(this.arrowStroke);
    g2.setPaint(this.arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, arrowBaseX, arrowBaseY);
    g2.draw(line);
    g2.fill(arrow);

    // draw the label
    double labelX = j2DX + Math.cos(this.angle) * (this.baseRadius
            + this.labelOffset);
    double labelY = j2DY + Math.sin(this.angle) * (this.baseRadius
            + this.labelOffset);
    g2.setFont(getFont());
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(
            getText(), g2, (float) labelX, (float) labelY, getTextAnchor(),
            getRotationAngle(), getRotationAnchor());
    if (getBackgroundPaint() != null) {
        g2.setPaint(getBackgroundPaint());
        g2.fill(hotspot);
    }
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, (float) labelX,
            (float) labelY, getTextAnchor(), getRotationAngle(),
            getRotationAnchor());
    if (isOutlineVisible()) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(hotspot);
    }

    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, hotspot, rendererIndex, toolTip, url);
    }

}
 
Example 16
Source File: StackedBarRenderer3D.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates an array of shapes representing the six sides of a block in a
 * vertical stack.
 *
 * @param x0  left edge of bar (in Java2D space).
 * @param width  the width of the bar (in Java2D units).
 * @param y0  the base of the block (in Java2D space).
 * @param y1  the top of the block (in Java2D space).
 * @param inverted  a flag indicating whether or not the block is inverted
 *     (this changes the order of the faces of the block).
 *
 * @return The sides of the block.
 */
private Shape[] createVerticalBlock(double x0, double width, double y0,
        double y1, boolean inverted) {
    Shape[] result = new Shape[6];
    Point2D p00 = new Point2D.Double(x0, y0);
    Point2D p01 = new Point2D.Double(x0 + width, y0);
    Point2D p02 = new Point2D.Double(p01.getX() + getXOffset(),
            p01.getY() - getYOffset());
    Point2D p03 = new Point2D.Double(p00.getX() + getXOffset(),
            p00.getY() - getYOffset());


    Point2D p0 = new Point2D.Double(x0, y1);
    Point2D p1 = new Point2D.Double(x0 + width, y1);
    Point2D p2 = new Point2D.Double(p1.getX() + getXOffset(),
            p1.getY() - getYOffset());
    Point2D p3 = new Point2D.Double(p0.getX() + getXOffset(),
            p0.getY() - getYOffset());

    GeneralPath right = new GeneralPath();
    right.moveTo((float) p1.getX(), (float) p1.getY());
    right.lineTo((float) p01.getX(), (float) p01.getY());
    right.lineTo((float) p02.getX(), (float) p02.getY());
    right.lineTo((float) p2.getX(), (float) p2.getY());
    right.closePath();

    GeneralPath left = new GeneralPath();
    left.moveTo((float) p0.getX(), (float) p0.getY());
    left.lineTo((float) p00.getX(), (float) p00.getY());
    left.lineTo((float) p03.getX(), (float) p03.getY());
    left.lineTo((float) p3.getX(), (float) p3.getY());
    left.closePath();

    GeneralPath back = new GeneralPath();
    back.moveTo((float) p2.getX(), (float) p2.getY());
    back.lineTo((float) p02.getX(), (float) p02.getY());
    back.lineTo((float) p03.getX(), (float) p03.getY());
    back.lineTo((float) p3.getX(), (float) p3.getY());
    back.closePath();

    GeneralPath front = new GeneralPath();
    front.moveTo((float) p0.getX(), (float) p0.getY());
    front.lineTo((float) p1.getX(), (float) p1.getY());
    front.lineTo((float) p01.getX(), (float) p01.getY());
    front.lineTo((float) p00.getX(), (float) p00.getY());
    front.closePath();

    GeneralPath top = new GeneralPath();
    top.moveTo((float) p0.getX(), (float) p0.getY());
    top.lineTo((float) p1.getX(), (float) p1.getY());
    top.lineTo((float) p2.getX(), (float) p2.getY());
    top.lineTo((float) p3.getX(), (float) p3.getY());
    top.closePath();

    GeneralPath bottom = new GeneralPath();
    bottom.moveTo((float) p00.getX(), (float) p00.getY());
    bottom.lineTo((float) p01.getX(), (float) p01.getY());
    bottom.lineTo((float) p02.getX(), (float) p02.getY());
    bottom.lineTo((float) p03.getX(), (float) p03.getY());
    bottom.closePath();

    result[0] = bottom;
    result[1] = back;
    result[2] = left;
    result[3] = right;
    result[4] = top;
    result[5] = front;
    if (inverted) {
        result[0] = top;
        result[4] = bottom;
    }
    return result;
}
 
Example 17
Source File: SxBeam.java    From SikuliNG with MIT License 4 votes vote down vote up
public void drawRayPolygon(Graphics g, Point p, Rectangle rect) {
    if (p == null || rect == null) {
      return;
    }

    Graphics2D g2d = (Graphics2D) g;

    Rectangle r = rect;
    Ellipse2D.Double ellipse =
            new Ellipse2D.Double(r.x, r.y, r.width - 1, r.height - 1);

    g2d.setColor(Color.red);
    g2d.fill(ellipse);
    //g2d.drawRect(rect.x,rect.y,rect.width,rect.height);

    // compute tangent points
    g2d.translate(rect.x + rect.width / 2, rect.y + rect.height / 2);

    float a0 = r.width / 2;
    float b0 = r.height / 2;
    float a = a0 * a0;
    float b = b0 * b0;

    float m = p.x - rect.x - rect.width / 2;
    float n = p.y - rect.y - rect.height / 2;
    float t1 = (1f + (a * n * n) / (b * m * m));
    float t2 = -2f * a * n / (m * m);
    float t3 = (b * a) / (m * m) - b;

    float s = (float) Math.sqrt(t2 * t2 - 4 * t1 * t3);
    float y1 = (-t2 + s) / (2 * t1);
    float y2 = (-t2 - s) / (2 * t1);

    float x1 = a / m - y1 * (a * n) / (b * m);
    float x2 = a / m - y2 * (a * n) / (b * m);

//      g2d.drawLine((int)m,(int)n,(int)x1,(int)y1);
//      g2d.drawLine((int)m,(int)n,(int)x2,(int)y2);
//
//
//      g2d.setColor(Color.black);
//      g2d.drawLine(0,0,(int)a0,(int)b0);
//
//
//
    GeneralPath flagShape = new GeneralPath();
    flagShape.moveTo(m, n);
    flagShape.lineTo(x1, y1);
    flagShape.lineTo(x2, y2);
    flagShape.closePath();

    g2d.fill(flagShape);

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 1.0f));

    //Rectangle smaller = new Rectangle(rect);
    ellipse =
            new Ellipse2D.Double(-r.width / 2 + 3, -r.height / 2 + 3, r.width - 6, r.height - 6);
    g2d.fill(ellipse);
  }
 
Example 18
Source File: PeakXICComponent.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public void paint() {

    // use Graphics2D for antialiasing
    Graphics2D g2 = new FXGraphics2D(this.getGraphicsContext2D());

    // turn on antialiasing
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // get scan numbers, one data point per each scan
    RawDataFile dataFile = peak.getDataFile();
    int scanNumbers[] = peak.getScanNumbers();

    // If we have no data, just return
    if (scanNumbers.length == 0)
      return;

    // for each datapoint, find [X:Y] coordinates of its point in painted
    // image
    int xValues[] = new int[scanNumbers.length];
    int yValues[] = new int[scanNumbers.length];

    // find one datapoint with maximum intensity in each scan
    for (int i = 0; i < scanNumbers.length; i++) {

      double dataPointIntensity = 0;
      DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);

      if (dataPoint != null)
        dataPointIntensity = dataPoint.getIntensity();

      // get retention time (X value)
      double retentionTime = dataFile.getScan(scanNumbers[i]).getRetentionTime();

      // calculate [X:Y] coordinates
      final double rtLen = rtRange.upperEndpoint() - rtRange.lowerEndpoint();
      xValues[i] = (int) Math
          .floor((retentionTime - rtRange.lowerEndpoint()) / rtLen * ((int) getWidth() - 1));
      yValues[i] = (int) getHeight()
          - (int) Math.floor(dataPointIntensity / maxIntensity * ((int) getHeight() - 1));

    }

    // create a path for a peak polygon
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    path.moveTo(xValues[0], (int) getHeight() - 1);

    // add data points to the path
    for (int i = 0; i < (xValues.length - 1); i++) {
      path.lineTo(xValues[i + 1], yValues[i + 1]);
    }
    path.lineTo(xValues[xValues.length - 1], (int) getHeight() - 1);

    // close the path to form a polygon
    path.closePath();

    // fill the peak area
    g2.setColor(XICColor);
    g2.fill(path);

  }
 
Example 19
Source File: StackedBarRenderer3D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates an array of shapes representing the six sides of a block in a
 * horizontal stack.
 *
 * @param x0  left edge of bar (in Java2D space).
 * @param width  the width of the bar (in Java2D units).
 * @param y0  the base of the block (in Java2D space).
 * @param y1  the top of the block (in Java2D space).
 * @param inverted  a flag indicating whether or not the block is inverted
 *     (this changes the order of the faces of the block).
 *
 * @return The sides of the block.
 */
private Shape[] createHorizontalBlock(double x0, double width, double y0,
        double y1, boolean inverted) {
    Shape[] result = new Shape[6];
    Point2D p00 = new Point2D.Double(y0, x0);
    Point2D p01 = new Point2D.Double(y0, x0 + width);
    Point2D p02 = new Point2D.Double(p01.getX() + getXOffset(),
            p01.getY() - getYOffset());
    Point2D p03 = new Point2D.Double(p00.getX() + getXOffset(),
            p00.getY() - getYOffset());

    Point2D p0 = new Point2D.Double(y1, x0);
    Point2D p1 = new Point2D.Double(y1, x0 + width);
    Point2D p2 = new Point2D.Double(p1.getX() + getXOffset(),
            p1.getY() - getYOffset());
    Point2D p3 = new Point2D.Double(p0.getX() + getXOffset(),
            p0.getY() - getYOffset());

    GeneralPath bottom = new GeneralPath();
    bottom.moveTo((float) p1.getX(), (float) p1.getY());
    bottom.lineTo((float) p01.getX(), (float) p01.getY());
    bottom.lineTo((float) p02.getX(), (float) p02.getY());
    bottom.lineTo((float) p2.getX(), (float) p2.getY());
    bottom.closePath();

    GeneralPath top = new GeneralPath();
    top.moveTo((float) p0.getX(), (float) p0.getY());
    top.lineTo((float) p00.getX(), (float) p00.getY());
    top.lineTo((float) p03.getX(), (float) p03.getY());
    top.lineTo((float) p3.getX(), (float) p3.getY());
    top.closePath();

    GeneralPath back = new GeneralPath();
    back.moveTo((float) p2.getX(), (float) p2.getY());
    back.lineTo((float) p02.getX(), (float) p02.getY());
    back.lineTo((float) p03.getX(), (float) p03.getY());
    back.lineTo((float) p3.getX(), (float) p3.getY());
    back.closePath();

    GeneralPath front = new GeneralPath();
    front.moveTo((float) p0.getX(), (float) p0.getY());
    front.lineTo((float) p1.getX(), (float) p1.getY());
    front.lineTo((float) p01.getX(), (float) p01.getY());
    front.lineTo((float) p00.getX(), (float) p00.getY());
    front.closePath();

    GeneralPath left = new GeneralPath();
    left.moveTo((float) p0.getX(), (float) p0.getY());
    left.lineTo((float) p1.getX(), (float) p1.getY());
    left.lineTo((float) p2.getX(), (float) p2.getY());
    left.lineTo((float) p3.getX(), (float) p3.getY());
    left.closePath();

    GeneralPath right = new GeneralPath();
    right.moveTo((float) p00.getX(), (float) p00.getY());
    right.lineTo((float) p01.getX(), (float) p01.getY());
    right.lineTo((float) p02.getX(), (float) p02.getY());
    right.lineTo((float) p03.getX(), (float) p03.getY());
    right.closePath();
    result[0] = bottom;
    result[1] = back;
    if (inverted) {
        result[2] = right;
        result[3] = left;
    }
    else {
        result[2] = left;
        result[3] = right;
    }
    result[4] = top;
    result[5] = front;
    return result;
}
 
Example 20
Source File: Test.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
private Shape[] createVerticalBlock(double x0, double width, double y0,
                                    double y1, boolean inverted) {
    Shape[] result = new Shape[6];
    Point2D p00 = new Point2D.Double(x0, y0);
    Point2D p01 = new Point2D.Double(x0 + width, y0);
    Point2D p02 = new Point2D.Double(p01.getX() + getXOffset(),
            p01.getY() - getYOffset());
    Point2D p03 = new Point2D.Double(p00.getX() + getXOffset(),
            p00.getY() - getYOffset());


    Point2D p0 = new Point2D.Double(x0, y1);
    Point2D p1 = new Point2D.Double(x0 + width, y1);
    Point2D p2 = new Point2D.Double(p1.getX() + getXOffset(),
            p1.getY() - getYOffset());
    Point2D p3 = new Point2D.Double(p0.getX() + getXOffset(),
            p0.getY() - getYOffset());

    GeneralPath right = new GeneralPath();
    right.moveTo((float) p1.getX(), (float) p1.getY());
    right.lineTo((float) p01.getX(), (float) p01.getY());
    right.lineTo((float) p02.getX(), (float) p02.getY());
    right.lineTo((float) p2.getX(), (float) p2.getY());
    right.closePath();

    GeneralPath left = new GeneralPath();
    left.moveTo((float) p0.getX(), (float) p0.getY());
    left.lineTo((float) p00.getX(), (float) p00.getY());
    left.lineTo((float) p03.getX(), (float) p03.getY());
    left.lineTo((float) p3.getX(), (float) p3.getY());
    left.closePath();

    GeneralPath back = new GeneralPath();
    back.moveTo((float) p2.getX(), (float) p2.getY());
    back.lineTo((float) p02.getX(), (float) p02.getY());
    back.lineTo((float) p03.getX(), (float) p03.getY());
    back.lineTo((float) p3.getX(), (float) p3.getY());
    back.closePath();

    GeneralPath front = new GeneralPath();
    front.moveTo((float) p0.getX(), (float) p0.getY());
    front.lineTo((float) p1.getX(), (float) p1.getY());
    front.lineTo((float) p01.getX(), (float) p01.getY());
    front.lineTo((float) p00.getX(), (float) p00.getY());
    front.closePath();

    GeneralPath top = new GeneralPath();
    top.moveTo((float) p0.getX(), (float) p0.getY());
    top.lineTo((float) p1.getX(), (float) p1.getY());
    top.lineTo((float) p2.getX(), (float) p2.getY());
    top.lineTo((float) p3.getX(), (float) p3.getY());
    top.closePath();

    GeneralPath bottom = new GeneralPath();
    bottom.moveTo((float) p00.getX(), (float) p00.getY());
    bottom.lineTo((float) p01.getX(), (float) p01.getY());
    bottom.lineTo((float) p02.getX(), (float) p02.getY());
    bottom.lineTo((float) p03.getX(), (float) p03.getY());
    bottom.closePath();

    result[0] = bottom;
    result[1] = back;
    result[2] = left;
    result[3] = right;
    result[4] = top;
    result[5] = front;
    if (inverted) {
        result[0] = top;
        result[4] = bottom;
    }
    return result;
}