Class DrawableAdapter

java.lang.Object
edu.cnu.mdi.graphics.drawable.DrawableAdapter
All Implemented Interfaces:
IDrawable
Direct Known Subclasses:
GridDrawer

public class DrawableAdapter extends Object implements IDrawable
A convenience base class that provides no-op (empty) implementations of all IDrawable methods. Subclasses may override only the behaviors they need, which makes this class useful when implementing the Adapter pattern.

The adapter also maintains standard properties such as visibility and enabled status, and an optional name field for identification in debugging or UI contexts.

Typical usage:

 class GridOverlay extends DrawableAdapter {
     @Override
     public void draw(Graphics2D g, IContainer container) {
         // custom drawing code here
     }
 }
 
Author:
heddle
  • Constructor Details

    • DrawableAdapter

      public DrawableAdapter()
      Creates a new adapter with no name.
    • DrawableAdapter

      public DrawableAdapter(String name)
      Creates a new adapter with the given name.
      Parameters:
      name - a human-readable identifier for this drawable
  • Method Details

    • draw

      public void draw(Graphics2D g, IContainer container)
      Render this drawable.

      The default implementation performs no drawing. Subclasses should override this method to render custom graphics.

      Specified by:
      draw in interface IDrawable
      Parameters:
      g - the 2D graphics context to draw with. The caller is responsible for restoring any graphics state (transform, clip, composite, etc.) if needed.
      container - the container being rendered into; may be used to query coordinate transforms, world bounds, etc.
    • prepareForRemoval

      public void prepareForRemoval()
      Called before this drawable is removed from a list or registry.

      Implementations can use this to release resources or unregister listeners. The default implementation does nothing.

      The default implementation does nothing, but subclasses may override to release resources or unregister listeners.

      Specified by:
      prepareForRemoval in interface IDrawable
    • setDirty

      public void setDirty(boolean dirty)
      Mark this drawable as "dirty".

      Implementations can use this to clear cached pixel-based data (e.g., precomputed polygons) so they will be recomputed on the next draw. The default implementation does nothing.

      The base adapter has no internal cache, but subclasses that cache computed shapes or pixel data may override this hook.

      Specified by:
      setDirty in interface IDrawable
      Parameters:
      dirty - whether cached data should be invalidated
    • getName

      public String getName()
      Returns the human-readable name for this drawable, or null if none was set.
      Specified by:
      getName in interface IDrawable
      Returns:
      the drawable name, or null
    • setName

      public void setName(String name)
      Sets the name for this drawable.
      Parameters:
      name - the new name, may be null
    • isVisible

      public boolean isVisible()
      Whether this drawable is currently visible.

      Callers should respect this flag and skip drawing when it returns false. Default is true.

      Specified by:
      isVisible in interface IDrawable
      Returns:
      true if the object should be rendered; false otherwise.
    • setVisible

      public void setVisible(boolean visible)
      Set whether this drawable should be visible.

      The default implementation ignores the flag. Implementations that track visibility should override this together with IDrawable.isVisible().

      Specified by:
      setVisible in interface IDrawable
      Parameters:
      visible - the new visibility state.
    • isEnabled

      public boolean isEnabled()
      Whether this drawable is currently enabled.

      "Enabled" can be used by callers to decide, for example, whether to process interaction or feedback for this drawable. Default is true.

      Specified by:
      isEnabled in interface IDrawable
      Returns:
      true if the object is enabled; false otherwise.
    • setEnabled

      public void setEnabled(boolean enabled)
      Set whether this drawable is enabled.

      The default implementation ignores the flag. Implementations that track enabled state should override this together with IDrawable.isEnabled().

      Specified by:
      setEnabled in interface IDrawable
      Parameters:
      enabled - the new enabled state.