jfig.commands
Class MoveObjectCommand

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

public class MoveObjectCommand
extends Command

move jfig objects.

MoveCommand allows the user to move objects in the jfig editor.

Use the "middle" mouse button (or "alt"+"left") for x/y-restricted moves.


Field Summary
protected  int dx
           
protected  int dy
           
protected  java.awt.Point endPoint
           
protected  int n_points
           
protected  FigObject object
           
protected  boolean restricted
           
static int SMART_LINKS_MOVE
           
static int SMART_LINKS_MOVEALL
           
static int SMART_LINKS_OFF
           
static int SMART_LINKS_SLIDE
           
protected  int smartLinksMode
           
protected  java.awt.Point startPoint
           
 
Fields inherited from class jfig.commands.Command
editor, objectCanvas, ready
 
Constructor Summary
MoveObjectCommand(FigBasicEditor editor, FigCanvas objectCanvas)
          a command object to encapsulate "move object" commands.
 
Method Summary
 boolean checkMovePoint(FigBbox bbox, java.awt.Point p, int dx, int dy)
           
 void checkSmartLinksMove(FigObject object, int dx, int dy)
          check the value of the "smart links modus" variable.
 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 FigObject moved (modified) by this command.
 java.util.Vector getSmartMoveAnchorCandidates(FigObject object)
          Determine the potential 'anchor' points for an object.
 void mousePressed(FigCanvasEvent evt)
          select the object to move (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

object

protected FigObject object

startPoint

protected java.awt.Point startPoint

endPoint

protected java.awt.Point endPoint

dx

protected int dx

dy

protected int dy

restricted

protected boolean restricted

SMART_LINKS_OFF

public static final int SMART_LINKS_OFF
See Also:
Constant Field Values

SMART_LINKS_MOVE

public static final int SMART_LINKS_MOVE
See Also:
Constant Field Values

SMART_LINKS_SLIDE

public static final int SMART_LINKS_SLIDE
See Also:
Constant Field Values

SMART_LINKS_MOVEALL

public static final int SMART_LINKS_MOVEALL
See Also:
Constant Field Values

smartLinksMode

protected int smartLinksMode
Constructor Detail

MoveObjectCommand

public MoveObjectCommand(FigBasicEditor editor,
                         FigCanvas objectCanvas)
a command object to encapsulate "move object" commands. This class maintains all status information for complete undo. It also supports "x/y restricted moves" and the xfig "smart links move" modi for rectangles.

Method Detail

getModifiedObjects

public FigObject[] getModifiedObjects()
return an array-wrapped reference to the FigObject moved (modified) by this command. The FigObject 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

checkSmartLinksMove

public void checkSmartLinksMove(FigObject object,
                                int dx,
                                int dy)
check the value of the "smart links modus" variable. at initial creation of this MoveObjectCommand. If one of the smart links modi (SMART_LINKS_MOVE or SMART_LINKS_SLIDE) is selected, we try to find all polyline (arc,spline,etc) objects connected to any 'anchor candidates', and move the corresponding polyline endpoints.

Currently, an 'anchor candidate' is the bbox of a rectangle, or the bbox of any rectangles in a compound object. (Is this how xfig works?)

Note that, unlike xfig, we also "smart move" all text objects which are wholly inside the moved rectangle, because this is a function I always missed in xfig :-)

Note that smart links support is currently experimental.


getSmartMoveAnchorCandidates

public java.util.Vector getSmartMoveAnchorCandidates(FigObject object)
Determine the potential 'anchor' points for an object. An object may have many such points, esp. in the case of a compond object.

REFACTOR 1: this should be a polymorphic method on FigObject (instead of a FigObject being passed as a paramater and using an if statement, as we do).

REFACTOR 2: concerning checkMovePoint(). This should also be a polymorphic method on FigObject, and possibly merged with this method. For Example, both methods would become:

  class FigObject { ...
      // looks at point p and "smart moves" by (dx,dy) if
      // it is somehow 'anchored' to this object.
      // returns true if it was changed
      public boolean checkSmartMovePoint(Point p, int dx, int dy);
  }
 
This would mean that each object type could determine its 'anchors'

Returns:
a list of FigBBox object which can be considered 'anchor' points for lines.

checkMovePoint

public boolean checkMovePoint(FigBbox bbox,
                              java.awt.Point p,
                              int dx,
                              int dy)

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 move (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 removed.

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 moved as soon as the users clicks on a position different from the startPoint.

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