anecho.gui
Class JMText

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by anecho.gui.JMText
All Implemented Interfaces:
java.awt.event.AdjustmentListener, java.awt.event.ComponentListener, java.awt.event.FocusListener, 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

public class JMText
extends java.awt.Container
implements java.awt.event.AdjustmentListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.ComponentListener, java.awt.event.FocusListener

A widget to display multicoloured text in a Java 1.1 environment with an effort made to clone the TextArea API as close as possible.

See Also:
Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int SCROLLBARS_BOTH
          JMSwingTextPane, a antialiasing TextPane
static int SCROLLBARS_HORIZONTAL_ONLY
          Do not show scroll bars
static int SCROLLBARS_NONE
          Show only horizontal scroll bars
static int SCROLLBARS_VERTICAL_ONLY
          Show only vertical scroll bars
 
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
JMText()
          JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)
JMText(int rows, int columns)
          JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)
JMText(java.lang.String text)
          JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)
JMText(java.lang.String text, int rows, int columns)
          JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)
JMText(java.lang.String text, int rows, int columns, int scrollbars)
          JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)
 
Method Summary
 void addKeyListener(java.awt.event.KeyListener listener)
          Allow a KeyListener to be added to this component.
 void addMouseListener(java.awt.event.MouseListener mouse)
          We need to make our own mouse-listener that'll report back to any listeners that may've registered to this component.
 void addNotify()
          This method notifies our component that it has been added to a new object.
 void addTextListener(java.awt.event.TextListener listener)
          Allow a TextListener to be added to this component.
 void adjustmentValueChanged(java.awt.event.AdjustmentEvent event)
          Monitor the scroll-bar adjustment values to see if "scrolling" of the text is required
 void append(java.lang.String str)
          Append the String to the JMText,
 void appendChar(char jchar, java.lang.String attrib)
          Append characters to JMText, one at a time, including the current attribute
 void componentHidden(java.awt.event.ComponentEvent event)
          If our component is hidden this method called, and internally recorded as being "minimised".
 void componentMoved(java.awt.event.ComponentEvent event)
          An empty method
 void componentResized(java.awt.event.ComponentEvent event)
          A method used to monitor if this component has been resized.
 void componentShown(java.awt.event.ComponentEvent event)
          This method is called when our component is shown and internally records the new size of our componenet and spools out any text that may have been held while it was minimised.
 void focusGained(java.awt.event.FocusEvent event)
          This method watches for the component to gain focus.
 void focusLost(java.awt.event.FocusEvent event)
          Empty method.
 java.awt.Dimension getPreferredSize()
          Calculate a preferred size from the text we have
 java.lang.String getSelectedText()
          return a String of the text currently selected in the JMText area
 int getSelectionEnd()
          Returns an integer value of where a selection ends.
 int getSelectionStart()
          Returns the beginning of a selection in an integer format based on the count of characters from the beginning of the text component.
 java.lang.String getText()
          Return a string of the text-content of JMText (does not return the markings)
 int getVerticalScrollbarPos()
          get the position of our vertical scrollbar
 boolean isDoubleBuffer()
          Report if we use double buffering for our display redraws
 void keyPressed(java.awt.event.KeyEvent event)
          The method to handle any KeyPresses.
 void keyReleased(java.awt.event.KeyEvent event)
          A method to handle a key being released
 void keyTyped(java.awt.event.KeyEvent event)
          A method to handle a key being typed.
 void mouseClicked(java.awt.event.MouseEvent event)
          This method handles mouse clicks for this component
 void mouseDragged(java.awt.event.MouseEvent event)
          The method is used to track mouse drags and properly support text selection via the mouse.
 void mouseEntered(java.awt.event.MouseEvent event)
          This method changes the cursor to the I-beam when it enters the text area.
 void mouseExited(java.awt.event.MouseEvent event)
          This method changes our cursor back to the default cursor (from the I-beam) when it leaves our component area.
 void mouseMoved(java.awt.event.MouseEvent event)
          Empty method.
 void mousePressed(java.awt.event.MouseEvent event)
          This method tracks when the mouse button is pressed...
 void mouseReleased(java.awt.event.MouseEvent event)
          This method watches for when the mouse is released and repaints our component.
 void paint(java.awt.Graphics graphicItem)
          The paint method will be over-ridden to give us complete control over this event
 java.awt.Point pointToArray(java.awt.Point pos)
          This translates a point on the screen into a location on our array of characters ! (This method is usually used in conjunction with marking text)
 void removeKeyListener(java.awt.event.KeyListener listener)
          Allow the removal of the given KeyListener from our component.
 void removeMouseListener(java.awt.event.MouseListener mouse)
          All registered MouseListeners to be removed from this component.
 void select(int selectionStart, int selectionEnd)
          Select a given area of text which will be indicated by highlighting
 void setCaretPosition(int position)
          This method allows setting of the cursor's position based on the count of characters from the beginning of the component.
 void setColumns(int newCols)
          Set the column-width of our magic widget! (That's the JMText widget, Y'know)
 void setDoubleBuffer(boolean status)
          Set our redraw status to use double buffering for our display redraws.
 void setEditable(boolean edit)
          Set the JMText area to be editable or not.
 void setFont(java.awt.Font newFont)
          Over-ride the setFont so that we can readjust our display for the new font-metrics
 void setMaxRows(int setMax)
          Set the maximum number of rows to be shown in the component.
 void setText(java.lang.String str)
          Set the text in JMText to whatever we are sent in the string, erasing everything else
 void setVerticalScrollbarPos(int pos)
          Set the position of our vertical scrollbar
 void update(java.awt.Graphics graphItem)
          This method passes to call to update the graphics on to our super-class.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

