jfig.commands
Class RotateObjectCommand

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

public class RotateObjectCommand
extends Command

A command object to manage object rotation for jfig.

A single rotation command maintains references to the target object, an anchor point (origin) for the rotation, and the rotation angle, measured in radians. In principle, the command can be undone, but rounding errors may occur due to the use of integer coordinates. Any target object may throw an Exception if the rotation around the specified angle is impossible - for example, xfig rectangles and compounds can only be rotated around multiples of 90 degreees.

Also, note that this class maintains a static boolean field "clockwise" which should be set previous to calling the RotateObjectCommand constructor, in order, to specify the desired rotation direction.


Field Summary
(package private)  java.awt.Point anchor
           
(package private)  double angle
           
static boolean CCW
           
(package private) static boolean clockwise
           
static boolean CW
           
(package private)  FigObject object
           
(package private)  FigObject rotatedCopy
           
 
Fields inherited from class jfig.commands.Command
editor, objectCanvas, ready
 
Constructor Summary
RotateObjectCommand(FigBasicEditor editor, FigCanvas objectCanvas)
           
 
Method Summary
 void execute()
          rotate the selected object / its newly created copy, where the rotation angle and direction are from our "clockwise" and "angle" variables.
 java.lang.String getDescription()
          one-line description of this command
 FigObject[] getModifiedObjects()
          return an FigObject array of length 2 with the following entries: the element at index 0 is the rotated object (or null), the element at index 1 is the copied and rotated clone (or null).
 boolean isReady()
          check whether this command is completed/ready, or not
 void mousePressed(FigCanvasEvent evt)
          react to a mouse click on the editor canvas
 void notifyEditor()
          provide a callback from commands to their editor.
static void setDirection(boolean _clockwise)
          called by the editor to distinguis between clockwise and anti- clockwise rotations (there are two command buttons, but we use only one RotateObjectCommand class to handle both commands).
 java.lang.String toString()
          return a (possibly verbose) description of this RotateObjectCommand object
 void undo()
          undo this command
 
Methods inherited from class jfig.commands.Command
cancel, message, statusMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CW

public static final boolean CW
See Also:
Constant Field Values

CCW

public static final boolean CCW
See Also:
Constant Field Values

clockwise

static boolean clockwise

object

FigObject object

rotatedCopy

FigObject rotatedCopy

anchor

java.awt.Point anchor

angle

double angle
Constructor Detail

RotateObjectCommand

public RotateObjectCommand(FigBasicEditor editor,
                           FigCanvas objectCanvas)
Method Detail

setDirection

public static void setDirection(boolean _clockwise)
called by the editor to distinguis between clockwise and anti- clockwise rotations (there are two command buttons, but we use only one RotateObjectCommand class to handle both commands).


getModifiedObjects

public FigObject[] getModifiedObjects()
return an FigObject array of length 2 with the following entries: the element at index 0 is the rotated object (or null), the element at index 1 is the copied and rotated clone (or null).

Overrides:
getModifiedObjects in class Command

execute

public void execute()
rotate the selected object / its newly created copy, where the rotation angle and direction are from our "clockwise" and "angle" variables.

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)
Description copied from class: Command
react to a mouse click on the editor canvas

This method provides the central callback from the editor to its current command object. Passing a FigCanvasEvent parameter, the editor provides information both about the screen coordinates and the world coordinates of the mouse event.

Naturally, mouse presses are ignored for class Command.

Overrides:
mousePressed in class Command

isReady

public boolean isReady()
check whether this command is completed/ready, or not

Overrides:
isReady in class Command

notifyEditor

public void notifyEditor()
provide a callback from commands to their editor.

This method serves as a callback from command objects to their editor. Because each command object is used for one single and atomic editing operation only, the editor has to create a new command once the previous command has execute()d. This is achieved by calling notifyEditor() from within a command, once the command has executed and is ready. The typical use is to implement the xfig-style editor modes, e.g. to create a new RotateObjectCommand directly after the previous RotateObjectCommand has finished.

Overrides:
notifyEditor in class Command

getDescription

public java.lang.String getDescription()
one-line description of this command

Overrides:
getDescription in class Command

toString

public java.lang.String toString()
return a (possibly verbose) description of this RotateObjectCommand object

Overrides:
toString in class Command