Example usage for java.awt.geom Point2D getX

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

Introduction

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

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

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;//  ww w.ja  va 2 s .  co 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:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected void paintAnnotations(Graphics2D g2d) {

    DecimalFormat mz_df = new DecimalFormat("0.0");

    // set font//  w  w w  . j  a  v a 2s .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:org.apache.fop.render.pcl.PCLRenderer.java

/**
 * Sets the current cursor position. The coordinates are transformed to the absolute position
 * on the logical PCL page and then passed on to the PCLGenerator.
 * @param x the x coordinate (in millipoints)
 * @param y the y coordinate (in millipoints)
 *///w w  w  .  j a  v  a  2s  .c o m
void setCursorPos(float x, float y) {
    try {
        Point2D transPoint = transformedPoint(x, y);
        gen.setCursorPos(transPoint.getX(), transPoint.getY());
    } catch (IOException ioe) {
        handleIOTrouble(ioe);
    }
}

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

protected void computeConnections() {

    connections = new HashMap<AnnotationObject, Polygon>();
    connections_cp = new HashMap<AnnotationObject, Point2D>();

    for (AnnotationObject a : theDocument.getAnnotations()) {
        Rectangle rect = rectangles_complete.get(a);
        Point2D cp = dataToScreenCoords(theDocument.getControlPoint(a));
        Point2D peak = dataToScreenCoords(a.getPeakPoint());

        // select anchor
        Point2D anchor = computeAnchor(rect, cp, peak);
        boolean add_cp = (peak.getY() > bottom(rect));

        if (anchor.distance(peak) > 10) {
            // create shape
            Polygon connection = new Polygon();
            connection.addPoint((int) anchor.getX(), (int) anchor.getY());
            if (add_cp)
                connection.addPoint((int) cp.getX(), (int) cp.getY());
            connection.addPoint((int) peak.getX(), (int) peak.getY());
            if (add_cp)
                connection.addPoint((int) cp.getX(), (int) cp.getY());

            // save
            connections.put(a, connection);
            if (add_cp)
                connections_cp.put(a, cp);
        }/*from   ww  w  .  j  a v a 2 s  .  c om*/
    }
}

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());//from  w ww  .  ja v  a 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:net.panthema.BispanningGame.GamePanel.java

void centerAndScaleGraph() {

    // clear layout
    MultiLayerTransformer mlTransformer = mVV.getRenderContext().getMultiLayerTransformer();
    mlTransformer.setToIdentity();//from w  w  w  .j a  va2s . 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:util.ModSpringLayout2.java

protected void moveNodes() {

    synchronized (getSize()) {
        try {//from w w  w . j  av a2s . com
            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:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected Point2D computeAnchor(Rectangle rect, Point2D cp, Point2D peak) {
    Point2D anchor;/*from ww  w .j  a va  2s  .c o 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:com.vgi.mafscaling.LogView.java

private void createGraghPanel() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false,
            true, false);//www  .j av a2  s .  c o  m
    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setPopupMenu(null);
    chart.setBackgroundPaint(new Color(60, 60, 65));

    rpmDataset = new XYSeriesCollection();
    rpmPlotRenderer = new XYLineAndShapeRenderer();
    dataset = new XYSeriesCollection();
    plotRenderer = new XYLineAndShapeRenderer();

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickLabelPaint(Color.WHITE);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickLabelPaint(Color.WHITE);
    yAxis.setAutoRangeIncludesZero(false);
    NumberAxis y2Axis = new NumberAxis();
    y2Axis.setTickLabelsVisible(false);
    y2Axis.setTickLabelPaint(Color.WHITE);
    y2Axis.setAutoRangeIncludesZero(false);

    plot = chartPanel.getChart().getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setBackgroundPaint(new Color(80, 80, 85));

    plot.setDataset(0, rpmDataset);
    plot.setRenderer(0, rpmPlotRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    plot.setDataset(1, dataset);
    plot.setRenderer(1, plotRenderer);
    plot.setRangeAxis(1, y2Axis);
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 1);

    LegendTitle legend = new LegendTitle(plot);
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemPaint(Color.WHITE);
    chart.addLegend(legend);

    xyMarker = new XYDomainMutilineAnnotation();
    plot.addAnnotation(xyMarker);

    chartMouseListener = new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            try {
                Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
                Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
                double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
                boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                if (setMarkers(x, isLeft)) {
                    try {
                        int selectedCol = logDataTable.getTable().getSelectedColumn();
                        if (selectedCol < 0)
                            selectedCol = 0;
                        if (logPlayWindow == null || startMarker != null || endMarker != null) {
                            logDataTable.getTable().setRowSelectionInterval((int) x, (int) x);
                            logDataTable.getTable().changeSelection((int) x, selectedCol, false, false);
                        } else {
                            logPlayWindow.setProgressBar((int) x);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            if (logPlayWindow == null)
                return;
            if (xyMarker.count() == 0)
                return;
            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
            double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
            if (x < 0 || (int) x >= logDataTable.getRowCount())
                return;
            if (SwingUtilities.isLeftMouseButton(event.getTrigger())) {
                if (startMarker == null) {
                    startMarker = new ValueMarker(x);
                    startMarker.setPaint(Color.GREEN);
                    startMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(startMarker);
                } else {
                    plot.removeDomainMarker(startMarker);
                    startMarker = null;
                }
            } else if (SwingUtilities.isRightMouseButton(event.getTrigger())) {
                if (endMarker == null) {
                    endMarker = new ValueMarker(x);
                    endMarker.setPaint(Color.GREEN);
                    endMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(endMarker);
                } else {
                    plot.removeDomainMarker(endMarker);
                    endMarker = null;
                }
            }
            chartPanel.repaint();
            logPlayWindow.setStartEndArea(startMarker, endMarker);
        }
    };

    chartPanel.addChartMouseListener(chartMouseListener);
}

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.//ww  w.  jav a 2s  .  c om
 * @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());
    }
}