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:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.EnclosingBallCalculatorImpl.java

@Override
public List<EnclosingBall> findEnclosingBalls(double[] firstDimension, double[] secondDimension,
        KDTree<Point2D> tree, double eps) {

    // an empty list of enclosing balls
    List<EnclosingBall> enclosingBalls = new ArrayList<>();
    // first ball: always add it to the list
    Point2D m_0 = new Point2D.Double(firstDimension[0], secondDimension[0]);
    Ellipse2D ball = new Ellipse2D.Double();
    ball.setFrameFromCenter(m_0.getX(), m_0.getY(), m_0.getX() + eps, m_0.getY() + eps);
    // make a new enclosing ball object
    EnclosingBall enclosingBall = new EnclosingBall(ball, eps);
    enclosingBall.getEnclosingPoints().add(m_0);
    enclosingBalls.add(enclosingBall);//from   w w  w.j a  v  a  2  s. co  m

    // now start counting from 1
    for (int i = 1; i < firstDimension.length; i++) {
        Point2D m_i = new Point2D.Double(firstDimension[i], secondDimension[i]);
        // try to get the points close to the current point:
        // i.e. points m_i such that ||m_i - m_t|| 2 <= radius 
        try {
            List<Point2D> nearestPoints = tree.nearestEuclidean(new double[] { m_i.getX(), m_i.getY() }, eps);
            for (Point2D nearest : nearestPoints) {
                EnclosingBall whichBallContainsPoint = whichBallContainsPoint(enclosingBalls, nearest);
                if (whichBallContainsPoint != null) {
                    if (!whichBallContainsPoint.getEnclosingPoints().contains(m_i)) {
                        whichBallContainsPoint.getEnclosingPoints().add(m_i);
                    }
                } else {
                    ball = new Ellipse2D.Double();
                    ball.setFrameFromCenter(nearest.getX(), nearest.getY(), nearest.getX() + eps,
                            nearest.getY() + eps);
                    enclosingBall = new EnclosingBall(ball, eps);
                    enclosingBall.getEnclosingPoints().add(nearest);
                    if (!enclosingBalls.contains(enclosingBall)) {
                        enclosingBalls.add(enclosingBall);
                    }
                }
            }
        } catch (KeySizeException ex) {
            Logger.getLogger(EnclosingBallCalculatorImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return enclosingBalls;
}

From source file:com.vgi.mafscaling.MafChartPanel.java

public void mousePressed(MouseEvent e) {
    Insets insets = chartPanel.getInsets();
    int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX());
    int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY());
    ChartEntity entity = chartPanel.getChartRenderingInfo().getEntityCollection().getEntity(x, y);
    if (entity == null || !(entity instanceof XYItemEntity))
        return;/*from  w  w  w.  j ava 2  s  .c  o  m*/
    IsMovable = true;
    chartPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    xyItemEntity = (XYItemEntity) entity;
    XYPlot plot = chartPanel.getChart().getXYPlot();
    Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
    Point2D p = chartPanel.translateScreenToJava2D(e.getPoint());
    initialMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge());
}

From source file:edu.uci.ics.jung.visualization.decorators.GradientEdgePaintTransformer.java

public Paint transform(E e) {
    Layout<V, E> layout = vv.getGraphLayout();
    Pair<V> p = layout.getGraph().getEndpoints(e);
    V b = p.getFirst();/*from  w ww .  jav  a 2 s .c o  m*/
    V f = p.getSecond();
    Point2D pb = transformer.transform(layout.transform(b));
    Point2D pf = transformer.transform(layout.transform(f));
    float xB = (float) pb.getX();
    float yB = (float) pb.getY();
    float xF = (float) pf.getX();
    float yF = (float) pf.getY();
    if ((layout.getGraph().getEdgeType(e)) == EdgeType.UNDIRECTED) {
        xF = (xF + xB) / 2;
        yF = (yF + yB) / 2;
    }
    if (selfLoop.evaluate(Context.<Graph<V, E>, E>getInstance(layout.getGraph(), e))) {
        yF += 50;
        xF += 50;
    }

    return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true);
}

From source file:edu.uci.ics.jung.visualization.control.LabelEditingGraphMousePlugin.java

/**
 * For primary modifiers (default, MouseButton1):
 * pick a single Vertex or Edge that// w  ww.  j  av a2s .  c om
  * is under the mouse pointer. If no Vertex or edge is under
  * the pointer, unselect all picked Vertices and edges, and
  * set up to draw a rectangle for multiple selection
  * of contained Vertices.
  * For additional selection (default Shift+MouseButton1):
  * Add to the selection, a single Vertex or Edge that is
  * under the mouse pointer. If a previously picked Vertex
  * or Edge is under the pointer, it is un-picked.
  * If no vertex or Edge is under the pointer, set up
  * to draw a multiple selection rectangle (as above)
  * but do not unpick previously picked elements.
 * 
 * @param e the event
 */
