BioLegato 0.7.3 GDE plugin

org.biolegato.gdesupport.canvas.textarea
Class BLTextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.biolegato.gdesupport.canvas.textarea.BLComponent
                  extended by org.biolegato.gdesupport.canvas.textarea.BLTextArea
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, GDEModelListener
Direct Known Subclasses:
GDETextArea

public class BLTextArea
extends BLComponent
implements GDEModelListener, java.awt.event.KeyListener, java.awt.event.MouseMotionListener, java.awt.event.MouseListener

A general canvas with more functionality support than JTextArea. This canvas was originally created to support the rectangular selection model, and has since supported rectangular selections, different colour schemes, sequence documents, and many other features. Please add more generic feature support as necessary. Also if you wish to add any functionality or handling specific to a plugin, please feel free to subclass this textarea.

Author:
Graham Alvare, Brian Fristensky
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 BLTextArea blTextAreaSelf
          Self-reference for inner classes.
protected  int column
          The current column of the caret.
protected  ColourMap currentMap
          Handles printing text
protected  java.util.List<CursorListener> cursorListeners
          Linked list to store all cursor listeners
protected  GDEModel datamodel
          Used for the relationship between the data model and the text area
protected  boolean insertMode
          If true new text will overwrite existing text.
protected  java.awt.Color invalidzone
          The colour of invalid areas in the textarea.
protected  java.util.List<ModeListener> modeListeners
          Linked list to store all mode change listeners
protected  javax.swing.JPopupMenu popup
          The right click menu for the text area.
protected  int row
          The current row of the caret
protected  boolean selectionMouse
          Used to track mouse holds and releases.
protected  boolean selectionMove
          Used to track the shift key.
static long serialVersionUID
          This constant is used for serialization purposes.
 
Fields inherited from class org.biolegato.gdesupport.canvas.textarea.BLComponent
columnWidth, rowHeight
 
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
BLTextArea(GDEModel datamodel)
          Creates a new instance of BLTextArea
 
Method Summary
 void addCursorListener(CursorListener listener)
          Adds a cursor listener to the BLTextArea.
 void addModeListener(ModeListener listener)
          Adds a cursor listener to the BLTextArea.
 void addPopupMenuItem(javax.swing.JMenuItem act)
          Adds an item to the BLTextArea's right-click popup menu.
protected  void changePosition(boolean select, int newx, int newy)
          Updates/moves the cursor to the new position.
 void clearSelection()
          Clears the current text selection
 void copy()
          Copies content from the current Editable object.
 void cut()
          Cuts content from the current Editable object.
 boolean delete(int x, int y, int w, int h)
          Deletes characters from the textarea's underlying Dataset NOTE: deletions are performed in a sequential manner
 boolean deleteSelection()
          Used to delete the current selection before an insertion or as part of a deletion.
 Cell[] getData()
          Used to obtain all of the text selected within the document.
 GDEModel getDataModel()
          Returns the Dataset associated with the BLTextArea
 boolean getInsertMode()
          Returns the insertion mode status of the textarea.
protected  int getMaxSX()
          Gets the maximum X co-ordinate of the selection area.
protected  int getMaxSY()
          Gets the maximum Y co-ordinate of the selection area.
protected  int getMinSX()
          Gets the minimum X co-ordinate of the selection area.
protected  int getMinSY()
          Gets the minimum Y co-ordinate of the selection area.
 boolean insert(int col, int y, Cell[] data)
          Inserts an array of sequences into the textarea's underlying Dataset
 boolean insert(int col, int y, java.lang.String data)
          Inserts a string into the textarea's underlying Dataset NOTE: this is a wrapper method for insert(x, y, data)
