Package adams.gui.core
Class BaseTextPane
-
- All Implemented Interfaces:
AnyChangeListenerSupporter,BaseTextComponent,TextPaneComponent,ImageObserver,MenuContainer,Serializable,Accessible,Scrollable
public class BaseTextPane extends JTextPane implements TextPaneComponent, AnyChangeListenerSupporter, BaseTextComponent
A customized JTextPane. Adds functionality for wordwrap, 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.JEditorPane
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport
-
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_AnyChangeListenersthe listeners for any changes to the text.-
Fields inherited from class javax.swing.JEditorPane
HONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITS
-
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 BaseTextPane()Creates a newBaseTextPane.BaseTextPane(StyledDocument doc)Creates a newBaseTextPane, with a specified document model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAnyChangeListener(ChangeListener l)Adds the listener for listening to any text changes.voidappend(String text)Appends the text at the end.voidappend(String text, AttributeSet a)Appends the text at the end.intcaretToLine(int position)Determines the line number for the caret position.intgetLineCount()Returns the number of lines in the document (= # of elements).DialoggetParentDialog()Tries to determine the dialog this panel is part of.FramegetParentFrame()Tries to determine the frame the container is part of.JInternalFramegetParentInternalFrame()Tries to determine the internal frame this panel is part of.booleangotoLine(int line)Jumps to the specified line.protected voidinitialize()Initializes the member variables.protected voidnotifyAnyChangeListeners()Notifies all listeners that some change to the text occurred.voidprintText()Pops up a print dialog.voidremoveAnyChangeListener(ChangeListener l)Removes the listener from listening to any text changes.voidselectFont()Pops up a dialog for selecting the font.voidsetCaretPositionLast()Sets the position of the cursor at the end.voidsetTextFont(Font font)Sets the font of the text pane.-
Methods inherited from class javax.swing.JTextPane
addStyle, createDefaultEditorKit, getCharacterAttributes, getInputAttributes, getLogicalStyle, getParagraphAttributes, getStyle, getStyledDocument, getStyledEditorKit, getUIClassID, insertComponent, insertIcon, paramString, removeStyle, replaceSelection, setCharacterAttributes, setDocument, setEditorKit, setLogicalStyle, setParagraphAttributes, setStyledDocument
-
Methods inherited from class javax.swing.JEditorPane
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText
-
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, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, 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, setFont, 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.BaseTextComponent
getText, setText
-
Methods inherited from interface adams.gui.core.TextPaneComponent
getCaretPosition, getDocument, getSelectedText, getText, isEditable, setCaretPosition, setEditable, setText
-
-
-
-
Field Detail
-
m_AnyChangeListeners
protected Set<ChangeListener> m_AnyChangeListeners
the listeners for any changes to the text.
-
-
Constructor Detail
-
BaseTextPane
public BaseTextPane()
Creates a newBaseTextPane. A new instance ofStyledEditorKitis created and set, and the document model set tonull.
-
BaseTextPane
public BaseTextPane(StyledDocument doc)
Creates a newBaseTextPane, with a specified document model. A new instance ofjavax.swing.text.StyledEditorKitis created and set.- Parameters:
doc- the document model
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the member variables.
-
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.
-
setTextFont
public void setTextFont(Font font)
Sets the font of the text pane.- Parameters:
font- the font to use
-
getLineCount
public int getLineCount()
Returns the number of lines in the document (= # of elements).- Returns:
- the number of lines
-
gotoLine
public boolean gotoLine(int line)
Jumps to the specified line.- Parameters:
line- 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
-
append
public void append(String text)
Appends the text at the end.- Parameters:
text- the text to append
-
append
public void append(String text, AttributeSet a)
Appends the text at the end.- Parameters:
text- the text to appenda- the attribute set, null if to use current
-
setCaretPositionLast
public void setCaretPositionLast()
Sets the position of the cursor at the end.- Specified by:
setCaretPositionLastin interfaceTextPaneComponent
-
addAnyChangeListener
public void addAnyChangeListener(ChangeListener l)
Adds the listener for listening to any text changes.- Specified by:
addAnyChangeListenerin interfaceAnyChangeListenerSupporter- Parameters:
l- the listener to add
-
removeAnyChangeListener
public void removeAnyChangeListener(ChangeListener l)
Removes the listener from listening to any text changes.- Specified by:
removeAnyChangeListenerin interfaceAnyChangeListenerSupporter- Parameters:
l- the listener to remove
-
notifyAnyChangeListeners
protected void notifyAnyChangeListeners()
Notifies all listeners that some change to the text occurred.
-
-