SCROLLBARS_BOTH

public static final int SCROLLBARS_BOTH
JMSwingTextPane, a antialiasing TextPane

See Also:
Constant Field Values

SCROLLBARS_VERTICAL_ONLY

public static final int SCROLLBARS_VERTICAL_ONLY
Show only vertical scroll bars

See Also:
Constant Field Values

SCROLLBARS_HORIZONTAL_ONLY

public static final int SCROLLBARS_HORIZONTAL_ONLY
Do not show scroll bars

See Also:
Constant Field Values

SCROLLBARS_NONE

public static final int SCROLLBARS_NONE
Show only horizontal scroll bars

See Also:
Constant Field Values
Constructor Detail

JMText

public JMText()
JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)


JMText

public JMText(java.lang.String text)
JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)

Parameters:
text - Text to be displayed after intial component creation

JMText

public JMText(int rows,
              int columns)
JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)

Parameters:
rows - Number of rows to be visible in the component
columns - Number of columns to be visible in the component

JMText

public JMText(java.lang.String text,
              int rows,
              int columns)
JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)

Parameters:
text - Text to initially be displayed when this component is created.
rows - Number of rows to be visible in the component
columns - Number of columns to be visible in the component

JMText

public JMText(java.lang.String text,
              int rows,
              int columns,
              int scrollbars)
JMText, a multi-colour text-area for Java 1.1 (originally developed for JamochaMUD)

Parameters:
text - Text to initially be displayed after creation of this component
rows - Number of rows in this component
columns - Number of columns in this component
scrollbars - Indicate whether scrollbars should be visible in this component
Method Detail

setMaxRows

public void setMaxRows(int setMax)
Set the maximum number of rows to be shown in the component.

Parameters:
setMax - Number of rows to be shown.

append

public void append(java.lang.String str)
Append the String to the JMText,

Parameters:
str - The string to be added to the JMText

appendChar

public void appendChar(char jchar,
                       java.lang.String attrib)
Append characters to JMText, one at a time, including the current attribute

Parameters:
jchar - the single char to be added
attrib - a "description" of the attributes of the character

paint

public void paint(java.awt.Graphics graphicItem)
The paint method will be over-ridden to give us complete control over this event

Overrides:
paint in class java.awt.Container
Parameters:
graphicItem - The Graphic object that we will draw on.

update

public void update(java.awt.Graphics graphItem)
This method passes to call to update the graphics on to our super-class.

Overrides:
update in class java.awt.Container
Parameters:
graphItem -

adjustmentValueChanged

public void adjustmentValueChanged(java.awt.event.AdjustmentEvent event)
Monitor the scroll-bar adjustment values to see if "scrolling" of the text is required

Specified by:
adjustmentValueChanged in interface java.awt.event.AdjustmentListener
Parameters:
event -

setText

public void setText(java.lang.String str)
Set the text in JMText to whatever we are sent in the string, erasing everything else

Parameters:
str - Text to set in the cleared JMText field. A null will leave the JMText area blank.

setCaretPosition

public void setCaretPosition(int position)
This method allows setting of the cursor's position based on the count of characters from the beginning of the component.

Parameters:
position - An integer-based position of the character counting from the first character of the component (not the first visible character)

getText

public java.lang.String getText()
Return a string of the text-content of JMText (does not return the markings)

Returns:
A string containing the entire text of the JMText including the "history"

setDoubleBuffer

public void setDoubleBuffer(boolean status)
Set our redraw status to use double buffering for our display redraws. Double buffering is a technique of "drawing" to a screen not visible to the user and then replacing the visible screen with the new one. When double buffering is not used the user can witness new information being written to the JMText area (if visible)

Parameters:
status - true enables double buffering while false disables it

isDoubleBuffer

public boolean isDoubleBuffer()
Report if we use double buffering for our display redraws

Returns:
true indicates double buffering is enabled, false indicates double buffering is not enabled.

select

public void select(int selectionStart,
                   int selectionEnd)
Select a given area of text which will be indicated by highlighting

Parameters:
selectionStart - The character number (from the beginning) to start the selection
selectionEnd - The number of characters from selectionStart

getSelectionEnd

public int getSelectionEnd()
Returns an integer value of where a selection ends.

Returns:
Return an integer representing the count from the beginning of the component. 0 is returned if there is not a selection present.

getSelectionStart

public int getSelectionStart()
Returns the beginning of a selection in an integer format based on the count of characters from the beginning of the text component.

Returns:
The integer value representing the beginning of the selection. 0 will be returned if there is no selection.

getSelectedText

