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.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java

public Element getElementForLocation(final Point2D point, final boolean onlySelected) {
    final ElementRenderer rendererRoot = getElementRenderer();
    final Element[] allNodes = rendererRoot.getElementsAt(point.getX(), point.getY());
    for (int i = allNodes.length - 1; i >= 0; i -= 1) {
        final Element element = allNodes[i];
        if (ModelUtility.isHideInLayoutGui(element) == true) {
            continue;
        }/*w  ww.  ja v a  2s  .c  o m*/

        styleResolver.resolve(element, resolvedStyle);
        if (resolvedStyle.getBooleanStyleProperty(ElementStyleKeys.VISIBLE) == false) {
            continue;
        }

        if (onlySelected == false || getRenderContext().getSelectionModel().isSelected(element)) {
            return element;
        }
    }
    return null;
}

From source file:spinworld.gui.RadarPlot.java

private void drawTicks(Graphics2D g2, Rectangle2D radarArea, double axisAngle, int cat) {
    double[] ticks = { 0.5d, 1d };
    for (int i = 0; i < ticks.length; i++) {
        double tick = ticks[i];
        Point2D middlePoint = getWebPoint(radarArea, axisAngle, tick);
        double xt = middlePoint.getX();
        double yt = middlePoint.getY();
        double angrad = Math.toRadians(-axisAngle);
        g2.translate(xt, yt);/*from   w w w. j  a v a2  s  . c o m*/
        g2.rotate(angrad);
        g2.drawLine(0, (int) -TICK_MARK_LENGTH / 2, 0, (int) TICK_MARK_LENGTH / 2);
        g2.rotate(-angrad);
        g2.translate(-xt, -yt);
        drawTickLabel(g2, radarArea, middlePoint, axisAngle, cat, tick);
    }
}

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

public Point2D normalize(final Point2D e) {
    final double topBorder = getTopBorder();
    final double leftBorder = getLeftBorder();

    final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage();
    final double x = (e.getX() / scaleFactor) - leftBorder;
    final double y = (e.getY() / scaleFactor) - topBorder;

    final Point2D o = getOffset();
    o.setLocation(x, y + o.getY());/*from  w ww.j  a v  a2 s .com*/
    return o;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

private void setPaint(final boolean invert, final double xoffset, final double yoffset, final boolean fill) {
    if (paint instanceof Color) {
        final Color color = (Color) paint;
        final int alpha = color.getAlpha();
        if (fill) {
            if (alpha != currentFillGState) {
                currentFillGState = alpha;
                PdfGState gs = fillGState[alpha];
                if (gs == null) {
                    gs = new PdfGState();
                    gs.setFillOpacity(alpha / 255.00f);
                    fillGState[alpha] = gs;
                }/* w  w  w.j ava 2 s .com*/
                cb.setGState(gs);
            }
            cb.setColorFill(color);
        } else {
            if (alpha != currentStrokeGState) {
                currentStrokeGState = alpha;
                PdfGState gs = strokeGState[alpha];
                if (gs == null) {
                    gs = new PdfGState();
                    gs.setStrokeOpacity(alpha / 255.0f);
                    strokeGState[alpha] = gs;
                }
                cb.setGState(gs);
            }
            cb.setColorStroke(color);
        }
    } else if (paint instanceof GradientPaint) {
        final GradientPaint gp = (GradientPaint) paint;
        final Point2D p1 = gp.getPoint1();
        transform.transform(p1, p1);
        final Point2D p2 = gp.getPoint2();
        transform.transform(p2, p2);
        final Color c1 = gp.getColor1();
        final Color c2 = gp.getColor2();
        final PdfShading shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float) p1.getX(),
                normalizeY((float) p1.getY()), (float) p2.getX(), normalizeY((float) p2.getY()), c1, c2);
        final PdfShadingPattern pat = new PdfShadingPattern(shading);
        if (fill) {
            cb.setShadingFill(pat);
        } else {
            cb.setShadingStroke(pat);
        }
    } else if (paint instanceof TexturePaint) {
        try {
            final TexturePaint tp = (TexturePaint) paint;
            final BufferedImage img = tp.getImage();
            final Rectangle2D rect = tp.getAnchorRect();
            final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
            final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight());
            final AffineTransform inverse = this.normalizeMatrix();
            inverse.translate(rect.getX(), rect.getY());
            inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight());
            final double[] mx = new double[6];
            inverse.getMatrix(mx);
            pattern.setPatternMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4],
                    (float) mx[5]);
            image.setAbsolutePosition(0, 0);
            pattern.addImage(image);
            if (fill) {
                cb.setPatternFill(pattern);
            } else {
                cb.setPatternStroke(pattern);
            }

        } catch (Exception ex) {
            if (fill) {
                cb.setColorFill(Color.gray);
            } else {
                cb.setColorStroke(Color.gray);
            }
        }
    } else {
        try {
            int type = BufferedImage.TYPE_4BYTE_ABGR;
            if (paint.getTransparency() == Transparency.OPAQUE) {
                type = BufferedImage.TYPE_3BYTE_BGR;
            }
            final BufferedImage img = new BufferedImage((int) width, (int) height, type);
            final Graphics2D g = (Graphics2D) img.getGraphics();
            g.transform(transform);
            final AffineTransform inv = transform.createInverse();
            Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight());
            fillRect = inv.createTransformedShape(fillRect);
            g.setPaint(paint);
            g.fill(fillRect);
            if (invert) {
                final AffineTransform tx = new AffineTransform();
                tx.scale(1, -1);
                tx.translate(-xoffset, -yoffset);
                g.drawImage(img, tx, null);
            }
            g.dispose();
            // g = null;
            final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
            final PdfPatternPainter pattern = cb.createPattern(width, height);
            image.setAbsolutePosition(0, 0);
            pattern.addImage(image);
            if (fill) {
                cb.setPatternFill(pattern);
            } else {
                cb.setPatternStroke(pattern);
            }
        } catch (Exception ex) {
            if (fill) {
                cb.setColorFill(Color.gray);
            } else {
                cb.setColorStroke(Color.gray);
            }
        }
    }
}

