Java Code Examples for java.awt.geom.Rectangle2D#getMinX()

The following examples show how to use java.awt.geom.Rectangle2D#getMinX() . 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: JGenProg2017_000_s.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 2
Source File: VisualTransformableNode.java    From workcraft with MIT License 6 votes vote down vote up
protected Rectangle2D transformToParentSpace(Rectangle2D rect) {
    if (rect == null) {
        return null;
    }

    Point2D p0 = new Point2D.Double(rect.getMinX(), rect.getMinY());
    Point2D p1 = new Point2D.Double(rect.getMaxX(), rect.getMaxY());

    AffineTransform t = getLocalToParentTransform();
    t.transform(p0, p0);
    t.transform(p1, p1);

    Rectangle2D.Double result = new Rectangle2D.Double(p0.getX(), p0.getY(), 0, 0);
    result.add(p1);

    return result;
}
 
Example 3
Source File: Chart_14_CategoryPlot_s.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 4
Source File: StandardGlyphVector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * For each glyph return posx, posy, advx, advy, visx, visy, visw, vish.
 */
public float[] getGlyphInfo() {
    setFRCTX();
    initPositions();
    float[] result = new float[glyphs.length * 8];
    for (int i = 0, n = 0; i < glyphs.length; ++i, n += 8) {
        float x = positions[i*2];
        float y = positions[i*2+1];
        result[n] = x;
        result[n+1] = y;

        int glyphID = glyphs[i];
        GlyphStrike s = getGlyphStrike(i);
        Point2D.Float adv = s.strike.getGlyphMetrics(glyphID);
        result[n+2] = adv.x;
        result[n+3] = adv.y;

        Rectangle2D vb = getGlyphVisualBounds(i).getBounds2D();
        result[n+4] = (float)(vb.getMinX());
        result[n+5] = (float)(vb.getMinY());
        result[n+6] = (float)(vb.getWidth());
        result[n+7] = (float)(vb.getHeight());
    }
    return result;
}
 
Example 5
Source File: JGenProg2017_0078_s.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 6
Source File: ImageCursorOverlay.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void drawCrosshair(Graphics2D graphics, AffineTransform i2vTransform, Point centerPixel,
                           Rectangle2D pixelViewRect) {
    Rectangle surroundImageRect = new Rectangle(centerPixel.x - 1, centerPixel.y - 1, 3, 3);
    Rectangle2D surroundViewRect = i2vTransform.createTransformedShape(surroundImageRect).getBounds2D();
    double scale = MAX_CROSSHAIR_SIZE / surroundViewRect.getBounds2D().getWidth();
    if (scale > 1) {
        double newWidth = surroundViewRect.getWidth() * scale;
        double newHeight = surroundViewRect.getHeight() * scale;
        double newX = surroundViewRect.getCenterX() - newWidth / 2;
        double newY = surroundViewRect.getCenterY() - newHeight / 2;
        surroundViewRect.setRect(newX, newY, newWidth, newHeight);
    }
    graphics.draw(surroundViewRect);

    Line2D.Double northLine = new Line2D.Double(surroundViewRect.getCenterX(), surroundViewRect.getMinY(),
                                                surroundViewRect.getCenterX(), pixelViewRect.getMinY());
    Line2D.Double eastLine = new Line2D.Double(surroundViewRect.getMaxX(), surroundViewRect.getCenterY(),
                                               pixelViewRect.getMaxX(), surroundViewRect.getCenterY());
    Line2D.Double southLine = new Line2D.Double(surroundViewRect.getCenterX(), surroundViewRect.getMaxY(),
                                                surroundViewRect.getCenterX(), pixelViewRect.getMaxY());
    Line2D.Double westLine = new Line2D.Double(surroundViewRect.getMinX(), surroundViewRect.getCenterY(),
                                               pixelViewRect.getMinX(), surroundViewRect.getCenterY());
    graphics.draw(northLine);
    graphics.draw(eastLine);
    graphics.draw(southLine);
    graphics.draw(westLine);
}
 
Example 7
Source File: AbstractCategoryItemRenderer.java    From buffer_bci with GNU General Public License v3.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 (<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) {

    // TODO: In JFreeChart 1.2.0, put this method in the
    // CategoryItemRenderer interface
    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);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 8
Source File: IntervalRectangle.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Sets this rectangle to be the same as the specified rectangle.
 *
 * @param  r  the rectangle to copy values from.
 */
