Ejemplo n.º 1
0
  /**
   * Tries to load/restore the window state of the given window.
   *
   * @param aNamespace the namespace to use for the window state;
   * @param aProperties the properties to read from;
   * @param aWindow the window to load the state for.
   */
  public static void loadWindowState(final Preferences aProperties, final Window aWindow) {
    // Special case: for FileDialog/JFileChooser we also should restore the
    // properties...
    loadFileDialogState(aProperties, aWindow);

    try {
      final int xPos = aProperties.getInt("winXpos", -1);
      final int yPos = aProperties.getInt("winYpos", -1);
      if ((xPos >= 0) && (yPos >= 0)) {
        aWindow.setLocation(xPos, yPos);
      }
    } catch (NumberFormatException exception) {
      // Ignore...
    }

    if (isNonResizableWindow(aWindow)) {
      // In case the window cannot be resized, don't restore its width &
      // height...
      return;
    }

    try {
      final int width = aProperties.getInt("winWidth", -1);
      final int height = aProperties.getInt("winHeight", -1);
      if ((width >= 0) && (height >= 0)) {
        aWindow.setSize(width, height);
      }
    } catch (NumberFormatException exception) {
      // Ignore...
    }
  }
Ejemplo n.º 2
0
  /**
   * Returns whether the given component is "actively" shown in screen, that is, it or any of its
   * ancestors is focused.
   *
   * @param aComponent the component to determine whether it is actively shown on screen, may be
   *     <code>null</code>.
   * @return <code>true</code> if the given component is actively shown, <code>false</code>
   *     otherwise.
   */
  public static final boolean isActivelyShown(final Component aComponent) {
    final KeyboardFocusManager kbdFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    final Window owner = kbdFocusManager.getFocusedWindow();

    return ((aComponent != null)
        && (owner != null)
        && ((owner == aComponent) || owner.isAncestorOf(aComponent)));
  }
Ejemplo n.º 3
0
  /**
   * Saves the window state to the given properties map.
   *
   * @param aNamespace the namespace to use for the window state;
   * @param aProperties the properties to fill;
   * @param aWindow the window to save the state for.
   */
  public static void saveWindowState(final Preferences aProperties, final Window aWindow) {
    // Special case: for FileDialog/JFileChooser we also store the properties...
    saveFileDialogState(aProperties, aWindow);

    final Point location = aWindow.getLocation();
    aProperties.put("winXpos", Integer.toString(location.x));
    aProperties.put("winYpos", Integer.toString(location.y));

    if (isNonResizableWindow(aWindow)) {
      // In case the window cannot be resized, don't restore its width &
      // height...
      return;
    }

    final Dimension dims = aWindow.getSize();
    aProperties.put("winWidth", Integer.toString(dims.width));
    aProperties.put("winHeight", Integer.toString(dims.height));
  }