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.gumtree.vis.plot1d.Plot1DPanel.java

private void moveLegend(Point2D point) {
    if (isInternalLegendEnabled && isInternalLegendSelected && legendPoint != null) {
        internalLegendSetup.setRect(internalLegendSetup.getX() + legendPoint.getX() - point.getX(),
                internalLegendSetup.getY() - legendPoint.getY() + point.getY(), internalLegendSetup.getWidth(),
                internalLegendSetup.getHeight());
        legendPoint = point;//from   w ww .ja v  a2s .  com
    }
}

From source file:lcmc.gui.ResourceGraph.java

/** Returns position of the last vertex. */
protected final Point2D getLastPosition() {
    double lastX = 0;
    double lastY = 0;
    final Map<Vertex, Point2D> vl = getVertexLocations();
    for (final Vertex v : vl.keySet()) {
        final Point2D last = vl.get(v);
        if (last != null) {
            if (last.getX() > lastX) {
                lastX = last.getX();//from  ww  w . ja  v a 2  s.  c  om
            }
            if (last.getY() > lastY) {
                lastY = last.getY();
            }
        }
    }
    putVertexLocations();
    return new Point2D.Double(lastX, lastY + 40);
}

From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java

protected void paintComponent(final Graphics g) {
    if (fpsCalculator.isActive()) {
        fpsCalculator.tick();//from   ww w.  j  a va  2s  .co m
    }

    final Graphics2D g2 = (Graphics2D) g.create();

    g2.setColor(new Color(224, 224, 224));
    g2.fillRect(0, 0, getWidth(), getHeight());

    final int leftBorder = (int) getLeftBorder();
    final int topBorder = (int) getTopBorder();
    final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage();

    // draw the page area ..
    final PageDefinition pageDefinition = getRenderContext().getContextRoot().getPageDefinition();
    final Rectangle2D.Double area = new Rectangle2D.Double(0, 0, pageDefinition.getWidth() * scaleFactor,
            getHeight());
    g2.translate(leftBorder * scaleFactor, topBorder * scaleFactor);
    g2.clip(area);
    g2.setColor(Color.WHITE);
    g2.fill(area);

    // draw the grid (unscaled, but translated)
    final Point2D offset = getOffset();
    if (offset.getX() != 0) {
        // The blackout area is for inline sub-reports and is the area where the subreport is not interested in
        // (so we can clip out).  The blackout area is only visible in the sub-report.
        final Rectangle2D.Double blackoutArea = new Rectangle2D.Double(0, 0, offset.getX() * scaleFactor,
                getHeight());
        g2.setColor(Color.LIGHT_GRAY);
        g2.fill(blackoutArea);
    }
    paintGrid(g2);
    paintElementAlignment(g2);
    g2.dispose();

    final Graphics2D logicalPageAreaG2 = (Graphics2D) g.create();
    // draw the renderable content ...
    logicalPageAreaG2.translate(leftBorder * scaleFactor, topBorder * scaleFactor);
    logicalPageAreaG2.clip(area);
    logicalPageAreaG2.scale(scaleFactor, scaleFactor);

    try {
        final ElementRenderer rendererRoot = getElementRenderer();
        if (rendererRoot != null) {
            if (rendererRoot.draw(logicalPageAreaG2) == false) {
                rendererRoot.handleError(designerContext, renderContext);

                logicalPageAreaG2.scale(1f / scaleFactor, 1f / scaleFactor);
                logicalPageAreaG2.setPaint(Color.WHITE);
                logicalPageAreaG2.fill(area);
            }
        }
    } catch (Exception e) {
        // ignore for now..
        UncaughtExceptionsModel.getInstance().addException(e);
    }

    logicalPageAreaG2.dispose();

    final OverlayRenderer[] renderers = new OverlayRenderer[4];
    renderers[0] = new OverlappingElementOverlayRenderer(getDefaultElement()); // displays the red border for warning
    renderers[1] = new SelectionOverlayRenderer(getDefaultElement());
    renderers[2] = new GuidelineOverlayRenderer(horizontalLinealModel, verticalLinealModel);
    renderers[3] = new SelectionRectangleOverlayRenderer(); // blue box when you shift and drag the region to select multiple
    // elements

    for (int i = 0; i < renderers.length; i++) {
        final OverlayRenderer renderer = renderers[i];
        final Graphics2D selectionG2 = (Graphics2D) g.create();

        renderer.validate(getRenderContext(), scaleFactor, offset);
        renderer.draw(selectionG2,
                new Rectangle2D.Double(getLeftBorder(), getTopBorder(), getWidth(), getHeight()), this);
        selectionG2.dispose();
    }
}

