syntaxhighlight
Class JTextComponentRowHeader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by syntaxhighlight.JTextComponentRowHeader
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class JTextComponentRowHeader
extends javax.swing.JPanel

A row header panel for JScrollPane showing the line numbers of JTextComponent. The text lines in JTextComponent must be fixed height.

Author:
Chan Wai Shing
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.Color borderColor
          The color of the border that joint the gutter and the script text area.
protected  int borderWidth
          The width of the border that joint the gutter and the script text area.
protected  javax.swing.text.Document document
          The document of the text component.
protected  javax.swing.event.DocumentListener documentListener
          The document listener for document.
protected  java.awt.Color highlightedColor
          The background of the row when it is highlighted.
protected  java.util.List<java.lang.Integer> highlightedLineList
          The list of line numbers that indicate which lines are needed to be highlighted.
protected  int largestRowNumber
          The cached largest row number (for determine panel width panelWidth).
protected  int lineNumberOffset
          The line number offset.
protected  boolean listenToDocumentUpdate
          Indicator indicate whether it is listening to the document change events or not.
protected  int paddingLeft
          The minimum padding from 'the leftmost of the line number text' to 'the left margin'.
protected  int paddingRight
          The minimum padding from 'the rightmost of the line number text' to 'the right margin' (not to the gutter border).
protected  int panelWidth
          The cached panel width.
protected  javax.swing.JScrollPane scrollPane
          The JScrollPane that it be added into.
protected  java.lang.Object textAntiAliasing
          The anti-aliasing setting of the line number text.
protected  javax.swing.text.JTextComponent textComponent
          The text component to listen the change events on.
protected  int textComponentHeight
          The cached text component height, for determine panel height.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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
JTextComponentRowHeader(javax.swing.JScrollPane scrollPane, javax.swing.text.JTextComponent textComponent)
          Constructor.
 
Method Summary
 boolean addHighlightedLine(int lineNumber)
          Add highlighted line.
 void checkPanelSize()
          Check whether the height of the row header panel match with the height of the text component or not.
 void clearHighlightedLine()
          Clear highlighted lines.
 java.awt.Color getBorderColor()
          The color of the border that joint the gutter and the script text area.
 int getBorderWidth()
          The width of the border that joint the gutter and the script text area.
 java.awt.Color getHighlightedColor()
          The background of the highlighted row.
 java.util.List<java.lang.Integer> getHighlightedLineList()
          Get the list of highlighted lines.
 int getLineNumberOffset()
          Get the line number offset
 int getPaddingLeft()
          The minimum padding from the 'leftmost of the line number text' to the 'left margin'.
 int getPaddingRight()
          The minimum padding from the 'rightmost of the line number text' to the 'right margin' (not to the gutter border).
 java.awt.Dimension getPreferredSize()
          
 java.lang.Object getTextAntiAliasing()
          The anti-aliasing setting of the line number text.
 boolean isListenToDocumentUpdate()
          Check if it is listening to the document change events.
 void paint(java.awt.Graphics g)
          
 void setBackground(java.awt.Color background)
          The background of the panel.
 void setBorderColor(java.awt.Color borderColor)
          The color of the border that joint the gutter and the script text area.
 void setBorderWidth(int borderWidth)
          The width of the border that joint the gutter and the script text area.
 void setFont(java.awt.Font font)
          The font of the line number.
 void setForeground(java.awt.Color foreground)
          The color of the line number.
 void setHighlightedColor(java.awt.Color highlightedColor)
          The background of the highlighted row.
 void setHighlightedLineList(java.util.List<java.lang.Integer> highlightedLineList)
          Set highlighted lines.
 void setLineNumberOffset(int offset)
          Set the line number offset.
 void setListenToDocumentUpdate(boolean listenToDocumentUpdate)
          Set to listen to document change events or not.
 void setPaddingLeft(int paddingLeft)
          The minimum padding from 'the leftmost of the line number text' to the 'left margin'.
 void setPaddingRight(int paddingRight)
          The minimum padding from the 'rightmost of the line number text' to the 'right margin' (not to the gutter border).
 void setTextAntiAliasing(java.lang.Object textAntiAliasing)
          The anti-aliasing setting of the line number text.
protected  void updatePanelSize()
          Update the panel size.
protected  void validateTextComponentDocument()
          Check if the 'document of the textComponent' has changed to another document or not.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, 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, transferFocusBackward, 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, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

textAntiAliasing

protected java.lang.Object textAntiAliasing
The anti-aliasing setting of the line number text. See RenderingHints.


borderColor

protected java.awt.Color borderColor
The color of the border that joint the gutter and the script text area.


highlightedColor

protected java.awt.Color highlightedColor
The background of the row when it is highlighted.


paddingLeft

protected int paddingLeft
The minimum padding from 'the leftmost of the line number text' to 'the left margin'.


paddingRight

protected int paddingRight
The minimum padding from 'the rightmost of the line number text' to 'the right margin' (not to the gutter border).


borderWidth

protected int borderWidth
The width of the border that joint the gutter and the script text area.


scrollPane

protected javax.swing.JScrollPane scrollPane
The JScrollPane that it be added into.


textComponent

protected javax.swing.text.JTextComponent textComponent
The text component to listen the change events on.


document

protected javax.swing.text.Document document
The document of the text component.


documentListener

protected javax.swing.event.DocumentListener documentListener
The document listener for document.


panelWidth

