List of usage examples for java.awt Rectangle getY
public double getY()
From source file:org.openstreetmap.josm.Main.java
static public void saveGuiGeometry() { // save the current window geometry String newGeometry = ""; try {/*from w w w. ja v a 2 s .c om*/ if (((JFrame) parent).getExtendedState() == JFrame.NORMAL) { Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle bounds = parent.getBounds(); int width = (int) bounds.getWidth(); int height = (int) bounds.getHeight(); int x = (int) bounds.getX(); int y = (int) bounds.getY(); if (width > screenDimension.width) width = screenDimension.width; if (height > screenDimension.height) width = screenDimension.height; if (x < 0) x = 0; if (y < 0) y = 0; newGeometry = width + "x" + height + "+" + x + "+" + y; } } catch (Exception e) { System.out.println("Failed to save GUI geometry: " + e); } pref.put("gui.geometry", newGeometry); }
From source file:org.pentaho.reporting.libraries.designtime.swing.LibSwingUtil.java
public static String rectangleToString(final Rectangle rectangle) { final StringBuilder buffer = new StringBuilder(); buffer.append(rectangle.getX());//from w ww. ja va 2s .c o m buffer.append(","); buffer.append(rectangle.getY()); buffer.append(","); buffer.append(rectangle.getWidth()); buffer.append(","); buffer.append(rectangle.getHeight()); return buffer.toString(); }
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
/** * /*from ww w . java 2 s . c o m*/ * * @param mouseEvent a <code>MouseEvent</code> value */ public void mouseReleased(MouseEvent mouseEvent) { firstMouseEvent = null; if (dragType == DRAG_TYPE_SELECT && photos != null) { // Find out thumbails inside the selection rectangle // First lets restrict search to those rows that intersect with selection int topRow = (int) dragSelectionRect.getMinY() / rowHeight; int bottomRow = ((int) dragSelectionRect.getMaxY() / rowHeight) + 1; int startPhoto = topRow * columnsToPaint; int endPhoto = bottomRow * columnsToPaint; if (endPhoto > photos.size()) { endPhoto = photos.size(); } // Find out which photos are selected for (int n = startPhoto; n < endPhoto; n++) { /* Performance optimization: Since getPhotoBounds() needs access to photo thumbnail which may not yet be loaded we will do first a rough check of if the table cell is in the selection area. */ Rectangle cellRect = getPhotoCellBounds(n); if (dragSelectionRect.intersects(cellRect)) { Rectangle photoRect = getPhotoBounds(n); if (dragSelectionRect.intersects(photoRect)) { selection.add(photos.get(n)); repaintPhoto(photos.get(n)); } } } fireSelectionChangeEvent(); // Redrw the selection area so that the selection rectangle is not shown anymore Rectangle repaintRect = dragSelectionRect; if (lastDragSelectionRect != null) { repaintRect = dragSelectionRect.union(lastDragSelectionRect); } repaint((int) repaintRect.getX() - 1, (int) repaintRect.getY() - 1, (int) repaintRect.getWidth() + 2, (int) repaintRect.getHeight() + 2); dragSelectionRect = null; lastDragSelectionRect = null; // Notify the mouse click handler that it has to do nothing dragJustEnded = true; } }
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 a2 s . co m 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 . ja v a2 s. co 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/*from w w w . j av a 2 s .c o m*/ */ 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 2 s . c o m*/ 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(); } } }