anecho.gui
Class JMSwingText

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JScrollPane
                  extended by anecho.gui.JMSwingText
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.HyperlinkListener, javax.swing.ScrollPaneConstants

public class JMSwingText
extends javax.swing.JScrollPane
implements java.awt.event.MouseListener, java.awt.event.KeyListener, javax.swing.event.HyperlinkListener

JMSwingText, a Swing-based text area for ANSI colours (originally developed for JamochaMUD)

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JScrollPane
javax.swing.JScrollPane.AccessibleJScrollPane, javax.swing.JScrollPane.ScrollBar
 
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
static int PAGEDOWN
          This variable indicates moving the scrollbars one "page" down.
static int PAGEUP
          This variable indicates moving the scrollbars one "page" up
 
Fields inherited from class javax.swing.JScrollPane
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport
 
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 javax.swing.ScrollPaneConstants
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JMSwingText()
          The constructor for JMSwingText.
 
Method Summary
 void addKeyListener(java.awt.event.KeyListener listener)
          Allow KeyListeners to be added to our JMSwingText.
 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 append(java.lang.String rawInput)
          Append text to our JMSwingText.
 void buildColourAttr(int colAt)
          A method to sift through ANSI colour numbers and assign them to the proper "area" (foreground, background, etc...)
 int checkEscape(java.lang.String token, int startPos)
          Here, we check for an ANSI colour escape in the 'token', starting at position 'i'.
 void clearScreen()
          Clear the text from the document.
 void copy()
          Copy any selected text to the system clipboard
 java.awt.Color getBackground()
           
 java.awt.Color[] getCurrentPalette()
          Return an array of colours representing our current palette
 java.awt.Font getFont()
           
 java.awt.Color getForeground()
           
 boolean getMarkLinks()
          This method returns whether URL marking has been enabled or not.
 java.lang.String getSelectedText()
          Return any texted that is currently selected
 int getSelectionEnd()
          Return the index of the end of the selected text
 int getSelectionStart()
          Return the index of the beginning of the selected text
 java.awt.Color[] getStandardColours()
          Returns an array representing the "Standard" colours to be used.
 java.lang.String getText()
          Return all of our text
 void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt)
          Methods for handling hyper-links in text.
 boolean isAntiAliasing()
          Return whether the current view has font anti-aliasing enabled or disabled
 boolean isBoldNotBright()
          This returns the state of our colour rendering, if we are using the 8 colour (bold) palette, or the 16 colour (bright) palette.
 boolean isEditable()
          This returns whether the user can edit the JMSwingText area.
 boolean isPaintBackground()
          Returns whether background painting is enabled.
 void keyPressed(java.awt.event.KeyEvent event)
          Send out any key events to our listeners
 void keyReleased(java.awt.event.KeyEvent event)
          Related our keyReleased event to our registered KeyListener
 void keyTyped(java.awt.event.KeyEvent event)
          Pass our keyTyped events to our KeyListener
 void mouseClicked(java.awt.event.MouseEvent event)
          Capture any mouse clicks so that we can snoop them if need be.
 void mouseDragged(java.awt.event.MouseEvent event)
          Empty Event
 void mouseEntered(java.awt.event.MouseEvent event)
          Empty event
 void mouseExited(java.awt.event.MouseEvent event)
          Empty Event
 void mouseMoved(java.awt.event.MouseEvent evt)
          Required event for mouseMoved
 void mousePressed(java.awt.event.MouseEvent event)
          Empty Event
 void mouseReleased(java.awt.event.MouseEvent event)
          Empty Event
 void movePage(int direction)
          Move the scrollbars either one page up or one page down
 void removeKeyListener(java.awt.event.KeyListener listener)
          Remove registered KeyListeners from our JMSwingText class
 void removeMouseListener(java.awt.event.MouseListener mouse)
          Remove given mouse listener from this widget
 void select(int start, int end)
          Select text marked by the start and end integers
 void setAntiAliasing(boolean status)
          Turn anti-aliasing of our letters on or off
 void setBackground(java.awt.Color newColour)
          Set the background colour of our text area
 void setBoldNotBright(boolean state)
          There are two different ways to interpret the "bold" feature on MU*'s.
 void setEditable(boolean state)
          This sets the text area editable or non-editable.
 void setFont(java.awt.Font newFont)
          Set the font to be used in our display.
 void setForeground(java.awt.Color newColour)
          Set the foreground (text) colour of our display
 void setMarkLinks(boolean status)
          This method enables the marking of web links, usually with an underline
 void setPaintBackground(boolean state)
          Tell us whether it is alright to paint the background colour or not.
 void setPalette(java.awt.Color[] newPal)
          Sets an entirely new colour palette based on the array given.
 void setSelectionEnd(int end)
          This method sets the end point of a selection
 void setSelectionStart(int start)
          Sets the index for the beginning of a selected area
 void setStandardPalette()
          Sets colours in the output window to the ones listed in the getStandardPalette method
 void setText(java.lang.String initialText)
          Sets the text to be displayed.
 
