jfig.commands
Class SelectLibraryObjectCommand

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

public class SelectLibraryObjectCommand
extends Command

browse FIG libraries and add selected objects to the current drawing

A SelectLibraryObjectCommand displays the SelectFromLibraryDialog window, to allow the user to browse and select FIG library objects. Once an object is selected, the outline of the object is presented as the canvas rubberband, and the user has the choice to (left): add the selected object to the drawing, (middle): select another library object, (right): cancel the command.

Note: to avoid further complication of jfig.gui.ModularEditor and to avoid too strong coupling between this class and ModularEditor instead of FigBasicEditor, this class uses a static reference to SelectFromLibraryDialog. This means that ModularEditor needs no knowledge about how the user selects FIG library objects. On the other hand, it is not possible to use different select dialogs at the same time.

To implement the xfig behavior, we also use a static boolean flag 'hasPreselectedObject' to indicate that the next new command object should not display the SelectFromLibraryDialog but use a copy of the last selected object instead (xfig left mouse button behaviour).

A final hack: as several important FIG attribute values are currently static (=global) in FigAttribs, we save and rescue the original parent drawings values before parsing the library object, and restore them after parsing. This situation should REALLY be corrected sometime.


Field Summary
(package private)  FigCompound buffer
           
(package private)  java.awt.Point endPoint
           
(package private) static java.awt.Frame frame
           
(package private) static boolean hasPreselectedObject
           
(package private) static SelectLibraryObjectDialog selectDialog
           
(package private)  java.awt.Point startPoint
           
 
Fields inherited from class jfig.commands.Command
editor, objectCanvas, ready
 
Constructor Summary
SelectLibraryObjectCommand(FigBasicEditor editor, FigCanvas objectCanvas)
           
 
Method Summary
 void cancel()
          cancel the current editor command
 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 library (compound) object (to be) created by this command.
 void hideSelectDialog()
           
 void mousePressed(FigCanvasEvent evt)
          react to a mouse click on the editor canvas
 void restoreGlobalAttributes()
           
 void saveGlobalAttributes()
           
 void selectObject()
          the user has selected an object in the SelectFromLibraryDialog window.
 void setSelectionListener()
           
 void showSelectDialog()
           
 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
isReady, message, notifyEditor, statusMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

selectDialog

static SelectLibraryObjectDialog selectDialog

frame

static java.awt.Frame frame

hasPreselectedObject

static boolean hasPreselectedObject

buffer

FigCompound buffer

startPoint

java.awt.Point startPoint

endPoint

java.awt.Point endPoint
Constructor Detail

SelectLibraryObjectCommand

public SelectLibraryObjectCommand(FigBasicEditor editor,
                                  FigCanvas objectCanvas)
Method Detail

getModifiedObjects

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

Overrides:
getModifiedObjects in class Command

cancel

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

cancel and cleanup the current command. Note that this method is empty for class Command, but might be implemented by subclasses.

Overrides:
cancel in class Command

showSelectDialog

public void showSelectDialog()

setSelectionListener

public void setSelectionListener()

hideSelectDialog

public void hideSelectDialog()

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

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

selectObject

public void selectObject()
the user has selected an object in the SelectFromLibraryDialog window.

Due to one of jfig's design errors, it is currently difficult to display the same objects in two different canvases, with different magnification (transformations). Because the selected library object is already displayed in the preview canvas of the SelectFromLibraryDialog, we cannot directly re-use the objectList available...

Therefore, we re-parse the selected object, using the current FigTrafo2D transformation of the editor's main drawing canvas.

Also note that we re-parse the object each time it is selected. However, while parsing is a little bit more expensive than a deep object copy, this should not be a too great problem on current hardware...


saveGlobalAttributes

public void saveGlobalAttributes()

restoreGlobalAttributes

public void restoreGlobalAttributes()

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

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