Example usage for java.awt Rectangle getX

List of usage examples for java.awt Rectangle getX

Introduction

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

Prototype

public double getX() 

Source Link

Document

Returns the X coordinate of the bounding Rectangle in double precision.

Usage

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

protected void handleSelectionDragEvent(MouseEvent e) {
    dragSelectionRect = new Rectangle(firstMouseEvent.getX(), firstMouseEvent.getY(), 0, 0);
    dragSelectionRect.add(e.getX(), e.getY());

    // Determine which area needs to be redrawn. If there is a selection marker rectangle already drawn
    // the redraw are must be union of the previous and current areas (current area can be also smaller!
    Rectangle repaintRect = dragSelectionRect;
    if (lastDragSelectionRect != null) {
        repaintRect = dragSelectionRect.union(lastDragSelectionRect);
    }//from ww w. j a  v  a  2s  . c om
    repaint((int) repaintRect.getX() - 1, (int) repaintRect.getY() - 1, (int) repaintRect.getWidth() + 2,
            (int) repaintRect.getHeight() + 2);
}

From source file:org.safs.selenium.webdriver.lib.WDLibrary.java

/**
 * Adjust the relative coordinate to screen absolute coordinate according to the webelement.
 * @param we WebElement, the component relative to which to adjust coordinate
 * @param point Point, the relative point, it will bring back the adjusted screen coordinate
 * @throws Exception//w  ww  . j  a va  2s  .c  o  m
 */
private static void translatePoint(WebElement we, Point point) throws Exception {
    String debugmsg = StringUtils.debugmsg(false);

    Rectangle rec = WDLibrary.getRectangleOnScreen(we);
    IndependantLog.debug(debugmsg + " webelement screen location is [" + rec.getX() + "," + rec.getY() + "]");

    //Translate the point according to webelement's left-up corner
    point.translate(rec.x, rec.y);

    //check and keep in screen boundaries
    if (point.x < 0)
        point.x = 0;
    if (point.y < 0)
        point.y = 0;
    if (point.x > ImageUtils.getScreenWidth() - 1)
        point.x = ImageUtils.getScreenWidth() - 1;
    if (point.y > ImageUtils.getScreenHeight() - 1)
        point.y = ImageUtils.getScreenHeight() - 1;
}

From source file:org.squidy.designer.Designer.java

/**
 * @param view// ww w. j  a  v  a  2  s.com
 */
private void initializeView(PFrame view) {
    view.setTitle(VIEW_TITLE);
    view.setDefaultCloseOperation(PFrame.DO_NOTHING_ON_CLOSE);

    view.addWindowListener(new WindowAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see java.awt.event.WindowAdapter#windowClosing(java.awt
         * .event.WindowEvent)
         */
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);

            // Remove view.
            PFrame view = (PFrame) e.getWindow();
            views.remove(view);
            view.dispose();

            if (LOG.isDebugEnabled()) {
                LOG.debug("Closing view. View count " + views.size());
            }

            // Store data if last view has been closed.
            if (views.size() == 0) {
                store(data);
                System.exit(0);
            }
        }
    });

    view.getCanvas().addInputEventListener(new PBasicInputEventHandler() {
        @Override
        public void mouseClicked(PInputEvent event) {
            super.mouseClicked(event);

            final PCamera camera = event.getCamera();

            if (!event.isHandled() && event.isLeftMouseButton() && event.getClickCount() == 2) {

                Rectangle bounds = getCanvas().getBounds();
                bounds.setBounds((int) (bounds.getX() - 30), ((int) bounds.getY() - 30),
                        ((int) bounds.getWidth() + 30), ((int) bounds.getHeight() + 30));

                camera.animateViewToCenterBounds(bounds, true, 1000);

                // Set all children of current node as draggable.
                for (Object child : getCanvas().getLayer().getChildrenReference()) {
                    if (child instanceof Draggable) {
                        ((Draggable) child).setDraggable(true);
                    }
                }
            }
        }
    });

    view.getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() {

        /*
        * (non-Javadoc)
        * 
        * @see
        * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseClicked
        * (edu.umd.cs.piccolo.event.PInputEvent)
        */
        @Override
        public void mouseClicked(PInputEvent event) {
            super.mouseClicked(event);

            if (event.isRightMouseButton() && event.getClickCount() > 1) {

                PLayer layer = getCanvas().getLayer();

                PCamera camera = new PCamera();
                camera.addLayer(layer);
                layer.getRoot().addChild(camera);

                PCanvas canvas = new PSwingCanvas();
                canvas.setCamera(camera);

                PFrame view = new PFrame("", false, canvas);
                views.add(view);
                initializeView(view);
                // view.setVisible(true);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Created view. View count " + views.size());
                }
            }
        }
    });
}

From source file:org.squidy.nodes.MouseIO.java

@Override
public void onStart() {

    // Search minimum/maximum of x/y.
    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    screenBounds = new Rectangle[devices.length];
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        screenBounds[i] = bounds;//from   www. j a v a  2s . c  om

        double x, y;
        x = bounds.getX();
        minX = Math.min(minX, x);
        x += bounds.getWidth();
        maxX = Math.max(maxX, x);
        y = bounds.getY();
        minY = Math.min(minY, y);
        y += bounds.getHeight();
        maxY = Math.max(maxY, y);
    }

    width = Math.abs(minX) + Math.abs(maxX);
    height = Math.abs(minY) + Math.abs(maxY);

    try {
        robot = new Robot();
        robot.setAutoDelay(0);
    } catch (AWTException e) {
        if (LOG.isErrorEnabled())
            LOG.error("Could not initialize Robot.");
        publishFailure(e);
    }

    if (openInputWindow) {
        inputWindow = InputWindow.getInstance();
        inputWindow.registerMouseListener(this);
    }

    if (directInput && isWindows) {
        if (cdim == null) {
            createDirectInputMouse();
            if (cdim != null) {
                if (cdim.Init(0) != 0) {
                    cdim = null;
                    publishFailure(new SquidyException("Could not initialize DirectInput mouse."));
                }
            }
        }
        if (cdim != null) {
            if (cdim.StartCapture() != 0)
                publishFailure(new SquidyException("Could not start DirectInput mouse."));
            else
                new Thread(new Runnable() {
                    public void run() {
                        while (processing) {
                            cdim.WaitForBufferedData();
                            if (processing)
                                processDirectInputMouseBufferedData();
                        }
                    }
                }, getId() + "_DIM").start();
        }
    }
}