jfig.commands
Class CreateTextCommand

java.lang.Object
  extended byjfig.commands.Command
      extended byjfig.commands.CreateTextCommand
All Implemented Interfaces:
java.util.EventListener, java.awt.event.KeyListener

public class CreateTextCommand
extends Command
implements java.awt.event.KeyListener

create FIG text objects.

Click the mouse to specify the text position and then enter the text. If the mouse is clicked again, the unfinished text object is created and the next text object is started.

The following keys have special meaning:

Note that the CreateTextCommand may reproduce itself (after receiving the RETURN key or on the next mouse click), to allow for easy entering of multiline text.

To allow input of German umlauts despite the JDK bugs, this method interprets the characters + a .. + O as umlauts ä .. Ö respectively.


Field Summary
protected  boolean debug
           
static int EDIT
           
protected  boolean editExistingText
           
static int IDLE
           
protected  java.lang.String newString
           
protected  java.lang.String oldString
           
protected  java.awt.Point P1
           
protected  java.lang.String str
           
protected  int textCursorIndex
           
protected  FigText textObject
           
 
Fields inherited from class jfig.commands.Command
editor, objectCanvas, ready
 
Constructor Summary
CreateTextCommand(FigBasicEditor editor, FigCanvas objectCanvas)
          create a CreateTextCommand object.
 
Method Summary
 void cancel()
          cancel: Cancel a CreateTextCommand.
(package private)  void deleteChar()
           
 void execute()
          execute: check whether we have a valid and not empty text object.
 void executeAndStartNewText()
          this method is called whenever the user pressed the RETURN or ENTER keys during editing a text object.
 void executeAndStartNewText(FigCanvasEvent evt)
          this method is called from mousePressed() whenever there is a non-null text object, implying that the previous text object has not already been registered with the edtior.
 java.lang.String getDescription()
          one-line description of this command
 FigObject[] getModifiedObjects()
          return an array-wrapped reference to the text object created by this command.
 java.awt.Point getOriginOfNextLine(FigText textObject)
          calculate and return the point position of a text object that is exactly one line below the given line of text, where the settings for font, font size, rotation angle, and font spacing are copied from given text object.
 void keyPressed(java.awt.event.KeyEvent evt)
           
 void keyReleased(java.awt.event.KeyEvent evt)
           
 void keyTyped(java.awt.event.KeyEvent evt)
          keyTyped(): this method is called by the editor to move the textCursor, append or insert a character right from the textCursor, and to delete characters.
 void mousePressed(FigCanvasEvent evt)
          react to a mouse click on the editor canvas
 java.lang.String toString()
          return a (possibly verbose) description of this Command object
 void undo()
          undo a CreateTextCommand, with one of the following two variants.
 
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

IDLE

public static final int IDLE
See Also:
Constant Field Values

EDIT

public static final int EDIT
See Also:
Constant Field Values

textObject

protected FigText textObject

str

protected java.lang.String str

newString

protected java.lang.String newString

oldString

protected java.lang.String oldString

editExistingText

protected boolean editExistingText

textCursorIndex

protected int textCursorIndex

P1

protected java.awt.Point P1

debug

protected boolean debug
Constructor Detail

CreateTextCommand

public CreateTextCommand(FigBasicEditor editor,
                         FigCanvas objectCanvas)
create a CreateTextCommand object.

Note that this command class is used both for creating a new text object, as well as for direct editing of an existing text object.

Method Detail

getModifiedObjects

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

Overrides:
getModifiedObjects in class Command

cancel

public void cancel()
cancel: Cancel a CreateTextCommand.

Unlike most other createXXX commands, we will want to keep the last edited text object (if any). Therefore, we will put any active text object in the editor's objectList by calling execute() from here.

Overrides:
cancel in class Command

execute

public void execute()
execute: check whether we have a valid and not empty text object. If so, insert it into the editor's object list, and register this Command with the UndoStack, redraw the object canvas.

Overrides:
execute in class Command

undo

public void undo()
undo a CreateTextCommand, with one of the following two variants. Naturally, a newly created text object will simply be deleted from the editor's object list. If this command was to edit an existing text however, the old text will be restored (from the oldString variable).

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

executeAndStartNewText

public void executeAndStartNewText()
this method is called whenever the user pressed the RETURN or ENTER keys during editing a text object. We copy the previous text objects string to the newString variable for later undo() and execute() to register the text object with the editor.

Then, we try to position the cursor one baseline below the previous text position and start a fresh CreateTextObject.


getOriginOfNextLine

public java.awt.Point getOriginOfNextLine(FigText textObject)
calculate and return the point position of a text object that is exactly one line below the given line of text, where the settings for font, font size, rotation angle, and font spacing are copied from given text object.


executeAndStartNewText

public void executeAndStartNewText(FigCanvasEvent evt)
this method is called from mousePressed() whenever there is a non-null text object, implying that the previous text object has not already been registered with the edtior. We copy the current text string from that text object to newString (for later undo), execute(), and tell the editor that we want another CreateTextCommand, at the last mouse- click position.


keyTyped

public void keyTyped(java.awt.event.KeyEvent evt)
keyTyped(): this method is called by the editor to move the textCursor, append or insert a character right from the textCursor, and to delete characters.

Note that this method will also be called for non-standard keys like VK_LEFT and VK_RIGHT (one method instead of separate keyPressed and keyTyped).

This method contains a hack to correct a problem with compose characters under Solaris, because Solaris/JDK 1.1.x won't react to the 'COMPOSE' key on the Sun keyboard. Therefore, it will interpret the keys ALT+a, ALT+A, ALT+u, ALT+U, ALT+o, ALT+O, and ALT+s as the corresponding German Umlauts.

Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent evt)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent evt)
Specified by:
keyReleased in interface java.awt.event.KeyListener

deleteChar

void deleteChar()

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