dog.gui
Class DTextArea

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--dog.gui.DContainer
                    |
                    +--dog.gui.DTextComponent
                          |
                          +--dog.gui.DTextArea
All Implemented Interfaces:
java.awt.event.AdjustmentListener, java.awt.datatransfer.ClipboardOwner, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, Referential, java.io.Serializable, TimerListener

public class DTextArea
extends DTextComponent
implements java.awt.event.AdjustmentListener, TimerListener

A component that allows the editing of multiple lines of text.

You may specify an alignment (LEFT, CENTER, or RIGHT) for the text within the component.

You can choose a scrollbar displaying policy and whether or not to wrap lines. By default, a vertical scrollbar is used if required, and word wrap is on.

See Also:
Serialized Form

Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  java.awt.event.ActionListener actionListener
           
protected  int align
          The alignment of the text.
static int CENTER
          The center alignment.
protected  int columns
          The number of columns in the DTextArea.
protected  boolean filled
          Is this component filled?
protected  boolean focus
          Do we currently have the focus?
protected  DScrollbar horizontal
          The horizontal scrollbar.
static int LEFT
          The left alignment.
protected  java.awt.Point pos
           
static int RIGHT
          The right alignment.
protected  int rows
          The number of rows in the DTextArea.
static int SCROLLBARS_BOTH
          Create and display both vertical and horizontal scrollbars.
static int SCROLLBARS_HORIZONTAL_ONLY
          Create and display horizontal scrollbar only.
static int SCROLLBARS_NONE
          Do not create or display any scrollbars for the text area.
static int SCROLLBARS_VERTICAL_ONLY
          Create and display vertical scrollbar only.
protected  int scrollbarVisibility
          The scrollbar policy.
protected  java.awt.Point selEnd
           
protected  java.awt.Point selStart
           
protected  int tabWidth
          Number of spaces to expand tabs to.
protected  java.lang.String[] textRows
           
protected  DScrollbar vertical
          The vertical scrollbar.
 
Fields inherited from class dog.gui.DTextComponent
editable, position, selectionEnd, selectionStart, text, textListener
 
Fields inherited from class dog.gui.DContainer
cancelButton, defaultButton, EAST, NORTH, NORTHEAST, NORTHWEST, reference, SOUTH, SOUTHEAST, SOUTHWEST, tooltip, WEST
 
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
DTextArea()
          Constructs a new text area.
DTextArea(java.lang.String text)
          Constructs a new text area initialized with the specified text.
DTextArea(java.lang.String text, int align)
          Constructs a new text area with the specified text and alignment.
DTextArea(java.lang.String text, int align, int scrollbarVisibility)
          Constructs a new text area with the specified text, alignment, and scrollbar policy.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Adds the specified action listener to receive action events from this component.
 void adjustmentValueChanged(java.awt.event.AdjustmentEvent event)
          A scrollbar was moved.
 void append(java.lang.String text)
          Inserts the specified string at the end.
 void deleteLeft()
          Deletes the character to the left of the caret.
 void deleteRight()
          Deletes the character to the right of the caret.
 void deleteSelection()
          Removes the selected text.
 void doLayout()
          Lays out this area.
 int getAlign()
          Returns the alignment of the text in this text area.
 int getCaretPosition()
          Returns the position of the text insertion caret.
 java.awt.Point getCaretPositionPoint()
          Returns the (x,y) coordinates of the text insertion caret.
 int getColumns()
          Returns the number of columns in this text area.
 java.awt.Dimension getMinimumSize()
          Returns the minimum size for this component.
protected  java.awt.Point getPoint(int offset)
          Returns the coordinates represented by the specified text offset.
 java.awt.Dimension getPreferredSize()
          Returns the preferred size for this component.
 int getRows()
          Returns the number of rows in the text area.
 int getScrollbarVisibility()
          Returns the scrollbar policy for this text area.
 int getSelectionEnd()
          Returns the selected text's end position.
 java.awt.Point getSelectionEndPoint()
          Returns the (x,y) coordinates of the selected text's end position.
 int getSelectionStart()
          Returns the selected text's start position.
 java.awt.Point getSelectionStartPoint()
          Returns the (x,y) coordinates of the selected text's start position.
 java.lang.String getText()
          Returns the entire text of this text area as a String.
 void insert(char ch, boolean selected)
          Inserts the specified character at the current caret position.
 void insert(java.lang.String text, boolean selected)
          Inserts the specified string at the current caret position.
 boolean isFilled()
          Indicates whether this component is filled.
 boolean isFocusTraversable()
          This component is focus-traversable if it is not disabled.
 void moveDown(boolean selected)
          Moves the caret down one line.
 void moveLeft(boolean selected)
          Moves the caret one character left.
 void moveLineEnd(boolean selected)
          Moves the caret to the end of the line.
 void moveLineStart(boolean selected)
          Moves the caret to the start of the line.
 void moveRight(boolean selected)
          Moves the caret one character right.
 void moveUp(boolean selected)
          Moves the caret up one line.
 void moveWordLeft(boolean selected)
          Moves the caret one word left.
 void moveWordRight(boolean selected)
          Moves the caret one word right.
 void paint(java.awt.Graphics g)
          Paints this view.
