Java Code Examples for java.awt.geom.Line2D#Double

The following examples show how to use java.awt.geom.Line2D#Double . 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: LineNeedle.java    From openstock with GNU General Public License v3.0 6 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) {

    Line2D shape = new Line2D.Double();

    double x = plotArea.getMinX() + (plotArea.getWidth() / 2);
    shape.setLine(x, plotArea.getMinY(), x, plotArea.getMaxY());

    Shape s = shape;

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s = getTransform().createTransformedShape(s);
    }

    defaultDisplay(g2, s);

}
 
Example 2
Source File: Cardumen_009_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a domain 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 drawDomainCrosshair(Graphics2D g2, Rectangle2D dataArea,
        PlotOrientation orientation, double value, ValueAxis axis,
        Stroke stroke, Paint paint) {

    if (axis.getRange().contains(value)) {
        Line2D line = null;
        if (orientation == PlotOrientation.VERTICAL) {
            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);
    }

}
 
Example 3
Source File: Arja_00112_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the 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
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

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

}
 
Example 4
Source File: Chart_14_CategoryPlot_t.java    From coming with MIT License 6 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.5
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, 
        PlotOrientation orientation, double value, ValueAxis axis, 
        Stroke stroke, Paint paint) {
    
    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line = null;
    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);
   
}
 
Example 5
Source File: ModifiedPlot.java    From chipster with MIT License 6 votes vote down vote up
/**
 * Utility method for drawing a crosshair on the chart (if required).
 *
 * @param g2  The graphics device.
 * @param dataArea  The data area.
 * @param value  The coordinate, where to draw the line.
 * @param stroke  The stroke to use.
 * @param paint  The paint to use.
 */
protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea,
                                  double value, Stroke stroke, 
                                  Paint paint) {

    double yy = getRangeAxis().valueToJava2D(
        value, dataArea, RectangleEdge.LEFT
    );
    Line2D line = new Line2D.Double(
        dataArea.getMinX(), yy, dataArea.getMaxX(), yy
    );
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
Example 6
Source File: XYLineAndShapeRenderer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new renderer.
 *
 * @param lines  lines visible?
 * @param shapes  shapes visible?
 */
public XYLineAndShapeRenderer(boolean lines, boolean shapes) {
    this.linesVisible = null;
    this.seriesLinesVisible = new BooleanList();
    this.baseLinesVisible = lines;
    this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0);

    this.shapesVisible = null;
    this.seriesShapesVisible = new BooleanList();
    this.baseShapesVisible = shapes;

    this.shapesFilled = null;
    this.useFillPaint = false;     // use item paint for fills by default
    this.seriesShapesFilled = new BooleanList();
    this.baseShapesFilled = true;

    this.drawOutlines = true;
    this.useOutlinePaint = false;  // use item paint for outlines by
                                   // default, not outline paint

    this.drawSeriesLineAsPath = false;
}
 
Example 7
Source File: LegendGraphicTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for cloning - checks that the line shape is cloned correctly.
 */
public void testCloning2() {
    Rectangle r = new Rectangle(1, 2, 3, 4);
    LegendGraphic g1 = new LegendGraphic(r, Color.black);
    Line2D l = new Line2D.Double(1.0, 2.0, 3.0, 4.0);
    g1.setLine(l);
    LegendGraphic g2 = null;
    try {
        g2 = (LegendGraphic) g1.clone();
    }
    catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));
    
    // check independence
    l.setLine(4.0, 3.0, 2.0, 1.0);
    assertFalse(g1.equals(g2));
   
}
 
Example 8
Source File: CyclicNumberAxis.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the axis.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param cursor  the cursor position.
 * @param plotArea  the plot area (<code>null</code> not permitted).
 * @param dataArea  the data area (<code>null</code> not permitted).
 * @param edge  the edge (<code>null</code> not permitted).
 * @param plotState  collects information about the plot
 *                   (<code>null</code> permitted).
 *
 * @return The axis state (never <code>null</code>).
 */