@SuppressWarnings("unchecked")
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == modifiers && e.getClickCount() == 2) {
        VisualizationViewer<V, E> vv = (VisualizationViewer) e.getSource();
        GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            Transformer<V, String> vs = vv.getRenderContext().getVertexLabelTransformer();
            if (vs instanceof MapTransformer) {
                Map<V, String> map = ((MapTransformer) vs).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();

                V vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
                if (vertex != null) {
                    String newLabel = vs.transform(vertex);
                    newLabel = JOptionPane.showInputDialog("New Vertex Label for " + vertex);
                    if (newLabel != null) {
                        map.put(vertex, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
            Transformer<E, String> es = vv.getRenderContext().getEdgeLabelTransformer();
            if (es instanceof MapTransformer) {
                Map<E, String> map = ((MapTransformer) es).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();
                // take away the view transform
                Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, p);
                E edge = pickSupport.getEdge(layout, ip.getX(), ip.getY());
                if (edge != null) {
                    String newLabel = JOptionPane.showInputDialog("New Edge Label for " + edge);
                    if (newLabel != null) {
                        map.put(edge, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
        }
        e.consume();
    }
}

From source file:algorithms.MedianDivergenceComputer.java

private void deriveMedianColormapToJNDRatio() {
    int len = points.size() / 2;
    ratios = new double[len];
    Iterator<Point2D> ptIt = points.iterator();

    int i = 0;/* w  ww . ja v a  2 s  . c  o m*/
    while (i < len && ptIt.hasNext()) {
        Point2D p1 = ptIt.next();
        Point2D p2 = ptIt.next();

        double dist = p1.distance(p2);

        Color colorA = colormap.getColor(p1.getX(), p1.getY());
        Color colorB = colormap.getColor(p2.getX(), p2.getY());

        // color distance
        double cdist = colorDiff(colorA, colorB);

        // filter zero divisions, as long as the value distance is small
        // DON'T protect colormaps that contain duplicate colors
        if (cdist == 0 && dist < 0.05)
            continue;
        double ratio = cdist / dist;
        ratios[i] = ratio;
        i++;
    }
    Arrays.sort(ratios);
}

From source file:ca.ubc.cs.ferret.cg.VertexLabelAsShapeRenderer.java

/**
 * Labels the specified vertex with the specified label.  
 * Uses the font specified by this instance's 
 * <code>VertexFontFunction</code>.  (If the font is unspecified, the existing
 * font for the graphics context is used.)  If vertex label centering
 * is active, the label is centered on the position of the vertex; otherwise
  * the label is offset slightly./*  ww  w  . j  a v  a2  s. c o  m*/
  */
public void labelVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v, String label) {
    Graph<V, E> graph = layout.getGraph();
    if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v)) == false) {
        return;
    }
    GraphicsDecorator g = rc.getGraphicsContext();
    Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label,
            rc.getPickedVertexState().isPicked(v), v);
    Dimension d = component.getPreferredSize();

    int h_offset = -d.width / 2;
    int v_offset = -d.height / 2;

    Point2D p = layout.transform(v);
    p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);

    int x = (int) p.getX();
    int y = (int) p.getY();

    g.draw(component, rc.getRendererPane(), x + h_offset, y + v_offset, d.width, d.height, true);

    Dimension size = component.getPreferredSize();
    Rectangle bounds = new Rectangle(-size.width / 2 - 2, -size.height / 2 - 2, size.width + 4, size.height);
    shapes.put(v, bounds);
}

From source file:edu.uci.ics.jung.algorithms.layout.AbstractLayout.java

/**
 * @param v//from  www. java2 s.c  o  m
 * @param xOffset
 * @param yOffset
 */
protected void offsetVertex(V v, double xOffset, double yOffset) {
    Point2D c = getCoordinates(v);
    c.setLocation(c.getX() + xOffset, c.getY() + yOffset);
    setLocation(v, c);
}

From source file:org.apache.fop.render.pcl.PCLImageHandlerGraphics2D.java