protected  java.lang.String paramString()
          Returns a parameter string for this component.
protected  void processActionEvent(java.awt.event.ActionEvent event)
          Processes action events occurring on this component by dispatching them to any registered ActionListener objects.
protected  void processEvent(java.awt.AWTEvent event)
          Processes events on this component.
protected  void processFocusEvent(java.awt.event.FocusEvent event)
          Process focus events.
protected  void processKeyEvent(java.awt.event.KeyEvent event)
          Process key events.
protected  void processMouseEvent(java.awt.event.MouseEvent event)
          Process mouse events.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent event)
          Process mouse motion events.
 void readFrom(java.io.Reader reader)
          Reads into the textarea buffer from a Reader.
 void removeActionListener(java.awt.event.ActionListener listener)
          Removes the specified action listener so that it no longer receives action events from this component.
 void select(int selectionStart, int selectionEnd)
          Selects the text found between the specified start and end locations.
 void select(java.awt.Point selectionStart, java.awt.Point selectionEnd)
          Selects the text found between the specified start and end coordinates.
 void selectAll()
          Selects all the text.
 void setAlign(int align)
          Sets the alignment of the text in this text area.
 void setColumns(int columns)
          Sets the number of columns for this text area.
 void setFilled(boolean filled)
          Sets whether to fill this component with the fill colour.
 void setRows(int rows)
          Sets the number of rows for this text area.
 void setScrollbarVisibility(int scrollbarVisibility)
          Sets the scrollbar policy for this text area.
 void setSelectionEnd(int selectionEnd)
          Sets the selection end to the specified position.
 void setSelectionStart(int selectionStart)
          Sets the selection start to the specified position.
 void setText(java.lang.String text)
          Sets the entire text of this text area.
 void timerFired(TimerEvent event)
          The timer fired, blink the caret.
 void writeTo(java.io.Writer writer)
          Writes the textarea buffer into a Writer.
 
Methods inherited from class dog.gui.DTextComponent
addTextListener, copySelection, cutSelection, getSelectedText, isEditable, lostOwnership, pasteSelection, processTextEvent, removeTextListener, setEditable
 
Methods inherited from class dog.gui.DContainer
addImpl, addPropertyChangeListener, alignParamString, drawActiveButtonBorder, drawActiveOptionBorder, drawArrow, drawBorder, drawButtonBorder, drawCheckbox, drawDarkBorder, drawDefaultButtonBorder, drawDisabledBorder, drawDisabledCheckbox, drawDisabledOption, drawExpander, drawFocusBorder, drawImage, drawLabel, drawOption, drawOptionBorder, drawPressedBorder, getCancelButton, getComponent, getDefaultButton, getDefaultToolkit, getImage, getImage, getImage, getReference, getRootPane, getTooltip, isPreloadImages, processCancelAction, processDefaultAction, removePropertyChangeListener, setCancelButton, setDefaultButton, setEnabled, setPreloadImages, setReference, setTooltip, toString
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addNotify, countComponents, deliverEvent, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleContext, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CENTER

public static final int CENTER
The center alignment.

LEFT

public static final int LEFT
The left alignment.

RIGHT

public static final int RIGHT
The right alignment.

SCROLLBARS_NONE

public static final int SCROLLBARS_NONE
Do not create or display any scrollbars for the text area.

SCROLLBARS_HORIZONTAL_ONLY

public static final int SCROLLBARS_HORIZONTAL_ONLY
Create and display horizontal scrollbar only.

SCROLLBARS_VERTICAL_ONLY

public static final int SCROLLBARS_VERTICAL_ONLY
Create and display vertical scrollbar only.

SCROLLBARS_BOTH

public static final int SCROLLBARS_BOTH
Create and display both vertical and horizontal scrollbars.

align

protected int align
The alignment of the text.

scrollbarVisibility

protected int scrollbarVisibility
The scrollbar policy.

filled

protected boolean filled
Is this component filled?

tabWidth

protected int tabWidth
Number of spaces to expand tabs to.

horizontal

protected DScrollbar horizontal
The horizontal scrollbar.

vertical

protected DScrollbar vertical
The vertical scrollbar.

focus

protected transient boolean focus
Do we currently have the focus?

actionListener

protected transient java.awt.event.ActionListener actionListener

textRows

protected java.lang.String[] textRows

selStart

protected java.awt.Point selStart

selEnd

