JHotDraw 7.4.1

org.jhotdraw.draw
Interface DrawingEditor

All Known Implementing Classes:
DefaultDrawingEditor, DrawingEditorProxy

public interface DrawingEditor

A drawing editor coordinates drawing tools and drawing views.

Usage of drawing editor in conjunction with the JHotDraw application framework:


Design Patterns

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.


Version:
$Id: DrawingEditor.java 604 2010-01-09 12:00:29Z rawcoder $
Author:
Werner Randelshofer

Field Summary
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 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.
 
Method Summary
 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.
 

Field Detail

ACTIVE_VIEW_PROPERTY

static final java.lang.String ACTIVE_VIEW_PROPERTY
The property name for the active view property.

See Also:
Constant Field Values

TOOL_PROPERTY

static final java.lang.String TOOL_PROPERTY
The property name for the active tool property.

See Also:
Constant Field Values

INPUT_MAP_PROPERTY

static final java.lang.String INPUT_MAP_PROPERTY
The property name for the input map property.

See Also:
Constant Field Values

ACTION_MAP_PROPERTY

static final java.lang.String ACTION_MAP_PROPERTY
The property name for the action map property.

See Also:
Constant Field Values
Method Detail

add

void add(DrawingView view)
Adds a drawing view to the editor. The editor invokes addNotify on the view, and it registers its tool as an event listener on the view.


remove

void remove(DrawingView view)
Removes a drawing view from the editor. The editor invokes removeNotify on the view, and it unregisters its tool on the view.


getDrawingViews

java.util.Collection<DrawingView> getDrawingViews()
Gets all drawing views associated with this editor.


getActiveView

DrawingView getActiveView()
Gets the editor's active drawing view. This can be null, if the editor has no views.


setActiveView

void setActiveView(DrawingView newValue)
Sets the editor's active drawing view. This can be set to null, if the editor has no views.


setTool

void setTool(Tool t)
Calls deactivate on the previously active tool of this drawing editor. Calls activate on the provided tool. Forwards all mouse, mouse moation and keyboard events that occur on the DrawingView to the provided tool.

This is a bound property.


getTool

Tool getTool()
Gets the current tool.

This is a bound property.


setCursor

void setCursor(java.awt.Cursor c)
Sets the cursor on the view(s) of the drawing editor.


findView

DrawingView findView(java.awt.Container c)
Finds a drawing view. This is used by Tool to identify the view of which it has received an event.


setDefaultAttribute

<T> void setDefaultAttribute(AttributeKey<T> key,
                             T value)
Sets a default attribute of the editor. The default attribute will be used by creation tools, to create a new figure.


getDefaultAttribute

<T> T getDefaultAttribute(AttributeKey<T> key)
Gets a default attribute from the editor. The default attribute will be used by creation tools, to create a new figure.


applyDefaultAttributesTo

void applyDefaultAttributesTo(Figure f)
Applies the default attributes to the specified figure.


getDefaultAttributes

java.util.Map<AttributeKey,java.lang.Object> getDefaultAttributes()
Returns an immutable Map with the default attributes of this editor.


setHandleAttribute

<T> void setHandleAttribute(AttributeKey<T> key,
                            T value)
Sets a handle attribute of the editor. The default attribute will be used by creation tools, to create a new figure.

Parameters:
key - AttributeKey.
value - Attribute value.

getHandleAttribute

<T> T getHandleAttribute(AttributeKey<T> key)
Gets a handle attribute from the editor. The default attribute will be used by creation tools, to create a new figure.

Parameters:
key - AttributeKey.
Returns:
If the handle attribute has been set, returns the previously set value. If the handle attribute has not been set, returns key.getDefaultValue().

setInputMap

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.

This is a bound property.


getInputMap

javax.swing.InputMap getInputMap()
Sets the input map used by the tool of this drawing editor as a fall back for handling keyboard events.

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.


setActionMap

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.

This is a bound property.


getActionMap

javax.swing.ActionMap getActionMap()
Gets the action map used by the tool of this drawing editor as a fall back for performing actions.

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.


setEnabled

void setEnabled(boolean newValue)
Sets the enabled state of the drawing editor. This is a bound property.


isEnabled

boolean isEnabled()
Gets the enabled state of the drawing editor.


addPropertyChangeListener

void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener.

Parameters:
listener -

removePropertyChangeListener

void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener.

Parameters:
listener -

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.