Java Code Examples for java.awt.Graphics2D#draw()

The following examples show how to use java.awt.Graphics2D#draw() . These examples are extracted from open source projects. 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 Project: Rails   File: TokenIcon.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {

        Ellipse2D.Double circle =
                new Ellipse2D.Double(x, y, diameter, diameter);
        Graphics2D g2d = (Graphics2D) g;
        Color oldColour = g2d.getColor();

        g2d.setColor(bgColour);
        g2d.fill(circle);
        g2d.setColor(Color.BLACK);
        g2d.draw(circle);

        g2d.setColor(oldColour);
        HexPoint center = new HexPoint(x + diameter / 2.0, y + diameter / 2.0);
        GUIToken.drawTokenText(text, g2d, fgColour, center, diameter);
    }
 
Example 2
/**
 * Draws a vertical line used to trace the mouse position to the horizontal
 * axis.
 *
 * @param g2 the graphics device.
 * @param x  the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {

        if (this.verticalTraceLine != null) {
            g2.draw(this.verticalTraceLine);
            this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x,
                    (int) dataArea.getMaxY());
        }
        else {
            this.verticalTraceLine = new Line2D.Float(x,
                    (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        }
        g2.draw(this.verticalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}
 
Example 3
@Override
public Dimension render(Graphics2D graphics)
{
	Widget puzzleAnswer = plugin.getPuzzleAnswer();

	if (config.showBrotherLoc())
	{
		renderBarrowsBrothers(graphics);
	}

	if (puzzleAnswer != null && config.showPuzzleAnswer() && !puzzleAnswer.isHidden())
	{
		Rectangle answerRect = puzzleAnswer.getBounds();
		graphics.setColor(Color.GREEN);
		graphics.draw(answerRect);
	}

	return null;
}
 
Example 4
/**
 * Returns an icon.
 *
 * @param shape  the shape.
 * @param fill  the fill flag.
 * @param outline  the outline flag.
 *
 * @return The icon.
 */
private Icon getIcon(Shape shape, final boolean fill, 
                     final boolean outline) {
    final int width = shape.getBounds().width;
    final int height = shape.getBounds().height;
    final GeneralPath path = new GeneralPath(shape);
    return new Icon() {
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Graphics2D g2 = (Graphics2D) g;
            path.transform(AffineTransform.getTranslateInstance(x, y));
            if (fill) {
                g2.fill(path);
            }
            if (outline) {
                g2.draw(path);
            }
            path.transform(AffineTransform.getTranslateInstance(-x, -y));
        }

        public int getIconWidth() {
            return width;
        }

        public int getIconHeight() {
            return height;
        }
    };
}
 
Example 5
/**
 * Draw polyline
 *
 * @param points The points array
 * @param g Graphics2D
 */
public static void drawPolyline(PointD[] points, Graphics2D g) {
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
    for (int i = 0; i < points.length; i++) {
        if (i == 0) {
            path.moveTo(points[i].X, points[i].Y);
        } else {
            path.lineTo(points[i].X, points[i].Y);
        }
    }

    g.draw(path);
}
 
Example 6
private void renderHullOverlay(Graphics2D graphics, NPC npc, Color color)
{
	Shape objectClickbox = npc.getConvexHull();
	if (objectClickbox != null)
	{
		graphics.setColor(color);
		graphics.setStroke(new BasicStroke(2));
		graphics.draw(objectClickbox);
		graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20));
		graphics.fill(objectClickbox);
	}
}
 