protected java.awt.Point selEnd

pos

protected java.awt.Point pos

rows

protected int rows
The number of rows in the DTextArea.

columns

protected int columns
The number of columns in the DTextArea.
Constructor Detail

DTextArea

public DTextArea()
Constructs a new text area.

DTextArea

public DTextArea(java.lang.String text)
Constructs a new text area initialized with the specified text.
Parameters:
text - the text to be displayed

DTextArea

public DTextArea(java.lang.String text,
                 int align)
Constructs a new text area with the specified text and alignment.
Parameters:
text - the text to be displayed
align - LEFT, CENTER, or RIGHT

DTextArea

public DTextArea(java.lang.String text,
                 int align,
                 int scrollbarVisibility)
Constructs a new text area with the specified text, alignment, and scrollbar policy.
Parameters:
text - the text to be displayed
align - LEFT, CENTER, or RIGHT
scrollbarVisibility - SCROLLBARS_NONE, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_VERTICAL_ONLY, or SCROLLBARS_BOTH
Method Detail

getText

public java.lang.String getText()
Returns the entire text of this text area as a String.
Overrides:
getText in class DTextComponent
See Also:
setText(java.lang.String)

setText

public void setText(java.lang.String text)
Sets the entire text of this text area.
Overrides:
setText in class DTextComponent
See Also:
getText()

getSelectionStart

public int getSelectionStart()
Returns the selected text's start position.
Overrides:
getSelectionStart in class DTextComponent

getSelectionStartPoint

public java.awt.Point getSelectionStartPoint()
Returns the (x,y) coordinates of the selected text's start position.

getPoint

protected java.awt.Point getPoint(int offset)
Returns the coordinates represented by the specified text offset.

setSelectionStart

public void setSelectionStart(int selectionStart)
Sets the selection start to the specified position. The new starting point is constrained to be before or at the current selection end.
Overrides:
setSelectionStart in class DTextComponent
Parameters:
selectionStart - the start position of the text

getSelectionEnd

public int getSelectionEnd()
Returns the selected text's end position.
Overrides:
getSelectionEnd in class DTextComponent

getSelectionEndPoint

public java.awt.Point getSelectionEndPoint()
Returns the (x,y) coordinates of the selected text's end position.

setSelectionEnd

public void setSelectionEnd(int selectionEnd)
Sets the selection end to the specified position. The new end point is constrained to be at or after the current selection start.
Overrides:
setSelectionEnd in class DTextComponent
Parameters:
selectionEnd - the start position of the text

select

public void select(int selectionStart,
                   int selectionEnd)
Selects the text found between the specified start and end locations.
Overrides:
select in class DTextComponent
Parameters:
selectionStart - the start position of the text
selectionEnd - the end position of the text

select

public void select(java.awt.Point selectionStart,
                   java.awt.Point selectionEnd)
Selects the text found between the specified start and end coordinates.
Parameters:
selectionStart - the start coordinates
selectionEnd - the end coordinates

selectAll

public void selectAll()
Selects all the text.
Overrides:
selectAll in class DTextComponent

getCaretPosition

public int getCaretPosition()
Returns the position of the text insertion caret.
Overrides:
getCaretPosition in class DTextComponent
Following copied from class: dog.gui.DTextComponent
Returns:
the position of the text insertion caret.

getCaretPositionPoint

public java.awt.Point getCaretPositionPoint()
Returns the (x,y) coordinates of the text insertion caret.

moveLeft

public void moveLeft(boolean selected)
Moves the caret one character left.
Overrides:
moveLeft in class DTextComponent

moveRight

public void moveRight(boolean selected)
Moves the caret one character right.
Overrides:
moveRight in class DTextComponent

moveWordLeft

public void moveWordLeft(boolean selected)
Moves the caret one word left.
Overrides:
moveWordLeft in class DTextComponent

moveWordRight

public void moveWordRight(boolean selected)
Moves the caret one word right.
Overrides:
moveWordRight in class DTextComponent

moveLineStart

public void moveLineStart(boolean selected)
Moves the caret to the start of the line.
Overrides:
moveLineStart in class DTextComponent

moveLineEnd

public void moveLineEnd(boolean selected)
Moves the caret to the end of the line.
Overrides:
moveLineEnd in class DTextComponent

moveUp

public void moveUp(boolean selected)
Moves the caret up one line.

moveDown

public void moveDown(boolean selected)
Moves the caret down one line.

deleteSelection

public void deleteSelection()
Removes the selected text.
Overrides:
deleteSelection in class DTextComponent

deleteRight

public void deleteRight()
Deletes the character to the right of the caret.
Overrides:
deleteRight in class DTextComponent

deleteLeft

public void deleteLeft()
Deletes the character to the left of the caret.
Overrides:
deleteLeft in class DTextComponent

insert

