Package adams.gui.core
Class BaseTextArea
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.text.JTextComponent
-
- javax.swing.JTextArea
-
- adams.gui.core.BaseTextArea
-
- All Implemented Interfaces:
AnyChangeListenerSupporter
,AppendableTextAreaComponent
,TextAreaComponent
,ImageObserver
,MenuContainer
,Serializable
,Accessible
,Scrollable
- Direct Known Subclasses:
TextEditorPanel.TextEditorArea
public class BaseTextArea extends JTextArea implements AppendableTextAreaComponent, AnyChangeListenerSupporter
A customized JTextArea. Adds functionality for printing and selecting fonts.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JTextArea
JTextArea.AccessibleJTextArea
-
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<ChangeListener>
m_AnyChangeListeners
the listeners for any changes to the text.-
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
-
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
Constructors Constructor Description BaseTextArea()
Constructs a new TextArea.BaseTextArea(int rows, int columns)
Constructs a new empty TextArea with the specified number of rows and columns.BaseTextArea(String text)
Constructs a new TextArea with the specified text displayed.BaseTextArea(String text, int rows, int columns)
Constructs a new TextArea with the specified text and number of rows and columns.BaseTextArea(Document doc)
Constructs a new BaseTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0).BaseTextArea(Document doc, String text, int rows, int columns)
Constructs a new BaseTextArea with the specified number of rows and columns, and the given model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAnyChangeListener(ChangeListener l)
Adds the listener for listening to any text changes.void
append(String str, int limit)
Appends the string at the end and keeps the number of lines to the given limit (discarding from the top).int
caretToLine(int position)
Determines the line number for the caret position.int
getLineCount()
Returns the number of lines in the document (= # of elements).Dialog
getParentDialog()
Tries to determine the dialog this panel is part of.Frame
getParentFrame()
Tries to determine the frame the container is part of.JInternalFrame
getParentInternalFrame()
Tries to determine the internal frame this panel is part of.Font
getTextFont()
Returns the text font in use.boolean
gotoLine(int index)
Jumps to the specified line.protected void
initialize()
Initializes the text area.protected void
notifyAnyChangeListeners()
Notifies all listeners that some change to the text occurred.void
printText()
Pops up a print dialog.void
removeAnyChangeListener(ChangeListener l)
Removes the listener from listening to any text changes.void
selectFont()
Pops up a dialog for selecting the font.void
setCaretPositionLast()
Sets the position of the cursor at the end.void
setTextFont(Font value)
Sets the text font.-
Methods inherited from class javax.swing.JTextArea
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, replaceRange, setColumns, setFont, setLineWrap, setRows, setTabSize, setWrapStyleWord
-
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, viewToModel2D, write
-
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, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, 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, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.gui.core.AppendableTextAreaComponent
append
-
Methods inherited from interface adams.gui.core.TextAreaComponent
getCaretPosition, getColumns, getDocument, getLineWrap, getRows, getSelectedText, getText, getWrapStyleWord, isEditable, setCaretPosition, setColumns, setEditable, setLineWrap, setRows, setText, setWrapStyleWord
-
-
-
-
Field Detail
-
m_AnyChangeListeners
protected Set<ChangeListener> m_AnyChangeListeners
the listeners for any changes to the text.
-
-
Constructor Detail
-
BaseTextArea
public BaseTextArea()
Constructs a new TextArea. A default model is set, the initial string is null, and rows/columns are set to 0.
-
BaseTextArea
public BaseTextArea(String text)
Constructs a new TextArea with the specified text displayed. A default model is created and rows/columns are set to 0.- Parameters:
text
- the text to be displayed, or null
-
BaseTextArea
public BaseTextArea(int rows, int columns)
Constructs a new empty TextArea with the specified number of rows and columns. A default model is created, and the initial string is null.- Parameters:
rows
- the number of rows >= 0columns
- the number of columns >= 0
-
BaseTextArea
public BaseTextArea(String text, int rows, int columns)
Constructs a new TextArea with the specified text and number of rows and columns. A default model is created.- Parameters:
text
- the text to be displayed, or nullrows
- the number of rows >= 0columns
- the number of columns >= 0
-
BaseTextArea
public BaseTextArea(Document doc)
Constructs a new BaseTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0).- Parameters:
doc
- the model to use
-
BaseTextArea
public BaseTextArea(Document doc, String text, int rows, int columns)
Constructs a new BaseTextArea with the specified number of rows and columns, and the given model. All of the constructors feed through this constructor.- Parameters:
doc
- the model to use, or create a default one if nulltext
- the text to be displayed, null if nonerows
- the number of rows >= 0columns
- the number of columns >= 0
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the text area.
-
getParentFrame
public Frame getParentFrame()
Tries to determine the frame the container is part of.- Returns:
- the parent frame if one exists or null if not
-
getParentDialog
public Dialog getParentDialog()
Tries to determine the dialog this panel is part of.- Returns:
- the parent dialog if one exists or null if not
-
getParentInternalFrame
public JInternalFrame getParentInternalFrame()
Tries to determine the internal frame this panel is part of.- Returns:
- the parent internal frame if one exists or null if not
-
printText
public void printText()
Pops up a print dialog.
-
selectFont
public void selectFont()
Pops up a dialog for selecting the font.
-
getLineCount
public int getLineCount()
Returns the number of lines in the document (= # of elements).- Overrides:
getLineCount
in classJTextArea
- Returns:
- the number of lines
-
gotoLine
public boolean gotoLine(int index)
Jumps to the specified line.- Parameters:
index
- the 0-based index for the line- Returns:
- true if successfully jumped
-
caretToLine
public int caretToLine(int position)
Determines the line number for the caret position.- Parameters:
position
- the caret position- Returns:
- the line number, -1 if failed to determine
-
setTextFont
public void setTextFont(Font value)
Sets the text font.- Specified by:
setTextFont
in interfaceTextAreaComponent
- Parameters:
value
- the font
-
getTextFont
public Font getTextFont()
Returns the text font in use.- Specified by:
getTextFont
in interfaceTextAreaComponent
- Returns:
- the font
-
setCaretPositionLast
public void setCaretPositionLast()
Sets the position of the cursor at the end.- Specified by:
setCaretPositionLast
in interfaceTextAreaComponent
-
append
public void append(String str, int limit)
Appends the string at the end and keeps the number of lines to the given limit (discarding from the top).- Parameters:
str
- the line to appendlimit
- the maximum number of lines to keep, ignored if <= 0
-
addAnyChangeListener
public void addAnyChangeListener(ChangeListener l)
Adds the listener for listening to any text changes.- Specified by:
addAnyChangeListener
in interfaceAnyChangeListenerSupporter
- Parameters:
l
- the listener to add
-
removeAnyChangeListener
public void removeAnyChangeListener(ChangeListener l)
Removes the listener from listening to any text changes.- Specified by:
removeAnyChangeListener
in interfaceAnyChangeListenerSupporter
- Parameters:
l
- the listener to remove
-
notifyAnyChangeListeners
protected void notifyAnyChangeListeners()
Notifies all listeners that some change to the text occurred.
-
-