@Override
public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea,
        Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) {

    AxisState ret = super.draw(g2, cursor, plotArea, dataArea, edge, 
            plotState);
    if (isAdvanceLineVisible()) {
        double xx = valueToJava2D(getRange().getUpperBound(), dataArea, 
                edge);
        Line2D mark = null;
        g2.setStroke(getAdvanceLineStroke());
        g2.setPaint(getAdvanceLinePaint());
        if (edge == RectangleEdge.LEFT) {
            mark = new Line2D.Double(cursor, xx, cursor 
                    + dataArea.getWidth(), xx);
        }
        else if (edge == RectangleEdge.RIGHT) {
            mark = new Line2D.Double(cursor - dataArea.getWidth(), xx, 
                    cursor, xx);
        }
        else if (edge == RectangleEdge.TOP) {
            mark = new Line2D.Double(xx, cursor + dataArea.getHeight(), xx, 
                    cursor);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            mark = new Line2D.Double(xx, cursor, xx, 
                    cursor - dataArea.getHeight());
        }
        g2.draw(mark);
    }
    return ret;
}
 
Example 9
Source File: jMutRepair_0020_t.java    From coming with 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 10
Source File: Lab.java    From DeconvolutionLab2 with GNU General Public License v3.0 5 votes vote down vote up
public static void showPlanar(RealSignal signal, String title) {
	if (signal == null) {
		return;
	}
	ArrayList<Line2D.Double> lines = Output.createOverlayPlanar(signal);
	imaging.show(signal.createPlanar(), title, Imager.Type.FLOAT, 0, lines);
}
 
Example 11
Source File: Diagram.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public DiagramGraph getClosestGraph(int x, int y) {
    double minDist = Double.MAX_VALUE;

    Point2D.Double a = new Point2D.Double();
    Point2D.Double b1 = new Point2D.Double();
    Point2D.Double b2 = new Point2D.Double();
    DiagramGraph closestGraph = null;
    for (DiagramGraph graph : getGraphs()) {
        double minDistGraph = Double.MAX_VALUE;
        int n = graph.getNumValues();
        for (int i = 0; i < n; i++) {
            a.setLocation(graph.getXValueAt(i), graph.getYValueAt(i));
            b1.setLocation(b2);
            transform.transformA2B(a, b2);
            if (i > 0) {
                Line2D.Double segment = new Line2D.Double(b1, b2);
                double v = segment.ptSegDist(x, y);
                if (v < minDistGraph) {
                    minDistGraph = v;
                }
            }
        }
        if (minDistGraph < minDist) {
            minDist = minDistGraph;
            closestGraph = graph;
        }
    }
    return closestGraph;
}
 
Example 12
Source File: FractalTree.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
private static void connectPoints(Graphics2D g,
                                  double x1, double y1,
                                  double x2, double y2, float c) {
    if (c == 0) {
        var line = new Line2D.Double(x1, y1, x2, y2);
        g.draw(line);
    } else {
        Path2D path = new Path2D.Double();
        path.moveTo(x1, y1);

        double dx = x2 - x1;
        double dy = y2 - y1;

        // center point
        double cx = x1 + dx / 2.0;
        double cy = y1 + dy / 2.0;

        // calculate only one Bezier control point,
        // and use it for both.
        // The normal vector is -dy, dx.
        double ctrlX = cx - dy * c;
        double ctrlY = cy + dx * c;

        path.curveTo(ctrlX, ctrlY, ctrlX, ctrlY, x2, y2);
        g.draw(path);
    }
}
 
Example 13
Source File: JGenProg2017_00102_t.java    From coming with 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 14
Source File: AbstractXYItemRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint.
 * @param stroke  the stroke.
 */
public void drawRangeLine(Graphics2D g2,
                          XYPlot plot,
                          ValueAxis axis,
                          Rectangle2D dataArea,
                          double value,
                          Paint paint,
                          Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v, 
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v, 
                dataArea.getMaxX(), v);
    }
    
    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example 15
