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

The following examples show how to use java.awt.geom.GeneralPath#moveTo() . 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: PlotterChooser.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath arrow = new GeneralPath();
	int h = 2;
	int w = 4;
	arrow.moveTo(getWidth() - GAP_RIGHT - w, getHeight() / 2);
	arrow.lineTo(getWidth() - GAP_RIGHT + w, getHeight() / 2);
	arrow.lineTo(getWidth() - GAP_RIGHT, getHeight() / 2 + 2 * h);
	arrow.closePath();

	Graphics2D g2 = (Graphics2D) g.create();
	if (isEnabled()) {
		g2.setColor(Color.BLACK);
	} else {
		g2.setColor(Color.GRAY);
	}
	g2.fill(arrow);
	g2.dispose();
}
 
Example 2
Source File: PointShapeFactory.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a shape representing a point.
 * 
 * @param point
 *          the location of the point
 * @return a shape
 */
public Shape createPoint(Point2D point) {
  GeneralPath path = new GeneralPath();
  path.moveTo((float) point.getX(), (float) (point.getY() - size/2));
  path.lineTo((float) (point.getX() + size * 1/8), (float) (point.getY() - size * 1/8));
  path.lineTo((float) (point.getX() + size/2), (float) (point.getY() - size * 1/8));
  path.lineTo((float) (point.getX() + size * 2/8), (float) (point.getY() + size * 1/8));
  path.lineTo((float) (point.getX() + size * 3/8), (float) (point.getY() + size/2));
  path.lineTo((float) (point.getX()), (float) (point.getY() + size * 2/8));
  path.lineTo((float) (point.getX() - size * 3/8), (float) (point.getY() + size/2));
  path.lineTo((float) (point.getX() - size * 2/8), (float) (point.getY() + size * 1/8));
  path.lineTo((float) (point.getX() - size/2), (float) (point.getY() - size * 1/8));
  path.lineTo((float) (point.getX() - size * 1/8), (float) (point.getY() - size * 1/8));
  path.closePath();
  return path;
}
 
Example 3
Source File: XYAreaRenderer2.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs a new renderer.
 *
 * @param labelGenerator  the tool tip generator to use.  <code>null</code>
 *                        is none.
 * @param urlGenerator  the URL generator (null permitted).
 */
public XYAreaRenderer2(XYToolTipGenerator labelGenerator,
                       XYURLGenerator urlGenerator) {
    super();
    this.showOutline = false;
    setBaseToolTipGenerator(labelGenerator);
    setURLGenerator(urlGenerator);
    GeneralPath area = new GeneralPath();
    area.moveTo(0.0f, -4.0f);
    area.lineTo(3.0f, -2.0f);
    area.lineTo(4.0f, 4.0f);
    area.lineTo(-4.0f, 4.0f);
    area.lineTo(-3.0f, -2.0f);
    area.closePath();
    this.legendArea = area;
}
 
Example 4
Source File: Elixir_001_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 5
Source File: AwtStrokeExample.java    From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Shape createStrokedShape(Shape shape)
{
	GeneralPath newshape = new GeneralPath(); // Start with an empty shape

	// Iterate through the specified shape, perturb its coordinates, and
	// use them to build up the new shape.
	float[] coords = new float[6];
	for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i
			.next())
	{
		int type = i.currentSegment(coords);
		switch (type)
		{
		case PathIterator.SEG_MOVETO:
			perturb(coords, 2);
			newshape.moveTo(coords[0], coords[1]);
			break;
		case PathIterator.SEG_LINETO:
			perturb(coords, 2);
			newshape.lineTo(coords[0], coords[1]);
			break;
		case PathIterator.SEG_QUADTO:
			perturb(coords, 4);
			newshape.quadTo(coords[0], coords[1], coords[2], coords[3]);
			break;
		case PathIterator.SEG_CUBICTO:
			perturb(coords, 6);
			newshape.curveTo(coords[0], coords[1], coords[2], coords[3],
					coords[4], coords[5]);
			break;
		case PathIterator.SEG_CLOSE:
			newshape.closePath();
			break;
		}
	}

	// Finally, stroke the perturbed shape and return the result
	return stroke.createStrokedShape(newshape);
}
 