Example 7
private void drawRectangle(Graphics2D graphics, Rectangle rect, Color color, boolean inList, boolean hiddenBox)
{
	graphics.setColor(Color.BLACK);
	graphics.drawRect(rect.x + 1, rect.y + 1, rect.width, rect.height);

	graphics.setColor(color);
	graphics.draw(rect);

	if (inList)
	{
		graphics.fill(rect);
	}

	graphics.setColor(Color.WHITE);
	// Minus symbol
	graphics.drawLine
		(
			rect.x + 2,
			rect.y + (rect.height / 2),
			rect.x + rect.width - 2,
			rect.y + (rect.height / 2)
		);

	if (!hiddenBox)
	{
		// Plus symbol
		graphics.drawLine
			(
				rect.x + (rect.width / 2),
				rect.y + 2,
				rect.x + (rect.width / 2),
				rect.y + rect.height - 2
			);
	}

}
 
Example 8
Source Project: ECG-Viewer   File: XYPlot.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws a range crosshair.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 *
 * @since 1.0.4
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea,
        PlotOrientation orientation, double value, ValueAxis axis,
        Stroke stroke, Paint paint) {

    if (!axis.getRange().contains(value)) {
        return;
    }
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Line2D line;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                dataArea.getMaxY());
    } else {
        double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy,
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 9
private void drawToolTip(Graphics2D g) {
	if (currentToolTip != null) {
		g.setFont(LABEL_FONT);
		Rectangle2D stringBounds = LABEL_FONT.getStringBounds(currentToolTip, g.getFontRenderContext());
		g.setColor(TOOLTIP_COLOR);
		Rectangle2D bg = new Rectangle2D.Double(toolTipX - stringBounds.getWidth() / 2 - 4, toolTipY
				- stringBounds.getHeight() / 2 - 2, stringBounds.getWidth() + 5, Math.abs(stringBounds.getHeight()) + 3);
		g.fill(bg);
		g.setColor(Color.black);
		g.draw(bg);
		g.drawString(currentToolTip, (float) (toolTipX - stringBounds.getWidth() / 2) - 2, (float) (toolTipY + 3));
	}
}
 
Example 10
Source Project: SIMVA-SoS   File: PaletteSample.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Draws the sample.
 *
 * @param g  the graphics device.
 */
@Override
public void paintComponent(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_OFF);
    Dimension size = getSize();
    Insets insets = getInsets();
    double ww = size.getWidth() - insets.left - insets.right;
    double hh = size.getHeight() - insets.top - insets.bottom;

    g2.setStroke(new BasicStroke(1.0f));

    double y1 = insets.top;
    double y2 = y1 + hh;
    double xx = insets.left;
    Line2D line = new Line2D.Double();
    int count = 0;
    while (xx <= insets.left + ww) {
        count++;
        line.setLine(xx, y1, xx, y2);
        g2.setPaint(this.palette.getColor(count));
        g2.draw(line);
        xx += 1;
    }
}
 
Example 11
private void drawTextAndEmbellishments(Label label,
                                       Graphics2D g2d,
                                       float x,
                                       float y) {

    label.handleDraw(g2d, x, y);

    if (!strikethrough && stdUnderline == null && imUnderline == null) {
        return;
    }

    float x1 = x;
    float x2 = x1 + (float)label.getLogicalBounds().getWidth();

    CoreMetrics cm = label.getCoreMetrics();
    if (strikethrough) {
        Stroke savedStroke = g2d.getStroke();
        g2d.setStroke(new BasicStroke(cm.strikethroughThickness,
                                      BasicStroke.CAP_BUTT,
                                      BasicStroke.JOIN_MITER));
        float strikeY = y + cm.strikethroughOffset;
        g2d.draw(new Line2D.Float(x1, strikeY, x2, strikeY));
        g2d.setStroke(savedStroke);
    }

    float ulOffset = cm.underlineOffset;
    float ulThickness = cm.underlineThickness;

    if (stdUnderline != null) {
        stdUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }

    if (imUnderline != null) {
        imUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }
}
 
Example 12
Source Project: coming   File: Arja_0062_s.java    License: MIT License 5 votes vote down vote up
/**
 * Draws a grid line against the domain axis.
 * <P>
 * Note that this default implementation assumes that the horizontal axis
 * is the domain axis. If this is not the case, you will need to override
 * this method.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the Java2D value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis,
 *     Rectangle2D, double)
 *
 * @since 1.2.0
 */
