public class BracketMatchingTextArea extends JTextArea implements 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.
|
JTextArea.AccessibleJTextArea
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private static String |
CLOSING_PARENS
The Constant CLOSING_PARENS holds the characters which serve as closing parenthesis.
|
private static 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 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 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 String |
OPENING_PARENS
The Constant OPENING_PARENS holds the characters which serve as opening parenthesis
|
private static 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 Object |
theDiffParensHighlight
The highlighter stores the highlights in an object which is used to denote the highlighting.
|
private Object |
theSameParensHighlight
The highlighter stores the highlights in an object which is used to denote the highlighting.
|
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
BracketMatchingTextArea()
Constructs a new TextArea.
|
BracketMatchingTextArea(Document doc)
Constructs a new JTextArea with the given document model, and defaults
for all of the other arguments (null, 0, 0).
|
BracketMatchingTextArea(Document doc,
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(String text)
Constructs a new TextArea with the specified text displayed.
|
BracketMatchingTextArea(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(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(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, setWrapStyleWord
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, 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, write
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
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
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, 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, transferFocusUpCycle
private static final long serialVersionUID
private static final Color HIGHLIGHT_COLOR_SAME_PARENS
private static final Color HIGHLIGHT_COLOR_DIFFERENT_PARENS
private static final Highlighter.HighlightPainter SAME_PAINTER
private static final Highlighter.HighlightPainter DIFF_PAINTER
private static final String OPENING_PARENS
private static final String CLOSING_PARENS
private Object theSameParensHighlight
private Object theDiffParensHighlight
public BracketMatchingTextArea()
public BracketMatchingTextArea(Document doc, 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 >= 0IllegalArgumentException
- if the rows or columns
arguments are negative.public BracketMatchingTextArea(Document doc)
doc
- the model to usepublic BracketMatchingTextArea(int rows, int columns)
rows
- the number of rows >= 0columns
- the number of columns >= 0IllegalArgumentException
- if the rows or columns
arguments are negative.public BracketMatchingTextArea(String text, int rows, int columns)
text
- the text to be displayed, or nullrows
- the number of rows >= 0columns
- the number of columns >= 0IllegalArgumentException
- if the rows or columns
arguments are negative.public BracketMatchingTextArea(String text)
text
- the text to be displayed, or nullprivate void init()
public void caretUpdate(CaretEvent e)
caretUpdate
in interface CaretListener
protected void resetHighlights() throws BadLocationException
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(String[] args)