From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java

/**
 * Translates a Java2D point on the chart to a screen location.
 * /*from ww w  .j a  va  2s . c o m*/
 * @param java2DPoint
 *          the Java2D point.
 * 
 * @return The screen location.
 */
public Point translateJava2DToScreen(final Point2D java2DPoint) {
    final Rectangle insets = this.getClientArea();
    final int x = (int) (java2DPoint.getX() * this.scaleX + insets.x);
    final int y = (int) (java2DPoint.getY() * this.scaleY + insets.y);
    return new Point(x, y);
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private void changeSelectedMask(Point2D point) {
    switch (getMaskDragIndicator()) {
    case Cursor.MOVE_CURSOR:
        moveMask(point);//from w w  w.j ava 2s  .  c  o  m
        break;
    case Cursor.W_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMax(point.getX());
        } else {
            changeMaskXMin(point.getX());
        }
        break;
    case Cursor.E_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMin(point.getX());
        } else {
            changeMaskXMax(point.getX());
        }
        break;
    case Cursor.N_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMin(point.getY());
        } else {
            changeMaskYMax(point.getY());
        }
        break;
    case Cursor.S_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMax(point.getY());
        } else {
            changeMaskYMin(point.getY());
        }
        break;
    case Cursor.NW_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMax(point.getX());
        } else {
            changeMaskXMin(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMin(point.getY());
        } else {
            changeMaskYMax(point.getY());
        }
        break;
    case Cursor.NE_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMin(point.getX());
        } else {
            changeMaskXMax(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMin(point.getY());
        } else {
            changeMaskYMax(point.getY());
        }
        break;
    case Cursor.SW_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMax(point.getX());
        } else {
            changeMaskXMin(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMax(point.getY());
        } else {
            changeMaskYMin(point.getY());
        }
        break;
    case Cursor.SE_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMin(point.getX());
        } else {
            changeMaskXMax(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMax(point.getY());
        } else {
            changeMaskYMin(point.getY());
        }
        break;
    default:
        break;
    }
    fireMaskUpdateEvent(getSelectedMask());
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void updatePointAndIndexIfPossible(int dataOffset) {
    Type updatedType = null;/*from  w w  w .  j  ava 2  s  .  c  om*/

    boolean needToReturnEarly = false;

    // If there is at least one point (Either ROI or Invest) absent from the
    // screen, we will show them up and return early.
    if (this.investPointIndex < 0) {
        this.investPointIndex = 0;
        this.investPoint = getPoint(this.investPointIndex, Type.Invest);
        this.updateInvestPoint();
        needToReturnEarly = true;
    }
    if (this.ROIPointIndex < 0) {
        this.ROIPointIndex = dataOffset + this.ROIPointIndex;
        this.ROIPoint = getPoint(this.ROIPointIndex, Type.ROI);
        this.updateROIPoint();
        needToReturnEarly = true;
    }

    if (needToReturnEarly) {
        return;
    }

    int tmpROIPointIndex = -1;
    int tmpInvestPointIndex = -1;
    Point2D tmpROIPoint = null;
    Point2D tmpInvestPoint = null;
    if (updatedType == null) {
        tmpROIPointIndex = dataOffset + this.ROIPointIndex;
        tmpInvestPointIndex = dataOffset + this.investPointIndex;
        tmpROIPoint = getPoint(tmpROIPointIndex, Type.ROI);
        tmpInvestPoint = getPoint(tmpInvestPointIndex, Type.Invest);

        if (tmpROIPoint == null) {
            if (tmpInvestPoint == null) {
                // No update can be performed. Returns early.
                return;
            }
            updatedType = Type.Invest;
        } else if (tmpInvestPoint == null) {
            assert (tmpROIPoint != null);
            updatedType = Type.ROI;
        } else {
            // Distance check.
            double d0 = Math.abs(tmpROIPoint.getX() - this.investPoint.getX());
            double d1 = Math.abs(tmpInvestPoint.getX() - this.ROIPoint.getX());
            if (d0 < d1) {
                updatedType = Type.ROI;
            } else {
                updatedType = Type.Invest;
            }
        }
    }

    assert (updatedType != null);

    if (updatedType == Type.ROI) {
        this.ROIPointIndex = dataOffset + this.ROIPointIndex;
        this.ROIPoint = tmpROIPoint != null ? tmpROIPoint : getPoint(this.ROIPointIndex, Type.ROI);
        this.updateROIPoint();
    } else {
        assert (updatedType == Type.Invest);
        this.investPointIndex = dataOffset + this.investPointIndex;
        this.investPoint = tmpInvestPoint != null ? tmpInvestPoint
                : getPoint(this.investPointIndex, Type.Invest);
        this.updateInvestPoint();
    }
}

