jfig.commands
Class CreateFreehandCommand

java.lang.Object
  extended byjfig.commands.Command
      extended byjfig.commands.CreateFreehandCommand
All Implemented Interfaces:
java.util.EventListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

public class CreateFreehandCommand
extends Command
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

create an open freehand line via mouse dragging.

CreateFreehandCommand allows the user to create a freehand line. Click the "left" mouse button at the line start point, then hold the mouse button and drag the mouse to draw the line. Releasing the left button finished the line. The final line is stored as a standard FIG polyline, and can later be modified via all FIG line editing commands.

Note that this semantics means that you cannot use the "right" button to immediately cancel a CreateFreehandCommand (use the "undo" command instead).

Note that the freehand line stores and uses all intermediate mouse positions - no optimizations are applied to reduce the number of points. Therefore, using very large freehand lines may incur performance problems.

This command class uses its own internal MouseMotionListener to handle redrawing via mouse dragging.


Field Summary
protected  int n_points
           
protected  FigPolyline polyline
           
 
Fields inherited from class jfig.commands.Command
editor, objectCanvas, ready
 
Constructor Summary
CreateFreehandCommand(FigBasicEditor editor, FigCanvas objectCanvas)
           
 
Method Summary
 void execute()
          execute the current editor command
 java.lang.String getDescription()
          one-line description of this command
 FigObject[] getModifiedObjects()
          return an array-wrapped reference to the freehand line object created by this command.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(FigCanvasEvent evt)
          mousePressed: create a new freehand line object and add points to it.
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 java.lang.String toString()
          return a (possibly verbose) description of this Command object
 void undo()
          undo this command
 
Methods inherited from class jfig.commands.Command
cancel, isReady, message, notifyEditor, statusMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

n_points

protected int n_points

polyline

protected FigPolyline polyline
Constructor Detail

CreateFreehandCommand

public CreateFreehandCommand(FigBasicEditor editor,
                             FigCanvas objectCanvas)
Method Detail

getModifiedObjects

public FigObject[] getModifiedObjects()
return an array-wrapped reference to the freehand line object created by this command. The line reference may be null.

Overrides:
getModifiedObjects in class Command

execute

public void execute()
Description copied from class: Command
execute the current editor command

This method is empty for class Command.

Overrides:
execute in class Command

undo

public void undo()
Description copied from class: Command
undo this command

Try to undo this command as far as possible. Don't try to undo() a command that has never been execute()d before. This method is empty for class Command.

Overrides:
undo in class Command

mousePressed

public void mousePressed(FigCanvasEvent evt)
mousePressed: create a new freehand line object and add points to it. The freehand line is finished once the user releases the mouse button.

Note: Unlike all other xfig/jfig commands, CreateFreehandCommand needs to react to mouse-movements, not to clicks only. Therefore, on the first mouse-click, we register this command object as a MouseMotionListener with the objectCanvas. Once we detect a mouseReleased event, we finish this command and create the final polyline object.

Overrides:
mousePressed in class Command

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

getDescription

public java.lang.String getDescription()
Description copied from class: Command
one-line description of this command

return a one-line desription of this command, e.g. to label the undo/redo buttons, if any

Overrides:
getDescription in class Command

toString

public java.lang.String toString()
Description copied from class: Command
return a (possibly verbose) description of this Command object

Overrides:
toString in class Command