Example usage for java.awt.geom Line2D getP1

List of usage examples for java.awt.geom Line2D getP1

Introduction

In this page you can find the example usage for java.awt.geom Line2D getP1.

Prototype

public abstract Point2D getP1();

Source Link

Document

Returns the start Point2D of this Line2D .

Usage

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void removeDomainAxisMarker(double x) {
    for (Entry<Line2D, Color> entry : domainMarkerMap.entrySet()) {
        Line2D line = entry.getKey();
        if (line.getP1().getX() == x) {
            domainMarkerMap.remove(line);
            break;
        }//ww  w.j av  a2s  .c  o  m
    }
    getXYPlot().setNotify(true);
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void removeRangeAxisMarker(double y) {
    for (Entry<Line2D, Color> entry : rangeMarkerMap.entrySet()) {
        Line2D line = entry.getKey();
        if (line.getP1().getY() == y) {
            rangeMarkerMap.remove(line);
            break;
        }/*  www .j a v  a  2  s  .  c  om*/
    }
    getXYPlot().setNotify(true);
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void removeMarker(double x, double y) {
    for (Entry<Line2D, Color> entry : markerMap.entrySet()) {
        Line2D line = entry.getKey();
        if (line.getP1().getX() == x && line.getP1().getY() == y) {
            markerMap.remove(line);//  w  w  w  . j  a v  a 2  s. c  om
            break;
        }
    }
    getXYPlot().setNotify(true);
}

From source file:org.gumtree.vis.awt.JChartPanel.java

private void findSelectedMarker(Point point) {
    Line2D marker = null;//from   w w w  . j  a v  a2 s . c  o m
    double distance = Double.MAX_VALUE;
    double cDis;
    for (Entry<Line2D, Color> entry : domainMarkerMap.entrySet()) {
        Line2D line = entry.getKey();
        Point2D p2 = line.getP2();
        double height = p2.getY();
        cDis = Double.MAX_VALUE;
        if (height < 1e-4) {
            double xScr = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()).getX();
            cDis = Math.abs(point.getX() - xScr);
        } else {
            Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart());
            if (newP2.getY() < point.getY()) {
                cDis = Math.abs(point.getX() - newP2.getX());
            } else {
                cDis = newP2.distance(point);
            }
        }
        if (cDis <= distance) {
            distance = cDis;
            marker = line;
        }
    }
    for (Entry<Line2D, Color> entry : rangeMarkerMap.entrySet()) {
        Line2D line = entry.getKey();
        Point2D p1 = line.getP1();
        Point2D p2 = line.getP2();
        double width = p2.getX();
        cDis = Double.MAX_VALUE;
        if (width < 1e-4) {
            double yScr = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart()).getY();
            cDis = Math.abs(point.getY() - yScr);
        } else {
            Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart());
            if (newP2.getX() > point.getX()) {
                cDis = Math.abs(point.getY() - newP2.getY());
            } else {
                cDis = newP2.distance(point);
            }
        }
        if (cDis <= distance) {
            distance = cDis;
            marker = line;
        }
    }
    for (Entry<Line2D, Color> entry : markerMap.entrySet()) {
        Line2D line = entry.getKey();
        Point2D p1 = line.getP1();
        p1 = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart());
        cDis = p1.distance(point);
        if (cDis <= distance) {
            distance = cDis;
            marker = line;
        }
    }
    if (distance < 5) {
        selectedMarker = marker;
    } else {
        selectedMarker = null;
    }
}

From source file:org.dwfa.ace.graph.AceGraphRenderer.java

/**
 * Passed Line's point2 must be inside the passed shape or
 * an IllegalArgumentException is thrown
 * /*from   w  w  w  .  j a  v  a2  s  . c  o  m*/
 * @param line line to subdivide
 * @param shape shape to compare with line
 * @return a line that intersects the shape boundary
 * @throws IllegalArgumentException if the passed line's point1 is not
 *             inside the shape
 */
protected Line2D getLastOutsideSegment(Line2D line, Shape shape) {
    if (shape.contains(line.getP2()) == false) {
        String errorString = "line end point: " + line.getP2() + " is not contained in shape: "
                + shape.getBounds2D();
        throw new IllegalArgumentException(errorString);
        // return null;
    }
    Line2D left = new Line2D.Double();
    Line2D right = new Line2D.Double();
    // subdivide the line until its left segment intersects
    // the shape boundary
    int iterations = 0;
    do {
        subdivide(line, left, right);
        line = right;
    } while (shape.contains(line.getP1()) == false && iterations++ < MAX_ITERATIONS);
    // now that right is completely inside shape,
    // return left, which must be partially outside
    return left;
}