Example 6
Source File: ClipPath.java    From openstock with GNU General Public License v3.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 7
Source File: FreeForm.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
@Override
public java.awt.Rectangle getBounds() {
    GeneralPath p = new GeneralPath();
    p.moveTo(points.get(0).x, points.get(0).y);
    for (int i = 1; i < points.size(); i++) {
        p.lineTo(points.get(i).x, points.get(i).y);
    }

    Rectangle2D r2d = p.getBounds2D();
    return new java.awt.Rectangle((int) r2d.getX(), (int) r2d.getY(), (int) r2d.getWidth(), (int) r2d.getHeight());
}
 
Example 8
Source File: StarTransition2D.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Shape getShape() {
    GeneralPath p = new GeneralPath();
    double angle = PI / 10;
    float r2 = 2.5f;
    double k = PI * 2 / 10;
    p.moveTo((float) cos(angle), (float) sin(angle));
    for (int a = 0; a < 5; a++) {
        p.lineTo((float) (r2 * cos(angle + k)), (float) (r2 * sin(angle + k)));
        angle += PI * 2.0 / 5.0;
        p.lineTo((float) cos(angle), (float) sin(angle));
    }
    p.closePath();
    return p;
}
 
Example 9
Source File: Arrow.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the arrowhead shape.
 * @param theta double the angle of the arrow
 * @return Shape
 */
protected Shape getHead(double theta) {
  GeneralPath path = new GeneralPath();
  path.moveTo(1, 0);
  path.lineTo(-headSize, -headSize/2);
  path.lineTo(-headSize, +headSize/2);
  path.closePath();
  AffineTransform rot = AffineTransform.getRotateInstance(-theta);
  Shape head = rot.createTransformedShape(path);
  return head;
}
 
Example 10
Source File: DoubleInterpolator.java    From GIFKR with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void paintButton(Graphics2D g, int width, int height) {
	g.setColor(Color.black);
	g.setStroke(new BasicStroke(1));

	double min = getMin();
	double max = getMax();
	double range = max - min;
	
	GeneralPath path = new GeneralPath();
	path.moveTo(keyframes.get(0).getTime() * width, (1f - (keyframes.get(0).getValue()-min)/range) * height);
	for(int i = 1; i < keyframes.size(); i++)
		path.lineTo(keyframes.get(i).getTime() * width, ((1f - (keyframes.get(i).getValue()-min)/range) * height-.5f));
	g.draw(path);
}
 
Example 11
Source File: lineutility.java    From mil-sym-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GeneralPath from a Path2D
 *
 * @param shape
 * @return
 */
protected static Shape createStrokedShape(Shape shape) {
    GeneralPath newshape = new GeneralPath(); // Start with an empty shape
    try {
        // Iterate through the specified shape, perturb its coordinates, and
        // use them to build up the new shape.
        float[] coords = new float[6];
        for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) {
            int type = i.currentSegment(coords);
            switch (type) {
                case PathIterator.SEG_MOVETO:
                    //perturb(coords, 2);
                    newshape.moveTo(coords[0], coords[1]);
                    break;
                case PathIterator.SEG_LINETO:
                    //perturb(coords, 2);
                    newshape.lineTo(coords[0], coords[1]);
                    break;
                case PathIterator.SEG_QUADTO:
                    //perturb(coords, 4);
                    newshape.quadTo(coords[0], coords[1], coords[2], coords[3]);
                    break;
                case PathIterator.SEG_CUBICTO:
                    //perturb(coords, 6);
                    newshape.curveTo(coords[0], coords[1], coords[2], coords[3],
                            coords[4], coords[5]);
                    break;
                case PathIterator.SEG_CLOSE:
                    newshape.closePath();
                    break;
            }

        }
    } catch (Exception exc) {
        ErrorLogger.LogException(_className, "createStrokedShape",
                new RendererException("Failed inside createStrokedShape", exc));
    }
    return newshape;
}
 
Example 12
Source File: BarRenderer3D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
public void drawBackground(Graphics2D g2, CategoryPlot plot, 
                           Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getBackgroundAlpha()));
    
    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // highlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);
            
    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX() 
                + getXOffset(), dataArea.getY(), 
                dataArea.getWidth() - getXOffset(), 
                dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }
    
    g2.setComposite(originalComposite);

}
 