protected int panelWidth
The cached panel width.


largestRowNumber

protected int largestRowNumber
The cached largest row number (for determine panel width panelWidth).


textComponentHeight

protected int textComponentHeight
The cached text component height, for determine panel height.


lineNumberOffset

protected int lineNumberOffset
The line number offset. E.g. set offset to 9 will make the first line number to appear at line 1 + 9 = 10


highlightedLineList

protected final java.util.List<java.lang.Integer> highlightedLineList
The list of line numbers that indicate which lines are needed to be highlighted.


listenToDocumentUpdate

protected boolean listenToDocumentUpdate
Indicator indicate whether it is listening to the document change events or not.

Constructor Detail

JTextComponentRowHeader

public JTextComponentRowHeader(javax.swing.JScrollPane scrollPane,
                               javax.swing.text.JTextComponent textComponent)
Constructor.

Parameters:
scrollPane - the JScrollPane that it be added into
textComponent - the text component to listen the change events on
Method Detail

validateTextComponentDocument

protected void validateTextComponentDocument()
Check if the 'document of the textComponent' has changed to another document or not.


checkPanelSize

public void checkPanelSize()
Check whether the height of the row header panel match with the height of the text component or not. If not, it will invoke updatePanelSize().


updatePanelSize

protected void updatePanelSize()
Update the panel size.


setFont

public void setFont(java.awt.Font font)
The font of the line number.

Overrides:
setFont in class javax.swing.JComponent

setForeground

public void setForeground(java.awt.Color foreground)
The color of the line number.

Overrides:
setForeground in class javax.swing.JComponent
Parameters:
foreground - the color

setBackground

public void setBackground(java.awt.Color background)
The background of the panel.

Overrides:
setBackground in class javax.swing.JComponent
Parameters:
background - the color

getPreferredSize

public java.awt.Dimension getPreferredSize()

Overrides:
getPreferredSize in class javax.swing.JComponent

paint

public void paint(java.awt.Graphics g)

Overrides:
paint in class javax.swing.JComponent

getTextAntiAliasing

public java.lang.Object getTextAntiAliasing()
The anti-aliasing setting of the line number text. See RenderingHints.

Returns:
the setting

setTextAntiAliasing

public void setTextAntiAliasing(java.lang.Object textAntiAliasing)
The anti-aliasing setting of the line number text. See RenderingHints.

Parameters:
textAntiAliasing - the setting

getBorderColor

public java.awt.Color getBorderColor()
The color of the border that joint the gutter and the script text area.

Returns:
the color

setBorderColor

public void setBorderColor(java.awt.Color borderColor)
The color of the border that joint the gutter and the script text area.

Parameters:
borderColor - the color

getHighlightedColor

public java.awt.Color getHighlightedColor()
The background of the highlighted row.

Returns:
the color

setHighlightedColor

public void setHighlightedColor(java.awt.Color highlightedColor)
The background of the highlighted row.

Parameters:
highlightedColor - the color

getPaddingLeft

public int getPaddingLeft()
The minimum padding from the 'leftmost of the line number text' to the 'left margin'.

Returns:
the padding in pixel

setPaddingLeft

public void setPaddingLeft(int paddingLeft)
The minimum padding from 'the leftmost of the line number text' to the 'left margin'.

Parameters:
paddingLeft - the padding in pixel

getPaddingRight

public int getPaddingRight()
The minimum padding from the 'rightmost of the line number text' to the 'right margin' (not to the gutter border).

Returns:
the padding in pixel

setPaddingRight

public void setPaddingRight(int paddingRight)
The minimum padding from the 'rightmost of the line number text' to the 'right margin' (not to the gutter border).

Parameters:
paddingRight - the padding in pixel

getBorderWidth

public int getBorderWidth()
The width of the border that joint the gutter and the script text area.

Returns:
the width in pixel

setBorderWidth

public void setBorderWidth(int borderWidth)
The width of the border that joint the gutter and the script text area.

Parameters:
borderWidth - the width in pixel

getLineNumberOffset

public int getLineNumberOffset()
Get the line number offset

Returns:
the offset

setLineNumberOffset

public void setLineNumberOffset(int offset)
Set the line number offset. E.g. set offset to 9 will make the first line number to appear at line 1 + 9 = 10

Parameters:
offset - the offset

getHighlightedLineList

public java.util.List<java.lang.Integer> getHighlightedLineList()
Get the list of highlighted lines.

Returns:
a copy of the list

setHighlightedLineList

public void setHighlightedLineList(java.util.List<java.lang.Integer> highlightedLineList)
Set highlighted lines. Note that this will clear all previous recorded highlighted lines.

Parameters:
highlightedLineList - the list that contain the highlighted lines

addHighlightedLine

public boolean addHighlightedLine(int lineNumber)
Add highlighted line.

Parameters:
lineNumber - the line number to highlight
Returns:
see the return value of List.add(Object)

clearHighlightedLine

public void clearHighlightedLine()
Clear highlighted lines.


isListenToDocumentUpdate

public boolean isListenToDocumentUpdate()
Check if it is listening to the document change events.

Returns:
true if it is listening, false if not

setListenToDocumentUpdate

public void setListenToDocumentUpdate(boolean listenToDocumentUpdate)
Set to listen to document change events or not. It is useful when a number of updates are needed to be done to the text component. May invoke () after setting this to true.

Parameters:
listenToDocumentUpdate - true to listen on document change, false not