public void drawDomainLine(Graphics2D g2, CategoryPlot plot,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument.");
    }
    if (stroke == null) {
        throw new IllegalArgumentException("Null 'stroke' argument.");
    }
    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value,
                dataArea.getMaxX(), value);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value,
                dataArea.getMaxY());
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example 13
@Override
public void draw(Graphics2D g2, Rectangle2D chartArea, Point2D anchor, ChartRenderingInfo info) {
    super.draw(g2, chartArea, anchor, info);

    if (info != null) {
        // for each CategoryItem, highlight the bar
        // this has to be done during painting so it carries over on repaints
        for (CategoryItemEntity entity : selectedEntities) {
            Rectangle2D area = ((Rectangle2D) entity.getArea())
                    .createIntersection(info.getPlotInfo().getDataArea());

            CategoryItemRenderer renderer = ((CategoryPlot) getPlot()).getRenderer();
            int row = entity.getDataset().getRowIndex(entity.getRowKey());
            int column = entity.getDataset().getColumnIndex(entity.getColumnKey());

            java.awt.Color baseColor = (java.awt.Color) renderer.getItemPaint(row, column);

            // redraw the bar with the base color
            // assuming bar was drawn with SimpleGradientBarPainter, this will be a flat color
            g2.setPaint(baseColor);
            g2.fill(area);

            // draw a brighter outline around the bar
            g2.setStroke(renderer.getBaseOutlineStroke());
            g2.setPaint(baseColor.darker());
            g2.draw(area);
        }
    }
}
 
Example 14
/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param selected  is the item selected?
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
        boolean selected, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    MultiValueCategoryDataset d = (MultiValueCategoryDataset) dataset;
    List values = d.getValues(row, column);
    if (values == null) {
        return;
    }
    int valueCount = values.size();
    for (int i = 0; i < valueCount; i++) {
        // current data point...
        double x1;
        if (this.useSeriesOffset) {
            x1 = domainAxis.getCategorySeriesMiddle(column,
                    dataset.getColumnCount(), visibleRow, visibleRowCount,
                    this.itemMargin, dataArea, plot.getDomainAxisEdge());
        }
        else {
            x1 = domainAxis.getCategoryMiddle(column, getColumnCount(),
                    dataArea, plot.getDomainAxisEdge());
        }
        Number n = (Number) values.get(i);
        double value = n.doubleValue();
        double y1 = rangeAxis.valueToJava2D(value, dataArea,
                plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, column, selected);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        if (getItemShapeFilled(row, column)) {
            if (this.useFillPaint) {
                g2.setPaint(getItemFillPaint(row, column, selected));
            }
            else {
                g2.setPaint(getItemPaint(row, column, selected));
            }
            g2.fill(shape);
        }
        if (this.drawOutlines) {
            if (this.useOutlinePaint) {
                g2.setPaint(getItemOutlinePaint(row, column, selected));
            }
            else {
                g2.setPaint(getItemPaint(row, column, selected));
            }
            g2.setStroke(getItemOutlineStroke(row, column, selected));
            g2.draw(shape);
        }
    }

}
 
Example 15
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    g2.setPaint(Color.blue);
    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame,
            this.widthRadius, this.widthRadius);
    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0,
            Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0,
            Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.outlinePaint);
    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt1.getX(), pt1.getY());
    g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}
 
Example 16
/**
 * 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  an optional info object that will be populated with
 *              entity information.
 */
