Example usage for java.awt Point getX

List of usage examples for java.awt Point getX

Introduction

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

Prototype

public double getX() 

Source Link

Usage

From source file:Main.java

public static Point positionToClickPoint(Container component, int caretPosition, Container invokedIn) {
    if (component == null) {
        return null;
    }//w ww . j av  a  2 s  .c  o  m

    //System.err.println("Checking: " + component.getClass().getName());
    if (component.getClass().getName().indexOf("EditorPane") >= 0) {
        try {
            java.lang.reflect.Method pointGetter = component.getClass().getMethod("modelToView",
                    new Class[] { Integer.TYPE });
            Rectangle rec = (Rectangle) pointGetter.invoke(component,
                    new Object[] { new Integer(caretPosition) });
            //System.err.println("Before: " + (int)rec.getY());
            // FIXME: somehow it fails here to convert point from scrollable component
            Point point = SwingUtilities.convertPoint(component, (int) rec.getX(), (int) rec.getY() + 10,
                    invokedIn);
            // FIXME: ugly hack :(
            if (point.getY() > 1024) {
                point = new Point((int) point.getX(), 250);
            }
            //System.err.println("After: " + (int)point.getY());
            return point;
        } catch (Exception e) {
            System.err.println("Method invocation exception caught");
            e.printStackTrace();

            //FIXME: BUG
            return null;
            //throw new RuntimeException("Method invocation exception caught");
        }
    }

    for (int i = 0; i < component.getComponentCount(); i++) {
        java.awt.Component childComponent = component.getComponent(i);
        if (childComponent instanceof javax.swing.JComponent) {
            Point point = positionToClickPoint((javax.swing.JComponent) childComponent, caretPosition,
                    invokedIn);
            if (point != null) {
                return point;
            }
        }
    }

    return null;
}

From source file:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param plot//from   w  ww  . jav a  2s . c  om
 * @param screenPoint
 * @param screenDataArea
 * @return
 */
public static Point translatePointToImageCoord(XYPlot plot, final Point screenPoint,
        final Rectangle2D screenDataArea) {
    final ValueAxis da = plot.getDomainAxis();
    final ValueAxis ra = plot.getRangeAxis();

    final double x = da.java2DToValue(screenPoint.getX(), screenDataArea, plot.getDomainAxisEdge());
    final double y = ra.java2DToValue(screenPoint.getY(), screenDataArea, plot.getRangeAxisEdge());

    Logger.getLogger(ChartTools.class.getName()).log(Level.INFO, "{0} - {1}", new Object[] { x, y });

    if (x > 0 && y > 0) {
        return new Point((int) x, (int) y);
    }

    //        final double axisXperc = (x - plot.getDomainAxis().getLowerBound())
    //                / (plot.getDomainAxis().getUpperBound() - plot.getDomainAxis().getLowerBound());
    //        final double axisYperc = (y - plot.getRangeAxis().getLowerBound())
    //                / (plot.getRangeAxis().getUpperBound() - plot.getRangeAxis().getLowerBound());
    //
    //        System.out.println(axisXperc + " - " + axisYperc);
    //        final int newX = (int) (axisXperc * this.imageWidth);
    //        final int newY = (int) (axisYperc * this.imageHeight);
    return null;
}

From source file:Main.java

/**
 * Zentriert ein Window relativ zu dem Parent-Window
 * //from w  w w.j  a  va 2 s . c o m
 * @param parent
 *            Parent-Window, wenn null, dann wird relativ zu dem Bildschirm
 *            zentriert
 * @param child
 *            Window das zentrirt werden soll.
 */
static public void centreWindow(Window parent, Window child) {
    if (child == null)
        return;
    Point parentLocation = null;
    Dimension parentSize = null;
    if (parent == null) {
        parentLocation = new Point(0, 0);
        parentSize = child.getToolkit().getScreenSize();
    } else {
        parentLocation = parent.getLocationOnScreen();
        parentSize = parent.getSize();
    }
    Dimension childSize = child.getSize();
    child.setLocation((int) (parentLocation.getX() + parentSize.getWidth() / 2 - childSize.getWidth() / 2),
            (int) (parentLocation.getY() + parentSize.getHeight() / 2 - childSize.getHeight() / 2));
}

From source file:smanilov.mandelbrot.compute.Computer.java

/**
 * Converts a pixel coordinate into a complex number.
 * @param pixelCenter The center of the pixel coordinate system.
 * @param scale log2(pixels) per unit in the complex plane. 
 * @param center The center of the view on the complex plane.
 *//*from  ww w . j a v a  2  s. c o  m*/
