Example usage for java.awt.geom Point2D getY

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

Introduction

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

Prototype

public abstract double getY();

Source Link

Document

Returns the Y coordinate of this Point2D in double precision.

Usage

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

protected void paintAnnotations(Graphics2D g2d) {

    DecimalFormat mz_df = new DecimalFormat("0.0");

    // set font//w ww .  ja  v  a  2  s .c  o m
    Font old_font = g2d.getFont();
    Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE);

    // compute bboxes
    PositionManager pman = new PositionManager();
    BBoxManager bbman = new BBoxManager();
    computeRectangles(pman, bbman);

    // compute connections
    computeConnections();

    // paint connections
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean selected = !is_printing && selections.contains(a);

        // paint arrow        
        Polygon connection = connections.get(a);
        if (connection != null) {
            g2d.setColor(theOptions.CONNECTION_LINES_COLOR);
            g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH))
                    : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH));
            g2d.draw(connection);
            g2d.setStroke(new BasicStroke(1));
        }

        // paint control point       
        if (selected) {
            g2d.setColor(Color.black);
            Point2D cp = connections_cp.get(a);
            if (cp != null) {
                int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH);
                g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s));
            }
        }
    }

    // paint glycans
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean highlighted = a.isHighlighted();
        boolean selected = !is_printing && selections.contains(a);

        // set scale
        theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a));

        // paint highlighted region
        if (highlighted) {
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setColor(theOptions.HIGHLIGHTED_COLOR);
            g2d.setXORMode(Color.white);
            g2d.fill(c_bbox);
            g2d.setPaintMode();

            g2d.setColor(Color.black);
            g2d.draw(c_bbox);
        }

        // paint glycan
        for (Glycan s : a.getStructures())
            theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman);

        // paint MZ text
        g2d.setFont(new_font);
        g2d.setColor(theOptions.MASS_TEXT_COLOR);
        String mz_text = mz_df.format(a.getPeakPoint().getX());
        Rectangle mz_bbox = rectangles_text.get(a);
        g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height);

        // paint selection        
        if (selected) {
            // paint rectangle
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setStroke(new BasicStroke(highlighted ? 2 : 1));
            g2d.setColor(Color.black);

            g2d.draw(c_bbox);

            g2d.setStroke(new BasicStroke(1));

            // paint resize points        
            Polygon p1 = new Polygon();
            int cx1 = right(c_bbox);
            int cy1 = top(c_bbox);
            p1.addPoint(cx1, cy1);
            p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1);
            p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p1);

            Polygon p2 = new Polygon();
            int cx2 = left(c_bbox);
            int cy2 = top(c_bbox);
            p2.addPoint(cx2, cy2);
            p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2);
            p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p2);
        }
    }

    g2d.setFont(old_font);
}

From source file:at.tuwien.ifs.somtoolbox.apps.viewer.MapPNode.java

public GeneralUnitPNode getGeneralUnitPNodeAtPos(Point2D p) {
    if (unitsNode.getFullBounds().contains(p)) {

        int xPos = (int) Math.floor(p.getX() / getUnitWidth());
        int yPos = (int) Math.floor(p.getY() / getUnitHeight());

        return getUnit(xPos, yPos);
    } else {/*from  w w w.j a v a  2  s .  c o  m*/
        return null;
    }
}

From source file:convcao.com.agent.ConvcaoNeptusInteraction.java

@Override
public void paint(Graphics2D g2, StateRenderer2D renderer) {
    Graphics2D g = (Graphics2D) g2.create();

    Point2D center = renderer.getScreenPosition(coords.squareCenter);
    double width = renderer.getZoom() * coords.cellWidth * coords.numCols;
    double height = renderer.getZoom() * coords.cellWidth * coords.numRows;
    g.setColor(new Color(0, 0, 255, 64));
    g.translate(center.getX(), center.getY());
    g.rotate(-renderer.getRotation());/*w ww.  j  ava 2 s  . c o m*/
    g.fill(new Rectangle2D.Double(-width / 2, -height / 2, width, height));
    g.rotate(renderer.getRotation());
    g.translate(-center.getX(), -center.getY());

    if (!active) {
        g.dispose();
        return;
    }

    g.setColor(Color.orange);
    int pos = 50;
    for (String v : nameTable.values()) {
        g.drawString(v + ": " + depths.get(v) + "m", 15, pos);
        pos += 20;
    }

    for (String vehicle : nameTable.values()) {
        LocationType src = positions.get(vehicle);
        LocationType dst = destinations.get(vehicle);

        if (!arrived.get(vehicle))
            g.setColor(Color.red.darker());
        else
            g.setColor(Color.green.darker());
        float dash[] = { 4.0f };
        g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash, 0.0f));
        g.draw(new Line2D.Double(renderer.getScreenPosition(src), renderer.getScreenPosition(dst)));

        Point2D dstPt = renderer.getScreenPosition(dst);

        if (!arrived.get(vehicle))
            g.setColor(Color.red.darker());
        else
            g.setColor(Color.green.darker());

        g.fill(new Ellipse2D.Double(dstPt.getX() - 4, dstPt.getY() - 4, 8, 8));
    }

    g.dispose();
}

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