protected  boolean isSelectedLine(int y)
          This function is used to test if a line is selected.
 boolean isSelectionEmpty()
          Tests if the selection shape is empty
 void keyPressed(java.awt.event.KeyEvent event)
          Processes key presses within the text area
 void keyReleased(java.awt.event.KeyEvent event)
          Processes key releases within the text area
 void keyTyped(java.awt.event.KeyEvent event)
          Processes the typing of keys within the text area
 void mouseClicked(java.awt.event.MouseEvent event)
          Handles mouse clicks.
 void mouseDragged(java.awt.event.MouseEvent event)
          Handles mouse drags.
 void mouseEntered(java.awt.event.MouseEvent event)
          Handles the mouse entering the component.
 void mouseExited(java.awt.event.MouseEvent event)
          Handles the mouse exiting the component.
 void mouseMoved(java.awt.event.MouseEvent event)
          Handles mouse movements.
 void mousePressed(java.awt.event.MouseEvent event)
          Handles mouse button presses.
 void mouseReleased(java.awt.event.MouseEvent event)
          Handles mouse button releases.
 void paintComponent(java.awt.Graphics gfx)
          Paints the current textarea (this uses the current clip bounds to determine the area to paint.
 void paste()
          Pastes content into the current Editable object.
protected  void refreshSize()
          Refreshes the size of the textarea (for scroll size purposes)
 void removePopupMenuItem(javax.swing.JMenuItem act)
          Removes an item from the BLTextArea's right-click popup menu.
 void sequenceAdded(GDEModel source, int index, Cell sequence)
          Called when a sequence is added to a Dataset.
 void sequenceChanged(GDEModel source, int index, Cell sequence, java.lang.String key)
          Called when a field in a sequence is modified.
 void sequenceRemoved(GDEModel source, int index, Cell sequence)
          Called when a sequence is removed from a Dataset.
 void setColourMap(ColourMap newMap)
          Changes the current colour map for unselected text.
 void setFont(java.awt.Font font)
          Updates the font for the canvas (ensures repaint)
 
Methods inherited from class org.biolegato.gdesupport.canvas.textarea.BLComponent
column2X, columnSize, maxColumns, maxRows, row2Y, rowSize, X2Column, Y2Row
 
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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, 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, 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

insertMode

protected boolean insertMode
If true new text will overwrite existing text.


selectionMove

protected boolean selectionMove
Used to track the shift key. If this is false, cancel the current selection on moving using the direction arrows. If this is true, stretch the current selection on moving using the direction arrows.


selectionMouse

protected boolean selectionMouse
Used to track mouse holds and releases. If this is false, cancel the current selection on any mouse click. If this is true, stretch the current selection on mouse movement.


row

protected int row
The current row of the caret


column

protected int column
The current column of the caret.


currentMap

protected ColourMap currentMap
Handles printing text


popup

protected javax.swing.JPopupMenu popup
The right click menu for the text area.


cursorListeners

protected java.util.List<CursorListener> cursorListeners
Linked list to store all cursor listeners


modeListeners

protected java.util.List<ModeListener> modeListeners
Linked list to store all mode change listeners


datamodel

protected GDEModel datamodel
Used for the relationship between the data model and the text area


invalidzone

protected final java.awt.Color invalidzone
The colour of invalid areas in the textarea.


blTextAreaSelf

public final BLTextArea blTextAreaSelf
Self-reference for inner classes.


serialVersionUID

public static final long serialVersionUID
This constant is used for serialization purposes.

See Also:
Constant Field Values
Constructor Detail

BLTextArea

public BLTextArea(GDEModel datamodel)
Creates a new instance of BLTextArea

Method Detail

addCursorListener

public void addCursorListener(CursorListener listener)
Adds a cursor listener to the BLTextArea.

Parameters:
listener - the cursor listener to add.

addModeListener

public void addModeListener(ModeListener listener)
Adds a cursor listener to the BLTextArea.

Parameters:
listener - the cursor listener to add.

getDataModel

public GDEModel getDataModel()
Returns the Dataset associated with the BLTextArea

Returns:
the SDatasetobject.

setColourMap

public void setColourMap(ColourMap newMap)
Changes the current colour map for unselected text.

Parameters:
newMap - the colour map to use

getData

public Cell[] getData()
Used to obtain all of the text selected within the document.

Returns:
the text currently selected in the document.

paintComponent

public void paintComponent(java.awt.Graphics gfx)
Paints the current textarea (this uses the current clip bounds to determine the area to paint.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
gfx - the graphics instance to paint the window to.

setFont

public void setFont(java.awt.Font font)
Updates the font for the canvas (ensures repaint)

Overrides:
setFont in class BLComponent
Parameters:
font - the new font to handle.

keyTyped

public void keyTyped(java.awt.event.KeyEvent event)
Processes the typing of keys within the text area

Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
event - the KeyEvent for the key typed

keyPressed

public void keyPressed(java.awt.event.KeyEvent event)
Processes key presses within the text area

Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
event - the KeyEvent for the key pressed

keyReleased

public void keyReleased(java.awt.event.KeyEvent event)
Processes key releases within the text area

Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
event - the KeyEvent for the key released

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Handles mouse clicks. This method sets the current caret and clears any selections (unless selectionMove is set, in which case it stretches the selection).

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
event - the MouseEvent object corresponding to the click.

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
Handles mouse button presses. This method sets the current caret and clears any selections (unless selectionMove is set).

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
event - the MouseEvent object corresponding to the press.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
Handles mouse button releases.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
event - the MouseEvent object corresponding to the release.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
Handles the mouse entering the component. Currently does nothing

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
event - the MouseEvent object corresponding to the enter.

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
Handles the mouse exiting the component. Currently does nothing

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
event - the MouseEvent object corresponding to the exit.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Handles mouse drags. Updates the selection and caret on drags.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
event - the MouseEvent object corresponding to the drag.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)
Handles mouse movements. Currently does nothing

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
event - the MouseEvent object corresponding to the movement.

refreshSize

protected void refreshSize()
Refreshes the size of the textarea (for scroll size purposes)

Specified by:
refreshSize in class BLComponent

addPopupMenuItem

public void addPopupMenuItem(javax.swing.JMenuItem act)
Adds an item to the BLTextArea's right-click popup menu.

Parameters:
act - the menu item to add.

removePopupMenuItem

public void removePopupMenuItem(javax.swing.JMenuItem act)
Removes an item from the BLTextArea's right-click popup menu.

Parameters:
act - the menu item to remove.

copy

public void copy()
Copies content from the current Editable object.


cut

public void cut()
Cuts content from the current Editable object.


paste

public void paste()
Pastes content into the current Editable object.


insert

public boolean insert(int col,
                      int y,
                      java.lang.String data)
Inserts a string into the textarea's underlying Dataset NOTE: this is a wrapper method for insert(x, y, data)

Parameters:
x - the X co-ordinate (column number) to insert the string at.
y - the Y co-ordinate (row number) to insert the string at.
data - the string to insert.
Returns:
whether or not the insertion was successful.

insert

public boolean insert(int col,
                      int y,
                      Cell[] data)
Inserts an array of sequences into the textarea's underlying Dataset

Parameters:
x - the X co-ordinate (column number) to insert the sequences at.
y - the Y co-ordinate (row number) to insert the sequences at.
data - the array of sequences to insert.
Returns:
whether or not the insertion was successful.

delete

public boolean delete(int x,
                      int y,
                      int w,
                      int h)
Deletes characters from the textarea's underlying Dataset NOTE: deletions are performed in a sequential manner

Parameters:
x - the X-offset/column number to start the deletion from.
y - the Y-offset/line number to delete characters from.
w - the width of the deletion (measured in characters along the X-axis).
h - the height of the deletion (measured in sequences along the Y-axis).
Returns:
a boolean corresponding to the result of the deletion (true = successful deletion)

deleteSelection

public boolean deleteSelection()
Used to delete the current selection before an insertion or as part of a deletion.

Returns:
whether or not the deletion was performed.

getInsertMode

public boolean getInsertMode()
Returns the insertion mode status of the textarea. Insertion mode is invoked by hitting the "INSERT" key. While in insertion mode, if you type a character key in front of some text the character key inserted will replace the first character of the text in front of the insertion point.

Returns:
whether or not insertion mode is on.

sequenceAdded

public void sequenceAdded(GDEModel source,
                          int index,
                          Cell sequence)
Called when a sequence is added to a Dataset.

Specified by:
sequenceAdded in interface GDEModelListener
Parameters:
index - the location the sequence was added.
sequence - the sequence added.
source - the source of the sequence insertion event.

sequenceChanged

public void sequenceChanged(GDEModel source,
                            int index,
                            Cell sequence,
                            java.lang.String key)
Called when a field in a sequence is modified.

Specified by:
sequenceChanged in interface GDEModelListener
Parameters:
index - the location of the sequence.
sequence - the sequence modified.
key - the value modified.
source - the source of the sequence alteration message.

sequenceRemoved

public void sequenceRemoved(GDEModel source,
                            int index,
                            Cell sequence)
Called when a sequence is removed from a Dataset.

Specified by:
sequenceRemoved in interface GDEModelListener
Parameters:
index - the location (line number) where the sequence was removed from.
sequence - the sequence removed from the SeDataset
source - the source of the sequence removal message.

changePosition

protected void changePosition(boolean select,
                              int newx,
                              int newy)
Updates/moves the cursor to the new position.

Parameters:
select - whether or not the position should maintain selection status (i.e. true for SHIFT key).
newx - the column co-ordinate of the new position.
newy - the row co-ordinate of the new position.

clearSelection

public void clearSelection()
Clears the current text selection


isSelectionEmpty

public boolean isSelectionEmpty()
Tests if the selection shape is empty

Returns:
true if the selection is empty

getMinSX

protected int getMinSX()
Gets the minimum X co-ordinate of the selection area.

Returns:
Math.min(sx1, sx2)

getMaxSX

protected int getMaxSX()
Gets the maximum X co-ordinate of the selection area.

Returns:
Math.max(sx1, sx2)

getMinSY

protected int getMinSY()
Gets the minimum Y co-ordinate of the selection area.

Returns:
Math.min(sy1, sy2)

getMaxSY

protected int getMaxSY()
Gets the maximum Y co-ordinate of the selection area.

Returns:
Math.max(y1, y2)

isSelectedLine

protected boolean isSelectedLine(int y)
This function is used to test if a line is selected. Currently in this class, the test is just if the selection is within the bounds of sy1 and sy2.

Parameters:
y - the Y co-ordinate (or line number) to test.
Returns:
true if the line is within the selection area, and should be printed as such.

BioLegato 0.7.3 GDE plugin

Copyright © 2008-2010 University of Manitoba.