@Override public void windowClosing(WindowEvent e) { exit(e); } }
private void saveSession(Window window) { String filename = sessionFilename(window); if (filename != null) { try { getContext().getSessionStorage().save(window, filename); } catch (IOException e) { logger.log(Level.WARNING, "couldn't save sesssion", e); } } }
/** * Save session state for the component hierarchy rooted by * the mainFrame. SingleFrameApplication subclasses that override * shutdown need to remember call {@code super.shutdown()}. */ @Override protected void shutdown() { saveSession(getMainFrame()); for(Window window : getVisibleSecondaryWindows()) { saveSession(window); } }
/** * Save session state for the component hierarchy rooted by * the mainFrame. SingleFrameApplication subclasses that override * shutdown need to remember call {@code super.shutdown()}. */ @Override protected void shutdown() { if (isReady()) { for (Window window : getVisibleSecondaryWindows()) { saveSession(window); } } }
configureWindow((Window) root); JFrame mainFrame = getMainFrame(); if (c == mainFrame) { mainFrame.addWindowListener(new MainFrameListener()); String filename = sessionFilename((Window) root); if (filename != null) { try { getContext().getSessionStorage().restore(root, filename); } catch (Exception e) { String msg = String.format("couldn't restore session [%s]", filename);
ShapePopup () { super("ShapePopup"); ApplicationActionMap actionMap = OmrGui.getApplication().getContext().getActionMap( SampleBrowser.this); add(new JMenuItem(actionMap.get("removeShapes"))); } }
throw new IllegalArgumentException("null JComponent"); JFrame f = getMainFrame(); f.getContentPane().add(c, BorderLayout.CENTER); initRootPaneContainer(f); f.setVisible(true);
@Override protected void end() { JFrame mainFrame = getMainFrame(); if (mainFrame != null || mainFrame.isDisplayable()) { mainFrame.setVisible(false); mainFrame.dispose(); } super.end(); } }
/** * Initialize and show the secondary JFrame. * <p> * This method is intended for showing "secondary" windows, like * message dialogs, about boxes, and so on. Unlike the {@code mainFrame}, * dismissing a secondary window will not exit the application. * <p> * Session state is only automatically saved if the specified * JFrame has a name, and then only for component descendants * that are named. * <p> * Throws an IllegalArgumentException if {@code c} is null * * @see #show(JComponent) * @see #show(JDialog) * @see #configureWindow */ public void show(JFrame c) { if (c == null) { throw new IllegalArgumentException("null JFrame"); } initRootPaneContainer(c); c.setVisible(true); }
/** * Sets the JFrame use to show this application. * <p> * This method should be called from the startup method by a * subclass that wants to construct and initialize the main frame * itself. Most applications can rely on the fact that {code * getMainFrame} lazily constructs the main frame and initializes * the {@code mainFrame} property. * <p> * If the main frame property was already initialized, either * implicitly through a call to {@code getMainFrame} or by * explicitly calling this method, an IllegalStateException is * thrown. If {@code mainFrame} is null, an IllegalArgumentException * is thrown. * <p> * This property is bound. * * @param mainFrame the new value of the mainFrame property * @see #getMainFrame */ protected final void setMainFrame(JFrame mainFrame) { getMainView().setFrame(mainFrame); }
/** * Return all of the visible JWindows, JDialogs, and JFrames per * Window.getWindows() on Java SE 6 */ private List<Window> getVisibleSecondaryWindows() { List<Window> rv = new ArrayList<Window>(); for (Window window : Window.getWindows()) { if (isVisibleWindow(window)) { rv.add(window); } } return rv; }
configureWindow((Window)root); JFrame mainFrame = getMainFrame(); if (c == mainFrame) { mainFrame.addWindowListener(new MainFrameListener()); String filename = sessionFilename((Window)root); if (filename != null) { try { getContext().getSessionStorage().restore(root, filename);
/** * Initialize the hierarchy with the specified root by * injecting resources. * <p> * By default the {@code show} methods * {@link ResourceMap#injectComponents inject resources} before * initializing the JFrame or JDialog's size, location, * and restoring the window's session state. If the app * is showing a window whose resources have already been injected, * or that shouldn't be initialized via resource injection, * this method can be overridden to defeat the default * behavior. * * @param root the root of the component hierarchy * @see ResourceMap#injectComponents * @see #show(JComponent) * @see #show(JFrame) * @see #show(JDialog) */ protected void configureWindow(Window root) { getContext().getResourceMap().injectComponents(root); }
throw new IllegalArgumentException("null JComponent"); JFrame f = getMainFrame(); f.getContentPane().add(c, BorderLayout.CENTER); initRootPaneContainer(f); f.setVisible(true);
/** * Launch the provided runnable with a busy cursor displayed if processing does not * complete within delay. * * @param runnable the processing to perform */ public static void launchWithDelayedCursor (Runnable runnable) { final JFrame frame = OmrGui.getApplication().getMainFrame(); final TimerTask timerTask = new TimerTask() { @Override public void run () { frame.setCursor(busyCursor); } }; Timer timer = new Timer(); try { timer.schedule(timerTask, delay); runnable.run(); // Here is the real stuff } finally { timer.cancel(); frame.setCursor(defaultCursor); } }
/** * Initialize and show the secondary JFrame. * <p> * This method is intended for showing "secondary" windows, like * message dialogs, about boxes, and so on. Unlike the {@code mainFrame}, * dismissing a secondary window will not exit the application. * <p> * Session state is only automatically saved if the specified * JFrame has a name, and then only for component descendants * that are named. * <p> * Throws an IllegalArgumentException if {@code c} is null * * @param c * @see #show(JComponent) * @see #show(JDialog) * @see #configureWindow */ public void show(JFrame c) { if (c == null) { throw new IllegalArgumentException("null JFrame"); } initRootPaneContainer(c); c.setVisible(true); }
/** * Sets the JFrame use to show this application. * <p> * This method should be called from the startup method by a * subclass that wants to construct and initialize the main frame * itself. Most applications can rely on the fact that {code * getMainFrame} lazily constructs the main frame and initializes * the {@code mainFrame} property. * <p> * If the main frame property was already initialized, either * implicitly through a call to {@code getMainFrame} or by * explicitly calling this method, an IllegalStateException is * thrown. If {@code mainFrame} is null, an IllegalArgumentException * is thrown. * <p> * This property is bound. * * @param mainFrame the new value of the mainFrame property * @see #getMainFrame */ protected final void setMainFrame(JFrame mainFrame) { getMainView().setFrame(mainFrame); }
if (isVisibleWindow(window)) { rv.add(window); if (frames != null) { for(Frame frame : frames) { if (isVisibleWindow(frame)) { rv.add(frame);
/** * Initialize the hierarchy with the specified root by * injecting resources. * <p> * By default the {@code show} methods * {@link ResourceMap#injectComponents inject resources} before * initializing the JFrame or JDialog's size, location, * and restoring the window's session state. If the application * is showing a window whose resources have already been injected, * or that shouldn't be initialized via resource injection, * this method can be overridden to defeat the default * behavior. * * @param root the root of the component hierarchy * @see ResourceMap#injectComponents * @see #show(JComponent) * @see #show(JFrame) * @see #show(JDialog) */ protected void configureWindow(Window root) { getContext().getResourceMap().injectComponents(root); }
private void saveSession(Window window) { String filename = sessionFilename(window); if (filename != null) { try { getContext().getSessionStorage().save(window, filename); } catch (IOException e) { logger.log(Level.WARNING, "couldn't save session", e); } } }