protected Rectangle computeRectangles(PositionManager pman, BBoxManager bbman) {

    DecimalFormat mz_df = new DecimalFormat("0.0");

    Rectangle all_bbox = null;//w  w  w  .ja  va2s .  c o m
    rectangles = new HashMap<AnnotationObject, Rectangle>();
    rectangles_text = new HashMap<AnnotationObject, Rectangle>();
    rectangles_complete = new HashMap<AnnotationObject, Rectangle>();
    for (AnnotationObject a : theDocument.getAnnotations()) {

        // set scale
        theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a));

        // compute bbox
        Point2D anchor = dataToScreenCoords(theDocument.getAnchor(a));
        Rectangle bbox = theGlycanRenderer.computeBoundingBoxes(a.getStructures(), false, false, pman, bbman,
                false);

        int x = (int) anchor.getX() - bbox.width / 2;
        int y = (int) anchor.getY() - bbox.height - theOptions.ANNOTATION_MARGIN
                - theOptions.ANNOTATION_MZ_SIZE;
        bbman.translate(x - bbox.x, y - bbox.y, a.getStructures());
        bbox.translate(x - bbox.x, y - bbox.y);

        // save bbox
        rectangles.put(a, bbox);

        // compute text bbox        
        String mz_text = mz_df.format(a.getPeakPoint().getX());
        Dimension mz_dim = textBounds(mz_text, theOptions.ANNOTATION_MZ_FONT, theOptions.ANNOTATION_MZ_SIZE);
        Rectangle text_bbox = new Rectangle((int) anchor.getX() - mz_dim.width / 2,
                (int) anchor.getY() - 2 * theOptions.ANNOTATION_MARGIN / 3 - mz_dim.height, mz_dim.width,
                mz_dim.height);

        // save text bbox
        rectangles_text.put(a, text_bbox);
        rectangles_complete.put(a, expand(union(bbox, text_bbox), theOptions.ANNOTATION_MARGIN / 2));

        // update all bbox
        all_bbox = union(all_bbox, bbox);
        all_bbox = union(all_bbox, text_bbox);
    }
    if (all_bbox == null)
        return new Rectangle(0, 0, 0, 0);
    return all_bbox;
}

From source file:util.ModSpringLayout2.java

protected void moveNodes() {

    synchronized (getSize()) {
        try {//from w ww  . ja  v a  2 s .  c o m
            for (V v : getGraph().getVertices()) {
                if (isLocked(v))
                    continue;
                SpringVertexData vd = getSpringData(v);
                if (vd == null)
                    continue;
                Point2D xyd = transform(v);

                vd.dx += vd.repulsiondx + vd.edgedx;
                vd.dy += vd.repulsiondy + vd.edgedy;

                //                    int currentCount = currentIteration % this.loopCountMax;
                //                    System.err.println(averageCounter+" --- vd.dx="+vd.dx+", vd.dy="+vd.dy);
                //                    System.err.println("averageDelta was "+averageDelta);

                averageDelta.setLocation(
                        ((averageDelta.getX() * averageCounter) + vd.dx) / (averageCounter + 1),
                        ((averageDelta.getY() * averageCounter) + vd.dy) / (averageCounter + 1));
                //                    System.err.println("averageDelta now "+averageDelta);
                //                    System.err.println();
                averageCounter++;

                // keeps nodes from moving any faster than 5 per time unit
                xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)),
                        xyd.getY() + Math.max(-5, Math.min(5, vd.dy)));

                Dimension d = getSize();
                int width = d.width;
                int height = d.height;

                if (xyd.getX() < 0) {
                    xyd.setLocation(0, xyd.getY());//                     setX(0);
                } else if (xyd.getX() > width) {
                    xyd.setLocation(width, xyd.getY()); //setX(width);
                }
                if (xyd.getY() < 0) {
                    xyd.setLocation(xyd.getX(), 0);//setY(0);
                } else if (xyd.getY() > height) {
                    xyd.setLocation(xyd.getX(), height); //setY(height);
                }

            }
        } catch (ConcurrentModificationException cme) {
            moveNodes();
        }
    }
}

