Class WindowBounds

java.lang.Object
slash.navigation.gui.WindowBounds

public class WindowBounds extends Object
Restores and persists the size and location of a Window through Preferences, and enforces a minimum size so a window can never be shrunk small enough to become un-findable. SimpleDialog (dialogs) uses this for the full restore/persist/min-clamp cycle; SingleFrameApplication (the main frame) keeps its own restore/persist logic and shares only the crop(java.lang.String, int, int, int) clamping helper with it. Keys are namespaced by keyPrefix (empty for the single main frame, "dialogName-" for dialogs).
Author:
Christian Pesch
  • Constructor Summary

    Constructors
    Constructor
    Description
    WindowBounds(Window window, Preferences preferences, String keyPrefix)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Point
    computeLocation(int savedX, int savedY, int width, int height, Rectangle bounds, Insets insets)
    Pure location computation: the stored x/y cropped so the window of the given size stays on the usable screen.
    static Dimension
    computeSize(int savedWidth, int savedHeight, Rectangle bounds, Insets insets)
    Pure size computation: the stored width/height cropped to the usable screen.
    static int
    crop(String name, int position, int minimum, int maximum)
    Clamps position into [minimum;maximum], leaving the "unset" sentinel -1 untouched so callers can distinguish "no stored value".
    void
    Installs listeners that persist size and location live as the user resizes/moves, matching the main frame's behaviour.
    void
     
    void
     
    void
    restore(Window locationRelativeTo)
    Restores size and location onto the window.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • crop

      public static int crop(String name, int position, int minimum, int maximum)
      Clamps position into [minimum;maximum], leaving the "unset" sentinel -1 untouched so callers can distinguish "no stored value".
    • computeSize

      public static Dimension computeSize(int savedWidth, int savedHeight, Rectangle bounds, Insets insets)
      Pure size computation: the stored width/height cropped to the usable screen. Returns null when there is no usable stored size (keep the packed size), preserving the historic width > 120 && height > 60 guard.
    • computeLocation

      public static Point computeLocation(int savedX, int savedY, int width, int height, Rectangle bounds, Insets insets)
      Pure location computation: the stored x/y cropped so the window of the given size stays on the usable screen. Returns null when unset.
    • restore

      public void restore(Window locationRelativeTo)
      Restores size and location onto the window. The caller must have packed the window first, so its current size is the packed preferred size — that becomes the minimum (every component stays visible), floored by the absolute minimum. A stored size is applied on top, clamped to the minimum; a stored location is applied, else the window is centered on locationRelativeTo.
    • installLivePersistence

      public void installLivePersistence()
      Installs listeners that persist size and location live as the user resizes/moves, matching the main frame's behaviour.
    • putLocation

      public void putLocation()
    • putSize

      public void putSize()