public void insert(char ch,
                   boolean selected)
Inserts the specified character at the current caret position.
Overrides:
insert in class DTextComponent

insert

public void insert(java.lang.String text,
                   boolean selected)
Inserts the specified string at the current caret position.
Overrides:
insert in class DTextComponent

append

public void append(java.lang.String text)
Inserts the specified string at the end.

getAlign

public int getAlign()
Returns the alignment of the text in this text area.
See Also:
setAlign(int)

setAlign

public void setAlign(int align)
Sets the alignment of the text in this text area.
Parameters:
align - LEFT, CENTER, or RIGHT
Throws:
java.lang.IllegalArgumentException - if the alignment is not one of the above.
See Also:
getAlign()

isFilled

public boolean isFilled()
Indicates whether this component is filled.

setFilled

public void setFilled(boolean filled)
Sets whether to fill this component with the fill colour.

getScrollbarVisibility

public int getScrollbarVisibility()
Returns the scrollbar policy for this text area.
See Also:
setScrollbarVisibility(int)

setScrollbarVisibility

public void setScrollbarVisibility(int scrollbarVisibility)
Sets the scrollbar policy for this text area.
Parameters:
scrollbarVisibility - SCROLLBARS_NONE, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_VERTICAL_ONLY, or SCROLLBARS_BOTH
Throws:
java.lang.IllegalArgumentException - if the policy is not one of the above.
See Also:
getScrollbarVisibility()

getRows

public int getRows()
Returns the number of rows in the text area.
See Also:
setRows(int), getColumns()

setRows

public void setRows(int rows)
Sets the number of rows for this text area.
Parameters:
rows - the number of rows.
Throws:
java.lang.IllegalArgumentException - if the value supplied for rows is less than zero.
See Also:
getRows(), setColumns(int)

getColumns

public int getColumns()
Returns the number of columns in this text area.
See Also:
setColumns(int), getRows()

setColumns

public void setColumns(int columns)
Sets the number of columns for this text area.
Parameters:
columns - the number of columns.
Throws:
java.lang.IllegalArgumentException - if the value supplied for columns is less than zero.
See Also:
getColumns(), setRows(int)

readFrom

public void readFrom(java.io.Reader reader)
              throws java.io.IOException
Reads into the textarea buffer from a Reader. Useful if the reader content is larger than Integer.MAX_VALUE characters. This method does not return until a read() returns -1 (end of stream).
Parameters:
reader - the reader to read from.
See Also:
writeTo(java.io.Writer)

writeTo

public void writeTo(java.io.Writer writer)
             throws java.io.IOException
Writes the textarea buffer into a Writer. Useful if the buffer is larger than Integer.MAX_VALUE characters.
Parameters:
writer - the writer to write to.
See Also:
readFrom(java.io.Reader)

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the minimum size for this component.
Overrides:
getMinimumSize in class java.awt.Container

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size for this component.
Overrides:
getPreferredSize in class java.awt.Container

doLayout

public void doLayout()
Lays out this area.
Overrides:
doLayout in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Paints this view.
Overrides:
paint in class java.awt.Container

isFocusTraversable

public boolean isFocusTraversable()
This component is focus-traversable if it is not disabled.
Overrides:
isFocusTraversable in class java.awt.Component

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Adds the specified action listener to receive action events from this component.
Parameters:
listener - the action listener

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Removes the specified action listener so that it no longer receives action events from this component.
Parameters:
listener - the action listener

processEvent

protected void processEvent(java.awt.AWTEvent event)
Processes events on this component. If the event is an ActionEvent, it invokes the processActionEvent method, else it invokes its superclass's processEvent.
Overrides:
processEvent in class DTextComponent
Parameters:
event - the event

processActionEvent

protected void processActionEvent(java.awt.event.ActionEvent event)
Processes action events occurring on this component by dispatching them to any registered ActionListener objects.
Parameters:
event - the action event

processFocusEvent

protected void processFocusEvent(java.awt.event.FocusEvent event)
Process focus events.
Overrides:
processFocusEvent in class java.awt.Component

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent event)
Process key events.
Overrides:
processKeyEvent in class java.awt.Component

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent event)
Process mouse events.
Overrides:
processMouseEvent in class DContainer

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent event)
Process mouse motion events.
Overrides:
processMouseMotionEvent in class DContainer

timerFired

public void timerFired(TimerEvent event)
The timer fired, blink the caret.
Specified by:
timerFired in interface TimerListener

adjustmentValueChanged

public void adjustmentValueChanged(java.awt.event.AdjustmentEvent event)
A scrollbar was moved.
Specified by:
adjustmentValueChanged in interface java.awt.event.AdjustmentListener

paramString

protected java.lang.String paramString()
Returns a parameter string for this component.
Overrides:
paramString in class DTextComponent