Class ImageTool

  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.AbstractTool
          extended by org.jhotdraw.draw.CreationTool
              extended by org.jhotdraw.draw.ImageTool
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener,, java.lang.Cloneable, java.util.EventListener, Tool

public class ImageTool
extends CreationTool

A tool to create new figures that implement the ImageHolderFigure interface, such as ImageFigure. The figure to be created is specified by a prototype.

Immediately, after the ImageTool has been activated, it opens a JFileChooser, letting the user specify an image file. The the user then performs the following mouse gesture:

  1. Press the mouse button and drag the mouse over the DrawingView. This defines the bounds of the created figure.

Design Patterns

The ImageTool and the ImageHolderFigure define the contracts of a smaller framework inside of the JHotDraw framework for structured drawing editors.
Contract: ImageHolderFigure, ImageTool.

The ImageTool creates new figures by cloning a prototype ImageHolderFigure object.
Prototype: ImageHolderFigure; Client: ImageTool.

$Id: 551 2009-09-03 05:50:46Z rawcoder $
Werner Randelshofer
See Also:
Serialized Form

Field Summary
protected  javax.swing.JFileChooser fileChooser
protected  java.awt.FileDialog fileDialog
protected  boolean useFileDialog
protected  java.lang.Thread workerThread
Fields inherited from class org.jhotdraw.draw.CreationTool
createdFigure, minimalSize, minimalSizeTreshold, presentationName, prototype, prototypeAttributes
Fields inherited from class org.jhotdraw.draw.AbstractTool
anchor, editor, isWorking, listenerList
Fields inherited from class org.jhotdraw.beans.AbstractBean
Constructor Summary
ImageTool(ImageHolderFigure prototype)
          Creates a new instance.
ImageTool(ImageHolderFigure prototype, java.util.Map<AttributeKey,java.lang.Object> attributes)
          Creates a new instance.
Method Summary
 void activate(DrawingEditor editor)
          Activates the tool for the given editor.
private  javax.swing.JFileChooser getFileChooser()
private  java.awt.FileDialog getFileDialog()
 boolean isUseFileDialog()
 void setUseFileDialog(boolean newValue)
Methods inherited from class org.jhotdraw.draw.CreationTool
createFigure, creationFinished, deactivate, getAddedFigure, getCreatedFigure, getPrototype, isToolDoneAfterCreation, mouseDragged, mousePressed, mouseReleased, setToolDoneAfterCreation, updateCursor
Methods inherited from class org.jhotdraw.draw.AbstractTool
addToolListener, addUndoableEditListener, constrainPoint, constrainPoint, createActionMap, createInputMap, draw, editCopy, editCut, editDelete, editDuplicate, editPaste, fireAreaInvalidated, fireAreaInvalidated, fireToolDone, fireToolStarted, getActionMap, getDrawing, getEditor, getInputMap, getToolTipText, getView, isActive, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, mouseMoved, removeToolListener, removeUndoableEditListener, setActionMap, setInputMap, supportsHandleInteraction, viewToDrawing
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected java.awt.FileDialog fileDialog


protected javax.swing.JFileChooser fileChooser


protected boolean useFileDialog


protected java.lang.Thread workerThread
Constructor Detail


public ImageTool(ImageHolderFigure prototype)
Creates a new instance.


public ImageTool(ImageHolderFigure prototype,
                 java.util.Map<AttributeKey,java.lang.Object> attributes)
Creates a new instance.

Method Detail


public void setUseFileDialog(boolean newValue)


public boolean isUseFileDialog()


public void activate(DrawingEditor editor)
Description copied from interface: Tool
Activates the tool for the given editor. This method is called whenever the user switches to this tool.

Specified by:
activate in interface Tool
activate in class CreationTool


private javax.swing.JFileChooser getFileChooser()


private java.awt.FileDialog getFileDialog()