kaapo.project.graphics
Class DirectTextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by kaapo.project.graphics.DirectTextArea
All Implemented Interfaces:
FocusListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, DocumentListener

public class DirectTextArea
extends JComponent
implements MouseListener, MouseMotionListener, FocusListener, DocumentListener

Text area component similar to JTextArea, suitable for diagram panel direct editing. The text area has two modes: mutable and immutable. The mode changes at run time. By default the area is immutable and merely renders the text. When double clicked, the text area switches to mutable mode and functions like a regular JTextArea. When focus is lost, the mode switches back to immutable.

Author:
hkovaska
See Also:
JTextArea, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  String attributeName
           
protected  DiagramComponent diagramComponent
           
protected  boolean documentListenerEnabled
           
protected  JTextArea immutableTextArea
          Like a normal text area, but always non-editable and all mouse listeners are removed.
protected  boolean isEditable
           
protected  ProjectManager projectManager
           
protected  JTextArea textArea
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DirectTextArea()
          Constructs a bare text area that has no associated diagram component.
DirectTextArea(DiagramComponent dc, String attributeName, ProjectManager pm)
           
 
Method Summary
 void addDocumentListener(DocumentListener dl)
          Adds a document listener to the contents of the text area.
 void changedUpdate(DocumentEvent e)
           
protected  void disableDocumentListener()
          Temporary disables the document listener that the DirectTextArea registered itself.
protected  void dispatchEventUp(MouseEvent e)
          Routes mouse event to parent diagram panel.
protected  void enableDocumentListener()
          Re-enables the document listener.
 void focusGained(FocusEvent e)
           
 void focusLost(FocusEvent e)
           
 Dimension getPreferredSize()
           
 String getText()
          Returns the contents of the text area.
 void insertUpdate(DocumentEvent e)
           
protected  void modifyAttribute(Object value)
          Sets the value of DC attribute using Project Manager.
 void mouseClicked(MouseEvent e)
           
 void mouseDragged(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mouseMoved(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void removeUpdate(DocumentEvent e)
           
 void setBounds(int x, int y, int width, int height)
           
 void setEditable(boolean editable)
          Sets the text area into editable or non-editable mode.
 void setText(String text)
          Sets the contents of the text area.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getWidth, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

isEditable

protected boolean isEditable

textArea

protected JTextArea textArea

immutableTextArea

protected JTextArea immutableTextArea
Like a normal text area, but always non-editable and all mouse listeners are removed. immutableTextArea uses the same model (Document) as textArea, so they should always be in sync.


projectManager

protected ProjectManager projectManager

diagramComponent

protected DiagramComponent diagramComponent

attributeName

protected String attributeName

documentListenerEnabled

protected boolean documentListenerEnabled
Constructor Detail

DirectTextArea

public DirectTextArea(DiagramComponent dc,
                      String attributeName,
                      ProjectManager pm)
Parameters:
dc - Associated diagram component
attributeName - Name of DC attribute that is used as the content of the text area.
pm - Project Manager that is used for modifying the DC attribute.

DirectTextArea

public DirectTextArea()
Constructs a bare text area that has no associated diagram component. To use this, you should write your own document listener.

Method Detail

addDocumentListener

public void addDocumentListener(DocumentListener dl)
Adds a document listener to the contents of the text area.

Parameters:
dl - Document listener

setEditable

public void setEditable(boolean editable)
Sets the text area into editable or non-editable mode.

Parameters:
editable -

getText

public String getText()
Returns the contents of the text area.


setText

public void setText(String text)
Sets the contents of the text area. Text may contain newlines.

Parameters:
text - New contents

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Overrides:
setBounds in class Component

dispatchEventUp

protected void dispatchEventUp(MouseEvent e)
Routes mouse event to parent diagram panel.

Parameters:
e - The mouse event

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Specified by:
mouseMoved in interface MouseMotionListener

focusGained

public void focusGained(FocusEvent e)
Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)
Specified by:
focusLost in interface FocusListener

modifyAttribute

protected void modifyAttribute(Object value)
Sets the value of DC attribute using Project Manager.

Parameters:
value - The new value

disableDocumentListener

protected void disableDocumentListener()
Temporary disables the document listener that the DirectTextArea registered itself.


enableDocumentListener

protected void enableDocumentListener()
Re-enables the document listener.


changedUpdate

public void changedUpdate(DocumentEvent e)
Specified by:
changedUpdate in interface DocumentListener

insertUpdate

public void insertUpdate(DocumentEvent e)
Specified by:
insertUpdate in interface DocumentListener

removeUpdate

public void removeUpdate(DocumentEvent e)
Specified by:
removeUpdate in interface DocumentListener