public class SequenceTextArea extends javax.swing.JComponent implements javax.swing.event.ListDataListener, SequenceCanvasObject, 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 been upgraded to also support different colour schemes, sequence documents, and many other features.
The rectangular selection model is based on GDE. In the rectangular selection model (also called the "box" or "column" selection model), a user selects text by "drawing" a box around it. This method is described on the following page as the "box" selection model: http://www.physics.nyu.edu/grierlab/idl_html_help/Editor6.html
Colour schemes are provided by the ColourMask class.
ColourMask
,
Serialized Formjavax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
SequenceTextArea |
blTextAreaSelf
Self-reference (used for inner-classes).
|
protected int |
col
The current column number/X-coordinate of the text caret cursor.
|
protected int |
colWidth
The width of each column in the text area.
|
protected Dataset |
datamodel
This reference is used to connect the data model/Dataset sequence object
container to the text area.
|
protected boolean |
insertMode
If set to true, when the user types text, it will overwrite whatever
existing text is already under the cursor.
|
protected javax.swing.JPopupMenu |
popup
The right click menu for the text area.
|
protected int |
row
The current row number/Y-coordinate of the text caret cursor.
|
protected int |
rowHeight
The height of each row (in pixels) in the text area.
|
static java.awt.Color |
SELECTBG
The background colour of selected text.
|
static java.awt.Color |
SELECTFG
The foreground colour of selected text.
|
protected boolean |
selectionMouse
Used to track mouse holds and releases.
|
protected boolean |
selectionMove
Used to track whether the shift key is pressed.
|
static long |
serialVersionUID
This constant is used for serialization purposes.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
SequenceTextArea(SequenceCanvas canvas,
Dataset datamodel)
Creates a new instance of a SequenceTextArea.
|
Modifier and Type | Method and Description |
---|---|
void |
changeCase()
Changes the case of the currently selected sequence.
|
protected void |
changePosition(boolean select,
int newx,
int newy)
Updates/moves the cursor to a new position.
|
void |
clearSelection()
Clears the current text selection (does NOT delete any text).
|
void |
contentsChanged(javax.swing.event.ListDataEvent e)
This method is called when a field in a sequence is modified.
|
boolean |
delete(int x,
int y,
int w,
int h,
boolean groupdel)
Deletes characters from the textarea's underlying Dataset
NOTE: deletions are performed in a sequential manner
|
void |
deleteSelection()
Deletes any text currently selected.
|
boolean |
deleteSelection(boolean protect)
Deletes any text currently selected.
|
void |
insert(int x,
int y,
char[] text,
boolean groupinsert)
Inserts a string into the textarea's underlying Dataset object.
|
void |
insertionMode(boolean mode)
This method receives insertion mode change updates.
|
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 |
isSelectionEmpty()
Tests if the text selection shape is empty (i.e.
|
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 keys typed within the text area.
|
void |
mouseClicked(java.awt.event.MouseEvent event)
Handles mouse clicks, by moving the text caret cursor.
|
void |
mouseDragged(java.awt.event.MouseEvent event)
Handles mouse drags.
|
void |
mouseEntered(java.awt.event.MouseEvent event)
Handles the mouse entering the text area.
|
void |
mouseExited(java.awt.event.MouseEvent event)
Handles the mouse exiting the text area.
|
void |
mouseMoved(java.awt.event.MouseEvent event)
Handles general 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 sequence text area component to a graphics object.
|
void |
readIn(DataFormat format,
java.util.Scanner source,
boolean overwrite)
Reads contents into the text area.
|
protected void |
refreshSize()
Refreshes the size of the text area (for scroll size purposes).
|
protected int |
row2Y(int r)
Converts a Dataset sequence container row number into a
Y coordinate "on the screen" (in the Graphics object).
|
void |
setFont(java.awt.Font font)
Updates the font for the text area.
|
void |
textLengthChanged(int x,
int y,
int length)
Manages text length changes.
|
void |
updateLength(int start,
int end)
Updates the internal counter which stores the length of the longest line
in the text area.
|
void |
writeOut(DataFormat fmt,
java.lang.Appendable dest)
Writes the current contents of the canvas object to an Appendable object.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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
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, transferFocusDownCycle, validate, validateTree
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, getAccessibleContext, 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, 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, transferFocusBackward, transferFocusUpCycle
protected int rowHeight
protected int colWidth
protected boolean insertMode
protected boolean selectionMove
Used to track whether the shift key is pressed. This will determine whether the selection is resized or cancelled when the user moved the cursor using the keyboard (up/down/left/right), or when the user clicks somewhere within the text area.
To sum up: (1) if this variable is set to false, then the SHIFT key is NOT currently pressed, therefore moving the cursor in the text area should CANCEL the current selection (if any text is selected); (2) if this variable is set to true then the SHIFT key IS currently pressed, therefore moving the cursor in the text area should SHRINK OR STRETCH the current selection (or create a new selection if no text is selected).
selectionMouse
protected boolean selectionMouse
selectionMove
protected int col
row
,
sx
,
sy
,
changePosition(boolean, int, int)
protected int row
col
,
sx
,
sy
,
changePosition(boolean, int, int)
protected javax.swing.JPopupMenu popup
SequenceCanvas
protected Dataset datamodel
public final SequenceTextArea blTextAreaSelf
public static final java.awt.Color SELECTFG
public static final java.awt.Color SELECTBG
public static final long serialVersionUID
public SequenceTextArea(SequenceCanvas canvas, Dataset datamodel)
canvas
- the parent canvas of the text area.datamodel
- the data model to view the text from.public void paintComponent(java.awt.Graphics gfx)
paintComponent
in class javax.swing.JComponent
gfx
- the graphics instance to paint the window to.public final void setFont(java.awt.Font font)
setFont
in class javax.swing.JComponent
font
- the new font for the text area.public void keyTyped(java.awt.event.KeyEvent event)
keyTyped
in interface java.awt.event.KeyListener
event
- the KeyEvent for the key typed.SequenceCanvas.editable
,
insertMode
,
changePosition(boolean, int, int)
,
deleteSelection(boolean)
,
Dataset.delete(int, int, int, boolean)
,
Dataset.insert(int, int, char[], int, int, boolean)
,
Dataset.getSequenceLength(int)
public void keyPressed(java.awt.event.KeyEvent event)
keyPressed
in interface java.awt.event.KeyListener
event
- the KeyEvent for the key pressed.SequenceCanvas.cutAct
,
SequenceCanvas.copyAct
,
SequenceCanvas.pasteAct
,
insertMode
,
selectionMove
,
changePosition(boolean, int, int)
,
deleteSelection(boolean)
public void keyReleased(java.awt.event.KeyEvent event)
keyReleased
in interface java.awt.event.KeyListener
event
- the KeyEvent for the key released.selectionMove
,
changePosition(boolean, int, int)
public void mouseClicked(java.awt.event.MouseEvent event)
mouseClicked
in interface java.awt.event.MouseListener
event
- the MouseEvent object corresponding to the mouse click.public void mousePressed(java.awt.event.MouseEvent event)
mousePressed
in interface java.awt.event.MouseListener
event
- the MouseEvent corresponding to the mouse button press.public void mouseReleased(java.awt.event.MouseEvent event)
mouseReleased
in interface java.awt.event.MouseListener
event
- the MouseEvent corresponding to the mouse button release.public void mouseEntered(java.awt.event.MouseEvent event)
mouseEntered
in interface java.awt.event.MouseListener
event
- the MouseEvent object corresponding to the mouse entering
the text area.public void mouseExited(java.awt.event.MouseEvent event)
mouseExited
in interface java.awt.event.MouseListener
event
- the MouseEvent object corresponding to the mouse leaving
the text area.public void mouseDragged(java.awt.event.MouseEvent event)
mouseDragged
in interface java.awt.event.MouseMotionListener
event
- the MouseEvent object corresponding to the mouse drag.public void mouseMoved(java.awt.event.MouseEvent event)
mouseMoved
in interface java.awt.event.MouseMotionListener
event
- the MouseEvent corresponding to text area mouse movement.public void changeCase()
changeCase
in interface SequenceCanvasObject
public void insert(int x, int y, char[] text, boolean groupinsert)
Inserts a string into the textarea's underlying Dataset object.
NOTE: this is a wrapper method for insert(x, y, data).
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.groupinsert
- whether to insert the text in all sequences that are
part of the same group as 'y'.public boolean delete(int x, int y, int w, int h, boolean groupdel)
x
- the X-offset/column number to start the deletion from.y
- the Y-offset/line number to start deleting characters from.w
- the width of the deletion; the number of characters along the
X-axis to delete, for each sequence. If a sequence affected by
the deletion is shorter than the deletion zone (x to x+w), then
that sequence will have its tail deleted instead (from x to the
end of the sequence). This avoids any errors.h
- the height of the deletion; the number of sequences along the
Y-axis to be affected by the deletion.groupdel
- whether to delete from sequences outside x,y,w,h that are
grouped to at least one sequence within x,y,w,h.public boolean deleteSelection(boolean protect)
Deletes any text currently selected. This function is often used before an insertion or as part of a deletion.
This function also obeys all sequence permissions/protections (as long as the protect boolean is set to true). In the case of text insertion, text may NOT be inserted if it contains a protected character. For example, if the sequence is a protein sequence and the unambiguous character protections are set to true, then the text "BZAZ" may not be inserted because it contains one unambiguous character (A, for alanine); however, the text "BZZZ" may be inserted, as long as the ambiguous character protections are set to false. See Dataset.isProtectionsOn for more information about character protections.
protect
- whether to protect the sequences via testing of sequenc
protections for each character deleted.keyTyped(java.awt.event.KeyEvent)
,
keyPressed(java.awt.event.KeyEvent)
,
readIn(org.biolegato.sequence.data.DataFormat, java.util.Scanner, boolean)
,
Dataset.isProtectionsOn(org.biolegato.sequence.data.Seq.Type, boolean, boolean, boolean, char[], int, int)
public void deleteSelection()
deleteSelection
in interface SequenceCanvasObject
SequenceCanvasObject.deleteSelection()
public void contentsChanged(javax.swing.event.ListDataEvent e)
contentsChanged
in interface javax.swing.event.ListDataListener
e
- the list data event corresponding to the modification. This
object contains information about the coordinates affected, and
is used to avoid repainting the canvas. Although, this method
does accept null as a parameter, passing null should be avoided,
because every time the null value is passed, the ENTIRE text
area is repainted (thereby slowing BioLegato).public void intervalAdded(javax.swing.event.ListDataEvent e)
intervalAdded
in interface javax.swing.event.ListDataListener
e
- the list data event corresponding to the addition. This object
contains information about the coordinates affected, and is used
to avoid repainting the canvas. Although, this method does
accept null as a parameter, passing null should be avoided,
because every time the null value is passed, the ENTIRE text
area is repainted (thereby slowing BioLegato).public void intervalRemoved(javax.swing.event.ListDataEvent e)
intervalRemoved
in interface javax.swing.event.ListDataListener
e
- the list data event corresponding to the deletion. This object
contains information about the coordinates affected, and is used
to avoid repainting the canvas. Although, this method does
accept null as a parameter, passing null should be avoided,
because every time the null value is passed, the ENTIRE text
area is repainted (thereby slowing BioLegato).public void textLengthChanged(int x, int y, int length)
x
- the X-coordinate/column where the text length change began.y
- the Y-coordinate/line number where the text length was changed.length
- the number of characters, by which the line was extended.
If length is less than zero, the line will be shrunk
instead of extended.public void insertionMode(boolean mode)
mode
- the new insertion mode status for the text area.SequenceCanvas.insertionMode(boolean)
,
keyPressed(java.awt.event.KeyEvent)
protected void changePosition(boolean select, int newx, int newy)
select
- whether 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.public final void clearSelection()
changePosition(boolean, int, int)
protected final void refreshSize()
Component.setSize(java.awt.Dimension)
,
JComponent.setPreferredSize(java.awt.Dimension)
,
JComponent.revalidate()
public final boolean isSelectionEmpty()
protected final int row2Y(int r)
r
- the row number to convert.rowHeight
public void updateLength(int start, int end)
start
- the first offset to examine for the updateend
- the last offset to examine for the updatelongestline
,
refreshSize()
public void readIn(DataFormat format, java.util.Scanner source, boolean overwrite) throws java.io.IOException
readIn
in interface SequenceCanvasObject
format
- the file format to write the data in.source
- the data source to read data from.overwrite
- whether to overwrite the data currently selected
in the canvas object.java.io.IOException
- throws an IOException if there is any error
reading data from the Scanner object.public void writeOut(DataFormat fmt, java.lang.Appendable dest) throws java.io.IOException
writeOut
in interface SequenceCanvasObject
fmt
- the format to write the data in.dest
- the destination Appendable object to write the data.java.io.IOException
- throws an IOException if there is any error
appending the data to the Appendable object.Copyright © 2008-2022 University of Manitoba.