Java Code Examples for java.awt.Frame#getFrames()

The following examples show how to use java.awt.Frame#getFrames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: _AppMenuBarHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", Float.valueOf(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
Example 2
Source File: _AppMenuBarHandler.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", new Float(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
Example 3
Source File: ApplicationApplet.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
private void disposeOwnedFrames() {
  Frame frame[] = Frame.getFrames();
  for(int i = 0, n = frame.length; i<n; i++) {
    if(frame[i].getClass().getName().startsWith("sun.plugin")) { //$NON-NLS-1$
      continue;                                                  // don't mess with plugin
    }
    if((frame[i] instanceof JFrame)&&((JFrame) frame[i]).getDefaultCloseOperation()==JFrame.EXIT_ON_CLOSE) {
      ((JFrame) frame[i]).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
    if(!existingFrames.contains(frame[i])) {
      frame[i].setVisible(false);
      frame[i].dispose();
    }
  }
  newFrames.clear();
}
 
Example 4
Source File: WindowUtils.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** @return A {@link Frame} to use when a valid frame of any sort is all that is needed. */
public static Frame getAnyFrame() {
    Frame frame = BaseWindow.getTopWindow();

    if (frame == null) {
        Frame[] frames = Frame.getFrames();

        for (Frame element : frames) {
            if (element.isDisplayable()) {
                return element;
            }
        }
        return getHiddenFrame(true);
    }
    return frame;
}
 
Example 5
Source File: GUIUtils.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows all drawing and table frames.
 *
 * Usually invoked when a model is initialized but may be invoked at other times
 * to show frames that have been closed.
 */
public static void showDrawingAndTableFrames() {
  Frame[] frames = Frame.getFrames();
  for(int i = 0; i<frames.length; i++) {
    if(!frames[i].isDisplayable()) {
      continue;
    }
    if((frames[i].getName()!=null)&&(frames[i].getName().indexOf("Tool")>-1)) { //$NON-NLS-1$
      continue;
    }
    if(OSPFrame.class.isInstance(frames[i])) {
      if(DataTableFrame.class.isInstance(frames[i])) {
        ((DataTableFrame) frames[i]).refreshTable();
      }
      frames[i].setVisible(true);
      ((OSPFrame) frames[i]).invalidateImage();                                 // make sure buffers are up to date
      frames[i].repaint();                                                      // repaint if frame is already showing
      frames[i].toFront();
    }
  }
  if((OSPRuntime.applet!=null)) {
    OSPRuntime.applet.getRootPane().repaint();
  }
}
 
Example 6
Source File: GUIUtils.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Enables and disables the menu bars in DrawingFrames and DrawingFrame3D.
 *
 * Usually invoked when a model is initialized but may be invoked at other times.
 */
public static void enableMenubars(boolean enable) {
  Frame[] frames = Frame.getFrames();
  for(int i = 0; i<frames.length; i++) {
    if(!frames[i].isDisplayable()) {
      continue;
    }
    if((frames[i].getName()!=null)&&(frames[i].getName().indexOf("Tool")>-1)) {       //$NON-NLS-1$
      continue;
    }
    Class<?> frame3d = null;
    try {
      frame3d = Class.forName("org.opensourcephysics.display3d.core.DrawingFrame3D"); //$NON-NLS-1$
    } catch(ClassNotFoundException ex) {}
    if(DrawingFrame.class.isInstance(frames[i])||((frame3d!=null)&&frame3d.isInstance(frames[i]))) {
      JMenuBar bar = ((JFrame) frames[i]).getJMenuBar();
      if(bar!=null) {
        for(int j = 0, n = bar.getMenuCount(); j<n; j++) {
          bar.getMenu(j).setEnabled(enable);
        }
      }
    }
  }
}
 
Example 7
Source File: _AppMenuBarHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", new Float(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
Example 8
Source File: SwingUtils.java    From swift-explorer with Apache License 2.0 6 votes vote down vote up
public static Frame tryFindSuitableFrameOwner ()
{
	Frame owner = null;
	// find a suitable owner, if any
	Frame[] allFrames = Frame.getFrames();
	if (allFrames != null) {
		for (Frame frame : allFrames) {
			if (frame == null)
				continue;
			if (!frame.isShowing())
				continue;
			if (!frame.isActive())
				continue;
			owner = frame;
			break;
		}
	}
	return owner ;
}
 
Example 9
Source File: _AppMenuBarHandler.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", new Float(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
Example 10
Source File: TimableEventQueue.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean isWaitCursor() {
    Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focus != null) {
        if (focus.getCursor().getType() == Cursor.WAIT_CURSOR) {
            LOG.finer("wait cursor on focus owner"); // NOI18N
            return true;
        }
        Window w = SwingUtilities.windowForComponent(focus);
        if (w != null && isWaitCursorOnWindow(w)) {
            LOG.finer("wait cursor on window"); // NOI18N
            return true;
        }
    }
    for (Frame f : Frame.getFrames()) {
        if (isWaitCursorOnWindow(f)) {
            LOG.finer("wait cursor on frame"); // NOI18N
            return true;
        }
    }
    LOG.finest("no wait cursor"); // NOI18N
    return false;
}
 
