public class BracketMatchingTextArea
extends javax.swing.JTextArea
implements javax.swing.event.CaretListener
JTextArea object in every other respect.
( { < [
) } > ]
{x) is highlighted as well.| Modifier and Type | Class and Description |
|---|---|
private static class |
BracketMatchingTextArea.BorderPainter
The Class BorderPainter is a simple highlight painter that just draws a rectangle around the selection.
|
javax.swing.JTextArea.AccessibleJTextAreajavax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBindingjavax.swing.JComponent.AccessibleJComponent| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
CLOSING_PARENS
The Constant CLOSING_PARENS holds the characters which serve as closing parenthesis.
|
private static javax.swing.text.Highlighter.HighlightPainter |
DIFF_PAINTER
The Constant PAINTER is the painter which is used to draw the highlighting for
matching parens of different kind.
|
private static java.awt.Color |
HIGHLIGHT_COLOR_DIFFERENT_PARENS
The Constant HIGHLIGHT_COLOR holds the color to be used for the highlighting frame,
if the matching parentheses are of different kind.
|
private static java.awt.Color |
HIGHLIGHT_COLOR_SAME_PARENS
The Constant HIGHLIGHT_COLOR holds the color to be used for the highlighting frame, if
the matching parentheses are of the same kind
|
private static java.lang.String |
OPENING_PARENS
The Constant OPENING_PARENS holds the characters which serve as opening parenthesis
|
private static javax.swing.text.Highlighter.HighlightPainter |
SAME_PAINTER
The Constant PAINTER is the painter which is used to draw the highlighting for
matching parens of same kind.
|
private static long |
serialVersionUID
The Constant serialVersionUID needed for serialisation reasons
|
private java.lang.Object |
theDiffParensHighlight
The highlighter stores the highlights in an object which is used to denote the highlighting.
|
private java.lang.Object |
theSameParensHighlight
The highlighter stores the highlights in an object which is used to denote the highlighting.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW| Constructor and Description |
|---|
BracketMatchingTextArea()
Constructs a new TextArea.
|
BracketMatchingTextArea(javax.swing.text.Document doc)
Constructs a new JTextArea with the given document model, and defaults
for all of the other arguments (null, 0, 0).
|
BracketMatchingTextArea(javax.swing.text.Document doc,
java.lang.String text,
int rows,
int columns)
Constructs a new JTextArea with the specified number of rows
and columns, and the given model.
|
BracketMatchingTextArea(int rows,
int columns)
Constructs a new empty TextArea with the specified number of
rows and columns.
|
BracketMatchingTextArea(java.lang.String text)
Constructs a new TextArea with the specified text displayed.
|
BracketMatchingTextArea(java.lang.String text,
int rows,
int columns)
Constructs a new TextArea with the specified text and number
of rows and columns.
|
| Modifier and Type | Method and Description |
|---|---|
void |
caretUpdate(javax.swing.event.CaretEvent e) |
private int |
findMatchingClose(int dot)
Find matching close paren.
|
private int |
findMatchingOpen(int dot)
Find matching open paren.
|
private void |
init() |
static void |
main(java.lang.String[] args) |
protected void |
resetHighlights()
resets both highlights
|
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, replaceRange, setColumns, setFont, setLineWrap, setRows, setTabSize, setWrapStyleWordaddCaretListener, 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, 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, writeaddAncestorListener, 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, updateadd, 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, validateTreeaction, 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, getPeer, 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, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleprivate static final long serialVersionUID
private static final java.awt.Color HIGHLIGHT_COLOR_SAME_PARENS
private static final java.awt.Color HIGHLIGHT_COLOR_DIFFERENT_PARENS
private static final javax.swing.text.Highlighter.HighlightPainter SAME_PAINTER
private static final javax.swing.text.Highlighter.HighlightPainter DIFF_PAINTER
private static final java.lang.String OPENING_PARENS
private static final java.lang.String CLOSING_PARENS
private java.lang.Object theSameParensHighlight
private java.lang.Object theDiffParensHighlight
public BracketMatchingTextArea()
public BracketMatchingTextArea(javax.swing.text.Document doc,
java.lang.String text,
int rows,
int columns)
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 >= 0java.lang.IllegalArgumentException - if the rows or columns
arguments are negative.public BracketMatchingTextArea(javax.swing.text.Document doc)
doc - the model to usepublic BracketMatchingTextArea(int rows,
int columns)
rows - the number of rows >= 0columns - the number of columns >= 0java.lang.IllegalArgumentException - if the rows or columns
arguments are negative.public BracketMatchingTextArea(java.lang.String text,
int rows,
int columns)
text - the text to be displayed, or nullrows - the number of rows >= 0columns - the number of columns >= 0java.lang.IllegalArgumentException - if the rows or columns
arguments are negative.public BracketMatchingTextArea(java.lang.String text)
text - the text to be displayed, or nullprivate void init()
public void caretUpdate(javax.swing.event.CaretEvent e)
caretUpdate in interface javax.swing.event.CaretListenerprotected void resetHighlights()
throws javax.swing.text.BadLocationException
javax.swing.text.BadLocationException - if the caret is invalidprivate int findMatchingClose(int dot)
dot - position to start search from (must be an opening paren)private int findMatchingOpen(int dot)
dot - position to start search from (must be a closing paren)public static void main(java.lang.String[] args)