Example 13
Source File: ArrowShape.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns arrow shape.
 *
 * @param type      requested shape type
 * @param bounds    painting bounds
 * @param direction arrow direction
 * @return arrow shape
 */
@NotNull
protected Shape createArrowButtonShape ( @NotNull final ShapeType type, @NotNull final Rectangle bounds,
                                         @NotNull final CompassDirection direction )
{
    final int x = bounds.x;
    final int y = bounds.y;
    final int w = bounds.width + ( type == ShapeType.border ? -1 : 0 );
    final int h = bounds.height + ( type == ShapeType.border ? -1 : 0 );

    final GeneralPath shape = new GeneralPath ( GeneralPath.WIND_EVEN_ODD );
    switch ( direction )
    {
        case north:
        {
            shape.moveTo ( x, y + h );
            shape.quadTo ( x + w / 2f, y + h * 2 / 3f, x + w, y + h );
            shape.lineTo ( x + w / 2f, y );
            break;
        }
        case south:
        {
            shape.moveTo ( x, y );
            shape.quadTo ( x + w / 2f, y + h / 3f, x + w, y );
            shape.lineTo ( x + w / 2f, y + h );
            break;
        }
        case west:
        {
            shape.moveTo ( x + w, y );
            shape.quadTo ( x + w * 2 / 3f, y + h / 2f, x + w, y + h );
            shape.lineTo ( x, y + h / 2f );
            break;
        }
        case east:
        {
            shape.moveTo ( x, y );
            shape.quadTo ( x + w / 3f, y + h / 2f, x, y + h );
            shape.lineTo ( x + w, y + h / 2f );
            break;
        }
    }
    shape.closePath ();

    return shape;
}
 
Example 14
Source File: LineRenderer3D.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the background for the plot.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area inside the axes.
 */
@Override
public void drawBackground(Graphics2D g2, CategoryPlot plot,
                           Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath leftWall = new GeneralPath();
    leftWall.moveTo(x0, y0);
    leftWall.lineTo(x0, y2);
    leftWall.lineTo(x1, y3);
    leftWall.lineTo(x1, y1);
    leftWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(leftWall);

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // higlight the background corners...
    g2.setPaint(Color.lightGray);
    Line2D corner = new Line2D.Double(x0, y0, x1, y1);
    g2.draw(corner);
    corner.setLine(x1, y1, x1, y3);
    g2.draw(corner);
    corner.setLine(x1, y1, x3, y1);
    g2.draw(corner);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX()
                + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(),
                dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}
 
