soc.client
Class SnippingTextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.TextComponent
          extended by java.awt.TextArea
              extended by soc.client.SnippingTextArea
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class SnippingTextArea
extends java.awt.TextArea

Limits lines displayed to MaximumLines. Note that the empty string is also considered a line.

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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private) static boolean isJava142
          A bug in Java 1.4.2: the first time replaceRange() is called, it deletes one char beyond what is requested, but only because it's a newline (java bug 5025532 and possibly 4910757).
(package private) static boolean isJavaOnOSX105
          Bug in Mac OS X java display: If multiple threads try to update display at once, can hang the GUI (with rainbow "beach ball").
(package private)  int lines
           
(package private)  int maximumLines
           
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SnippingTextArea(int rows, int columns, int maxLines)
          Creates a SnippingTextArea which limits hard line breaks to maxLines, and uses SCROLLBARS_VERTICAL_ONLY.
SnippingTextArea(java.lang.String text, int maxLines)
          Creates a new SnippingTextArea object with specified text, which limits hard line breaks to maxLines, and uses SCROOBARS_VERTICAL_ONLY.
SnippingTextArea(java.lang.String text, int rows, int columns, int scrollbars, int maxLines)
          Creates a new SnippingTextArea object with specified text, rows, columns, and scroll bar visibility, which limits hard line breaks to maxLines.
 
Method Summary
 void append(java.lang.String newString)
           
protected  int countNewLines(java.lang.String s)
          Count the lines in a string of text.
 int getMaximumLines()
          Maximum lines this text area will display.
 void insert(java.lang.String newString, int x)
           
 int lines()
           
 void replaceRange(java.lang.String newString, int x, int y)
           
 void setMaximumLines(int newMax)
          Set the maximum lines this text area will display, contents are snipped if necessary.
 void setText(java.lang.String newString)
           
 void snipText()
          Remove lines at the beginning of the text, until there are only maxLines in the component.
 
Methods inherited from class java.awt.TextArea
addNotify, 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, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart
 
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, getBaseline, getBaselineResizeBehavior, 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

isJava142

static final boolean isJava142
A bug in Java 1.4.2: the first time replaceRange() is called, it deletes one char beyond what is requested, but only because it's a newline (java bug 5025532 and possibly 4910757). Afterwards it appears to work normally, resulting in the oldest line in the display will be short 1 char. To avoid we work on the text itself for 1.4.2. It flickers, but works. Added 2004-06-24 by Chad McHenry - JSettlers 1.1 CVS

Since:
1.1.06

isJavaOnOSX105

static final boolean isJavaOnOSX105
Bug in Mac OS X java display: If multiple threads try to update display at once, can hang the GUI (with rainbow "beach ball"). Non-display threads continue execution. We avoid this by not snipping our text area's length. - JDM 2009-05-21 Still present in OS X 10.7 and 10.8 per olivierdeckers bug report. - JDM 2012-10-20 To identify osx from within java, see technote TN2110: http://developer.apple.com/library/mac/technotes/tn2002/tn2110.html

Since:
1.1.06

maximumLines

int maximumLines

lines

int lines
Constructor Detail

SnippingTextArea

public SnippingTextArea(int rows,
                        int columns,
                        int maxLines)
Creates a SnippingTextArea which limits hard line breaks to maxLines, and uses SCROLLBARS_VERTICAL_ONLY.


SnippingTextArea

public SnippingTextArea(java.lang.String text,
                        int maxLines)
Creates a new SnippingTextArea object with specified text, which limits hard line breaks to maxLines, and uses SCROOBARS_VERTICAL_ONLY.


SnippingTextArea

public SnippingTextArea(java.lang.String text,
                        int rows,
                        int columns,
                        int scrollbars,
                        int maxLines)
Creates a new SnippingTextArea object with specified text, rows, columns, and scroll bar visibility, which limits hard line breaks to maxLines.

Method Detail

getMaximumLines

public int getMaximumLines()
Maximum lines this text area will display.


setMaximumLines

public void setMaximumLines(int newMax)
Set the maximum lines this text area will display, contents are snipped if necessary.


lines

public int lines()
Returns:
current number of lines in text

setText

public void setText(java.lang.String newString)
Overrides:
setText in class java.awt.TextComponent

replaceRange

public void replaceRange(java.lang.String newString,
                         int x,
                         int y)
Overrides:
replaceRange in class java.awt.TextArea

insert

public void insert(java.lang.String newString,
                   int x)
Overrides:
insert in class java.awt.TextArea

append

public void append(java.lang.String newString)
Overrides:
append in class java.awt.TextArea

countNewLines

protected int countNewLines(java.lang.String s)
Count the lines in a string of text.


snipText

public void snipText()
Remove lines at the beginning of the text, until there are only maxLines in the component.