public java.lang.String getSelectedText()
return a String of the text currently selected in the JMText area

Returns:
Returns a String of the selected text, if any.

setEditable

public void setEditable(boolean edit)
Set the JMText area to be editable or not. Currently this is only a "stub" call

Parameters:
edit - true indicates this area is editable, false disables editing

addTextListener

public void addTextListener(java.awt.event.TextListener listener)
Allow a TextListener to be added to this component.

Parameters:
listener - The listener to be added

addKeyListener

public void addKeyListener(java.awt.event.KeyListener listener)
Allow a KeyListener to be added to this component.

Overrides:
addKeyListener in class java.awt.Component
Parameters:
listener - The KeyListener to be added.

removeKeyListener

public void removeKeyListener(java.awt.event.KeyListener listener)
Allow the removal of the given KeyListener from our component.

Overrides:
removeKeyListener in class java.awt.Component
Parameters:
listener - The listener to be removed.

keyPressed

public void keyPressed(java.awt.event.KeyEvent event)
The method to handle any KeyPresses.

Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
event - The event we are listening for.

keyReleased

public void keyReleased(java.awt.event.KeyEvent event)
A method to handle a key being released

Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
event - The Key Released event we are waiting for.

keyTyped

public void keyTyped(java.awt.event.KeyEvent event)
A method to handle a key being typed.

Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
event - The event we are listening for.

componentHidden

public void componentHidden(java.awt.event.ComponentEvent event)
If our component is hidden this method called, and internally recorded as being "minimised".

Specified by:
componentHidden in interface java.awt.event.ComponentListener
Parameters:
event - The event we are listening for.

componentMoved

public void componentMoved(java.awt.event.ComponentEvent event)
An empty method

Specified by:
componentMoved in interface java.awt.event.ComponentListener
Parameters:
event - Empty event

componentResized

public void componentResized(java.awt.event.ComponentEvent event)
A method used to monitor if this component has been resized. This method is important for handling the number of columns/rows available.

Specified by:
componentResized in interface java.awt.event.ComponentListener
Parameters:
event - Our Component Resized Event

componentShown

public void componentShown(java.awt.event.ComponentEvent event)
This method is called when our component is shown and internally records the new size of our componenet and spools out any text that may have been held while it was minimised.

Specified by:
componentShown in interface java.awt.event.ComponentListener
Parameters:
event - Our component event.

addMouseListener

public void addMouseListener(java.awt.event.MouseListener mouse)
We need to make our own mouse-listener that'll report back to any listeners that may've registered to this component. Or something. This may not make a lotta sense, I'm tired.

Overrides:
addMouseListener in class java.awt.Component
Parameters:
mouse - The mouseListener to add to this componenet.

removeMouseListener

public void removeMouseListener(java.awt.event.MouseListener mouse)
All registered MouseListeners to be removed from this component.

Overrides:
removeMouseListener in class java.awt.Component
Parameters:
mouse - The MouseListener to be removed.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
This method handles mouse clicks for this component

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
event - Our Mouse Event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
This method changes the cursor to the I-beam when it enters the text area.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
event - Our event

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
This method changes our cursor back to the default cursor (from the I-beam) when it leaves our component area.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
event - Our mouse event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
This method tracks when the mouse button is pressed... used mostly when the user selects text.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
event - Our mouse event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
This method watches for when the mouse is released and repaints our component. This is to ensure that selections are properly painted.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
event - Our mouse event.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
The method is used to track mouse drags and properly support text selection via the mouse.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
event - Our mouse listener.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)
Empty method.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
event -

focusGained

public void focusGained(java.awt.event.FocusEvent event)
This method watches for the component to gain focus. If the component has not already been initialised, that method is called here.

Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
event - Our focus event

focusLost

public void focusLost(java.awt.event.FocusEvent event)
Empty method.

Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
event - Our focus event.

pointToArray

public java.awt.Point pointToArray(java.awt.Point pos)
This translates a point on the screen into a location on our array of characters ! (This method is usually used in conjunction with marking text)

Parameters:
pos - The coordinates of the mouse pointer in our component.
Returns:
This returns a Dimension indicating the column and row that coordinate with the mouse position on our component.

addNotify

public void addNotify()
This method notifies our component that it has been added to a new object.

Overrides:
addNotify in class java.awt.Container

setFont

public void setFont(java.awt.Font newFont)
Over-ride the setFont so that we can readjust our display for the new font-metrics

Overrides:
setFont in class java.awt.Container
Parameters:
newFont - The font to use in the current component.

setVerticalScrollbarPos

public void setVerticalScrollbarPos(int pos)
Set the position of our vertical scrollbar

Parameters:
pos - The position of our vertical scrollbar.

getVerticalScrollbarPos

public int getVerticalScrollbarPos()
get the position of our vertical scrollbar

Returns:
Returns an integer representation of the location of our scrollbar

setColumns

public void setColumns(int newCols)
Set the column-width of our magic widget! (That's the JMText widget, Y'know)

Parameters:
newCols - The number of columns this component should contain.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Calculate a preferred size from the text we have

Overrides:
getPreferredSize in class java.awt.Container
Returns:
Returns a dimension representative of the preferred size of our component.