cynosurex.awt
Class EnhancedTextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.TextComponent
          extended by java.awt.TextArea
              extended by cynosurex.awt.EnhancedTextArea
All Implemented Interfaces:
cynosurex.internal.AuthorCommon, cynosurex.internal.CommonInterface, cynosurex.internal.CompanyCommon, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible

public class EnhancedTextArea
extends java.awt.TextArea
implements cynosurex.internal.CommonInterface, java.lang.Runnable

EnhancedTextArea enhances the standard TextArea class by creating a multithreaded TextArea to calculate the current line and column position. The thread is set to minimum priority, sleeps, and only wakes up to do the calculation when the cursor position changes.

Version:
2.0
Author:
Chieh Cheng
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.TextArea
java.awt.TextArea.AccessibleAWTTextArea
 
Nested classes/interfaces inherited from class java.awt.TextComponent
java.awt.TextComponent.AccessibleAWTTextComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int PATCH_1_1
           
static int PATCH_1_5
           
static int PATCH_NONE
           
static int PATCH_UNDEFINED
           
 
Fields inherited from class java.awt.TextArea
SCROLLBARS_BOTH, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE, SCROLLBARS_VERTICAL_ONLY
 
Fields inherited from class java.awt.TextComponent
textListener
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface cynosurex.internal.CommonInterface
copyright, copyrightYears, notice, program, version
 
Fields inherited from interface cynosurex.internal.AuthorCommon
author, copyrightSymbol, noticeMsg, rights
 
Fields inherited from interface cynosurex.internal.CompanyCommon
company, email, website
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
EnhancedTextArea()
          Constructor to create an EnhancedTextArea.
EnhancedTextArea(int row, int col)
          Constructor to create an EnhancedTextArea with the specified row(s) and column(s).
EnhancedTextArea(java.lang.String str)
          Constructor to create an EnhancedTextArea with the specified String.
EnhancedTextArea(java.lang.String str, int row, int col)
          Constructor to create an EnhancedTextArea with the specified String, row(s), and column(s).
EnhancedTextArea(java.lang.String str, int row, int col, int scroll)
           
 
Method Summary
 int getCaretColPosition()
          This method returns the current caret column position.
 int getCaretRowPosition()
          This method returns the current caret row position.
 java.lang.Integer getNumOfCharacters()
          This method returns the number of characters (including all white space) in the text area.
 java.lang.Integer getNumOfLines()
          This method returns the number of lines in the text area.
 java.lang.Integer getNumOfWords()
          This method returns the number of words (separated by white space) in the text area.
 int getSelectionEnd()
          This method overrides the method in the super class.
 int getSelectionStart()
          This method overrides the method in the super class.
 int[] getSelectionStartAndEnd()
          This method returns the text selection start and end in an integer array with two elements.
 int getTextSelectionPatch()
          This method returns the text selection patch that is in use.
 void insert(java.lang.String text)
          Inserts text at the current caret position.
 void insert(java.lang.String str, int pos)
          Inserts the specified text at the specified position in this text area.
 void replaceRange(java.lang.String str, int start, int end)
          Replaces text between the indicated start and end positions with the specified replacement text.
 void run()
          This method is called by the EnhancedTextArea thread to update the current position of the cursor.
 void select(int start, int end)
           
 void setCaretPosition(int row, int col)
          This method sets the caret row and column position.
 void setCaretPosition(Position p)
          This method sets the caret row and column position.
 void setTextSelectionPatch(int patch)
          The Java 1.1 API introduced a bug in the TextArea class, which return the wrong text selection position on OS using both carriage-return and line-feed characters.
 
Methods inherited from class java.awt.TextArea
addNotify, append, appendText, getAccessibleContext, getColumns, getMinimumSize, getMinimumSize, getPreferredSize, getPreferredSize, getRows, getScrollbarVisibility, insertText, minimumSize, minimumSize, paramString, preferredSize, preferredSize, replaceText, setColumns, setRows
 
Methods inherited from class java.awt.TextComponent
addTextListener, enableInputMethods, getBackground, getCaretPosition, getInputMethodRequests, getListeners, getSelectedText, getText, getTextListeners, isEditable, processEvent, processTextEvent, removeNotify, removeTextListener, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setText
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PATCH_NONE

public static final int PATCH_NONE
See Also:
Constant Field Values