Example 15
Source File: TrafficLight2.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public BufferedImage create3LightsHousingImage(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 RoundRectangle2D BACKGROUND = new RoundRectangle2D.Double(0.125 * IMAGE_WIDTH, 0.055 * IMAGE_HEIGHT, 0.75 * IMAGE_WIDTH, 0.9 * IMAGE_HEIGHT, 0.75 * IMAGE_WIDTH, 0.3 * IMAGE_HEIGHT);
    G2.setPaint(new Color(0.8f, 0.8f, 0.8f, 0.5f));
    G2.fill(BACKGROUND);

    final GeneralPath FRAME = new GeneralPath();
    FRAME.setWindingRule(Path2D.WIND_EVEN_ODD);
    FRAME.moveTo(0.125 * IMAGE_WIDTH, 0.205 * IMAGE_HEIGHT);
    FRAME.curveTo(0.125 * IMAGE_WIDTH, 0.12 * IMAGE_HEIGHT, 0.2875 * IMAGE_WIDTH, 0.055 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.055 * IMAGE_HEIGHT);
    FRAME.curveTo(0.7125 * IMAGE_WIDTH, 0.055 * IMAGE_HEIGHT, 0.875 * IMAGE_WIDTH, 0.12 * IMAGE_HEIGHT, 0.875 * IMAGE_WIDTH, 0.205 * IMAGE_HEIGHT);
    FRAME.curveTo(0.875 * IMAGE_WIDTH, 0.205 * IMAGE_HEIGHT, 0.875 * IMAGE_WIDTH, 0.805 * IMAGE_HEIGHT, 0.875 * IMAGE_WIDTH, 0.805 * IMAGE_HEIGHT);
    FRAME.curveTo(0.875 * IMAGE_WIDTH, 0.89 * IMAGE_HEIGHT, 0.7125 * IMAGE_WIDTH, 0.955 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.955 * IMAGE_HEIGHT);
    FRAME.curveTo(0.2875 * IMAGE_WIDTH, 0.955 * IMAGE_HEIGHT, 0.125 * IMAGE_WIDTH, 0.89 * IMAGE_HEIGHT, 0.125 * IMAGE_WIDTH, 0.805 * IMAGE_HEIGHT);
    FRAME.curveTo(0.125 * IMAGE_WIDTH, 0.805 * IMAGE_HEIGHT, 0.125 * IMAGE_WIDTH, 0.205 * IMAGE_HEIGHT, 0.125 * IMAGE_WIDTH, 0.205 * IMAGE_HEIGHT);
    FRAME.closePath();
    FRAME.moveTo(0.0 * IMAGE_WIDTH, 0.2 * IMAGE_HEIGHT);
    FRAME.curveTo(0.0 * IMAGE_WIDTH, 0.2 * IMAGE_HEIGHT, 0.0 * IMAGE_WIDTH, 0.8 * IMAGE_HEIGHT, 0.0 * IMAGE_WIDTH, 0.8 * IMAGE_HEIGHT);
    FRAME.curveTo(0.0 * IMAGE_WIDTH, 0.91 * IMAGE_HEIGHT, 0.225 * IMAGE_WIDTH, 1.0 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 1.0 * IMAGE_HEIGHT);
    FRAME.curveTo(0.775 * IMAGE_WIDTH, 1.0 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 0.91 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 0.8 * IMAGE_HEIGHT);
    FRAME.curveTo(1.0 * IMAGE_WIDTH, 0.8 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 0.2 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 0.2 * IMAGE_HEIGHT);
    FRAME.curveTo(1.0 * IMAGE_WIDTH, 0.09 * IMAGE_HEIGHT, 0.775 * IMAGE_WIDTH, 0.0 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.0 * IMAGE_HEIGHT);
    FRAME.curveTo(0.225 * IMAGE_WIDTH, 0.0 * IMAGE_HEIGHT, 0.0 * IMAGE_WIDTH, 0.09 * IMAGE_HEIGHT, 0.0 * IMAGE_WIDTH, 0.2 * IMAGE_HEIGHT);
    FRAME.closePath();
    G2.setPaint(new Color(0.2f, 0.2f, 0.2f, 0.5f));
    G2.fill(FRAME);

    G2.dispose();
    return IMAGE;
}
 
