Example usage for javax.swing SwingUtilities convertPoint

List of usage examples for javax.swing SwingUtilities convertPoint

Introduction

In this page you can find the example usage for javax.swing SwingUtilities convertPoint.

Prototype

public static Point convertPoint(Component source, int x, int y, Component destination) 

Source Link

Document

Convert the point (x,y) in source coordinate system to destination coordinate system.

Usage

From source file:Main.java

public static Point positionToClickPoint(Container component, int caretPosition, Container invokedIn) {
    if (component == null) {
        return null;
    }/* w ww  .  ja  v a 2s .  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:it.unibas.spicygui.controllo.provider.MyPopupSceneMatcher.java

public void creaSliderIniziale() {
    LayerWidget constraLayerWidget = myGraphScene.getConstraintsLayer();
    if (checkSliderShow(constraLayerWidget) == null) {
        JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
        int x = (frame.getSize().width / 2) - 20;
        int y = (int) (frame.getSize().height * 0.5);
        Point point = SwingUtilities.convertPoint(frame, x, y, myGraphScene);
        showSliderImpl(constraLayerWidget, point);
    }// w w  w . j a  va 2 s  .c o  m
}

From source file:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetCorrespondencesTGD.java

private Point calculateRandomPoint(GraphSceneGlassPane glassPane) {
    JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
    int x = (frame.getSize().width / 2) - 20;
    int y = random.nextInt((int) (frame.getSize().height * 0.5)) + (int) (frame.getSize().height * 0.2);
    Point point = SwingUtilities.convertPoint(frame, x, y, glassPane);
    return point;
}

From source file:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetCorrespondencesMappingTask.java

private Point calculatePoint(GraphSceneGlassPane glassPane) {
    JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
    int x = (frame.getSize().width / 2) + offsetX;
    int y = (frame.getSize().height / 8) + offsetY;
    if (offsetX < 300)
        offsetX += 20;/*from  w  ww . ja va  2 s  .com*/
    else
        offsetX = 0;
    if (y <= (int) (frame.getSize().height * 0.9))
        offsetY += 35;
    Point point = SwingUtilities.convertPoint(frame, x, y, glassPane);
    return point;
}

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * Return absolute location of given component.
 * // w w w .  j  a  va 2 s  .  c o m
 * @param component
 *          the component to locate
 * @return the absolute POINT location of given component.
 */
public static Point getAbsoluteLocation(JComponent component) {
    return SwingUtilities.convertPoint(component, 0, 0, MagicUIComponents.magicForm.getContentPane());
}