Example usage for java.awt.geom Point2D.Double Point2D.Double

List of usage examples for java.awt.geom Point2D.Double Point2D.Double

Introduction

In this page you can find the example usage for java.awt.geom Point2D.Double Point2D.Double.

Prototype

public Double(double x, double y) 

Source Link

Document

Constructs and initializes a Point2D with the specified coordinates.

Usage

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected Point2D computeAnchor(Rectangle rect, Point2D cp, Point2D peak) {
    Point2D anchor;//  w  w  w.  ja v a  2 s  .co m

    if (peak.getY() > bottom(rect)) {
        if (cp.getY() > bottom(rect))
            anchor = new Point2D.Double(midx(rect), bottom(rect));
        else if (cp.getY() < top(rect))
            anchor = new Point2D.Double(midx(rect), top(rect));
        else if (cp.getX() < left(rect))
            anchor = new Point2D.Double(left(rect), midy(rect));
        else
            anchor = new Point2D.Double(right(rect), midy(rect));
    } else {
        if (peak.getY() < top(rect))
            anchor = new Point2D.Double(midx(rect), top(rect));
        else if (peak.getX() < left(rect))
            anchor = new Point2D.Double(left(rect), midy(rect));
        else
            anchor = new Point2D.Double(right(rect), midy(rect));
    }
    return anchor;
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public Point2D screenToDataCoords(Point2D p) {

    double x = thePlot.getDomainAxis().java2DToValue(p.getX(), data_area, thePlot.getDomainAxisEdge());
    double y = thePlot.getRangeAxis().java2DToValue(p.getY(), data_area, thePlot.getRangeAxisEdge());
    return new Point2D.Double(x, y);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public Point2D dataToScreenCoords(Point2D p) {

    double x = thePlot.getDomainAxis().valueToJava2D(p.getX(), data_area, thePlot.getDomainAxisEdge());
    double y = thePlot.getRangeAxis().valueToJava2D(p.getY(), data_area, thePlot.getRangeAxisEdge());
    return new Point2D.Double(x, y);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

private void placeStructures(Vector<AnnotationObject> annotations, boolean init) {

    // get starting point
    double y = thePlot.getRangeAxis().getRange().getUpperBound();
    double cur_x = thePlot.getDomainAxis().getRange().getLowerBound();

    double all_width = 0.;
    for (AnnotationObject a : annotations) {
        if (a.hasAnnotations())
            all_width += screenToDataX(rectangles_complete.get(a).width);
    }//from   w w w  . j  a va2 s. co  m

    double min_pp_x = annotations.firstElement().getPeakPoint().getX();
    double max_pp_x = annotations.lastElement().getPeakPoint().getX();
    double center_pp_x = (max_pp_x + min_pp_x) / 2;

    cur_x = Math.max(cur_x, center_pp_x - all_width / 2);

    // place annotations
    for (AnnotationObject a : annotations) {
        Point2D pp = a.getPeakPoint();
        if (a.hasAnnotations()) {
            double cur_width = screenToDataX(rectangles_complete.get(a).width);
            double x = cur_x + cur_width / 2.;
            theDocument.getAnchor(a).setLocation(x, y);
            theDocument.getControlPoints().put(a,
                    theDocument.computeControlPoint(new Point2D.Double(x, y), pp));

            cur_x += cur_width;
        } else {
            theDocument.getAnchor(a).setLocation(pp.getX(), pp.getY());
            theDocument.getControlPoints().put(a, theDocument.computeControlPoint(pp, pp));
        }
    }

    // refine control points
    for (int i = 0; i < annotations.size(); i++) {
        AnnotationObject ai = annotations.get(i);
        Point2D aai = theDocument.getAnchor(ai);
        Point2D cpi = theDocument.getControlPoint(ai);

        if (aai.getX() < cpi.getX()) {
            for (int l = i + 1; l < annotations.size(); l++) {
                AnnotationObject al = annotations.get(l);
                Point2D aal = theDocument.getAnchor(al);
                Point2D cpl = theDocument.getControlPoint(al);

                if (aal.getX() > cpi.getX())
                    break;
                if (cpl.getY() < cpi.getY()) {
                    cpl.setLocation(cpl.getX(), cpi.getY());
                    ai = al;
                    aai = aal;
                    cpi = cpl;
                } else
                    break;
            }
        } else {
            for (int l = i - 1; l >= 0; l--) {
                AnnotationObject al = annotations.get(l);
                Point2D aal = theDocument.getAnchor(al);
                Point2D cpl = theDocument.getControlPoint(al);

                if (aal.getX() < cpi.getX())
                    break;
                if (cpl.getY() < cpi.getY()) {
                    cpl.setLocation(cpl.getX(), cpi.getY());
                    ai = al;
                    aai = aal;
                    cpi = cpl;
                } else
                    break;
            }
        }
    }

    // fire events
    if (init)
        theDocument.fireDocumentInit();
    else
        theDocument.fireDocumentChanged();
}

From source file:org.yccheok.jstock.gui.analysis.OperatorFigure.java

@Override
public void read(DOMInput in) throws IOException {
    double x = in.getAttribute("x", 0d);
    double y = in.getAttribute("y", 0d);
    double w = in.getAttribute("w", 0d);
    double h = in.getAttribute("h", 0d);
    setBounds(new Point2D.Double(x, y), new Point2D.Double(x + w, y + h));
    readAttributes(in);/*from   ww w  .j a  v a2  s  . c o m*/
    in.openElement("model");
    in.openElement("name");
    setName((String) in.readObject());
    in.closeElement();
    in.openElement("attribute");
    setAttribute((String) in.readObject());
    in.closeElement();
    in.openElement("value");
    setValue((String) in.readObject());
    in.closeElement();

    in.openElement("connectors");
    connectors.clear();
    final int size = in.getElementCount();

    for (int i = 0; i < size; i++) {
        final AbstractConnector c = (AbstractConnector) in.readObject(i);
        connectors.add(c);
    }
    in.closeElement();

    in.closeElement();
}