From source file:org.apache.fop.svg.AbstractFOPTextPainter.java

/**
 * Paint a single text run on the Graphics2D at a given location.
 * @param run the text run to paint/*from  w w  w. j  a  v  a2  s .  c o  m*/
 * @param g2d the Graphics2D to paint to
 * @param loc the current location of the "cursor"
 * @return the new location of the "cursor" after painting the text run
 */
protected Point2D paintTextRun(StrokingTextPainter.TextRun run, Graphics2D g2d, Point2D loc) {
    AttributedCharacterIterator aci = run.getACI();
    aci.first();

    updateLocationFromACI(aci, loc);
    AffineTransform at = g2d.getTransform();
    loc = at.transform(loc, null);

    // font
    Font font = getFont(aci);
    if (font != null) {
        nativeTextHandler.setOverrideFont(font);
    }

    // color
    TextPaintInfo tpi = (TextPaintInfo) aci
            .getAttribute(GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO);
    if (tpi == null) {
        return loc;
    }
    Paint foreground = tpi.fillPaint;
    if (foreground instanceof Color) {
        Color col = (Color) foreground;
        g2d.setColor(col);
    }
    g2d.setPaint(foreground);

    // text anchor
    TextNode.Anchor anchor = (TextNode.Anchor) aci
            .getAttribute(GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);

    // text
    String txt = getText(aci);
    float advance = getStringWidth(txt, font);
    float tx = 0;
    if (anchor != null) {
        switch (anchor.getType()) {
        case TextNode.Anchor.ANCHOR_MIDDLE:
            tx = -advance / 2;
            break;
        case TextNode.Anchor.ANCHOR_END:
            tx = -advance;
            break;
        default: //nop
        }
    }

    // draw string
    double x = loc.getX();
    double y = loc.getY();
    try {
        try {
            nativeTextHandler.drawString(g2d, txt, (float) x + tx, (float) y);
        } catch (IOException ioe) {
            if (g2d instanceof AFPGraphics2D) {
                ((AFPGraphics2D) g2d).handleIOException(ioe);
            }
        }
    } finally {
        nativeTextHandler.setOverrideFont(null);
    }
    loc.setLocation(loc.getX() + advance, loc.getY());
    return loc;
}

From source file:lcmc.common.ui.ResourceGraph.java

/** Returns positions of the vertices (by value). */
final public void getPositions(final Map<String, Point2D> positions) {
    mGraphLock.lock();//  w w  w  .  j a va  2s  .c  o m
    try {
        for (final Vertex v : graph.getVertices()) {
            final Info info = getInfo(v);
            final Point2D p = new Point2D.Double();
            final Point2D loc = layout.transform(v);
            if (loc == null) {
                continue;
            }
            p.setLocation(loc);
            p.setLocation(p.getX() + (getDefaultVertexWidth(v) - getVertexWidth(v)) / 2,
                    p.getY() + (getDefaultVertexHeight(v) - getVertexHeight(v)) / 2);
            if (info != null) {
                final String id = getId(info);
                if (id != null) {
                    positions.put(id, p);
                }
            }
        }
    } finally {
        mGraphLock.unlock();
    }
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Draws the label for one axis.//from   w  w w  . ja  v a 2 s  .co  m
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area
 * @param value  the value of the label (ignored).
 * @param cat  the category (zero-based index).
 * @param startAngle  the starting angle.
 * @param extent  the extent of the arc.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value, int cat, double startAngle,
        double extent) {
    FontRenderContext frc = g2.getFontRenderContext();

    String label = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        // if series are in rows, then the categories are the column keys
        label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
    } else {
        // if series are in columns, then the categories are the row keys
        label = this.labelGenerator.generateRowLabel(this.dataset, cat);
    }

    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    Point2D labelLocation = calculateLabelLocation(labelBounds, ascent, plotArea, startAngle);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}

From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java

protected RootLevelBand findRootBandForPosition(final Point2D point) {
    if (getElementRenderer() == null) {
        return null;
    }/*from  w  ww . j  av  a2s .  c  o  m*/

    final Element[] elementsAt = getElementRenderer().getElementsAt(point.getX(), point.getY());
    for (int i = elementsAt.length - 1; i >= 0; i -= 1) {
        final Element element = elementsAt[i];
        if (element instanceof RootLevelBand) {
            return (RootLevelBand) element;
        }
    }

    final Section section = getElementRenderer().getElement();
    if (section instanceof RootLevelBand) {
        return (RootLevelBand) section;
    }
    return null;
}