PATCH_1_1

public static final int PATCH_1_1
See Also:
Constant Field Values

PATCH_1_5

public static final int PATCH_1_5
See Also:
Constant Field Values

PATCH_UNDEFINED

public static final int PATCH_UNDEFINED
See Also:
Constant Field Values
Constructor Detail

EnhancedTextArea

public EnhancedTextArea()
Constructor to create an EnhancedTextArea.


EnhancedTextArea

public EnhancedTextArea(java.lang.String str)
Constructor to create an EnhancedTextArea with the specified String.

Parameters:
str - the string to be displayed in the text area

EnhancedTextArea

public EnhancedTextArea(int row,
                        int col)
Constructor to create an EnhancedTextArea with the specified row(s) and column(s).

Parameters:
row - row(s) of the initial text area
col - column(s) of the initial text area

EnhancedTextArea

public EnhancedTextArea(java.lang.String str,
                        int row,
                        int col)
Constructor to create an EnhancedTextArea with the specified String, row(s), and column(s).

Parameters:
str - the string to be displayed in the text area
row - row(s) of the initial text area
col - column(s) of the initial text area

EnhancedTextArea

public EnhancedTextArea(java.lang.String str,
                        int row,
                        int col,
                        int scroll)
Method Detail

getCaretColPosition

public int getCaretColPosition()
This method returns the current caret column position.


getCaretRowPosition

public int getCaretRowPosition()
This method returns the current caret row position.


getNumOfCharacters

public java.lang.Integer getNumOfCharacters()
This method returns the number of characters (including all white space) in the text area.


getNumOfLines

public java.lang.Integer getNumOfLines()
This method returns the number of lines in the text area.


getNumOfWords

public java.lang.Integer getNumOfWords()
This method returns the number of words (separated by white space) in the text area.


getSelectionStart

public int getSelectionStart()
This method overrides the method in the super class. It checks the text selection patch to determine if it needs to calculate the correct position. If not, it calls the method in the super class.

Overrides:
getSelectionStart in class java.awt.TextComponent
See Also:
getTextSelectionPatch(), setTextSelectionPatch(int)

getSelectionEnd

public int getSelectionEnd()
This method overrides the method in the super class. It checks the text selection patch to determine if it needs to calculate the correct position. If not, it calls the method in the super class.

Overrides:
getSelectionEnd in class java.awt.TextComponent
See Also:
getTextSelectionPatch(), setTextSelectionPatch(int)

getSelectionStartAndEnd

public int[] getSelectionStartAndEnd()
This method returns the text selection start and end in an integer array with two elements. This is the method which calculates the true cursor position if the text selection patch is set.

See Also:
getTextSelectionPatch(), setTextSelectionPatch(int)

getTextSelectionPatch

public int getTextSelectionPatch()
This method returns the text selection patch that is in use.

See Also:
setTextSelectionPatch(int)

insert

public void insert(java.lang.String text)
Inserts text at the current caret position.


insert

public void insert(java.lang.String str,
                   int pos)
Inserts the specified text at the specified position in this text area.

Overrides:
insert in class java.awt.TextArea

replaceRange

public void replaceRange(java.lang.String str,
                         int start,
                         int end)
Replaces text between the indicated start and end positions with the specified replacement text. The text at the end position will not be replaced. The text at the start position will be replaced (unless the start position is the same as the end position). The text position is zero-based. The inserted substring may be of a different length than the text it replaces.

Overrides:
replaceRange in class java.awt.TextArea

run

public void run()
This method is called by the EnhancedTextArea thread to update the current position of the cursor. Do not call this method.

Specified by:
run in interface java.lang.Runnable

select

public void select(int start,
                   int end)
Overrides:
select in class java.awt.TextComponent

setCaretPosition

public void setCaretPosition(Position p)
This method sets the caret row and column position.

Parameters:
p - position to set the caret

setCaretPosition

public void setCaretPosition(int row,
                             int col)
This method sets the caret row and column position.

Parameters:
row - row to set the caret
col - column to set the caret

setTextSelectionPatch

public void setTextSelectionPatch(int patch)
The Java 1.1 API introduced a bug in the TextArea class, which return the wrong text selection position on OS using both carriage-return and line-feed characters. If this patch is set to PATCH_1_1, EnhancedTextArea will calculate the correct text selection position.