Example 16
Source File: XYPointerAnnotation.java    From ECG-Viewer with GNU General Public License v2.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 17
Source File: TrafficLight2.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public BufferedImage create2LightsRedImage(final int WIDTH, final int HEIGHT, final boolean IS_ON) {
    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();
    if (!IS_ON) {
        final Ellipse2D RED_OFF = new Ellipse2D.Double(0.1875 * IMAGE_WIDTH, 0.11428571428571428 * IMAGE_HEIGHT, 0.625 * IMAGE_WIDTH, 0.35714285714285715 * IMAGE_HEIGHT);
        G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.40714285714285714 * IMAGE_HEIGHT), (0.59375f * IMAGE_WIDTH), new float[]{0.0f, 0.98f, 0.99f, 1.0f}, new Color[]{new Color(0.3019607843f, 0f, 0f, 1f), new Color(0.0039215686f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f)}));
        G2.fill(RED_OFF);

        final Ellipse2D RED_HIGHLIGHT_OFF = new Ellipse2D.Double(0.2625 * IMAGE_WIDTH, 0.12142857142857143 * IMAGE_HEIGHT, 0.4625 * IMAGE_WIDTH, 0.14285714285714285 * IMAGE_HEIGHT);
        G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.15 * IMAGE_HEIGHT), (0.2125f * IMAGE_WIDTH), new float[]{0.0f, 0.98f, 1.0f}, new Color[]{new Color(1f, 1f, 1f, 0.2235294118f), new Color(1f, 1f, 1f, 0.0274509804f), new Color(1f, 1f, 1f, 0.0274509804f)}));
        G2.fill(RED_HIGHLIGHT_OFF);
    } else {
        final Ellipse2D RED_GLOW = new Ellipse2D.Double(0.0 * IMAGE_WIDTH, 0.0 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 0.5714285714285714 * IMAGE_HEIGHT);
        G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.2857142857142857 * IMAGE_HEIGHT), (0.5f * IMAGE_WIDTH), new float[]{0.0f, 0.98f, 0.99f, 1.0f}, new Color[]{new Color(1f, 0f, 0f, 1f), new Color(1f, 0f, 0f, 0f), new Color(1f, 0f, 0f, 0f), new Color(1f, 0f, 0f, 0f)}));
        G2.fill(RED_GLOW);

        final Ellipse2D RED_ON = new Ellipse2D.Double(0.1875 * IMAGE_WIDTH, 0.11428571428571428 * IMAGE_HEIGHT, 0.625 * IMAGE_WIDTH, 0.35714285714285715 * IMAGE_HEIGHT);
        G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.40714285714285714 * IMAGE_HEIGHT), (0.59375f * IMAGE_WIDTH), new float[]{0.0f, 0.98f, 0.99f, 1.0f}, new Color[]{new Color(1f, 0f, 0f, 1f), new Color(0.2549019608f, 0f, 0f, 1f), new Color(0.2470588235f, 0f, 0f, 1f), new Color(0.2470588235f, 0f, 0f, 1f)}));
        G2.fill(RED_ON);

        final GeneralPath RED_HIGHLIGHT_ON = new GeneralPath();
        RED_HIGHLIGHT_ON.setWindingRule(Path2D.WIND_EVEN_ODD);
        RED_HIGHLIGHT_ON.moveTo(0.2625 * IMAGE_WIDTH, 0.18571428571428572 * IMAGE_HEIGHT);
        RED_HIGHLIGHT_ON.curveTo(0.2625 * IMAGE_WIDTH, 0.17142857142857143 * IMAGE_HEIGHT, 0.375 * IMAGE_WIDTH, 0.12142857142857143 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.12142857142857143 * IMAGE_HEIGHT);
        RED_HIGHLIGHT_ON.curveTo(0.625 * IMAGE_WIDTH, 0.12142857142857143 * IMAGE_HEIGHT, 0.725 * IMAGE_WIDTH, 0.16428571428571428 * IMAGE_HEIGHT, 0.725 * IMAGE_WIDTH, 0.18571428571428572 * IMAGE_HEIGHT);
        RED_HIGHLIGHT_ON.curveTo(0.725 * IMAGE_WIDTH, 0.22857142857142856 * IMAGE_HEIGHT, 0.625 * IMAGE_WIDTH, 0.2642857142857143 * IMAGE_HEIGHT, 0.5 * IMAGE_WIDTH, 0.2642857142857143 * IMAGE_HEIGHT);
        RED_HIGHLIGHT_ON.curveTo(0.375 * IMAGE_WIDTH, 0.2642857142857143 * IMAGE_HEIGHT, 0.2625 * IMAGE_WIDTH, 0.2357142857142857 * IMAGE_HEIGHT, 0.2625 * IMAGE_WIDTH, 0.18571428571428572 * IMAGE_HEIGHT);
        RED_HIGHLIGHT_ON.closePath();
        G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.15 * IMAGE_HEIGHT), (0.2125f * IMAGE_WIDTH), new float[]{0.0f, 0.98f, 1.0f}, new Color[]{new Color(1f, 1f, 1f, 0.6745098039f), new Color(1f, 1f, 1f, 0.0862745098f), new Color(1f, 1f, 1f, 0.0862745098f)}));
        G2.fill(RED_HIGHLIGHT_ON);
    }
    final Ellipse2D RED_INNER_SHADOW = new Ellipse2D.Double(0.1875 * IMAGE_WIDTH, 0.11428571428571428 * IMAGE_HEIGHT, 0.625 * IMAGE_WIDTH, 0.35714285714285715 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.29285714285714287 * IMAGE_HEIGHT), (0.3125f * IMAGE_WIDTH), new float[]{0.0f, 0.55f, 0.5501f, 0.78f, 0.79f, 1.0f}, new Color[]{new Color(0.0039215686f, 0.0039215686f, 0.0039215686f, 0f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 0f, 0.1215686275f), new Color(0f, 0f, 0f, 0.1294117647f), new Color(0f, 0f, 0f, 0.4980392157f)}));
    G2.fill(RED_INNER_SHADOW);

    G2.dispose();
    return IMAGE;
}
 