From source file:KIDLYRenderer.java

/**
 * Draws an item label.  This method is overridden so that the bar can be
 * used to calculate the label anchor point.
 *
 * @param g2  the graphics device./*from   w  w  w  . j a v  a2 s .  c  o m*/
 * @param data  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param plot  the plot.
 * @param generator  the label generator.
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2, CategoryDataset data, int row, int column, CategoryPlot plot,
        CategoryItemLabelGenerator generator, Rectangle2D bar, boolean negative) {

    String label = generator.generateLabel(data, row, column);
    if (label == null) {
        return; // nothing to do
    }

    Font labelFont = getItemLabelFont(row, column);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(row, column);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(row, column);
    } else {
        position = getNegativeItemLabelPosition(row, column);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(),
                (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                } else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
    }
}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Multiplies the range on the range axis by the specified factor.
 *
 * @param factor the zoom factor.//  w  w  w .j a  v  a  2s .  c o m
 * @param info the plot rendering info.
 * @param source the source point (in Java2D space).
 * @param useAnchor use source point as zoom anchor?
 *
 * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)
 *
 * @since 1.0.7
 */
@Override
public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) {

    if (useAnchor) {
        // get the source coordinate - this plot has always a VERTICAL
        // orientation
        double sourceY = source.getY();
        double anchorY = this.rangeAxis.java2DToValue(sourceY, info.getDataArea(), RectangleEdge.LEFT);
        this.rangeAxis.resizeRange2(factor, anchorY);
    } else {
        this.rangeAxis.resizeRange(factor);
    }
}

From source file:net.panthema.BispanningGame.GamePanel.java

void centerAndScaleGraph() {

    // clear layout
    MultiLayerTransformer mlTransformer = mVV.getRenderContext().getMultiLayerTransformer();
    mlTransformer.setToIdentity();//  w  ww. j  av  a  2s.c  o m

    if (mGraph.getVertexCount() == 0)
        return;

    // calculate bounding box of layout
    double xMin = Double.POSITIVE_INFINITY;
    double yMin = Double.POSITIVE_INFINITY;
    double xMax = Double.NEGATIVE_INFINITY;
    double yMax = Double.NEGATIVE_INFINITY;

    for (Integer v : mGraph.getVertices()) {
        Point2D p = mLayout.transform(v);
        if (p.getX() < xMin)
            xMin = p.getX();
        if (p.getX() > xMax)
            xMax = p.getX();
        if (p.getY() < yMin)
            yMin = p.getY();
        if (p.getY() > yMax)
            yMax = p.getY();
    }

    System.err.println("xMin: " + xMin + " xMax: " + xMax + " yMin: " + yMin + " yMax: " + yMax);

    // shift and scale layout
    Dimension vv_size = mVV.getSize();
    System.err.println("vv_size: " + vv_size);

    double xSize = xMax - xMin;
    double ySize = yMax - yMin;

    double xRatio = vv_size.getWidth() / xSize;
    double yRatio = vv_size.getHeight() / ySize;
    double ratio = 0.75 * Math.min(xRatio, yRatio);

    System.err.println("ratio: " + ratio);

    mlTransformer.getTransformer(Layer.LAYOUT).scale(ratio, ratio, new Point2D.Double(0, 0));

    double xShift = -xMin + (vv_size.getWidth() / ratio - xSize) / 2.0;
    double yShift = -yMin + (vv_size.getHeight() / ratio - ySize) / 2.0;
    mlTransformer.getTransformer(Layer.LAYOUT).translate(xShift, yShift);
}

From source file:tufts.vue.RichTextBox.java

public void setBoxLocation(Point2D p) {
    setBoxLocation((float) p.getX(), (float) p.getY());
}

From source file:de.laures.cewolf.jfree.ThermometerPlot.java

/**
 * Multiplies the range on the range axis/axes by the specified factor.
 *
 * @param factor  the zoom factor.//from w  ww. j a v  a2 s  .  c  o m
 * @param state  the plot state.
 * @param source  the source point.
 * @param useAnchor  a flag that controls whether or not the source point is used for the zoom anchor.
 *
 * @since 1.0.7
 */
public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor) {
    double anchorY = this.getRangeAxis().java2DToValue(source.getY(), state.getDataArea(), RectangleEdge.LEFT);
    this.rangeAxis.resizeRange(factor, anchorY);
}