Class ViewConfiguration<T extends BaseView>

java.lang.Object
edu.cnu.mdi.view.ViewConfiguration<T>
Type Parameters:
T - the concrete BaseView subtype produced by this configuration

public class ViewConfiguration<T extends BaseView> extends Object
Describes everything needed to register a BaseView with the ViewManager, including optional deferred (lazy) creation and virtual-desktop placement.

Eager vs. lazy creation

When lazily is false the view is created immediately when ViewManager.addConfiguration(ViewConfiguration) is called. When true a placeholder entry appears in the Views menu (rendered in italics to signal "not yet open") and the view is created only when the user selects that item.

Virtual-desktop placement

column, dh, dv, and constraint are forwarded to VirtualView.moveTo(BaseView, int, int, int, int) once the view has been realized and made visible.

Menu-item positioning is now managed entirely by ViewManager. ViewConfiguration no longer carries a menuIndex field; doing so coupled two unrelated concerns and was fragile when other items or separators were inserted between configuration registration and view realization.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    Target virtual desktop column for the initial placement.
    final int
    Placement constraint such as VirtualView.CENTER, VirtualView.UPPERLEFT, etc.
    final int
    Additional horizontal pixel offset applied after the constraint.
    final int
    Additional vertical pixel offset applied after the constraint.
    final boolean
    If true the view is created only when the user first requests it from the Views menu; otherwise it is created immediately.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ViewConfiguration(String menuTitle, ViewFactory<T> factory, boolean lazily, int column, int dh, int dv, int constraint)
    Full constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends BaseView>
    ViewConfiguration<T>
    eager(String menuTitle, ViewFactory<T> factory, int column, int dh, int dv, int constraint)
    Convenience factory for an eagerly-created view configuration.
    Returns the menu title associated with this configuration.
    Returns the view instance, creating it on first call if necessary.
    boolean
    Returns true if the view has already been created.
    static <T extends BaseView>
    ViewConfiguration<T>
    lazy(String menuTitle, ViewFactory<T> factory, int column, int dh, int dv, int constraint)
    Convenience factory for a lazily-created view configuration.
    boolean
    Returns true if this still-unrealized lazy configuration's eventual view was open -- present and visible, not merely present-but-hidden or iconified-closed -- the last time Desktop's layout was saved.

    Methods inherited from class java.lang.Object

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

    • lazily

      public final boolean lazily
      If true the view is created only when the user first requests it from the Views menu; otherwise it is created immediately.
    • column

      public final int column
      Target virtual desktop column for the initial placement.
    • dh

      public final int dh
      Additional horizontal pixel offset applied after the constraint.
    • dv

      public final int dv
      Additional vertical pixel offset applied after the constraint.
    • constraint

      public final int constraint
      Placement constraint such as VirtualView.CENTER, VirtualView.UPPERLEFT, etc.
  • Constructor Details

    • ViewConfiguration

      public ViewConfiguration(String menuTitle, ViewFactory<T> factory, boolean lazily, int column, int dh, int dv, int constraint)
      Full constructor.
      Parameters:
      menuTitle - label shown in the Views menu; must not be blank
      factory - factory that creates the view; must not be null
      lazily - true to defer creation until first use
      column - target virtual desktop column
      dh - additional horizontal pixel offset
      dv - additional vertical pixel offset
      constraint - placement constraint (e.g. VirtualView.CENTER)
      Throws:
      IllegalArgumentException - if menuTitle is blank or factory is null
  • Method Details

    • lazy

      public static <T extends BaseView> ViewConfiguration<T> lazy(String menuTitle, ViewFactory<T> factory, int column, int dh, int dv, int constraint)
      Convenience factory for a lazily-created view configuration. The view is not constructed until the user selects it from the Views menu.
      Type Parameters:
      T - the concrete view type
      Parameters:
      menuTitle - the menu label
      factory - the view factory
      column - target virtual column
      dh - additional horizontal pixel offset
      dv - additional vertical pixel offset
      constraint - placement constraint
      Returns:
      a new lazy ViewConfiguration
    • eager

      public static <T extends BaseView> ViewConfiguration<T> eager(String menuTitle, ViewFactory<T> factory, int column, int dh, int dv, int constraint)
      Convenience factory for an eagerly-created view configuration. The view is constructed immediately when the configuration is registered.
      Type Parameters:
      T - the concrete view type
      Parameters:
      menuTitle - the menu label
      factory - the view factory
      column - target virtual column
      dh - additional horizontal pixel offset
      dv - additional vertical pixel offset
      constraint - placement constraint
      Returns:
      a new eager ViewConfiguration
    • getMenuTitle

      public String getMenuTitle()
      Returns the menu title associated with this configuration.
      Returns:
      the menu title; never null
    • isRealized

      public boolean isRealized()
      Returns true if the view has already been created.
      Returns:
      true if realized
    • getView

      public T getView()
      Returns the view instance, creating it on first call if necessary.

      After creation, virtual-desktop placement and the BaseView.onFirstRealize() lifecycle hook are scheduled on the Swing EDT via invokeLater so that any pending setVisible(true) call (which BaseView itself queues) has already been processed before placement is attempted.

      Returns:
      the realized view; never null
      Throws:
      IllegalStateException - if the factory returns null
    • wasOpenInSavedLayout

      public boolean wasOpenInSavedLayout()
      Returns true if this still-unrealized lazy configuration's eventual view was open -- present and visible, not merely present-but-hidden or iconified-closed -- the last time Desktop's layout was saved.

      Answers without creating the view: the probed property-name prefix is derived from getMenuTitle() via BaseView.sanitizeForKey(java.lang.String), the exact same transform BaseView itself applies to a view's own title when deriving BaseView.getPropertyName() -- by this framework's own convention every registration uses the identical string for both the menu title and the eventual view's title, so this reliably predicts the property-name prefix the view would use once realized.

      Used by ViewManager.restorePreviouslyOpenLazyViews() to decide which lazy configurations to eagerly realize at startup. Always false once isRealized() -- there is nothing left to probe for.

      Returns:
      true if the saved layout marks this view as having been open (not just present) when it was saved