Source File: StandardXYItemRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a new renderer.  To specify the type of renderer, use one of
 * the constants: {@link #SHAPES}, {@link #LINES} or
 * {@link #SHAPES_AND_LINES}.
 *
 * @param type  the type of renderer.
 * @param toolTipGenerator  the item label generator (<code>null</code>
 *                          permitted).
 * @param urlGenerator  the URL generator.
 */
public StandardXYItemRenderer(int type,
                              XYToolTipGenerator toolTipGenerator,
                              XYURLGenerator urlGenerator) {

    super();
    setBaseToolTipGenerator(toolTipGenerator);
    setURLGenerator(urlGenerator);
    if ((type & SHAPES) != 0) {
        this.baseShapesVisible = true;
    }
    if ((type & LINES) != 0) {
        this.plotLines = true;
    }
    if ((type & IMAGES) != 0) {
        this.plotImages = true;
    }
    if ((type & DISCONTINUOUS) != 0) {
        this.plotDiscontinuous = true;
    }

    this.shapesFilled = null;
    this.seriesShapesFilled = new BooleanList();
    this.baseShapesFilled = true;
    this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0);
    this.drawSeriesLineAsPath = false;
}
 
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: ValueAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the axis line, tick marks and tick mark labels.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the plot area.
 * @param dataArea  the data area.
 * @param edge  the edge that the axis is aligned with.
 * @param info  the plot rendering info.
 * 
 * @return The width or height used to draw the axis.
 */
protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor,
        Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge,
        PlotRenderingInfo info) {
                                          
    AxisState state = new AxisState(cursor);

    if (isAxisLineVisible()) {
        drawAxisLine(g2, cursor, dataArea, edge);
    }

    double ol = getTickMarkOutsideLength();
    double il = getTickMarkInsideLength();

    List ticks = refreshTicks(g2, state, dataArea, edge);
    state.setTicks(ticks);
    g2.setFont(getTickLabelFont());
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        if (isTickLabelsVisible()) {
            g2.setPaint(getTickLabelPaint());
            float[] anchorPoint = calculateAnchorPoint(tick, cursor, 
                    dataArea, edge);
            TextUtilities.drawRotatedString(tick.getText(), g2, 
                    anchorPoint[0], anchorPoint[1], tick.getTextAnchor(), 
                    tick.getAngle(), tick.getRotationAnchor());
        }

        if (isTickMarksVisible() && tick.getTickType().equals(TickType.MAJOR)) {
            float xx = (float) valueToJava2D(tick.getValue(), dataArea, 
                    edge);
            Line2D mark = null;
            g2.setStroke(getTickMarkStroke());
            g2.setPaint(getTickMarkPaint());
            if (edge == RectangleEdge.LEFT) {
                mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx);
            }
            else if (edge == RectangleEdge.RIGHT) {
                mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx);
            }
            else if (edge == RectangleEdge.TOP) {
                mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
            }
            else if (edge == RectangleEdge.BOTTOM) {
                mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il);
            }
            g2.draw(mark);
        }
    }
    
    // need to work out the space used by the tick labels...
    // so we can update the cursor...
    double used = 0.0;
    if (isTickLabelsVisible()) {
        if (edge == RectangleEdge.LEFT) {
            used += findMaximumTickLabelWidth(ticks, g2, plotArea, 
                    isVerticalTickLabels());  
            state.cursorLeft(used);      
        }
        else if (edge == RectangleEdge.RIGHT) {
            used = findMaximumTickLabelWidth(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorRight(used);      
        }
        else if (edge == RectangleEdge.TOP) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorUp(used);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorDown(used);
        }
    }
   
    return state;
}
 
Example 18
Source File: Cardumen_000_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 19
Source File: Arja_0062_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 20
Source File: AbstractGraphics2D.java    From pentaho-reporting with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Draws a line, using the current color, between the points <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
 * in this graphics context's coordinate system.
 *
 * @param x1
 *          the first point's <i>x</i> coordinate.
 * @param y1
 *          the first point's <i>y</i> coordinate.
 * @param x2
 *          the second point's <i>x</i> coordinate.
 * @param y2
 *          the second point's <i>y</i> coordinate.
 */
public void drawLine( final int x1, final int y1, final int x2, final int y2 ) {
  final Line2D line = new Line2D.Double( (double) x1, (double) y1, (double) x2, (double) y2 );
  draw( line );
}