public interface DrawingEditor
Usage of drawing editor in conjunction with the JHotDraw application framework:
Applications which provide a single document
interface (SDI) there is typically one drawing editor instance per
View. So that each view can have its own toolbars
and drawing palettes.Framework
The following interfaces define the contracts of a framework for structured
drawing editors:
Contract: Drawing, Figure, DrawingView,
DrawingEditor, Handle and
Tool.
Mediator
DrawingEditor acts as a mediator for coordinating drawing tools
and drawing views:
Mediator: DrawingEditor; Colleagues: DrawingView,
Tool.
Mediator
DrawingEditor acts as a mediator for coordinating keyboard input from
Tools and Swing action objects:
Mediator: DrawingEditor; Colleagues:
Tool, javax.swing.Action.
Model-View-Controller
The following classes implement together the Model-View-Controller design
pattern:
Model: Drawing; View: DrawingView; Controller:
DrawingEditor.
Observer
State changes of tools can be observed by other objects. Specifically
DrawingEditor observes area invalidations of tools and repaints
its active drawing view accordingly.
Subject: Tool;
Observer: ToolListener; Event:
ToolEvent; Concrete Observer: DrawingEditor.
Proxy
To remove the need for null-handling, AbstractTool makes use of
a proxy for DrawingEditor.
Subject: DrawingEditor; Proxy: DrawingEditorProxy;
Client: AbstractTool.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACTION_MAP_PROPERTY
The property name for the action map property.
|
static java.lang.String |
ACTIVE_VIEW_PROPERTY
The property name for the active view property.
|
static java.lang.String |
DEFAULT_ATTRIBUTE_PROPERTY_PREFIX
The prefix for default attribute property changes.
|
static java.lang.String |
INPUT_MAP_PROPERTY
The property name for the input map property.
|
static java.lang.String |
TOOL_PROPERTY
The property name for the active tool property.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(DrawingView view)
Adds a drawing view to the editor.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a
PropertyChangeListener. |
void |
applyDefaultAttributesTo(Figure f)
Applies the default attributes to the specified figure.
|
DrawingView |
findView(java.awt.Container c)
Finds a drawing view.
|
javax.swing.ActionMap |
getActionMap()
Gets the action map used by the tool of this drawing editor as a fall back
for performing actions.
|
DrawingView |
getActiveView()
Gets the editor's active drawing view.
|
<T> T |
getDefaultAttribute(AttributeKey<T> key)
Gets a default attribute from the editor.
|
java.util.Map<AttributeKey,java.lang.Object> |
getDefaultAttributes()
Returns an immutable Map with the default attributes of this editor.
|
java.util.Collection<DrawingView> |
getDrawingViews()
Gets all drawing views associated with this editor.
|
<T> T |
getHandleAttribute(AttributeKey<T> key)
Gets a handle attribute from the editor.
|
javax.swing.InputMap |
getInputMap()
Sets the input map used by the tool of this drawing editor as a fall back
for handling keyboard events.
|
Tool |
getTool()
Gets the current tool.
|
boolean |
isEnabled()
Gets the enabled state of the drawing editor.
|
void |
remove(DrawingView view)
Removes a drawing view from the editor.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a
PropertyChangeListener. |
void |
setActionMap(javax.swing.ActionMap newValue)
Sets the action map used by the tool of this drawing editor as a fall back
for performing actions.
|
void |
setActiveView(DrawingView newValue)
Sets the editor's active drawing view.
|
void |
setCursor(java.awt.Cursor c)
Sets the cursor on the view(s) of the drawing editor.
|
<T> void |
setDefaultAttribute(AttributeKey<T> key,
T value)
Sets a default attribute of the editor.
|
void |
setEnabled(boolean newValue)
Sets the enabled state of the drawing editor.
|
<T> void |
setHandleAttribute(AttributeKey<T> key,
T value)
Sets a handle attribute of the editor.
|
void |
setInputMap(javax.swing.InputMap newValue)
Sets the input map used by the tool of this drawing editor as a fall back
for handling keyboard events.
|
void |
setTool(Tool t)
Calls deactivate on the previously active tool of this drawing editor.
|
static final java.lang.String ACTIVE_VIEW_PROPERTY
static final java.lang.String TOOL_PROPERTY
static final java.lang.String INPUT_MAP_PROPERTY
static final java.lang.String ACTION_MAP_PROPERTY
static final java.lang.String DEFAULT_ATTRIBUTE_PROPERTY_PREFIX
void add(DrawingView view)
void remove(DrawingView view)
java.util.Collection<DrawingView> getDrawingViews()
DrawingView getActiveView()
void setActiveView(DrawingView newValue)
void setTool(Tool t)
This is a bound property.
Tool getTool()
This is a bound property.
void setCursor(java.awt.Cursor c)
DrawingView findView(java.awt.Container c)
<T> void setDefaultAttribute(AttributeKey<T> key, T value)
Fires a property change event with the name of the attribute key,
and the prefix "defaultAttribute.".
<T> T getDefaultAttribute(AttributeKey<T> key)
void applyDefaultAttributesTo(Figure f)
java.util.Map<AttributeKey,java.lang.Object> getDefaultAttributes()
<T> void setHandleAttribute(AttributeKey<T> key, T value)
key - AttributeKey.value - Attribute value.<T> T getHandleAttribute(AttributeKey<T> key)
key - AttributeKey.void setInputMap(javax.swing.InputMap newValue)
This is a bound property.
javax.swing.InputMap getInputMap()
Tools use the input map of the drawing editor to determine what
to do when a key was pressed that the tool can not handle.
This is a bound property.
void setActionMap(javax.swing.ActionMap newValue)
This is a bound property.
javax.swing.ActionMap getActionMap()
Tools use the action map of the drawing editor to determine what
to do when an action needs to be invoked from the InputMap of the
drawing editor.
This is a bound property.
void setEnabled(boolean newValue)
boolean isEnabled()
void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener.listener - void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener.listener -