Methods inherited from class javax.swing.JScrollPane
createHorizontalScrollBar, createVerticalScrollBar, createViewport, getAccessibleContext, getColumnHeader, getCorner, getHorizontalScrollBar, getHorizontalScrollBarPolicy, getRowHeader, getUI, getUIClassID, getVerticalScrollBar, getVerticalScrollBarPolicy, getViewport, getViewportBorder, getViewportBorderBounds, isValidateRoot, isWheelScrollingEnabled, paramString, setColumnHeader, setColumnHeaderView, setComponentOrientation, setCorner, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setLayout, setRowHeader, setRowHeaderView, setUI, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportBorder, setViewportView, setWheelScrollingEnabled, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
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, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, 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, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, 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

PAGEUP

public static final int PAGEUP
This variable indicates moving the scrollbars one "page" up

See Also:
Constant Field Values

PAGEDOWN

public static final int PAGEDOWN
This variable indicates moving the scrollbars one "page" down.

See Also:
Constant Field Values
Constructor Detail

JMSwingText

public JMSwingText()
The constructor for JMSwingText. There is no guarantee that this component will be fully initialised before a program calls some of its methods. Therefore, we will check our colours, fonts, etc to see if they have already been set. If not, we will set them to our defaults

Method Detail

append

public void append(java.lang.String rawInput)
Append text to our JMSwingText. Revised method supplied by Stephane Boisjoli 2004-11-26

Parameters:
rawInput - The input to be added to the current JMSwingText area.

setEditable

public void setEditable(boolean state)
This sets the text area editable or non-editable.

Parameters:
state - true sets the text area editable. false sets the text area non-editable.

isEditable

public boolean isEditable()
This returns whether the user can edit the JMSwingText area.

Returns:
true The JMSwingText component is editable false The JMSwingText component is read-only

checkEscape

public int checkEscape(java.lang.String token,
                       int startPos)
Here, we check for an ANSI colour escape in the 'token', starting at position 'i'. If this is indeed a real colour escape, we will return i as the end of the escape, modifying the 'currentAttrib' and "eating" the escape

Parameters:
token - is a string that is to be checked to see if it is an ANSI colour escape
startPos - is the starting position of the token, incase the token is more than an "escape"
Returns:
This integer represents to end of the "escape" if there is one.

buildColourAttr

public void buildColourAttr(int colAt)
A method to sift through ANSI colour numbers and assign them to the proper "area" (foreground, background, etc...)

Parameters:
colAt - The ANSI colour code to be processed by this method

setPaintBackground

public void setPaintBackground(boolean state)
Tell us whether it is alright to paint the background colour or not. Some combinations of Java 1.1.x and Swing seem to have trouble with background painting and just paint a solid coloured square instead of text!!

Parameters:
state - true indicates we should handle painting the background colour false indicates we should not paint the background colour ourselves

isPaintBackground

public boolean isPaintBackground()
Returns whether background painting is enabled. Background painting allows the program to change the colour of the background. Otherwise the background will always be the user-defined colour

Returns:
true Background painting is enabled false Background painting is not enabled

setForeground

public void setForeground(java.awt.Color newColour)
Set the foreground (text) colour of our display

Overrides:
setForeground in class javax.swing.JComponent
Parameters:
newColour - The colour to set our foreground (text)

getForeground

public java.awt.Color getForeground()
Overrides:
getForeground in class java.awt.Component

setBackground

public void setBackground(java.awt.Color newColour)
Set the background colour of our text area

Overrides:
setBackground in class javax.swing.JComponent
Parameters:
newColour - The colour to set our background

getBackground

public java.awt.Color getBackground()
Overrides:
getBackground in class java.awt.Component

getFont

public java.awt.Font getFont()
Specified by:
getFont in interface java.awt.MenuContainer
Overrides:
getFont in class java.awt.Component

setFont

public void setFont(java.awt.Font newFont)
Set the font to be used in our display.

Overrides:
setFont in class javax.swing.JComponent
Parameters:
newFont - The java.awt.Font to use for our display

getText

public java.lang.String getText()
Return all of our text

Returns:
Return all the text current in our text widget.

setText

public void setText(java.lang.String initialText)
Sets the text to be displayed. If the display aready contains text it is removed first.

Parameters:
initialText -

getSelectedText

public java.lang.String getSelectedText()
Return any texted that is currently selected

Returns:
returns any text currently selected in our text widget

select

public void select(int start,
                   int end)