/** {@inheritDoc} */
public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
    PCLRenderingContext pclContext = (PCLRenderingContext) context;
    ImageGraphics2D imageG2D = (ImageGraphics2D) image;
    Dimension imageDim = imageG2D.getSize().getDimensionMpt();
    PCLGenerator gen = pclContext.getPCLGenerator();

    Point2D transPoint = pclContext.transformedPoint(pos.x, pos.y);
    gen.setCursorPos(transPoint.getX(), transPoint.getY());

    boolean painted = false;
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution());
    tempGen.setDitheringQuality(gen.getDitheringQuality());
    try {//from  www . ja va  2 s. c  om
        GraphicContext ctx = (GraphicContext) pclContext.getGraphicContext().clone();

        AffineTransform prepareHPGL2 = new AffineTransform();
        prepareHPGL2.scale(0.001, 0.001);
        ctx.setTransform(prepareHPGL2);

        PCLGraphics2D graphics = new PCLGraphics2D(tempGen);
        graphics.setGraphicContext(ctx);
        graphics.setClippingDisabled(false /*pclContext.isClippingDisabled()*/);
        Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imageDim.getWidth(), imageDim.getHeight());
        imageG2D.getGraphics2DImagePainter().paint(graphics, area);

        //If we arrive here, the graphic is natively paintable, so write the graphic
        gen.writeCommand(
                "*c" + gen.formatDouble4(pos.width / 100f) + "x" + gen.formatDouble4(pos.height / 100f) + "Y");
        gen.writeCommand("*c0T");
        gen.enterHPGL2Mode(false);
        gen.writeText("\nIN;");
        gen.writeText("SP1;");
        //One Plotter unit is 0.025mm!
        double scale = imageDim.getWidth() / UnitConv.mm2pt(imageDim.getWidth() * 0.025);
        gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;");
        gen.writeText("IR0,100,0,100;");
        gen.writeText("PU;PA0,0;\n");
        baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream
        gen.writeText("\n");

        gen.enterPCLMode(false);
        painted = true;
    } catch (UnsupportedOperationException uoe) {
        log.debug(
                "Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + uoe.getMessage());
    }

    if (!painted) {
        //Fallback solution: Paint to a BufferedImage
        FOUserAgent ua = context.getUserAgent();
        ImageManager imageManager = ua.getFactory().getImageManager();
        ImageRendered imgRend;
        try {
            imgRend = (ImageRendered) imageManager.convertImage(imageG2D,
                    new ImageFlavor[] { ImageFlavor.RENDERED_IMAGE }/*, hints*/);
        } catch (ImageException e) {
            throw new IOException("Image conversion error while converting the image to a bitmap"
                    + " as a fallback measure: " + e.getMessage());
        }

        gen.paintBitmap(imgRend.getRenderedImage(), new Dimension(pos.width, pos.height),
                pclContext.isSourceTransparencyEnabled());
    }
}

From source file:com.vgi.mafscaling.MafChartPanel.java

public void movePoint(MouseEvent event) {
    try {// w w w .ja va 2 s.com
        if (IsMovable) {
            int itemIndex = xyItemEntity.getItem();
            int seriesIndex = xyItemEntity.getSeriesIndex();
            if (!pointDraggableSet.contains(seriesIndex))
                return;
            XYSeries series = ((XYSeriesCollection) xyItemEntity.getDataset()).getSeries(seriesIndex);
            XYPlot plot = chartPanel.getChart().getXYPlot();
            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            Point2D p = chartPanel.translateScreenToJava2D(event.getPoint());
            double finalMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea,
                    plot.getRangeAxisEdge());
            double difference = finalMovePointY - initialMovePointY;
            if (series.getY(itemIndex).doubleValue() + difference > plot.getRangeAxis().getRange().getLength()
                    || series.getY(itemIndex).doubleValue() + difference < 0.0)
                initialMovePointY = finalMovePointY;
            series.updateByIndex(itemIndex, series.getY(itemIndex).doubleValue() + difference);
            chartHolder.onMovePoint(itemIndex, series.getX(itemIndex).doubleValue(),
                    series.getY(itemIndex).doubleValue());
            chartPanel.getChart().fireChartChanged();
            chartPanel.updateUI();
            initialMovePointY = finalMovePointY;
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e);
    }
}

From source file:at.knowcenter.wag.egov.egiz.pdf.operator.path.construction.CurveToReplicateFinalPoint.java

@Override
public void process(PDFOperator operator, List<COSBase> operands) throws IOException {
    try {/*from w w  w  . j av a2 s . c om*/
        PDFPage pdfPage = (PDFPage) context;

        COSNumber x1 = (COSNumber) operands.get(0);
        COSNumber y1 = (COSNumber) operands.get(1);
        COSNumber x3 = (COSNumber) operands.get(2);
        COSNumber y3 = (COSNumber) operands.get(3);

        Point2D p1 = transform(x1.doubleValue(), y1.doubleValue());
        Point2D p3 = transform(x3.doubleValue(), y3.doubleValue());

        pdfPage.getCurrentPath().curveTo((float) p1.getX(), (float) p1.getY(), (float) p3.getX(),
                (float) p3.getY(), (float) p3.getX(), (float) p3.getY());

        if (log.isTraceEnabled()) {
            log.trace("Appending cubic Bezier curve with x1:" + p1.getX() + ",y1:" + p1.getY() + ", x3:"
                    + p3.getX() + ",y3:" + p3.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'y'.", e);
    }
}