/** Returns the value from the desktop. */ protected Object getValueFromDesktop() { if (this.toolkit == null) { this.toolkit = Toolkit.getDefaultToolkit(); } Object value = toolkit.getDesktopProperty(getKey()); pcl = new WeakPCL(this, toolkit, getKey(), UIManager.getLookAndFeel()); toolkit.addPropertyChangeListener(getKey(), pcl); return value; }
/** * Returns an point which has been adjusted to take into account of the desktop bounds, taskbar * and multi-monitor configuration. * * <p>This adustment may be cancelled by invoking the application with * -Djavax.swing.adjustPopupLocationToFit=false */ Point adjustPopupLocationToFitScreen(int xPosition, int yPosition) { Point popupLocation = new Point(xPosition, yPosition); if (popupPostionFixDisabled == true || GraphicsEnvironment.isHeadless()) { return popupLocation; } // Get screen bounds Rectangle scrBounds; GraphicsConfiguration gc = getCurrentGraphicsConfiguration(popupLocation); Toolkit toolkit = Toolkit.getDefaultToolkit(); if (gc != null) { // If we have GraphicsConfiguration use it to get screen bounds scrBounds = gc.getBounds(); } else { // If we don't have GraphicsConfiguration use primary screen scrBounds = new Rectangle(toolkit.getScreenSize()); } // Calculate the screen size that popup should fit Dimension popupSize = JPopupMenu.this.getPreferredSize(); long popupRightX = (long) popupLocation.x + (long) popupSize.width; long popupBottomY = (long) popupLocation.y + (long) popupSize.height; int scrWidth = scrBounds.width; int scrHeight = scrBounds.height; if (!canPopupOverlapTaskBar()) { // Insets include the task bar. Take them into account. Insets scrInsets = toolkit.getScreenInsets(gc); scrBounds.x += scrInsets.left; scrBounds.y += scrInsets.top; scrWidth -= scrInsets.left + scrInsets.right; scrHeight -= scrInsets.top + scrInsets.bottom; } int scrRightX = scrBounds.x + scrWidth; int scrBottomY = scrBounds.y + scrHeight; // Ensure that popup menu fits the screen if (popupRightX > (long) scrRightX) { popupLocation.x = scrRightX - popupSize.width; if (popupLocation.x < scrBounds.x) { popupLocation.x = scrBounds.x; } } if (popupBottomY > (long) scrBottomY) { popupLocation.y = scrBottomY - popupSize.height; if (popupLocation.y < scrBounds.y) { popupLocation.y = scrBounds.y; } } return popupLocation; }
@Override public void done() { Toolkit.getDefaultToolkit().beep(); startButton.setEnabled(true); setCursor(null); EpubUtils.outputMessage(taskOutput, "Done"); }
/* * Executed in event dispatching thread */ @Override public void done() { try { String value = get(); myMessage.messageChanged(value); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (CancellationException e) { myMessage.messageChanged("Operation Cancelled"); } catch (Exception e) { e.printStackTrace(); } Toolkit.getDefaultToolkit().beep(); // startButton.setEnabled(true); // cancelButton.setEnabled(false); setCursor(null); // turn off the wait cursor StartButton.setEnabled(true); cancelButton.setEnabled(false); taskOutput.append("Done!\n"); }
/** * Invalides the current value so that the next invocation of <code>createValue</code> will ask * for the property again. */ public void invalidate() { if (pcl != null) { toolkit.removePropertyChangeListener(getKey(), pcl); toolkit = null; pcl = null; value = null; } }
@Override public boolean rejectFocusRequest(FocusEvent.Cause cause) { // Cross-app activation requests are not allowed. if (cause != FocusEvent.Cause.MOUSE_EVENT && !((LWCToolkit) Toolkit.getDefaultToolkit()).isApplicationActive()) { focusLogger.fine("the app is inactive, so the request is rejected"); return true; } return false; }
/** * *********************************************************** Callbacks from the AWTWindow and * AWTView objc classes. *********************************************************** */ private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite) { // Fix for 7150349: ingore "gained" notifications when the app is inactive. if (gained && !((LWCToolkit) Toolkit.getDefaultToolkit()).isApplicationActive()) { focusLogger.fine("the app is inactive, so the notification is ignored"); return; } LWWindowPeer oppositePeer = (opposite == null) ? null : opposite.getPeer(); responder.handleWindowFocusEvent(gained, oppositePeer); }
public MetalworksFrame() { super("Metalworks"); final int inset = 50; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2); buildContent(); buildMenus(); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { quit(); } }); UIManager.addPropertyChangeListener(new UISwitchListener((JComponent) getRootPane())); }
@Override // PlatformWindow public void toFront() { final long nsWindowPtr = getNSWindowPtr(); LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit(); Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); if (w != null && acc.getPeer(w) != null && ((LWWindowPeer) acc.getPeer(w)).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME && !lwcToolkit.isApplicationActive()) { lwcToolkit.activateApplicationIgnoringOtherApps(); } updateFocusabilityForAutoRequestFocus(false); nativePushNSWindowToFront(nsWindowPtr); updateFocusabilityForAutoRequestFocus(true); }
public static void makeMenuBar(JFrame frame, final AirspaceBuilderController controller) { JMenuBar menuBar = new JMenuBar(); final JCheckBoxMenuItem resizeNewShapesItem; final JCheckBoxMenuItem enableEditItem; JMenu menu = new JMenu("File"); { JMenuItem item = new JMenuItem("Open..."); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(OPEN); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Open URL..."); item.setActionCommand(OPEN_URL); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Save..."); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(SAVE); item.addActionListener(controller); menu.add(item); menu.addSeparator(); item = new JMenuItem("Load Demo Shapes"); item.setActionCommand(OPEN_DEMO_AIRSPACES); item.addActionListener(controller); menu.add(item); } menuBar.add(menu); menu = new JMenu("Shape"); { JMenu subMenu = new JMenu("New"); for (final AirspaceFactory factory : defaultAirspaceFactories) { JMenuItem item = new JMenuItem(factory.toString()); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.createNewEntry(factory); } }); subMenu.add(item); } menu.add(subMenu); resizeNewShapesItem = new JCheckBoxMenuItem("Fit new shapes to viewport"); resizeNewShapesItem.setActionCommand(SIZE_NEW_SHAPES_TO_VIEWPORT); resizeNewShapesItem.addActionListener(controller); resizeNewShapesItem.setState(controller.isResizeNewShapesToViewport()); menu.add(resizeNewShapesItem); enableEditItem = new JCheckBoxMenuItem("Enable shape editing"); enableEditItem.setActionCommand(ENABLE_EDIT); enableEditItem.addActionListener(controller); enableEditItem.setState(controller.isEnableEdit()); menu.add(enableEditItem); } menuBar.add(menu); menu = new JMenu("Selection"); { JMenuItem item = new JMenuItem("Deselect"); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(CLEAR_SELECTION); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Delete"); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); item.setActionCommand(REMOVE_SELECTED); item.addActionListener(controller); menu.add(item); } menuBar.add(menu); frame.setJMenuBar(menuBar); controller.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals((e.getPropertyName()))) { resizeNewShapesItem.setSelected(controller.isResizeNewShapesToViewport()); } else if (ENABLE_EDIT.equals(e.getPropertyName())) { enableEditItem.setSelected(controller.isEnableEdit()); } } }); }
void dispose() { kit.removePropertyChangeListener(key, this); }
public void actionPerformed(ActionEvent e) { if (isDirectorySelected()) { File dir = getDirectory(); if (dir != null) { try { // Strip trailing ".." dir = ShellFolder.getNormalizedFile(dir); } catch (IOException ex) { // Ok, use f as is } changeDirectory(dir); return; } } JFileChooser chooser = getFileChooser(); String filename = getFileName(); FileSystemView fs = chooser.getFileSystemView(); File dir = chooser.getCurrentDirectory(); if (filename != null) { // Remove whitespaces from end of filename int i = filename.length() - 1; while (i >= 0 && filename.charAt(i) <= ' ') { i--; } filename = filename.substring(0, i + 1); } if (filename == null || filename.length() == 0) { // no file selected, multiple selection off, therefore cancel the approve action resetGlobFilter(); return; } File selectedFile = null; File[] selectedFiles = null; // Unix: Resolve '~' to user's home directory if (File.separatorChar == '/') { if (filename.startsWith("~/")) { filename = System.getProperty("user.home") + filename.substring(1); } else if (filename.equals("~")) { filename = System.getProperty("user.home"); } } if (chooser.isMultiSelectionEnabled() && filename.length() > 1 && filename.charAt(0) == '"' && filename.charAt(filename.length() - 1) == '"') { List<File> fList = new ArrayList<File>(); String[] files = filename.substring(1, filename.length() - 1).split("\" \""); // Optimize searching files by names in "children" array Arrays.sort(files); File[] children = null; int childIndex = 0; for (String str : files) { File file = fs.createFileObject(str); if (!file.isAbsolute()) { if (children == null) { children = fs.getFiles(dir, false); Arrays.sort(children); } for (int k = 0; k < children.length; k++) { int l = (childIndex + k) % children.length; if (children[l].getName().equals(str)) { file = children[l]; childIndex = l + 1; break; } } } fList.add(file); } if (!fList.isEmpty()) { selectedFiles = fList.toArray(new File[fList.size()]); } resetGlobFilter(); } else { selectedFile = fs.createFileObject(filename); if (!selectedFile.isAbsolute()) { selectedFile = fs.getChild(dir, filename); } // check for wildcard pattern FileFilter currentFilter = chooser.getFileFilter(); if (!selectedFile.exists() && isGlobPattern(filename)) { changeDirectory(selectedFile.getParentFile()); if (globFilter == null) { globFilter = new GlobFilter(); } try { globFilter.setPattern(selectedFile.getName()); if (!(currentFilter instanceof GlobFilter)) { actualFileFilter = currentFilter; } chooser.setFileFilter(null); chooser.setFileFilter(globFilter); return; } catch (PatternSyntaxException pse) { // Not a valid glob pattern. Abandon filter. } } resetGlobFilter(); // Check for directory change action boolean isDir = (selectedFile != null && selectedFile.isDirectory()); boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile)); boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled(); boolean isFileSelEnabled = chooser.isFileSelectionEnabled(); boolean isCtrl = (e != null && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0); if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) { changeDirectory(selectedFile); return; } else if ((isDir || !isFileSelEnabled) && (!isDir || !isDirSelEnabled) && (!isDirSelEnabled || selectedFile.exists())) { selectedFile = null; } } if (selectedFiles != null || selectedFile != null) { if (selectedFiles != null || chooser.isMultiSelectionEnabled()) { if (selectedFiles == null) { selectedFiles = new File[] {selectedFile}; } chooser.setSelectedFiles(selectedFiles); // Do it again. This is a fix for bug 4949273 to force the // selected value in case the ListSelectionModel clears it // for non-existing file names. chooser.setSelectedFiles(selectedFiles); } else { chooser.setSelectedFile(selectedFile); } chooser.approveSelection(); } else { if (chooser.isMultiSelectionEnabled()) { chooser.setSelectedFiles(null); } else { chooser.setSelectedFile(null); } chooser.cancelSelection(); } }
// ------------------------------------------- public static void centerWindow(Window w) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = w.getSize(); w.setLocation( (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); }