@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);

    float anchorX = (float) domainAxis.valueToJava2D(
            this.x, dataArea, domainEdge);
    float anchorY = (float) rangeAxis.valueToJava2D(
            this.y, dataArea, rangeEdge);

    if (orientation == PlotOrientation.HORIZONTAL) {
        float tempAnchor = anchorX;
        anchorX = anchorY;
        anchorY = tempAnchor;
    }

    g2.setFont(getFont());
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(
            getText(), g2, anchorX, anchorY, getTextAnchor(),
            getRotationAngle(), getRotationAnchor());
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(hotspot);
    }
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());
    if (this.outlineVisible) {
        g2.setStroke(this.outlineStroke);
        g2.setPaint(this.outlinePaint);
        g2.draw(hotspot);
    }

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

}
 
Example 17
private static void testHugeImage(final int width, final int height)
    throws ArrayIndexOutOfBoundsException
{
    System.out.println("---\n" + "testHugeImage: "
        + "width=" + width + ", height=" + height);

    final BasicStroke stroke = createStroke(2.5f, false, 0);

    // size > 24bits (exceed both tile and buckets arrays)
    System.out.println("image size = " + width + " x "+height);

    final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);

    final Graphics2D g2d = (Graphics2D) image.getGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

        g2d.setBackground(Color.WHITE);
        g2d.clearRect(0, 0, width, height);

        g2d.setStroke(stroke);
        g2d.setColor(Color.BLACK);

        final Path2D.Float path = new Path2D.Float(WIND_NON_ZERO, 32);
        path.moveTo(0, 0);
        path.lineTo(width, 0);
        path.lineTo(width, height);
        path.lineTo(0, height);
        path.lineTo(0, 0);

        final long start = System.nanoTime();

        g2d.draw(path);

        final long time = System.nanoTime() - start;

        System.out.println("paint: duration= " + (1e-6 * time) + " ms.");

        if (SAVE_IMAGE) {
            try {
                final File file = new File("CrashTest-huge-"
                    + width + "x" +height + ".bmp");

                System.out.println("Writing file: " + file.getAbsolutePath());
                ImageIO.write(image, "BMP", file);
            } catch (IOException ex) {
                System.out.println("Writing file failure:");
                ex.printStackTrace();
            }
        }
    } finally {
        g2d.dispose();
    }
}
 
Example 18
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
        XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
 
Example 19
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param selected  is the data item selected?
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawShape2(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, int pass, int series, int item,
        boolean selected, ValueAxis domainAxis, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item, selected);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1,
                    transX1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1,
                    transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item, selected));
                }
                else {
                    g2.setPaint(getItemPaint(series, item, selected));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item,
                            selected));
                }
                else {
                    g2.setPaint(getItemPaint(series, item, selected));
                }
                g2.setStroke(getItemOutlineStroke(series, item, selected));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item, selected)) {
        drawItemLabel(g2, orientation, dataset, series, item, selected, 
                xx, yy, (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null 
            && ShapeUtilities.isPointInRect(xx, yy, dataArea)) {
        addEntity(entities, entityArea, dataset, series, item, selected,
                xx, yy);
    }
}
 
Example 20
Source Project: astor   File: LongNeedle.java    License: GNU General Public License v2.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.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 
                          Point2D rotate, double angle) {

    GeneralPath shape1 = new GeneralPath();
    GeneralPath shape2 = new GeneralPath();
    GeneralPath shape3 = 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() * getRotateX()));
    //float midY = (float) (minY + (plotArea.getHeight() * getRotateY()));
    float midX = (float) (minX + (plotArea.getWidth() * 0.5));
    float midY = (float) (minY + (plotArea.getHeight() * 0.8));
    float y = maxY - (2 * (maxY - midY));
    if (y < minY) {
        y = minY;
    }
    shape1.moveTo(minX, midY);
    shape1.lineTo(midX, minY);
    shape1.lineTo(midX, y);
    shape1.closePath();

    shape2.moveTo(maxX, midY);
    shape2.lineTo(midX, minY);
    shape2.lineTo(midX, y);
    shape2.closePath();

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

    Shape s1 = shape1;
    Shape s2 = shape2;
    Shape s3 = shape3;

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


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

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


    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(s1);
        g2.draw(s2);
        g2.draw(s3);
    }
}