Class ViewPropertiesBuilder

java.lang.Object
edu.cnu.mdi.view.ViewPropertiesBuilder

public class ViewPropertiesBuilder extends Object
Fluent builder for constructing the 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 Details

    • ViewPropertiesBuilder

      public ViewPropertiesBuilder()
      Create an empty builder.
  • Method Details

    • put

      public ViewPropertiesBuilder put(String key, Object value)
      Store an arbitrary property value.
      Parameters:
      key - the property key
      value - the property value
      Returns:
      this builder
    • title

      public ViewPropertiesBuilder title(String title)
      Set the view title.
      Parameters:
      title - the title
      Returns:
      this builder
    • visible

      public ViewPropertiesBuilder visible(boolean visible)
      Set the initial visibility of the view.
      Parameters:
      visible - true if initially visible
      Returns:
      this builder
    • fraction

      public ViewPropertiesBuilder fraction(double fraction)
      Set the fraction of the application height to use for the view.
      Parameters:
      fraction - the height fraction
      Returns:
      this builder
    • aspect

      public ViewPropertiesBuilder aspect(double aspect)
      Set the aspect ratio used with fractional sizing.
      Parameters:
      aspect - the aspect ratio
      Returns:
      this builder
    • toolbarBits

      public ViewPropertiesBuilder toolbarBits(long toolBits)
      Set the toolbar bit mask.
      Parameters:
      toolBits - the toolbar bits, typically assembled from ToolBits
      Returns:
      this builder
    • wheelZoom

      public ViewPropertiesBuilder wheelZoom(boolean enabled)
      Set whether mouse-wheel zoom is enabled.
      Parameters:
      enabled - true to enable mouse-wheel zoom
      Returns:
      this builder
    • background

      public ViewPropertiesBuilder background(Color color)
      Set the background color.
      Parameters:
      color - the background color
      Returns:
      this builder
    • worldSystem

      public ViewPropertiesBuilder worldSystem(Rectangle2D.Double worldSystem)
      Set the initial world system.
      Parameters:
      worldSystem - the world system rectangle
      Returns:
      this builder
    • useContainer

      public ViewPropertiesBuilder useContainer(boolean useContainer)
      Set whether to use a container for the view.
      Parameters:
      useContainer - true to use a container
      Returns:
      this builder
    • containerClass

      public ViewPropertiesBuilder containerClass(Class<?> containerClass)
      Set the explicit container class to instantiate.

      Deprecated in favour of containerFactory(edu.cnu.mdi.view.ContainerFactory). Providing a Class requires the framework to find a (Rectangle2D.Double) constructor via reflection, which means errors surface at runtime rather than at compile time. Prefer containerFactory(ContainerFactory) for all new code.

      Parameters:
      containerClass - the container class
      Returns:
      this builder
      See Also:
    • containerFactory

      public ViewPropertiesBuilder containerFactory(ContainerFactory factory)
      Set a ContainerFactory used to construct this view's IContainer.

      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 under PropertyUtils.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 Class stored in a Properties map.

      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; passing null removes any previously set factory and restores the default behaviour
      Returns:
      this builder
    • scrollable

      public ViewPropertiesBuilder scrollable(boolean scrollable)
      Set whether the view should be scrollable.
      Parameters:
      scrollable - true if scrollable
      Returns:
      this builder
    • left

      public ViewPropertiesBuilder left(int left)
      Set the left position.
      Parameters:
      left - the left pixel coordinate
      Returns:
      this builder
    • top

      public ViewPropertiesBuilder top(int top)
      Set the top position.
      Parameters:
      top - the top pixel coordinate
      Returns:
      this builder
    • width

      public ViewPropertiesBuilder width(int width)
      Set the initial width.
      Parameters:
      width - the width in pixels
      Returns:
      this builder
    • height

      public ViewPropertiesBuilder height(int height)
      Set the initial height.
      Parameters:
      height - the height in pixels
      Returns:
      this builder
    • splitWestComponent

      public ViewPropertiesBuilder splitWestComponent(JComponent component)
      Set a split-pane west component.
      Parameters:
      component - the west component
      Returns:
      this builder
    • boxZoomPolicy

      public ViewPropertiesBuilder boxZoomPolicy(ARubberband.Policy policy)
      Set the rubber-band box zoom policy.
      Parameters:
      policy - the rubber-band policy
      Returns:
      this builder
    • build

      public Properties build()
      Build a new Properties object 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

      public ViewOptions 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 existing build() method remains available for APIs that require a Properties object.

      Returns:
      immutable snapshot of the configured properties