Example 18
Source File: DigitalRadial.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage create_100FT_POINTER_Image(final int WIDTH) {
    if (WIDTH <= 0) {
        return null;
    }

    final BufferedImage IMAGE = UTIL.createImage(WIDTH, (int) (1.0 * 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 POINTER100FT = new GeneralPath();
    POINTER100FT.setWindingRule(Path2D.WIND_EVEN_ODD);
    POINTER100FT.moveTo(IMAGE_WIDTH * 0.5186915887850467, IMAGE_HEIGHT * 0.4719626168224299);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.514018691588785, IMAGE_HEIGHT * 0.4719626168224299, IMAGE_WIDTH * 0.5093457943925234, IMAGE_HEIGHT * 0.4672897196261682, IMAGE_WIDTH * 0.5093457943925234, IMAGE_HEIGHT * 0.4672897196261682);
    POINTER100FT.lineTo(IMAGE_WIDTH * 0.5093457943925234, IMAGE_HEIGHT * 0.20093457943925233);
    POINTER100FT.lineTo(IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.16822429906542055);
    POINTER100FT.lineTo(IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.20093457943925233);
    POINTER100FT.lineTo(IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.4672897196261682);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.4672897196261682, IMAGE_WIDTH * 0.48130841121495327, IMAGE_HEIGHT * 0.4719626168224299, IMAGE_WIDTH * 0.48130841121495327, IMAGE_HEIGHT * 0.4719626168224299);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.4719626168224299, IMAGE_HEIGHT * 0.48130841121495327, IMAGE_WIDTH * 0.4672897196261682, IMAGE_HEIGHT * 0.49065420560747663, IMAGE_WIDTH * 0.4672897196261682, IMAGE_HEIGHT * 0.5);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.4672897196261682, IMAGE_HEIGHT * 0.514018691588785, IMAGE_WIDTH * 0.4766355140186916, IMAGE_HEIGHT * 0.5280373831775701, IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.5327102803738317);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.5327102803738317, IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.5794392523364486, IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.5887850467289719);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.48598130841121495, IMAGE_HEIGHT * 0.5934579439252337, IMAGE_WIDTH * 0.48130841121495327, IMAGE_HEIGHT * 0.5981308411214953, IMAGE_WIDTH * 0.48130841121495327, IMAGE_HEIGHT * 0.6074766355140186);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.48130841121495327, IMAGE_HEIGHT * 0.616822429906542, IMAGE_WIDTH * 0.49065420560747663, IMAGE_HEIGHT * 0.6261682242990654, IMAGE_WIDTH * 0.5, IMAGE_HEIGHT * 0.6261682242990654);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.5093457943925234, IMAGE_HEIGHT * 0.6261682242990654, IMAGE_WIDTH * 0.5186915887850467, IMAGE_HEIGHT * 0.616822429906542, IMAGE_WIDTH * 0.5186915887850467, IMAGE_HEIGHT * 0.6074766355140186);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.5186915887850467, IMAGE_HEIGHT * 0.5981308411214953, IMAGE_WIDTH * 0.514018691588785, IMAGE_HEIGHT * 0.5934579439252337, IMAGE_WIDTH * 0.5046728971962616, IMAGE_HEIGHT * 0.5887850467289719);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.5046728971962616, IMAGE_HEIGHT * 0.5794392523364486, IMAGE_WIDTH * 0.5046728971962616, IMAGE_HEIGHT * 0.5327102803738317, IMAGE_WIDTH * 0.5093457943925234, IMAGE_HEIGHT * 0.5327102803738317);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.5233644859813084, IMAGE_HEIGHT * 0.5280373831775701, IMAGE_WIDTH * 0.5327102803738317, IMAGE_HEIGHT * 0.514018691588785, IMAGE_WIDTH * 0.5327102803738317, IMAGE_HEIGHT * 0.5);
    POINTER100FT.curveTo(IMAGE_WIDTH * 0.5327102803738317, IMAGE_HEIGHT * 0.49065420560747663, IMAGE_WIDTH * 0.5280373831775701, IMAGE_HEIGHT * 0.48130841121495327, IMAGE_WIDTH * 0.5186915887850467, IMAGE_HEIGHT * 0.4719626168224299);
    POINTER100FT.closePath();
    final Point2D POINTER100FT_START = new Point2D.Double(0, POINTER100FT.getBounds2D().getMinY());
    final Point2D POINTER100FT_STOP = new Point2D.Double(0, POINTER100FT.getBounds2D().getMaxY());
    final float[] POINTER100FT_FRACTIONS = {
        0.0f,
        0.31f,
        0.3101f,
        0.32f,
        1.0f
    };
    final Color[] POINTER100FT_COLORS = {
        new Color(255, 255, 255, 255),
        new Color(255, 255, 255, 255),
        new Color(255, 255, 255, 255),
        new Color(32, 32, 32, 255),
        new Color(32, 32, 32, 255)
    };
    final LinearGradientPaint POINTER100FT_GRADIENT = new LinearGradientPaint(POINTER100FT_START, POINTER100FT_STOP, POINTER100FT_FRACTIONS, POINTER100FT_COLORS);
    G2.setPaint(POINTER100FT_GRADIENT);
    G2.fill(POINTER100FT);

    G2.dispose();

    return IMAGE;
}
 