From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java

public Point2D getPointInChart(MouseEvent e) {
    Insets insets = getInsets();//from  w  w  w.ja va 2 s  . c  om
    //System.out.println("inset.top="+insets.top+" inset.left="+insets.left);
    //System.out.println("scaleX="+chartPaneltest.getScaleX()+" scaleY="+chartPaneltest.getScaleY());
    //System.out.println(e.getX());
    //   int mouseX = (int) ((e.getX() - insets.left) / chartPaneltest.getScaleX());
    //   int mouseY = (int) ((e.getY() - insets.top) / chartPaneltest.getScaleY());
    int mouseX = (int) (e.getX() - insets.left);
    int mouseY = (int) (e.getY() - insets.top);
    //   Point2D pt = new Point2D.Double();
    //pt.setLocation(mouseX, mouseY);
    //return pt;

    //   System.out.println("x = " + mouseX + ", y = " + mouseY);

    Point2D p = chartPaneltest.translateScreenToJava2D(new Point(mouseX, mouseY));
    XYPlot plot = (XYPlot) chart.getPlot();
    ChartRenderingInfo info = chartPaneltest.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();

    ValueAxis domainAxis = plot.getDomainAxis();
    RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    ValueAxis rangeAxis = plot.getRangeAxis();
    RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

    double chartX = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge);
    double chartY = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge);
    Point2D pt2 = new Point2D.Double();

    //double scale = (double)CHART_SIZE_X/(double)CHART_SIZE_Y;
    //System.out.println("scale="+scale);
    pt2.setLocation(chartX, chartY);
    //System.out.println("Chart: x = " + (chartX) + ", y = " + chartY);
    return pt2;

}

From source file:lcmc.gui.ResourceGraph.java

/** Returns positions of the vertices (by value). */
final void getPositions(final Map<String, Point2D> positions) {
    mGraphLock.lock();//from  www .j  av  a2  s  . 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:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeSelectedMask(MouseEvent e) {
    // TODO Auto-generated method stub
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    //TODO: resize the mask
    Rectangle2D screenArea = getScreenDataArea();
    if (screenArea.contains(screenPoint)) {
        //             Point2D chartPoint = translateScreenToChart(screenPoint);

        changeSelectedMask(// w w  w.  j a va  2s .  co  m
                ChartMaskingUtilities.translateScreenX(screenPoint.getX(), getScreenDataArea(), getChart()));
        repaint();
    }
}

From source file:spinworld.gui.RadarPlot.java

/**
 * Draws a radar plot polygon.//  w  w  w  . j  a  v a2 s .co m
 *
 * @param g2 the graphics device.
 * @param plotArea the area we are plotting in (already adjusted).
 * @param centre the centre point of the radar axes
 * @param info chart rendering info.
 * @param series the series within the dataset we are plotting
 * @param catCount the number of categories per radar plot
 * @param headH the data point height
 * @param headW the data point width
 */
protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info,
        int series, int catCount, double headH, double headW) {

    Polygon polygon = new Polygon();

    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    // plot the data...
    for (int cat = 0; cat < catCount; cat++) {

        Number dataValue = getPlotValue(series, cat);

        if (dataValue != null) {
            double value = dataValue.doubleValue();

            // Finds our starting angle from the centre for this axis

            double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount);

            // The following angle calc will ensure there isn't a top
            // vertical axis - this may be useful if you don't want any
            // given criteria to 'appear' move important than the
            // others..
            //  + (getDirection().getFactor()
            //        * (cat + 0.5) * 360 / catCount);

            // find the point at the appropriate distance end point
            // along the axis/angle identified above and add it to the
            // polygon

            double _maxValue = getMaxValue(cat).doubleValue();
            double _origin = getOrigin(cat).doubleValue();
            double lowerBound = Math.min(_origin, _maxValue);
            double upperBound = Math.max(_origin, _maxValue);
            boolean lesser = value < lowerBound;
            boolean greater = value > upperBound;
            if ((lesser || greater) && !drawOutOfRangePoints) {
                continue;
            }
            if (lesser) {
                value = lowerBound;
            }
            if (greater) {
                value = upperBound;
            }
            double length = _maxValue == _origin ? 0 : (value - lowerBound) / (upperBound - lowerBound);
            if (_maxValue < _origin) { // inversed
                length = 1 - length;
            }
            Point2D point = getWebPoint(plotArea, angle, length);
            polygon.addPoint((int) point.getX(), (int) point.getY());

            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);

            double px = point.getX();
            double py = point.getY();
            g2.setPaint(paint);
            if (lesser || greater) {
                // user crosshair for out-of-range data points distinguish
                g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL));
                double delta = 3;
                g2.draw(new Line2D.Double(px - delta, py, px + delta, py));
                g2.draw(new Line2D.Double(px, py - delta, px, py + delta));
            } else {
                // put an elipse at the point being plotted..
                Ellipse2D head = new Ellipse2D.Double(px - headW / 2, py - headH / 2, headW, headH);
                g2.fill(head);
                g2.setStroke(getHeadOutlineStroke(series));
                g2.setPaint(outlinePaint);
                g2.draw(head);
            }

            if (entities != null) {
                int row = 0;
                int col = 0;
                if (this.dataExtractOrder == TableOrder.BY_ROW) {
                    row = series;
                    col = cat;
                } else {
                    row = cat;
                    col = series;
                }
                String tip = null;
                if (this.toolTipGenerator != null) {
                    tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col);
                }

                String url = null;
                if (this.urlGenerator != null) {
                    url = this.urlGenerator.generateURL(this.dataset, row, col);
                }

                Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH),
                        (int) (headW * 2), (int) (headH * 2));
                CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset,
                        this.dataset.getRowKey(row), this.dataset.getColumnKey(col));
                entities.add(entity);
            }
        }
    }
    // Plot the polygon

    Paint paint = getSeriesPaint(series);
    g2.setPaint(paint);
    g2.setStroke(getSeriesOutlineStroke(series));
    g2.draw(polygon);

    // Lastly, fill the web polygon if this is required

    if (this.webFilled) {
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2.fill(polygon);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    }
}

From source file:org.apache.fop.render.rtf.RTFHandler.java

/** {@inheritDoc} */
public void endInstreamForeignObject(InstreamForeignObject ifo) {
    if (bDefer) {
        return;/*from  w w w  . j a  va2s  .  c o  m*/
    }

    try {
        XMLObj child = ifo.getChildXMLObj();
        Document doc = child.getDOMDocument();
        String ns = child.getNamespaceURI();

        ImageInfo info = new ImageInfo(null, null);
        // Set the resolution to that of the FOUserAgent
        FOUserAgent ua = ifo.getUserAgent();
        ImageSize size = new ImageSize();
        size.setResolution(ua.getSourceResolution());

        // Set the image size to the size of the svg.
        Point2D csize = new Point2D.Float(-1, -1);
        Point2D intrinsicDimensions = child.getDimension(csize);
        if (intrinsicDimensions == null) {
            ResourceEventProducer eventProducer = ResourceEventProducer.Provider
                    .get(getUserAgent().getEventBroadcaster());
            eventProducer.ifoNoIntrinsicSize(this, child.getLocator());
            return;
        }
        size.setSizeInMillipoints((int) Math.round(intrinsicDimensions.getX() * 1000),
                (int) Math.round(intrinsicDimensions.getY() * 1000));
        size.calcPixelsFromSize();
        info.setSize(size);

        ImageXMLDOM image = new ImageXMLDOM(info, doc, ns);

        FOUserAgent userAgent = ifo.getUserAgent();
        ImageManager manager = userAgent.getFactory().getImageManager();
        Map hints = ImageUtil.getDefaultHints(ua.getImageSessionContext());
        Image converted = manager.convertImage(image, FLAVORS, hints);
        putGraphic(ifo, converted);

    } catch (ImageException ie) {
        ResourceEventProducer eventProducer = ResourceEventProducer.Provider
                .get(getUserAgent().getEventBroadcaster());
        eventProducer.imageError(this, null, ie, null);
    } catch (IOException ioe) {
        ResourceEventProducer eventProducer = ResourceEventProducer.Provider
                .get(getUserAgent().getEventBroadcaster());
        eventProducer.imageIOError(this, null, ioe, null);
    }
}

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

private void moveSelectedText(MouseEvent e) {
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    Rectangle2D screenArea = getScreenDataArea();
    if (screenArea.contains(screenPoint)) {

        if (textMovePoint != null) {
            //               Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            double screenX = ChartMaskingUtilities.translateScreenX(e.getX() / getScaleX(), getScreenDataArea(),
                    getChart());/*w  w  w  .j  a v a  2s  . com*/
            double screenY = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(),
                    0);
            //               Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            Point2D point = new Point2D.Double(screenX, screenY);
            selectedTextWrapper.setRect(selectedTextWrapper.getMinX() + point.getX() - textMovePoint.getX(),
                    selectedTextWrapper.getMinY() + point.getY() - textMovePoint.getY(),
                    selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
            if (point != null) {
                this.textMovePoint = point;
            }
            repaint();
        }
    }
}