jfig.commands
Class CopyObjectCommand

java.lang.Object
  extended byjfig.commands.Command
      extended byjfig.commands.CopyObjectCommand

public class CopyObjectCommand
extends Command

copy jfig objects.

CopyCommand allows the user to copy objects in the jfig editor, including all their attributes.

Use the middle mouse button (or "alt"+"left") for x/y-restricted copies, or the right mouse button to cancel a copy operation.


Field Summary
protected  FigObject clone
           
protected  int dx
           
protected  int dy
           
protected  java.awt.Point endPoint
           
protected  int n_points
           
protected  boolean restricted
           
protected  FigObject source
           
protected  java.awt.Point startPoint
           
 
Fields inherited from class jfig.commands.Command
editor, objectCanvas, ready
 
Constructor Summary
CopyObjectCommand(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 FigObject array of length 2 with the following entries: the object at index 0 is the original (source) object or null, the object at index 1 is the copied (clone) object or null.
 void mousePressed(FigCanvasEvent evt)
          select the object to copy (at position startPoint) and its new position (endPoint).
 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

source

protected FigObject source

clone

protected FigObject clone

startPoint

protected java.awt.Point startPoint

endPoint

protected java.awt.Point endPoint

dx

protected int dx

dy

protected int dy

restricted

protected boolean restricted
Constructor Detail

CopyObjectCommand

public CopyObjectCommand(FigBasicEditor editor,
                         FigCanvas objectCanvas)
Method Detail

getModifiedObjects

public FigObject[] getModifiedObjects()
return an FigObject array of length 2 with the following entries: the object at index 0 is the original (source) object or null, the object at index 1 is the copied (clone) object or 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)
select the object to copy (at position startPoint) and its new position (endPoint).

To allow for selection of stacked objects at/near startPoint, we use the following algorithm: First, we simply use editor.findObjectAt() to find the topmost object (if any) at or near startPoint. If an object is found, its corners are highlighted, while all other object markers are recopyd.

If the user clicks again on/near startPoint - and with the SHIFT-key hold down, the editor.findNextObjectAt() method is called repeatedly, to find the next objects.

The selected object is copied as soon as the users clicks on a position different from the startPoint.

If the "middle" mouse button is pressed (or use "ALT"+"left" button), the CopyCommand restricts the target position to allow for directly horizontal/vertical copies.

Overrides:
mousePressed in class Command

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