Example 19
Source File: LivreBase.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
public Shape getRegiaoVDocumentos() {
    if (Regiao == null) {
        final int v1 = getHeight() / 3;
        final int h1 = getWidth() / 2;
        final int repo = v1 / 3;
        final int L = getLeft();
        int recuo = h1 / 8;
        final int T = getTop() + recuo;
        final int TH = T + getHeight() - repo - recuo;
        final int LW = L + getWidth() - recuo;
        CubicCurve2D c = new CubicCurve2D.Double();
        c.setCurve(L, TH, L + h1, TH + v1, LW - h1, TH - v1, LW, TH);
        GeneralPath pa = new GeneralPath();
        pa.setWindingRule(GeneralPath.WIND_EVEN_ODD);

        pa.moveTo(LW, TH);
        pa.lineTo(LW, T);
        pa.lineTo(L, T);
        pa.lineTo(L, TH);
        pa.append(c, false);

        int tam = recuo / 2;

        pa.moveTo(L + tam, T);
        pa.lineTo(L + tam, T - tam);
        pa.lineTo(LW + tam, T - tam);
        pa.lineTo(LW + tam, TH - tam);
        pa.lineTo(LW, TH - tam);
        pa.lineTo(LW, T);
        pa.lineTo(L + tam, T);

        tam = recuo;

        pa.moveTo(L + tam, T - (tam / 2));
        pa.lineTo(L + tam, T - tam);
        pa.lineTo(LW + tam, T - tam);
        pa.lineTo(LW + tam, TH - tam);
        pa.lineTo(LW + (tam / 2), TH - tam);
        pa.lineTo(LW + (tam / 2), T - (tam / 2));
        pa.lineTo(L + tam, T - (tam / 2));

        pa.closePath();

        Regiao = pa;
        final int ptToMove = 3;
        this.reposicionePonto[ptToMove] = new Point(-tam / 2, -repo);
        ptsToMove[ptToMove] = 1;
    }
    return Regiao;
}
 
Example 20
Source File: GraphicsLib.java    From osp with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Compute a cardinal spline, a series of cubic Bezier splines smoothly
 * connecting a set of points. Cardinal splines maintain C(1)
 * continuity, ensuring the connected spline segments form a differentiable
 * curve, ensuring at least a minimum level of smoothness.
 * @param pts the points to interpolate with a cardinal spline
 * @param start the starting index from which to read points
 * @param npoints the number of points to consider
 * @param slack a parameter controlling the "tightness" of the spline to
 * the control points, 0.10 is a typically suitable value
 * @param closed true if the cardinal spline should be closed (i.e. return
 * to the starting point), false for an open curve
 * @return the cardinal spline as a Java2D {@link java.awt.geom.GeneralPath}
 * instance.
 */
public static GeneralPath cardinalSpline(float pts[], int start, int npoints, float slack, boolean closed) {
  GeneralPath path = new GeneralPath();
  path.moveTo(pts[start], pts[start+1]);
  return cardinalSpline(path, pts, start, npoints, slack, closed, 0f, 0f);
}