JHotDraw 6.0b1

org.jhotdraw.framework
Interface DrawingView

All Superinterfaces:
DrawingChangeListener, java.awt.image.ImageObserver
All Known Implementing Classes:
NullDrawingView, StandardDrawingView, ZoomDrawingView

public interface DrawingView
extends java.awt.image.ImageObserver, DrawingChangeListener

DrawingView renders a Drawing and listens to its changes. It receives user input and delegates it to the current tool.


Design Patterns

 o Observer
DrawingView observes drawing for changes via the DrawingListener interface.
 o State
DrawingView plays the role of the StateContext in the State pattern. Tool is the State.
 o Strategy
DrawingView is the StrategyContext in the Strategy pattern with regard to the UpdateStrategy.
DrawingView is the StrategyContext for the PointConstrainer.

See Also:
Drawing, Painter, Tool

Field Summary
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 Figure add(Figure figure)
          Adds a figure to the drawing.
 void addAll(java.util.Collection figures)
          Adds a collections of figures to the drawing.
 void addFigureSelectionListener(FigureSelectionListener fsl)
          Add a listener for selection changes in this DrawingView.
 void addToSelection(Figure figure)
          Adds a figure to the current selection.
 void addToSelectionAll(java.util.Collection figures)
          Adds a collections of figures to the current selection.
 void addToSelectionAll(FigureEnumeration fe)
          Adds a FigureEnumeration to the current selection.
 void checkDamage()
          Checks whether the drawing has some accumulated damage
 void clearSelection()
          Clears the current selection.
 java.awt.Image createImage(int width, int height)
          Creates an image with the given dimensions
 void draw(java.awt.Graphics g, FigureEnumeration fe)
          Draws the given figures.
 void drawAll(java.awt.Graphics g)
          Draws the contents of the drawing view.
 void drawBackground(java.awt.Graphics g)
          Draws the background.
 void drawDrawing(java.awt.Graphics g)
          Draws the drawing.
 void drawHandles(java.awt.Graphics g)
          Draws the currently active handles.
 Drawing drawing()
          Gets the drawing.
 DrawingEditor editor()
          Gets the editor.
 Handle findHandle(int x, int y)
          Finds a handle at the given coordinates.
 void freezeView()
          Freezes the view by acquiring the drawing lock.
 java.awt.Color getBackground()
          Gets the background color of the DrawingView
 FigureEnumeration getConnectionFigures(Figure inFigure)
          Returns a FigureEnumeration of connection figures
 PointConstrainer getConstrainer()
          Gets the current grid setting.
 Painter getDisplayUpdate()
          Gets the current display update strategy.
 FigureSelection getFigureSelection()
          Gets the current selection as a FigureSelection.
 java.awt.Graphics getGraphics()
          Gets a graphic to draw into
 java.awt.Dimension getMinimumSize()
          Gets the minimum dimension of the drawing.
 java.awt.Dimension getPreferredSize()
          Gets the preferred dimension of the drawing..
 java.awt.Dimension getSize()
          Gets the size of the drawing.
 FigureEnumeration insertFigures(FigureEnumeration inFigures, int dx, int dy, boolean bCheck)
          Inserts figures in a drawing at given offset.
 boolean isFigureSelected(Figure checkFigure)
          Test whether a given figure is selected.
 boolean isInteractive()
          Check whether the DrawingView is interactive, i.e.
 java.awt.Point lastClick()
          Gets the position of the last click inside the view.
 void paint(java.awt.Graphics g)
          Paints the drawing view.
 Figure remove(Figure figure)
          Removes a figure from the drawing.
 void removeFigureSelectionListener(FigureSelectionListener fsl)
          Remove a listener for selection changes in this DrawingView.
 void removeFromSelection(Figure figure)
          Removes a figure from the selection.
 void repairDamage()
          Repair the damaged area
 FigureEnumeration selection()
          Gets an enumeration over the currently selected figures.
 int selectionCount()
          Gets the number of selected figures.
 FigureEnumeration selectionZOrdered()
          Gets the currently seleced figures in Z order.
 void setBackground(java.awt.Color c)
          Sets the background color of the DrawingView
 void setConstrainer(PointConstrainer p)
          Sets the current point constrainer.
 void setCursor(Cursor c)
          Sets the cursor of the DrawingView
 void setDisplayUpdate(Painter updateStrategy)
          Sets the current display update strategy.
 void setDrawing(Drawing d)
          Sets and installs another drawing in the view.
 void setEditor(DrawingEditor editor)
          Sets the view's editor.
 void toggleSelection(Figure figure)
          If a figure isn't selected it is added to the selection.
 Tool tool()
          Gets the current tool.
 void unfreezeView()
          Unfreezes the view by releasing the drawing lock.
 
Methods inherited from interface java.awt.image.ImageObserver
imageUpdate
 
Methods inherited from interface org.jhotdraw.framework.DrawingChangeListener
drawingInvalidated, drawingRequestUpdate, drawingTitleChanged
 

Method Detail

setEditor

void setEditor(DrawingEditor editor)
Sets the view's editor.


tool

Tool tool()
Gets the current tool.


drawing

Drawing drawing()
Gets the drawing.


setDrawing

void setDrawing(Drawing d)
Sets and installs another drawing in the view.


editor

DrawingEditor editor()
Gets the editor.


