Class DrawableAdapter
- All Implemented Interfaces:
IDrawable
- Direct Known Subclasses:
GridDrawer
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 Summary
ConstructorsConstructorDescriptionCreates a new adapter with no name.DrawableAdapter(String name) Creates a new adapter with the given name. -
Method Summary
Modifier and TypeMethodDescriptionvoiddraw(Graphics2D g, IContainer container) Render this drawable.getName()Returns the human-readable name for this drawable, ornullif none was set.booleanWhether this drawable is currently enabled.booleanWhether this drawable is currently visible.voidCalled before this drawable is removed from a list or registry.voidsetDirty(boolean dirty) Mark this drawable as "dirty".voidsetEnabled(boolean enabled) Set whether this drawable is enabled.voidSets the name for this drawable.voidsetVisible(boolean visible) Set whether this drawable should be visible.
-
Constructor Details
-
DrawableAdapter
public DrawableAdapter()Creates a new adapter with no name. -
DrawableAdapter
Creates a new adapter with the given name.- Parameters:
name- a human-readable identifier for this drawable
-
-
Method Details
-
draw
Render this drawable.The default implementation performs no drawing. Subclasses should override this method to render custom graphics.
- Specified by:
drawin interfaceIDrawable- 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:
prepareForRemovalin interfaceIDrawable
-
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.
-
getName
Returns the human-readable name for this drawable, ornullif none was set. -
setName
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 istrue. -
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:
setVisiblein interfaceIDrawable- 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. -
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:
setEnabledin interfaceIDrawable- Parameters:
enabled- the new enabled state.
-