edu.umd.cs.piccolox.event
Class PStyledTextEventHandler

java.lang.Object
  extended by edu.umd.cs.piccolo.event.PBasicInputEventHandler
      extended by edu.umd.cs.piccolox.event.PStyledTextEventHandler
All Implemented Interfaces:
PInputEventListener, EventListener

public class PStyledTextEventHandler
extends PBasicInputEventHandler

Author:
Lance Good

Field Summary
protected  PCanvas canvas
          Canvas onto which this event handler is attached.
protected  DocumentListener docListener
          A listener that will handle programatic changes to the underlying document and update the view accordingly.
protected  PStyledText editedText
          The Styled text being edited.
protected  JTextComponent editor
          Editor used to edit a PStyledText's content when it is in edit mode.
 
Constructor Summary
PStyledTextEventHandler(PCanvas canvas)
          Basic constructor for PStyledTextEventHandler.
PStyledTextEventHandler(PCanvas canvas, JTextComponent editor)
          Constructor for PStyledTextEventHandler that allows an editor to be specified.
 
Method Summary
protected  JTextComponent createDefaultEditor()
          Creates a default editor component to be used when editing a PStyledText node.
protected  DocumentListener createDocumentListener()
          Returns a document listener that will reshape the editor whenever a change occurs to its attached document.
 PStyledText createText()
          Creates a PStyledText instance and attaches a simple document to it.
 void dispatchEventToEditor(PInputEvent event)
          Intercepts Piccolo2D events and dispatches the underlying swing one to the current editor.
protected  void initEditor(JTextComponent newEditor)
          Installs the editor onto the canvas.
 void mousePressed(PInputEvent event)
          A callback that is invoked any time the mouse is pressed on the canvas.
 void reshapeEditor()
          Adjusts the shape of the editor to fit the current document.
protected  void reshapeEditorLater()
          Sometimes we need to invoke this later because the document events seem to get fired before the text is actually incorporated into the document.
 void startEditing(PInputEvent event, PStyledText text)
          Begins editing the provided text node as a result of the provided event.
 void stopEditing(PInputEvent event)
          Stops editing the current text node.
 
Methods inherited from class edu.umd.cs.piccolo.event.PBasicInputEventHandler
acceptsEvent, getEventFilter, keyboardFocusGained, keyboardFocusLost, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseReleased, mouseWheelRotated, mouseWheelRotatedByBlock, paramString, processEvent, setEventFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canvas

protected PCanvas canvas
Canvas onto which this event handler is attached.


editor

protected JTextComponent editor
Editor used to edit a PStyledText's content when it is in edit mode.


docListener

protected DocumentListener docListener
A listener that will handle programatic changes to the underlying document and update the view accordingly.


editedText

protected PStyledText editedText
The Styled text being edited.

Constructor Detail

PStyledTextEventHandler

public PStyledTextEventHandler(PCanvas canvas)
Basic constructor for PStyledTextEventHandler.

Parameters:
canvas - canvas to which this handler will be attached

PStyledTextEventHandler

public PStyledTextEventHandler(PCanvas canvas,
                               JTextComponent editor)
Constructor for PStyledTextEventHandler that allows an editor to be specified.

Parameters:
canvas - canvas to which this handler will be attached
editor - component to display when editing a PStyledText node
Method Detail

initEditor

protected void initEditor(JTextComponent newEditor)
Installs the editor onto the canvas. Making it the editor that will be used whenever a PStyledText node needs editing.

Parameters:
newEditor - component responsible for a PStyledText node while it is being edited.

createDefaultEditor

protected JTextComponent createDefaultEditor()
Creates a default editor component to be used when editing a PStyledText node.

Returns:
a freshly created JTextComponent subclass that can be used to edit PStyledText nodes

createDocumentListener

protected DocumentListener createDocumentListener()
Returns a document listener that will reshape the editor whenever a change occurs to its attached document.

Returns:
a DocumentListener

createText

public PStyledText createText()
Creates a PStyledText instance and attaches a simple document to it. If possible, it configures its font information too.

Returns:
a new PStyledText instance

mousePressed

public void mousePressed(PInputEvent event)
A callback that is invoked any time the mouse is pressed on the canvas. If the press occurs directly on the canvas, it create a new PStyledText instance and puts it in editing mode. If the click is on a node, it marks changes it to editing mode.

Overrides:
mousePressed in class PBasicInputEventHandler
Parameters:
event - mouse click event that can be queried

startEditing

public void startEditing(PInputEvent event,
                         PStyledText text)
Begins editing the provided text node as a result of the provided event. Will swap out the text node for an editor.

Parameters:
event - the event responsible for starting the editing
text - text node being edited

stopEditing

public void stopEditing(PInputEvent event)
Stops editing the current text node.

Parameters:
event - the event responsible for stopping the editing

dispatchEventToEditor

public void dispatchEventToEditor(PInputEvent event)
Intercepts Piccolo2D events and dispatches the underlying swing one to the current editor.

Parameters:
event - the swing event being intercepted

reshapeEditor

public void reshapeEditor()
Adjusts the shape of the editor to fit the current document.


reshapeEditorLater

protected void reshapeEditorLater()
Sometimes we need to invoke this later because the document events seem to get fired before the text is actually incorporated into the document.



Copyright © 1995-2010 Piccolo2D. All Rights Reserved.