Interface ContainerFactory

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ContainerFactory
Factory interface for creating an IContainer with a given initial world coordinate system.

Purpose

This interface replaces the previous reflection-based convention that required container classes to expose a (Rectangle2D.Double) constructor discoverable only at runtime via Class.getDeclaredConstructor(java.lang.Class<?>...). Using a functional interface instead provides several concrete benefits:

  • Compile-time safety — mismatched signatures are caught by javac, not at first use.
  • IDE navigation — a constructor reference or lambda can be followed with "Go to definition"; a Class stored in a Properties map cannot.
  • Richer initialization — a lambda factory can call additional setup methods that a bare constructor cannot.

Usage

Register via ViewPropertiesBuilder.containerFactory(ContainerFactory):

   // Constructor reference — simplest case.
   ContainerFactory f = MyContainer::new;

   // Lambda — when extra initialization is needed after construction.
   ContainerFactory f = ws -> {
       MyContainer c = new MyContainer(ws);
       c.setGridEnabled(true);
       c.setSnapInterval(10);
       return c;
   };

   Properties props = new ViewPropertiesBuilder()
       .title("My View")
       .worldSystem(world)
       .containerFactory(f)
       .build();
 

Fallback behaviour

When no ContainerFactory is registered, the framework falls back to constructing a default BaseContainer. The legacy PropertyUtils.CONTAINERCLASS key is still honoured for backward compatibility, but new code should always prefer this interface.

Contract

Implementations must not return null. If construction fails the factory should throw a descriptive RuntimeException rather than returning null, so the caller can surface a meaningful error.

  • Method Summary

    Modifier and Type
    Method
    Description
    Create a new IContainer initialised to the given world coordinate rectangle.
  • Method Details

    • create

      IContainer create(Rectangle2D.Double worldSystem)
      Create a new IContainer initialised to the given world coordinate rectangle.
      Parameters:
      worldSystem - the initial world window; never null
      Returns:
      a fully constructed, non-null container
      Throws:
      RuntimeException - if the container cannot be created