Class ViewPropertiesBuilder
Properties used to initialize
a BaseView.
This is intended primarily for default view configurations, replacing the
older pattern of assembling raw Object... keyVals arrays.
The builder stores values directly into a Properties instance using
the same keys consumed by PropertyUtils and BaseView.
Because Properties ultimately extends Hashtable,
non-String values such as colors, classes, or components may be stored
directly when appropriate.
Only a commonly used subset of properties is given dedicated fluent methods
here. For less common properties, use put(String, Object).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaspect(double aspect) Set the aspect ratio used with fractional sizing.background(Color color) Set the background color.boxZoomPolicy(ARubberband.Policy policy) Set the rubber-band box zoom policy.build()Build a newPropertiesobject containing the configured values.Build an immutable, explicitly typed view configuration.containerClass(Class<?> containerClass) Set the explicit container class to instantiate.containerFactory(ContainerFactory factory) Set aContainerFactoryused to construct this view'sIContainer.fraction(double fraction) Set the fraction of the application height to use for the view.height(int height) Set the initial height.left(int left) Set the left position.Store an arbitrary property value.scrollable(boolean scrollable) Set whether the view should be scrollable.splitWestComponent(JComponent component) Set a split-pane west component.Set the view title.toolbarBits(long toolBits) Set the toolbar bit mask.top(int top) Set the top position.useContainer(boolean useContainer) Set whether to use a container for the view.visible(boolean visible) Set the initial visibility of the view.wheelZoom(boolean enabled) Set whether mouse-wheel zoom is enabled.width(int width) Set the initial width.worldSystem(Rectangle2D.Double worldSystem) Set the initial world system.
-
Constructor Details
-
ViewPropertiesBuilder
public ViewPropertiesBuilder()Create an empty builder.
-
-
Method Details
-
put
Store an arbitrary property value.- Parameters:
key- the property keyvalue- the property value- Returns:
- this builder
-
title
Set the view title.- Parameters:
title- the title- Returns:
- this builder
-
visible
Set the initial visibility of the view.- Parameters:
visible-trueif initially visible- Returns:
- this builder
-
fraction
Set the fraction of the application height to use for the view.- Parameters:
fraction- the height fraction- Returns:
- this builder
-
aspect
Set the aspect ratio used with fractional sizing.- Parameters:
aspect- the aspect ratio- Returns:
- this builder
-
toolbarBits
Set the toolbar bit mask.- Parameters:
toolBits- the toolbar bits, typically assembled fromToolBits- Returns:
- this builder
-
wheelZoom
Set whether mouse-wheel zoom is enabled.- Parameters:
enabled-trueto enable mouse-wheel zoom- Returns:
- this builder
-
background
Set the background color.- Parameters:
color- the background color- Returns:
- this builder
-
worldSystem
Set the initial world system.- Parameters:
worldSystem- the world system rectangle- Returns:
- this builder
-
useContainer
Set whether to use a container for the view.- Parameters:
useContainer-trueto use a container- Returns:
- this builder
-
containerClass
Set the explicit container class to instantiate.Deprecated in favour of
containerFactory(edu.cnu.mdi.view.ContainerFactory). Providing aClassrequires the framework to find a(Rectangle2D.Double)constructor via reflection, which means errors surface at runtime rather than at compile time. PrefercontainerFactory(ContainerFactory)for all new code.- Parameters:
containerClass- the container class- Returns:
- this builder
- See Also:
-
containerFactory
Set aContainerFactoryused to construct this view'sIContainer.When this property is present the framework calls
ContainerFactory.create(java.awt.geom.Rectangle2D.Double)instead of using the reflection-based path that previously looked for a(Rectangle2D.Double)constructor on the class stored underPropertyUtils.CONTAINERCLASS. Prefer this method for all new code because:- Constructor mismatches are caught at compile time, not at first use.
- The factory can perform additional initialization that a bare constructor cannot.
- An IDE can follow a method reference or lambda; it cannot follow a
Classstored in aPropertiesmap.
Example:
new ViewPropertiesBuilder() .title("My View") .worldSystem(world) .containerFactory(MyContainer::new) .build(); // Or with extra initialization: .containerFactory(ws -> { MyContainer c = new MyContainer(ws); c.setGridEnabled(true); return c; })- Parameters:
factory- the container factory; passingnullremoves any previously set factory and restores the default behaviour- Returns:
- this builder
-
scrollable
Set whether the view should be scrollable.- Parameters:
scrollable-trueif scrollable- Returns:
- this builder
-
left
Set the left position.- Parameters:
left- the left pixel coordinate- Returns:
- this builder
-
top
Set the top position.- Parameters:
top- the top pixel coordinate- Returns:
- this builder
-
width
Set the initial width.- Parameters:
width- the width in pixels- Returns:
- this builder
-
height
Set the initial height.- Parameters:
height- the height in pixels- Returns:
- this builder
-
splitWestComponent
Set a split-pane west component.- Parameters:
component- the west component- Returns:
- this builder
-
boxZoomPolicy
Set the rubber-band box zoom policy.- Parameters:
policy- the rubber-band policy- Returns:
- this builder
-
build
Build a newPropertiesobject containing the configured values.A defensive copy is returned so the builder may continue to be reused independently if desired.
- Returns:
- a new properties object
-
buildOptions
Build an immutable, explicitly typed view configuration.This is the preferred terminal operation for new view classes. Pass the result directly to
BaseView(ViewOptions). The existingbuild()method remains available for APIs that require aPropertiesobject.- Returns:
- immutable snapshot of the configured properties
-