add

Figure add(Figure figure)
Adds a figure to the drawing.

Returns:
the added figure.

remove

Figure remove(Figure figure)
Removes a figure from the drawing.

Returns:
the removed figure

addAll

void addAll(java.util.Collection figures)
Adds a collections of figures to the drawing.


getSize

java.awt.Dimension getSize()
Gets the size of the drawing.


getMinimumSize

java.awt.Dimension getMinimumSize()
Gets the minimum dimension of the drawing.


getPreferredSize

java.awt.Dimension getPreferredSize()
Gets the preferred dimension of the drawing..


setDisplayUpdate

void setDisplayUpdate(Painter updateStrategy)
Sets the current display update strategy.

See Also:
Painter

getDisplayUpdate

Painter getDisplayUpdate()
Gets the current display update strategy.

See Also:
Painter

selection

FigureEnumeration selection()
Gets an enumeration over the currently selected figures. The selection is a snapshot of the current selection which does not get changed anymore

Returns:
an enumeration with the currently selected figures.

selectionZOrdered

FigureEnumeration selectionZOrdered()
Gets the currently seleced figures in Z order. The selection is a snapshot of the current selection which does not get changed anymore

Returns:
an enumeration with the currently selected figures.
See Also:
selection()

selectionCount

int selectionCount()
Gets the number of selected figures.


isFigureSelected

boolean isFigureSelected(Figure checkFigure)
Test whether a given figure is selected.


addToSelection

void addToSelection(Figure figure)
Adds a figure to the current selection.


addToSelectionAll

void addToSelectionAll(java.util.Collection figures)
Adds a collections of figures to the current selection.


addToSelectionAll

void addToSelectionAll(FigureEnumeration fe)
Adds a FigureEnumeration to the current selection.


removeFromSelection

void removeFromSelection(Figure figure)
Removes a figure from the selection.


toggleSelection

void toggleSelection(Figure figure)
If a figure isn't selected it is added to the selection. Otherwise it is removed from the selection.


clearSelection

void clearSelection()
Clears the current selection.


getFigureSelection

FigureSelection getFigureSelection()
Gets the current selection as a FigureSelection. A FigureSelection can be cut, copied, pasted.


findHandle

Handle findHandle(int x,
                  int y)
Finds a handle at the given coordinates.

Returns:
the hit handle, null if no handle is found.

lastClick

java.awt.Point lastClick()
Gets the position of the last click inside the view.


setConstrainer

void setConstrainer(PointConstrainer p)
Sets the current point constrainer.


getConstrainer

PointConstrainer getConstrainer()
Gets the current grid setting.


checkDamage

void checkDamage()
Checks whether the drawing has some accumulated damage


repairDamage

void repairDamage()
Repair the damaged area


paint

void paint(java.awt.Graphics g)
Paints the drawing view. The actual drawing is delegated to the current update strategy.

See Also:
Painter

createImage

java.awt.Image createImage(int width,
                           int height)
Creates an image with the given dimensions


getGraphics

java.awt.Graphics getGraphics()
Gets a graphic to draw into


getBackground

java.awt.Color getBackground()
Gets the background color of the DrawingView


setBackground

void setBackground(java.awt.Color c)
Sets the background color of the DrawingView


drawAll

void drawAll(java.awt.Graphics g)
Draws the contents of the drawing view. The view has three layers: background, drawing, handles. The layers are drawn in back to front order.


draw

void draw(java.awt.Graphics g,
          FigureEnumeration fe)
Draws the given figures. The view has three layers: background, drawing, handles. The layers are drawn in back to front order.


drawHandles

void drawHandles(java.awt.Graphics g)
Draws the currently active handles.


drawDrawing

void drawDrawing(java.awt.Graphics g)
Draws the drawing.


drawBackground

void drawBackground(java.awt.Graphics g)
Draws the background. If a background pattern is set it is used to fill the background. Otherwise the background is filled in the background color.


setCursor

void setCursor(Cursor c)
Sets the cursor of the DrawingView


freezeView

void freezeView()
Freezes the view by acquiring the drawing lock.

See Also:
Drawing.lock()

unfreezeView

void unfreezeView()
Unfreezes the view by releasing the drawing lock.

See Also:
Drawing.unlock()

addFigureSelectionListener

void addFigureSelectionListener(FigureSelectionListener fsl)
Add a listener for selection changes in this DrawingView.

Parameters:
fsl - jhotdraw.framework.FigureSelectionListener

removeFigureSelectionListener

void removeFigureSelectionListener(FigureSelectionListener fsl)
Remove a listener for selection changes in this DrawingView.

Parameters:
fsl - jhotdraw.framework.FigureSelectionListener

getConnectionFigures

FigureEnumeration getConnectionFigures(Figure inFigure)
Returns a FigureEnumeration of connection figures


insertFigures

FigureEnumeration insertFigures(FigureEnumeration inFigures,
                                int dx,
                                int dy,
                                boolean bCheck)
Inserts figures in a drawing at given offset. Optional check for connection figures

Returns:
enumeration which has been added to the drawing. The figures in the enumeration can have changed during adding them (e.g. they could have been decorated).

isInteractive

boolean isInteractive()
Check whether the DrawingView is interactive, i.e. whether it accepts user input and whether it can display a drawing.


JHotDraw 6.0b1