List of usage examples for java.awt Window getGraphicsConfiguration
public GraphicsConfiguration getGraphicsConfiguration()
From source file:Utils.java
/** * <p>/* ww w. j a v a2 s . c om*/ * Returns the <code>Point</code> at which a window should be placed to * center that window on the screen. * </p> * <p> * Some thought was taken as to whether to implement a method such as this, * or to simply make a method that, given a window, will center it. It was * decided that it is better to not alter an object within a method. * </p> * * @param window The window to calculate the center point for. This object * can not be null. * * @return the <code>Point</code> at which the window should be placed to * center that window on the screen. */ private static Rectangle getUsableDeviceBounds(Window window) { Window owner = window.getOwner(); GraphicsConfiguration gc = null; if (owner == null) { gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } else { gc = owner.getGraphicsConfiguration(); } Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle bounds = gc.getBounds(); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); return bounds; }
From source file:Utilities.java
/** * Finds out the monitor where the user currently has the input focus. * This method is usually used to help the client code to figure out on * which monitor it should place newly created windows/frames/dialogs. * * @return the GraphicsConfiguration of the monitor which currently has the * input focus//from w w w. ja v a2 s. co m */ private static GraphicsConfiguration getCurrentGraphicsConfiguration() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null) { Window w = SwingUtilities.getWindowAncestor(focusOwner); if (w != null) { return w.getGraphicsConfiguration(); } } return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); }
From source file:net.pms.newgui.components.WindowProperties.java
private boolean updateScreenBounds(@Nonnull Window eventWindow) { Rectangle bounds = eventWindow.getGraphicsConfiguration().getBounds(); if (bounds == null) { if (screenBounds == null) { return false; }// w w w. ja v a 2 s .c o m } else if (bounds.equals(screenBounds)) { return false; } screenBounds = bounds; return true; }
From source file:net.pms.newgui.components.WindowProperties.java
private boolean updateScreenInsets(@Nonnull Window eventWindow) { Insets insets = eventWindow.getToolkit().getScreenInsets(eventWindow.getGraphicsConfiguration()); if (insets == null) { if (screenInsets == null) { return false; }//from w w w .ja va 2 s .c o m } else if (insets.equals(screenInsets)) { return false; } screenInsets = insets; return true; }
From source file:net.pms.newgui.components.WindowProperties.java
/** * Creates a new instance using the specified parameters. * * @param window the {@link Window} whose properties to keep track of. * @param standardSize the standard size of {@code window}. * @param mimimumSize the minimum size of {@code window}. * @param windowConfiguration the {@link WindowPropertiesConfiguration} * instance for reading and writing the window properties. *///from ww w . j a v a 2s . c o m public WindowProperties(@Nonnull Window window, @Nullable Dimension standardSize, @Nullable Dimension mimimumSize, @Nullable WindowPropertiesConfiguration windowConfiguration) { if (window == null) { throw new IllegalArgumentException("window cannot be null"); } this.window = window; this.minimumSize = mimimumSize; if (mimimumSize != null) { window.setMinimumSize(mimimumSize); } this.windowConfiguration = windowConfiguration; if (windowConfiguration != null) { getConfiguration(); GraphicsConfiguration windowGraphicsConfiguration = window.getGraphicsConfiguration(); if (windowBounds != null && effectiveScreenBounds != null && graphicsDevice != null && graphicsDevice.equals(windowGraphicsConfiguration.getDevice().getIDstring()) && screenBounds != null && screenBounds.equals(windowGraphicsConfiguration.getBounds())) { setWindowBounds(); } else { Rectangle screen = effectiveScreenBounds != null ? effectiveScreenBounds : windowGraphicsConfiguration.getBounds(); if (standardSize != null && screen.width >= standardSize.width && screen.height >= standardSize.height) { window.setSize(standardSize); } else if (mimimumSize != null && (window.getWidth() < mimimumSize.width || window.getHeight() < mimimumSize.getHeight())) { window.setSize(mimimumSize); } window.setLocationByPlatform(true); } if (window instanceof Frame) { // Set maximized state int maximizedState = windowState & Frame.MAXIMIZED_BOTH; if (maximizedState != 0) { ((Frame) window).setExtendedState(((Frame) window).getExtendedState() | maximizedState); } } } window.addWindowListener(this); window.addComponentListener(this); }
From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java
/** * @param isInitial// w w w . ja v a 2s . co m */ private void loadData(final boolean isInitial) { label.setText(""); String hostName = properties.getProperty("hostName"); String dbUserName = properties.getProperty("dbUserName"); String dbPassword = properties.getProperty("dbPassword"); int index = 0; List<String> dbNamesList = masterPanel.getDbNamesForMaster(); List<String> otherNamesList = masterPanel.getDbNameList(); if (dbNamesList == null || dbNamesList.size() == 0) { return; } //dbNamesList.clear(); //otherNamesList.clear(); //dbNamesList.add("testfish"); Vector<String> items = new Vector<String>(dbNamesList); Collections.sort(items); if (!isInitial) { index = dbList.getSelectedIndex(); if (index == -1) { return; } } databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue(); DBMSUserMgr mgr = DBMSUserMgr.getInstance(); do { if (mgr.connect(dbUserName, dbPassword, hostName, databaseName)) { if (isInitial) { HashSet<String> dbNameHashSet = new HashSet<String>(); DefaultListModel model = new DefaultListModel(); for (String nm : items) { model.addElement(nm); dbNameHashSet.add(nm); } dbList.setModel(model); model = new DefaultListModel(); for (String nm : otherNamesList) { if (!dbNameHashSet.contains(nm)) { model.addElement(nm); } } otherDBList.setModel(model); } label.setText(getFormattedResStr("MSTR_USR_DB", databaseName)); if (!mgr.doesDBHaveTable(databaseName, "specifyuser")) { items.remove(0); databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue(); continue; } Vector<UserData> userDataList = new Vector<UserData>(); String sql = "SELECT SpecifyUserId, Name, Password, EMail FROM specifyuser"; Vector<Object[]> data = BasicSQLUtils.query(mgr.getConnection(), sql); for (Object[] c : data) { UserData ud = new UserData((Integer) c[0], (String) c[1], (String) c[2], "(On user's machine)", (String) c[3]); userDataList.add(ud); sql = String.format( "SELECT LastName, FirstName, EMail FROM agent WHERE SpecifyUserID = %d ORDER BY TimestampModified, TimestampCreated LIMIT 0,1", ud.getId()); Vector<Object[]> uData = BasicSQLUtils.query(mgr.getConnection(), sql); if (uData.size() > 0) { Object[] d = uData.get(0); ud.setLastName((String) d[0]); ud.setFirstName((String) d[1]); String email = (String) d[2]; if (StringUtils.isNotEmpty(email) && StringUtils.isEmpty(ud.getEmail())) { ud.setEmail(email); } } else { // error } } mgr.close(); userModel.setUserData(userDataList); UIHelper.calcColumnWidths(userTable); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Window window = getTopWindow(); Insets screenInsets = Toolkit.getDefaultToolkit() .getScreenInsets(window.getGraphicsConfiguration()); Rectangle screenRect = window.getGraphicsConfiguration().getBounds(); screenRect.height -= screenInsets.top + screenInsets.bottom; screenRect.width -= screenInsets.left + screenInsets.right; Rectangle rect = window.getBounds(); Dimension size = window.getPreferredSize(); // Make sure the window isn't larger than the screen size.width = Math.min(size.width, screenRect.width); size.height = Math.min(size.height, screenRect.height); if (size.height > rect.height || size.width > rect.width) { window.setBounds(rect.x, rect.y, size.width, size.height); UIHelper.centerWindow(getTopWindow()); } } }); if (isInitial && items.size() > 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dbList.setSelectedIndex(0); } }); } break; } else if (items.size() > 1) { items.remove(0); databaseName = isInitial ? items.get(0) : (String) dbList.getSelectedValue(); } else { break; } } while (true); }
From source file:Filter3dTest.java
/** * Creates an image compatible with the current display. */// w w w .j ava 2s . c o m public BufferedImage createCompatibleImage(int w, int h, int transparancy) { Window window = device.getFullScreenWindow(); if (window != null) { GraphicsConfiguration gc = window.getGraphicsConfiguration(); return gc.createCompatibleImage(w, h, transparancy); } return null; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param window//ww w. ja va2 s . c o m * @param x * @param y * @param w * @param h */ public static void positionAndFitToScreen(final java.awt.Window window, final int x, final int y, final int w, final int h) { Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration()); Rectangle winRect = window.getGraphicsConfiguration().getBounds(); Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); int xCoord = Math.max(0, x); int yCoord = Math.max(0, y); int width = w; int height = h; if ((xCoord + width) > size.width) { xCoord = size.width - width; xCoord = (winRect.width - width) / 2; width = Math.min(winRect.width - screenInsets.left - screenInsets.right, width); } if (yCoord + height > size.height) { yCoord = size.height - x; yCoord = (winRect.height - height) / 2; height = Math.min(winRect.height - screenInsets.top - screenInsets.bottom, height); } window.setBounds(xCoord, yCoord, width, height); }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Center and make the window visible// www. j ava2 s. c om * @param window the window to center * @param width sets the dialog to this width (can be null) * @param height sets the dialog to this height (can be null) */ public static void centerWindow(final java.awt.Window window, final Integer width, final Integer height) { JFrame topFrame = (JFrame) UIRegistry.getTopWindow(); Insets screenInsets = null; Rectangle screenRect = null; if (width != null || height != null) { Dimension s = window.getSize(); if (width != null) s.width = width; if (height != null) s.height = height; window.setSize(s); } // if there is a registered TOPFRAME, and it's not the same as the window being passed in... if (topFrame != null && topFrame != window) { screenRect = topFrame.getBounds(); screenInsets = topFrame.getInsets(); } else { screenRect = window.getGraphicsConfiguration().getBounds(); screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration()); } // Make sure we don't place the demo off the screen. int centerWidth = screenRect.width < window.getSize().width ? screenRect.x : screenRect.x + screenRect.width / 2 - window.getSize().width / 2; int centerHeight = screenRect.height < window.getSize().height ? screenRect.y : screenRect.y + screenRect.height / 2 - window.getSize().height / 2; centerHeight = centerHeight < screenInsets.top ? screenInsets.top : centerHeight; window.setLocation(centerWidth, centerHeight); }