BioLegato 0.7.5 GDE plugin

org.biolegato.gdesupport.canvas
Class GDETextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.biolegato.gdesupport.canvas.GDETextArea
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, javax.swing.event.ListDataListener, GDECanvasObject

public class GDETextArea
extends javax.swing.JComponent
implements javax.swing.event.ListDataListener, GDECanvasObject, 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
 GDETextArea blTextAreaSelf
          Self-reference for inner classes.
protected  int column
          The current column of the caret.
protected  int columnWidth
          The width of each column in the textarea
protected  Dataset 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  javax.swing.JPopupMenu popup
          The right click menu for the text area.
protected  int row
          The current row of the caret
protected  int rowHeight
          The height of each row in the textarea
static java.awt.Color SELECTBG
          The BACKG colour of selected text
static java.awt.Color SELECTFG
          The FOREG colour of selected text
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 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
GDETextArea(GDECanvas canvas, Dataset datamodel)
          Creates a new instance of GDETextArea
 
Method Summary
 void changeCase()
          Changes the case of the currently selected sequence (if the sequence is of inconsistent case, the case of the entire sequence is changed to the opposite case of the first character in the sequence.
protected  void changePosition(boolean select, int newx, int newy)
          Updates/moves the cursor to the new position.
 void clearSelection()
          Clears the current text selection
 int columnSize()
          Returns the size of one column of the textarea.
 void contentsChanged(javax.swing.event.ListDataEvent e)
          Called when a field in a sequence is modified.
 void copyClipboard()
          Used to obtain all of the text selected within the document.
 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
 void deleteSelection()
          Used to delete the current selection before an insertion or as part of a deletion.
 boolean gdeleteSection()
          Used to delete the current selection before an insertion or as part of a deletion.
 int getLineLength(int line)
          Retrieves the length of a line in the document.
 void insert(int x, int y, char[] text, boolean groupinsert)
          Inserts a string into the textarea's underlying Dataset NOTE: this is a wrapper method for insert(x, y, data)
 void intervalAdded(javax.swing.event.ListDataEvent e)
          Called when a sequence is added to a Dataset.
 void intervalRemoved(javax.swing.event.ListDataEvent e)
          Called when a sequence is removed from a Dataset.
 boolean isProtectionsOn(Seq.Type type, boolean protect_align, boolean protect_ambig, boolean protect_uambig, char[] test, int start, int end)
          Checks a string against all of a sequence's protection settings.
 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.
 boolean pdelete(int x, int y, int w, int h)
          Removes text from one line of a document (doesn't do any group processing - permission processing only).
protected  void refreshSize()
          Refreshes the size of the textarea (for scroll size purposes)
protected  int row2Y(int r)
          Converts a row number into a Y co-ordinate
 int rowSize()
          Returns the size of one row of the textarea.
 void setFont(java.awt.Font font)
          Updates the font for the canvas (ensures repaint)
 void updateLength(int start, int end)
          Updates the internal counter storing the length of the longest line
 void writeOut(DataFormat format, java.lang.Appendable dest)
          Writes the selected sequences out to an appendable object
 
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

rowHeight

protected int rowHeight
The height of each row in the textarea


columnWidth

protected int columnWidth
The width of each column in the textarea


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.


popup

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


datamodel

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


blTextAreaSelf

public final GDETextArea blTextAreaSelf
Self-reference for inner classes.


SELECTFG

public static final java.awt.Color SELECTFG
The FOREG colour of selected text


SELECTBG

public static final java.awt.Color SELECTBG
The BACKG colour of selected text


serialVersionUID

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

See Also:
Constant Field Values
Constructor Detail

GDETextArea

public GDETextArea(GDECanvas canvas,
                   Dataset datamodel)
Creates a new instance of GDETextArea

Parameters:
canvas - the parent canvas of the text area
datamodel - the data model to view the text from
Method Detail

copyClipboard

public void copyClipboard()
Used to obtain all of the text selected within the document.

Specified by:
copyClipboard in interface GDECanvasObject

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 final void setFont(java.awt.Font font)
Updates the font for the canvas (ensures repaint)

Overrides:
setFont in class javax.swing.JComponent
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 final void refreshSize()
Refreshes the size of the textarea (for scroll size purposes)


paste

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

Specified by:
paste in interface GDECanvasObject

changeCase

public void changeCase()
Changes the case of the currently selected sequence (if the sequence is of inconsistent case, the case of the entire sequence is changed to the opposite case of the first character in the sequence.

Specified by:
changeCase in interface GDECanvasObject

insert

public void insert(int x,
                   int y,
                   char[] text,
                   boolean groupinsert)
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.
text - the string to insert.

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)

pdelete

public boolean pdelete(int x,
                       int y,
                       int w,
                       int h)
Removes text from one line of a document (doesn't do any group processing - permission processing only).

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 lines)
Returns:
whether the deletion was a success.

gdeleteSection

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

Returns:
whether or not the deletion was performed.

deleteSelection

public void deleteSelection()
Used to delete the current selection before an insertion or as part of a deletion. NOTE: non-grouped

Specified by:
deleteSelection in interface GDECanvasObject

getLineLength

public int getLineLength(int line)
Retrieves the length of a line in the document.

Parameters:
line - the line line to find the length of.
Returns:
the length of the line (in characters).

isProtectionsOn

public boolean isProtectionsOn(Seq.Type type,
                               boolean protect_align,
                               boolean protect_ambig,
                               boolean protect_uambig,
                               char[] test,
                               int start,
                               int end)
Checks a string against all of a sequence's protection settings. This is done by obtaining the sequence's protection settings, the type of the sequence, and whether the text contains a character in any protected character class.

Parameters:
type - the type of the sequence to test against.
protect_align - the status of alignment character protection
protect_ambig - the status of ambiguous character protection
protect_uambig - the status of unambiguous character protection
test - the text to test.
start - the start index of text to test
end - the end index of text to test
Returns:
true if the text violates the protection settings of the sequence.

intervalAdded

public void intervalAdded(javax.swing.event.ListDataEvent e)
Called when a sequence is added to a Dataset.

Specified by:
intervalAdded in interface javax.swing.event.ListDataListener
Parameters:
e - the list data event corresponding to the addition

contentsChanged

public void contentsChanged(javax.swing.event.ListDataEvent e)
Called when a field in a sequence is modified.

Specified by:
contentsChanged in interface javax.swing.event.ListDataListener
Parameters:
e - the list data event corresponding to the modification

intervalRemoved

public void intervalRemoved(javax.swing.event.ListDataEvent e)
Called when a sequence is removed from a Dataset.

Specified by:
intervalRemoved in interface javax.swing.event.ListDataListener
Parameters:
e - the list data event corresponding to the deletion

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 final void clearSelection()
Clears the current text selection


isSelectionEmpty

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

Returns:
true if the selection is empty

row2Y

protected final int row2Y(int r)
Converts a row number into a Y co-ordinate

Parameters:
r - the row number
Returns:
the corresponding Y value

rowSize

public int rowSize()
Returns the size of one row of the textarea.

Returns:
the row size of textarea.

columnSize

public int columnSize()
Returns the size of one column of the textarea.

Returns:
the column size of textarea.

updateLength

public void updateLength(int start,
                         int end)
Updates the internal counter storing the length of the longest line

Parameters:
start - the first offset to examine for the update
end - the last offset to examine for the update

writeOut

public void writeOut(DataFormat format,
                     java.lang.Appendable dest)
              throws java.io.IOException
Writes the selected sequences out to an appendable object

Specified by:
writeOut in interface GDECanvasObject
Parameters:
format - the file format to write
dest - the destination of the sequence data
Throws:
java.io.IOException - throws an IOException if there is any error appending the data

BioLegato 0.7.5 GDE plugin

Copyright © 2008-2011 University of Manitoba.