@Override
public final void setRect(final Rectangle2D r) {
    if (r != this) {        // Optimization for methods chaining like r.setRect(Shapes.transform(…, r))
        xmin = r.getMinX();
        ymin = r.getMinY();
        xmax = r.getMaxX();
        ymax = r.getMaxY();
    }
}
 
Example 9
Source File: 1_AbstractCategoryItemRenderer.java    From SimFix with GNU General Public License v2.0 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: jKali_0019_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 11
Source File: JGenProg2017_00124_s.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 12
Source File: AbstractCategoryItemRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a grid line against 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.
 *
 * @see #drawDomainGridline(Graphics2D, CategoryPlot, Rectangle2D, double)
 */
@Override
public void drawRangeGridline(Graphics2D g2, CategoryPlot plot,
        ValueAxis axis, Rectangle2D dataArea, double value) {

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

    PlotOrientation orientation = plot.getOrientation();
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    Line2D line = null;
    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);
    }

    Paint paint = plot.getRangeGridlinePaint();
    if (paint == null) {
        paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getRangeGridlineStroke();
    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);

}
 
Example 13
Source File: LogarithmicAxis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts a data value to a coordinate in Java2D space, assuming that
 * the axis runs along one edge of the specified plotArea.
 * Note that it is possible for the coordinate to fall outside the
 * plotArea.
 *
 * @param value  the data value.
 * @param plotArea  the area for plotting the data.
 * @param edge  the axis location.
 *
 * @return The Java2D coordinate.
 */
public double valueToJava2D(double value, Rectangle2D plotArea,
                            RectangleEdge edge) {

    Range range = getRange();
    double axisMin = switchedLog10(range.getLowerBound());
    double axisMax = switchedLog10(range.getUpperBound());

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = plotArea.getMinX();
        max = plotArea.getMaxX();
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        min = plotArea.getMaxY();
        max = plotArea.getMinY();
    }

    value = switchedLog10(value);

    if (isInverted()) {
        return max - (((value - axisMin) / (axisMax - axisMin))
                * (max - min));
    }
    else {
        return min + (((value - axisMin) / (axisMax - axisMin))
                * (max - min));
    }

}
 
Example 14
Source File: LinkAndBrushChartPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {

	// if we've been panning, we need to reset now that the mouse is
	// released...
	Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle");
	Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
	if (getChartFieldValueByName("panLast") != null) {
		setChartFieldValue(getChartFieldByName("panLast"), null);
		setCursor(Cursor.getDefaultCursor());
	} else if (zoomRectangle != null) {
		boolean hZoom = false;
		boolean vZoom = false;
		if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
			hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
			vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
		} else {
			hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
			vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
		}

		boolean zoomTrigger1 = hZoom
				&& Math.abs(e.getX() - zoomPoint.getX()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
		boolean zoomTrigger2 = vZoom
				&& Math.abs(e.getY() - zoomPoint.getY()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
		if (zoomTrigger1 || zoomTrigger2) {
			if (hZoom && e.getX() < zoomPoint.getX() || vZoom && e.getY() < zoomPoint.getY()) {
				restoreAutoBounds();
			} else {
				double x, y, w, h;
				Rectangle2D screenDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
				double maxX = screenDataArea.getMaxX();
				double maxY = screenDataArea.getMaxY();
				// for mouseReleased event, (horizontalZoom || verticalZoom)
				// will be true, so we can just test for either being false;
				// otherwise both are true
				if (!vZoom) {
					x = zoomPoint.getX();
					y = screenDataArea.getMinY();
					w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
					h = screenDataArea.getHeight();
				} else if (!hZoom) {
					x = screenDataArea.getMinX();
					y = zoomPoint.getY();
					w = screenDataArea.getWidth();
					h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
				} else {
					x = zoomPoint.getX();
					y = zoomPoint.getY();
					w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
					h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
				}
				Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
				zoom(zoomArea);
			}
			setChartFieldValue(getChartFieldByName("zoomPoint"), null);
			setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
		} else {
			// erase the zoom rectangle
			Graphics2D g2 = (Graphics2D) getGraphics();
			if ((Boolean) getChartFieldValueByName("useBuffer")) {
				repaint();
			} else {
				drawZoomRectangle(g2, true);
			}
			g2.dispose();
			setChartFieldValue(getChartFieldByName("zoomPoint"), null);
			setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
		}

	}

	else if (e.isPopupTrigger()) {
		if (getChartFieldValueByName("popup") != null) {
			displayPopupMenu(e.getX(), e.getY());
		}
	}

}
 
Example 15
Source File: CrosshairOverlay.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a crosshair vertically on the plot.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param x  the x-value in Java2D space.
 * @param crosshair  the crosshair.
 */
protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea,
        double x, Crosshair crosshair) {

    if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) {
        Line2D line = new Line2D.Double(x, dataArea.getMinY(), x,
                dataArea.getMaxY());
        Paint savedPaint = g2.getPaint();
        Stroke savedStroke = g2.getStroke();
        g2.setPaint(crosshair.getPaint());
        g2.setStroke(crosshair.getStroke());
        g2.draw(line);
        if (crosshair.isLabelVisible()) {
            String label = crosshair.getLabelGenerator().generateLabel(
                    crosshair);
            RectangleAnchor anchor = crosshair.getLabelAnchor();
            Point2D pt = calculateLabelPoint(line, anchor, 5, 5);
            float xx = (float) pt.getX();
            float yy = (float) pt.getY();
            TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor);
            Shape hotspot = TextUtilities.calculateRotatedStringBounds(
                    label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
            if (!dataArea.contains(hotspot.getBounds2D())) {
                anchor = flipAnchorH(anchor);
                pt = calculateLabelPoint(line, anchor, 5, 5);
                xx = (float) pt.getX();
                yy = (float) pt.getY();
                alignPt = textAlignPtForLabelAnchorV(anchor);
                hotspot = TextUtilities.calculateRotatedStringBounds(
                       label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
            }
            g2.setPaint(crosshair.getLabelBackgroundPaint());
            g2.fill(hotspot);
            g2.setPaint(crosshair.getLabelOutlinePaint());
            g2.draw(hotspot);
            TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt);
        }
        g2.setPaint(savedPaint);
        g2.setStroke(savedStroke);
    }
}
 