Example 11
Source File: WindowsMenu.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void menuSelected(MenuEvent event) {

    // Remove all previous items
    while (getItemCount() > 2)
      remove(2);

    int windowsAdded = 0;
    // Create a menu item for each window
    for (Frame window : Frame.getFrames()) {

      if (window.isVisible()) {
        FrameMenuItem newItem = new FrameMenuItem(window, this);
        add(newItem);
        windowsAdded++;
      }
    }

    // Disable the Close all button if we only have the main window
    closeAllMenuItem.setEnabled(windowsAdded > 1);
  }
 
Example 12
Source File: _AppMenuBarHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", new Float(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
Example 13
Source File: _AppMenuBarHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", new Float(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
Example 14
Source File: DesktopProperty.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the UIs of all the known Frames.
 */
protected void updateAllUIs() {
    Frame[] appFrames = Frame.getFrames();
    for (Frame appFrame : appFrames) {
        updateWindowUI(appFrame);
    }
}
 
Example 15
Source File: GUIUtils.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Repaints all OSPFrames.
 */
public static void repaintOSPFrames() {
  Frame[] frames = Frame.getFrames();
  for(int i = 0; i<frames.length; i++) {
    if(!frames[i].isVisible()||!frames[i].isDisplayable()||!OSPFrame.class.isInstance(frames[i])) {
      continue;
    }
    ((OSPFrame) frames[i]).repaint();
  }
}
 
Example 16
Source File: FrameApplet.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
private void disposeOwnedFrames() {
  Frame frame[] = Frame.getFrames();
  for(int i = 0, n = frame.length; i<n; i++) {
    if((frame[i] instanceof JFrame)&&((JFrame) frame[i]).getDefaultCloseOperation()==JFrame.EXIT_ON_CLOSE) {
      ((JFrame) frame[i]).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
    if(!existingFrames.contains(frame[i])) { // remove any frames that have been created by this applet
      frame[i].setVisible(false);
      removeWindowListeners(frame[i]);
      frame[i].dispose();
    }
  }
}
 
Example 17
Source File: Utils.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Frame getActiveFrame() {
	Frame result = null;
	Frame[] frames = Frame.getFrames();
	for (int i = 0; i < frames.length; i++) {
		Frame frame = frames[i];
		if (frame.isVisible()) {
			result = frame;
			break;
		}
	}
	return result;
}
 
Example 18
Source File: KeystoreOptionsSubPanel.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private Component findDialogParent() {
    Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (parent == null) {
        parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    }
    if (parent == null) {
        Frame[] f = Frame.getFrames();
        parent = f.length == 0 ? null : f[f.length - 1];
    }
    return parent;
}
 
Example 19
Source File: QuitCommand.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private static boolean closeFrames(boolean significant) {
    for (Frame frame : Frame.getFrames()) {
        if (frame instanceof SignificantFrame == significant && frame.isShowing()) {
            try {
                if (!CloseCommand.close(frame)) {
                    return false;
                }
            } catch (Exception exception) {
                Log.error(exception);
            }
        }
    }
    return true;
}
 
Example 20
Source File: GUIUtils.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Disposes all OSP frames except the given frame.
 *
 * Usually invoked when the control window is being closed.
 *
 * @param frame will not be disposed
 */
public static void closeAndDisposeOSPFrames(Frame frame) {
  Frame[] frames = Frame.getFrames();
  for(int i = 0; i<frames.length; i++) {
    if(frames[i]==frame) {
      continue;
    }
    // if (frames[i] instanceof org.opensourcephysics.controls.Launcher.LauncherFrame)continue;
    if(OSPFrame.class.isInstance(frames[i])) {
      ((OSPFrame) frames[i]).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      ((OSPFrame) frames[i]).setVisible(false);
      ((OSPFrame) frames[i]).dispose();
    }
  }
}