Class TextAreaPainter
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- net.sf.gridarta.textedit.textarea.TextAreaPainter
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.swing.text.TabExpander
public class TextAreaPainter extends javax.swing.JComponent implements javax.swing.text.TabExpanderThe text area repaint manager. It performs double buffering and paints lines of text.- See Also:
- Serialized Form
-
-
Field Summary
-
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
-
-
Constructor Summary
Constructors Constructor Description TextAreaPainter(@NotNull JEditTextArea textArea, @NotNull TextAreaSelection selection, @NotNull TextAreaCaret caret, @NotNull TextAreaDefaults defaults, @NotNull TextAreaBrackets brackets, @NotNull TextAreaConfig config, boolean paintInvalid)Creates a new repaint manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCurrentLineIndex()Returns the currently painted line.intgetDefaultCharWidth()This works only for fonts with fixed line height.intgetFirstLine()Returns the line displayed at the text area's origin.@Nullable java.awt.FontMetricsgetFontMetrics()Returns the font metrics used by this component.intgetHorizontalOffset()Returns the horizontal offset of drawn lines.@NotNull java.awt.DimensiongetMinimumSize()@NotNull java.awt.DimensiongetPreferredSize()@NotNull SyntaxStylesgetStyles()Returns the syntax styles used to paint colorized text.intgetVisibleLines()voidinvalidateLine(int line)Marks a line as needing a repaint.voidinvalidateLineRange(int firstLine, int lastLine)Marks a range of lines as needing a repaint.voidinvalidateSelectedLines()Repaints the lines containing the selection.booleanisBlockCaretEnabled()Returns whether the caret should be drawn as a block.booleanisBracketHighlightEnabled()Returns whether bracket highlighting is enabled.intlineToY(int line)Converts a line index to a y co-ordinate.floatnextTabStop(float x, int tabOffset)intoffsetToX(int line, int offset)Converts an offset in a line into an x co-ordinate.intoffsetToX2(int line, int offset)Converts an offset in a line into an x co-ordinate.voidpaint(@NotNull java.awt.Graphics g)Repaints the text.voidrecalculateVisibleLines()Recalculates the number of visible lines.voidsetCurrentLineIndex(int lineIndex)Sets the currently painted line.booleansetFirstLine(int firstLine)voidsetFont(@NotNull java.awt.Font font)booleansetHorizontalOffset(int horizontalOffset)voidsetStyles(@NotNull SyntaxStyles styles)Sets the syntax styles used to paint colorized text.intxToOffset(int line, int x)Converts a x co-ordinate to an offset within a line.intxyToOffset(int x, int y)Converts a point to an offset, from the start of the text.intyToLine(int y)Converts a y co-ordinate to a line index.-
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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, updateUI
-
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, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Constructor Detail
-
TextAreaPainter
public TextAreaPainter(@NotNull @NotNull JEditTextArea textArea, @NotNull @NotNull TextAreaSelection selection, @NotNull @NotNull TextAreaCaret caret, @NotNull @NotNull TextAreaDefaults defaults, @NotNull @NotNull TextAreaBrackets brackets, @NotNull @NotNull TextAreaConfig config, boolean paintInvalid)Creates a new repaint manager. This should be not be called directly.- Parameters:
textArea- the associated text area that is painteddefaults- the text attributes to usebrackets- the brackets to paintconfig- the text area configuration options to usepaintInvalid- whether invalid lines should be painted as red tildes
-
-
Method Detail
-
getDefaultCharWidth
public int getDefaultCharWidth()
This works only for fonts with fixed line height. It's sort of hack to avoid the use of deprecated methods.- Returns:
- default line height in pixels
-
getStyles
@NotNull public @NotNull SyntaxStyles getStyles()
Returns the syntax styles used to paint colorized text.- Returns:
- the styles
- See Also:
Token
-
setStyles
public void setStyles(@NotNull @NotNull SyntaxStyles styles)Sets the syntax styles used to paint colorized text.- Parameters:
styles- the syntax styles- See Also:
Token
-
isBracketHighlightEnabled
public boolean isBracketHighlightEnabled()
Returns whether bracket highlighting is enabled. When bracket highlighting is enabled, the bracket matching the one before the caret (if any) is highlighted.- Returns:
- whether bracket highlighting is enabled
-
isBlockCaretEnabled
public boolean isBlockCaretEnabled()
Returns whether the caret should be drawn as a block.- Returns:
- whether the caret should be drawn as a block
-
getFontMetrics
@Nullable public @Nullable java.awt.FontMetrics getFontMetrics()
Returns the font metrics used by this component.- Returns:
- the font metrics
-
setFont
public final void setFont(@NotNull @NotNull java.awt.Font font)- Overrides:
setFontin classjavax.swing.JComponent
-
paint
public void paint(@NotNull @NotNull java.awt.Graphics g)Repaints the text.- Overrides:
paintin classjavax.swing.JComponent- Parameters:
g- the graphics context
-
invalidateLine
public void invalidateLine(int line)
Marks a line as needing a repaint.- Parameters:
line- the line to invalidate
-
invalidateLineRange
public void invalidateLineRange(int firstLine, int lastLine)Marks a range of lines as needing a repaint.- Parameters:
firstLine- the first line to invalidatelastLine- the last line to invalidate
-
invalidateSelectedLines
public void invalidateSelectedLines()
Repaints the lines containing the selection.
-
nextTabStop
public float nextTabStop(float x, int tabOffset)- Specified by:
nextTabStopin interfacejavax.swing.text.TabExpander
-
getPreferredSize
@NotNull public @NotNull java.awt.Dimension getPreferredSize()
- Overrides:
getPreferredSizein classjavax.swing.JComponent
-
getMinimumSize
@NotNull public @NotNull java.awt.Dimension getMinimumSize()
- Overrides:
getMinimumSizein classjavax.swing.JComponent
-
getCurrentLineIndex
public int getCurrentLineIndex()
Returns the currently painted line.- Returns:
- the line index
-
setCurrentLineIndex
public void setCurrentLineIndex(int lineIndex)
Sets the currently painted line.- Parameters:
lineIndex- the line index
-
recalculateVisibleLines
public void recalculateVisibleLines()
Recalculates the number of visible lines. This should not be called directly.
-
getVisibleLines
public int getVisibleLines()
-
getFirstLine
public int getFirstLine()
Returns the line displayed at the text area's origin.
-
setFirstLine
public boolean setFirstLine(int firstLine)
-
lineToY
public int lineToY(int line)
Converts a line index to a y co-ordinate.- Parameters:
line- the line
-
getHorizontalOffset
public int getHorizontalOffset()
Returns the horizontal offset of drawn lines.
-
setHorizontalOffset
public boolean setHorizontalOffset(int horizontalOffset)
-
offsetToX2
public int offsetToX2(int line, int offset)Converts an offset in a line into an x co-ordinate. This is a fast version that should only be used if no changes were made to the text since the last repaint.- Parameters:
line- the lineoffset- the offset, from the start of the line
-
offsetToX
public int offsetToX(int line, int offset)Converts an offset in a line into an x co-ordinate. This is a slow version that can be used any time.- Parameters:
line- the lineoffset- the offset, from the start of the line
-
yToLine
public int yToLine(int y)
Converts a y co-ordinate to a line index.- Parameters:
y- the y co-ordinate
-
xToOffset
public int xToOffset(int line, int x)Converts a x co-ordinate to an offset within a line.- Parameters:
line- the linex- the x co-ordinate
-
xyToOffset
public int xyToOffset(int x, int y)Converts a point to an offset, from the start of the text.- Parameters:
x- the x co-ordinate of the pointy- the y co-ordinate of the point
-
-