Example 16
Source File: CrosshairOverlay.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a crosshair horizontally across the plot.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param y  the y-value in Java2D space.
 * @param crosshair  the crosshair.
 */
protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea,
        double y, Crosshair crosshair) {

    if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) {
        Line2D line = new Line2D.Double(dataArea.getMinX(), y,
                dataArea.getMaxX(), y);
        Paint savedPaint = g2.getPaint();
        Stroke savedStroke = g2.getStroke();
        g2.setPaint(crosshair.getPaint());
        g2.setStroke(crosshair.getStroke());
        g2.draw(line);
        if (crosshair.isLabelVisible()) {
            String label = crosshair.getLabelGenerator().generateLabel(
                    crosshair);
            RectangleAnchor anchor = crosshair.getLabelAnchor();
            Point2D pt = calculateLabelPoint(line, anchor, 5, 5);
            float xx = (float) pt.getX();
            float yy = (float) pt.getY();
            TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor);
            Shape hotspot = TextUtilities.calculateRotatedStringBounds(
                    label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
            if (!dataArea.contains(hotspot.getBounds2D())) {
                anchor = flipAnchorV(anchor);
                pt = calculateLabelPoint(line, anchor, 5, 5);
                xx = (float) pt.getX();
                yy = (float) pt.getY();
                alignPt = textAlignPtForLabelAnchorH(anchor);
                hotspot = TextUtilities.calculateRotatedStringBounds(
                       label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
            }

            g2.setPaint(crosshair.getLabelBackgroundPaint());
            g2.fill(hotspot);
            g2.setPaint(crosshair.getLabelOutlinePaint());
            g2.draw(hotspot);
            TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt);
        }
        g2.setPaint(savedPaint);
        g2.setStroke(savedStroke);
    }
}
 
Example 17
Source File: patch1-Chart-1-jMutRepair_patch1-Chart-1-jMutRepair_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 18
Source File: Arja_0089_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 19
Source File: PointerNeedle.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
@Override
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                          Point2D rotate, double angle) {

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

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

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

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

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

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

    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(shape1);
        g2.draw(shape2);
    }
}
 
Example 20
Source File: ZoomHandlerFX.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
private double percentW(double x, Rectangle2D r) {
    return (x - r.getMinX()) / r.getWidth();
}