private static Complex toComplex(double x, double y, Point pixelCenter, int scale, Point2D center) {
    double dx = (double) (x - pixelCenter.getX());
    double dy = (double) (-y + pixelCenter.getY());
    double real = (double) dx / (1 << scale) + center.getX();
    double imaginary = (double) dy / (1 << scale) + center.getY();
    return new Complex(real, imaginary);
}

From source file:oct.util.Util.java

public static double[][] getXYArraysFromPoints(List<Point> points) {
    double[] x = new double[points.size()];
    double[] y = new double[points.size()];
    ListIterator<Point> pi = points.listIterator();
    for (int i = 0; pi.hasNext(); i++) {
        Point p = pi.next();
        x[i] = p.getX();
        y[i] = p.getY();//  w  w w  .  j  a v a  2 s .c  o  m
    }
    return new double[][] { x, y };
}

From source file:net.sf.webphotos.tools.Thumbnail.java

private static Image estampar(Image im) {
    try {//from w  w  w  .  j  a  va2s .co  m
        Image temp = new ImageIcon(im).getImage();

        BufferedImage buf = new BufferedImage(temp.getWidth(null), temp.getHeight(null),
                BufferedImage.TYPE_INT_RGB);

        Graphics2D g2 = (Graphics2D) buf.getGraphics();

        g2.drawImage(temp, 0, 0, null);
        g2.setBackground(Color.BLUE);

        Dimension dimensaoFoto = new Dimension(im.getWidth(null), im.getHeight(null));

        // aplicar texto
        if (texto != null) {
            Util.out.println("aplicando texto " + texto);

            Font fonte = new Font(txFamilia, txEstilo, txTamanho);
            g2.setFont(fonte);
            FontMetrics fm = g2.getFontMetrics(fonte);
            Dimension dimensaoTexto = new Dimension(fm.stringWidth(texto), fm.getHeight());
            Point posTexto = calculaPosicao(dimensaoFoto, dimensaoTexto, txMargem, txPosicao);

            g2.setPaint(txCorFundo);
            g2.drawString(texto, (int) posTexto.getX() + 1, (int) posTexto.getY() + 1 + fm.getHeight());
            g2.setPaint(txCorFrente);
            g2.drawString(texto, (int) posTexto.getX(), (int) posTexto.getY() + fm.getHeight());
        }

        // aplicar marca dagua
        if (marcadagua != null) {
            Image marca = new ImageIcon(marcadagua).getImage();
            int rule = AlphaComposite.SRC_OVER;
            float alpha = (float) mdTransparencia / 100;
            Point pos = calculaPosicao(dimensaoFoto, new Dimension(marca.getWidth(null), marca.getHeight(null)),
                    mdMargem, mdPosicao);

            g2.setComposite(AlphaComposite.getInstance(rule, alpha));
            g2.drawImage(marca, (int) pos.getX(), (int) pos.getY(), null);
        }

        g2.dispose();
        //return (Image) buf;
        return Toolkit.getDefaultToolkit().createImage(buf.getSource());
    } catch (Exception e) {
        Util.err.println("[Thumbnail.estampar]/ERRO: Inesperado - " + e.getMessage());
        e.printStackTrace(Util.err);
        return im;
    }
}

From source file:org.kalypso.ogc.gml.map.widgets.AbstractCreateGeometeryWidget.java

/**
 * This method transforms the AWT-Point to a GM_Point.
 * //from  www.j a v a 2 s.c  o m
 * @param mapPanel
 *          The MapPanel of the map.
 * @param p
 *          The AWT-Point.
 */
protected static GM_Point transform(final IMapPanel mapPanel, final Point p) {
    if (p == null)
        return null;

    final GeoTransform projection = mapPanel.getProjection();
    final IMapModell mapModell = mapPanel.getMapModell();
    if (mapModell == null || projection == null)
        return null;

    String coordinatesSystem = mapModell.getCoordinatesSystem();
    if (coordinatesSystem == null) {
        coordinatesSystem = KalypsoDeegreePlugin.getDefault().getCoordinateSystem();
    }

    final double x = p.getX();
    final double y = p.getY();

    return GeometryFactory.createGM_Point(projection.getSourceX(x), projection.getSourceY(y),
            coordinatesSystem);
}

From source file:org.pmedv.blackboard.EditorUtils.java

/**
 * Finds the mouse hovered {@link Pin} for the current {@link BoardEditor}
 * //w  w w.j  av  a 2  s.c o  m
 * @param e The mouse event to find the pin for
 * @param editor the current {@link BoardEditor}
 * @return the pin, or null if no {@link Pin} is being hovered
 * 
 */
