Class ViewConfiguration<T extends BaseView>
- Type Parameters:
T- the concreteBaseViewsubtype produced by this configuration
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 ordering
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
FieldsModifier and TypeFieldDescriptionfinal intTarget virtual desktop column for the initial placement.final intPlacement constraint such asVirtualView.CENTER,VirtualView.UPPERLEFT, etc.final intAdditional horizontal pixel offset applied after the constraint.final intAdditional vertical pixel offset applied after the constraint.final booleanIftruethe view is created only when the user first requests it from the Views menu; otherwise it is created immediately. -
Constructor Summary
ConstructorsConstructorDescriptionViewConfiguration(String menuTitle, ViewFactory<T> factory, boolean lazily, int column, int dh, int dv, int constraint) Full constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.getView()Returns the view instance, creating it on first call if necessary.booleanReturnstrueif 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.booleanReturnstrueif this still-unrealized lazy configuration's eventual view was open -- present and visible, not merely present-but-hidden or iconified-closed -- the last timeDesktop's layout was saved.
-
Field Details
-
lazily
public final boolean lazilyIftruethe view is created only when the user first requests it from the Views menu; otherwise it is created immediately. -
column
public final int columnTarget virtual desktop column for the initial placement. -
dh
public final int dhAdditional horizontal pixel offset applied after the constraint. -
dv
public final int dvAdditional vertical pixel offset applied after the constraint. -
constraint
public final int constraintPlacement constraint such asVirtualView.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 blankfactory- factory that creates the view; must not benulllazily-trueto defer creation until first usecolumn- target virtual desktop columndh- additional horizontal pixel offsetdv- additional vertical pixel offsetconstraint- placement constraint (e.g.VirtualView.CENTER)- Throws:
IllegalArgumentException- ifmenuTitleis blank orfactoryisnull
-
-
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 labelfactory- the view factorycolumn- target virtual columndh- additional horizontal pixel offsetdv- additional vertical pixel offsetconstraint- 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 labelfactory- the view factorycolumn- target virtual columndh- additional horizontal pixel offsetdv- additional vertical pixel offsetconstraint- placement constraint- Returns:
- a new eager
ViewConfiguration
-
getMenuTitle
Returns the menu title associated with this configuration.- Returns:
- the menu title; never
null
-
isRealized
public boolean isRealized()Returnstrueif the view has already been created.- Returns:
trueif realized
-
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 viainvokeLaterso that any pendingsetVisible(true)call (whichBaseViewitself queues) has already been processed before placement is attempted.- Returns:
- the realized view; never
null - Throws:
IllegalStateException- if the factory returnsnull
-
wasOpenInSavedLayout
public boolean wasOpenInSavedLayout()Returnstrueif this still-unrealized lazy configuration's eventual view was open -- present and visible, not merely present-but-hidden or iconified-closed -- the last timeDesktop's layout was saved.Answers without creating the view: the probed property-name prefix is derived from
getMenuTitle()viaBaseView.sanitizeForKey(java.lang.String), the exact same transformBaseViewitself applies to a view's own title when derivingBaseView.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. AlwaysfalseonceisRealized()-- there is nothing left to probe for.- Returns:
trueif the saved layout marks this view as having been open (not just present) when it was saved
-