Select text marked by the start and end integers

Parameters:
start - The starting point of our selection. This number is the count of characters from the beginning of our entire text.
end - The end point of our selection. This number is the count of characters from the beginning of our text.

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 for this widget

removeMouseListener

public void removeMouseListener(java.awt.event.MouseListener mouse)
Remove given mouse listener from this widget

Overrides:
removeMouseListener in class java.awt.Component
Parameters:
mouse - The mouselistener to remove

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Capture any mouse clicks so that we can snoop them if need be.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
event - The captured mouse event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
Empty event

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

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
Empty Event

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
Empty Event

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

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
Empty Event

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

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Empty Event

Parameters:
event - Mouse Event

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Required event for mouseMoved

Parameters:
evt - Mouse Event

addKeyListener

public void addKeyListener(java.awt.event.KeyListener listener)
Allow KeyListeners to be added to our JMSwingText.

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

removeKeyListener

public void removeKeyListener(java.awt.event.KeyListener listener)
Remove registered KeyListeners from our JMSwingText class

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

keyPressed

public void keyPressed(java.awt.event.KeyEvent event)
Send out any key events to our listeners

Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
event - The received keyPressed event

keyReleased

public void keyReleased(java.awt.event.KeyEvent event)
Related our keyReleased event to our registered KeyListener

Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
event - received KeyEvent

keyTyped

public void keyTyped(java.awt.event.KeyEvent event)
Pass our keyTyped events to our KeyListener

Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
event - Our KeyEvent

hyperlinkUpdate

public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt)
Methods for handling hyper-links in text. To be completed. Fix Me XXX.

Specified by:
hyperlinkUpdate in interface javax.swing.event.HyperlinkListener
Parameters:
evt - Hyperlink event

setAntiAliasing

public void setAntiAliasing(boolean status)
Turn anti-aliasing of our letters on or off

Parameters:
status - The variable that tells us to either turn on anti-aliasing with true, or turn off anti-aliasing with false.

isAntiAliasing

public boolean isAntiAliasing()
Return whether the current view has font anti-aliasing enabled or disabled

Returns:
true anti-aliasing is enabled false anti-aliasing is disabled

copy

public void copy()
Copy any selected text to the system clipboard


setBoldNotBright

public void setBoldNotBright(boolean state)
There are two different ways to interpret the "bold" feature on MU*'s. The first technique takes the "bold" command and makes the text bold. The second technique uses a palette at about half-brightness, and when the "bold" command is received, it turns the brightness up to full.

Parameters:
state - true - Create the characters as bold, using a limited palette false - Use the 16 colour palatte instead of bolding characters

isBoldNotBright

public boolean isBoldNotBright()
This returns the state of our colour rendering, if we are using the 8 colour (bold) palette, or the 16 colour (bright) palette.

Returns:
true - We are using the 8 colour (bold) palette false - We are using the 16 colour (bright) palette

movePage

public void movePage(int direction)
Move the scrollbars either one page up or one page down

Parameters:
direction - PAGEDOWN - move the scrollbars one page down PAGEUP - move the scrollbars one page up

getCurrentPalette

public java.awt.Color[] getCurrentPalette()
Return an array of colours representing our current palette

Returns:

setPalette

public void setPalette(java.awt.Color[] newPal)
Sets an entirely new colour palette based on the array given. This array must contain 16 colours, preferrably 8 "normal" colours and 8 "bold" colours.

Parameters:
newPal - An array of colours to be used.

setStandardPalette

public void setStandardPalette()
Sets colours in the output window to the ones listed in the getStandardPalette method


getStandardColours

public java.awt.Color[] getStandardColours()
Returns an array representing the "Standard" colours to be used.

Returns:
An array of Color objects, each representing one of the 16 colours of the colour palette.

getSelectionStart

public int getSelectionStart()
Return the index of the beginning of the selected text

Returns:
the index of the beginning of the selected text

getSelectionEnd

public int getSelectionEnd()
Return the index of the end of the selected text

Returns:
The index of the end of the selected text

setSelectionStart

public void setSelectionStart(int start)
Sets the index for the beginning of a selected area

Parameters:
start - index to begin the selection

setSelectionEnd

public void setSelectionEnd(int end)
This method sets the end point of a selection

Parameters:
end - the index to end the current selection

clearScreen

public void clearScreen()
Clear the text from the document. This actually clears all text from the existing document. We should ensure this is the best solution. Fix Me XXX


setMarkLinks

public void setMarkLinks(boolean status)
This method enables the marking of web links, usually with an underline

Parameters:
status - true Enable link marking (default) false disable link marking

getMarkLinks

public boolean getMarkLinks()
This method returns whether URL marking has been enabled or not.

Returns:
true link marking is enabled false link marking is disabled