public static Pin findPin(int x, int y, BoardEditor editor) {

    for (Layer layer : editor.getModel().getLayers()) {

        for (Item item : layer.getItems()) {

            if (item instanceof Part) {

                Part p = (Part) item;

                for (Pin pin : p.getConnections().getPin()) {

                    Point point = new Point(pin.getX(), pin.getY());

                    int rot = p.getRotation();

                    if (rot != 0) {

                        if (Math.abs(rot) == 90 || Math.abs(rot) == 270) {
                            rot -= 180;
                        }

                        point = BoardUtil.rotatePoint((int) point.getX(), (int) point.getY(), 0, 0, rot);
                    }

                    if (x >= (item.getXLoc() + point.getX() - 3) && x <= (item.getXLoc() + point.getX() + 3)
                            && y >= (item.getYLoc() + point.getY() - 3)
                            && y <= (item.getYLoc() + point.getY()) + 3) {
                        return pin;
                    }

                }

            }

        }

    }

    return null;
}

From source file:net.chaosserver.timelord.swingui.SwingUtil.java

/**
 * Repair location is designed to detect if a box is partially
 * off-screen and move the box back onto the screen.
 *
 * @param component component to repair//  w  w w . j a v a2s .  c  o  m
 */
public static void repairLocation(Component component) {
    Point locationPoint = component.getLocation();
    Point locationOnScreenPoint = null;
    if (component.isVisible()) {
        locationOnScreenPoint = component.getLocationOnScreen();
    }
    Dimension componentSize = component.getSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    if (log.isDebugEnabled()) {
        log.debug("Repairing location on [" + component.getClass().getName() + "].  Original location point = ["
                + locationPoint + "] and location on screen point = [" + locationOnScreenPoint
                + "].  The screen size is [" + screenSize + "] and the component size is [" + componentSize
                + "]");
    }

    // Is the dialog to far to the left?  Then fix.
    if (locationPoint.getX() < 0) {
        locationPoint.setLocation(0, locationPoint.getY());
    }
    if (locationPoint.getY() < 0) {
        locationPoint.setLocation(locationPoint.getX(), 0);
    }
    // component.setLocation(locationPoint);

    // Is the dialog too wide?
    if (locationPoint.getX() + componentSize.getWidth() > screenSize.getWidth()) {

        componentSize.width = (int) (screenSize.getWidth() - locationPoint.getX());
    }
    if (locationPoint.getY() + componentSize.getHeight() > screenSize.getHeight()) {

        componentSize.height = (int) (screenSize.getHeight() - locationPoint.getY());
    }

    // component.setSize(componentSize);
}

From source file:nl.b3p.viewer.image.ImageTool.java

public static BufferedImage drawGeometries(BufferedImage bi, CombineImageSettings settings, int srid, Bbox bbox,
        int width, int height) throws Exception {
    List wktGeoms = settings.getWktGeoms();
    if (wktGeoms == null || wktGeoms.size() <= 0) {
        return bi;
    }/*from   www  . j av  a2s  .com*/
    BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    //        BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D gbi = newBufIm.createGraphics();
    gbi.drawImage(bi, 0, 0, null);
    for (int i = 0; i < wktGeoms.size(); i++) {
        gbi.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        CombineImageWkt ciw = (CombineImageWkt) wktGeoms.get(i);
        Color color = settings.getDefaultWktGeomColor();
        if (ciw.getColor() != null) {
            color = ciw.getColor();
        }
        gbi.setColor(color);
        String wktGeom = ciw.getWktGeom();
        Geometry geom = geometrieFromText(wktGeom, srid);
        Shape shape = createImage(geom, srid, bbox, width, height);
        Point centerPoint = null;
        if (geom instanceof Polygon) {
            gbi.fill(shape);
        } else if (geom instanceof com.vividsolutions.jts.geom.Point) {
            centerPoint = calculateCenter(shape, srid, bbox, width, height);
            gbi.fill(new Ellipse2D.Double(centerPoint.getX(), centerPoint.getY(), 8, 8));
        } else {
            float strokeWidth = ciw.getStrokeWidth() != null ? ciw.getStrokeWidth() : 3f;
            gbi.setStroke(new BasicStroke(strokeWidth));
            gbi.draw(shape);
        }
        if (ciw.getLabel() != null) {
            if (centerPoint == null) {
                centerPoint = calculateCenter(shape, srid, bbox, width, height);
            }
            gbi.setColor(Color.black);
            gbi.drawString(ciw.getLabel(), (float) centerPoint.getX(), (float) centerPoint.getY());
        }
    }
    gbi.dispose();
    return newBufIm;
}