public void saveWindowPos(Window window) { WindowLocation pos = new WindowLocation(window.getClass().getSimpleName(), window.getX(), window.getY(), window.getWidth(), window.getHeight() ); windowPos.put(pos.getWindowId(), pos); partialSync(settings -> settings.windowPos = windowPos); }
@Override public void mouseDragged(MouseEvent e) { Point newPos = e.getPoint(); SwingUtilities.convertPointToScreen(newPos, SizeGrip.this); int xDelta = newPos.x - origPos.x; int yDelta = newPos.y - origPos.y; Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this); if (wind!=null) { // Should always be true if (getComponentOrientation().isLeftToRight()) { int w = wind.getWidth(); if (newPos.x>=wind.getX()) { w += xDelta; } int h = wind.getHeight(); if (newPos.y>=wind.getY()) { h += yDelta; } wind.setSize(w,h); } else { // RTL int newW = Math.max(1, wind.getWidth()-xDelta); int newH = Math.max(1, wind.getHeight()+yDelta); wind.setBounds(newPos.x, wind.getY(), newW, newH); } // invalidate()/validate() needed pre-1.6. wind.invalidate(); wind.validate(); } origPos.setLocation(newPos); }
@Override public void componentMoved(ComponentEvent e) { setX(window.getX()); setY(window.getY()); } });
int getX() { if (isDesktopNotification) { return parent.getX(); } else { return notifyCanvas.getX(); } }
@Override public void mousePressed(MouseEvent e) { Point clickPoint = new Point(e.getPoint()); SwingUtilities.convertPointToScreen(clickPoint, fComponent); dX = clickPoint.x - fWindow.getX(); dY = clickPoint.y - fWindow.getY(); } };
private static void saveFramePosition(Window window) { int x = window.getX(); int y = window.getY(); int width = window.getWidth(); int height = window.getHeight(); mainNode.putInt(FRAME_X_KEY, x); mainNode.putInt(FRAME_Y_KEY, y); mainNode.putInt(FRAME_WIDTH_KEY, width); mainNode.putInt(FRAME_HEIGHT_KEY, height); }
static void placeWindow(Window window) { int count = windows.size(); if (count == 0) { centerOnScreen(window); } else { Window last = windows.get(count - 1); int x = last.getX() + WINDOW_POSITION_SHIFT; int y = last.getY() + WINDOW_POSITION_SHIFT; window.setLocation(x, y); } windows.add(window); }
static void placeWindow(Window window) { int count = windows.size(); if (count == 0) { centerOnScreen(window); } else { Window last = windows.get(count - 1); int x = last.getX() + WINDOW_POSITION_SHIFT; int y = last.getY() + WINDOW_POSITION_SHIFT; window.setLocation(x, y); } windows.add(window); }
public static void ensureWindowIsVisible( Window w ) { int width = w.getWidth(); int height = w.getHeight(); Toolkit toolkit = Toolkit.getDefaultToolkit(); GraphicsConfiguration gc = w.getGraphicsConfiguration(); Insets screenInsets = toolkit.getScreenInsets( gc ); Rectangle screenSize = gc.getBounds(); w.setLocation( Math.max( screenInsets.left, Math.min( w.getX(), screenSize.width - screenInsets.right - width ) ), Math.max( screenInsets.top, Math.min( w.getY(), screenSize.height - screenInsets.bottom - height ) ) ); }
public void windowClosed(final WindowEvent e) { if (lastpos == null) lastpos = new Point(); lastpos.x = e.getWindow().getX(); lastpos.y = e.getWindow().getY(); }
Window currentWindow = ... ; Point2D windowCenter = new Point2D(currentWindow.getX() + currentWindow.getWidth()/2, currentWindow.getY() + currentWindow.getHeight()/2); Screen currentScreen = Screen.getScreens().stream() .filter(screen -> screen.getBounds().contains(windowCenter)) .findAny().get();
@RunsInCurrentThread static @Nonnull Point absoluteCenterOf(@Nonnull Window window) { Insets insets = window.getInsets(); int w = window.getWidth() - (insets.left + insets.right); int h = window.getHeight() - (insets.top + insets.bottom); int x = window.getX() + insets.left; int y = window.getY() + insets.top; return new Point(x + (w / 2), y + (h / 2)); }
public static Window center(Window w, Window reference) { double refCenterX = reference.getX() + (reference.getSize().getWidth()/2); double refCenterY = reference.getY() + (reference.getSize().getHeight()/2); int newX = (int) (refCenterX - (w.getSize().getWidth()/2)); int newY = (int) (refCenterY - (w.getSize().getHeight()/2)); w.setLocation(newX, newY); return w; }
public void windowClosed(final WindowEvent e) { position.x = e.getWindow().getX(); position.y = e.getWindow().getY(); }
public void windowClosed(final WindowEvent e) { pos.x = e.getWindow().getX(); pos.y = e.getWindow().getY(); }
void setY(final int y) { if (isDesktopNotification) { parent.setLocation(parent.getX(), y); } else { notifyCanvas.setLocation(notifyCanvas.getX(), y); } }
@Override public void windowClosing(WindowEvent e) { filterWindowPrefs.putInt("x", e.getWindow().getX()); filterWindowPrefs.putInt("y", e.getWindow().getY()); filterWindowPrefs.putInt("width", e.getWindow().getWidth()); filterWindowPrefs.putInt("height", e.getWindow().getHeight()); } });
@Override public void windowClosing(WindowEvent e) { preferences.putInt("x", e.getWindow().getX()); preferences.putInt("y", e.getWindow().getY()); preferences.putInt("width", e.getWindow().getWidth()); preferences.putInt("height", e.getWindow().getHeight()); } });
/** Returns whether one of the upper corners of the given window is * accessible. */ public static boolean onScreen(Window w) { return onScreen(w.getLocation()) || onScreen(new Point(w.getX() + w.getWidth()-1, w.getY())); }
/** Each time this method is invoked, the position/size of the window which is closing will be written to the FollowAppAttributes object. */ public void windowClosing (final WindowEvent e) { final Window window = (Window)e.getSource(); attributes_.setWidth(window.getWidth()); attributes_.setHeight(window.getHeight()); attributes_.setX(window.getX()); attributes_.setY(window.getY()); }