Package org.fife.ui.rtextarea
Class LineNumberList
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.fife.ui.rtextarea.AbstractGutterComponent
org.fife.ui.rtextarea.LineNumberList
- All Implemented Interfaces:
MouseListener
,MouseMotionListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,MouseInputListener
Renders line numbers in the gutter.
- Version:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Listens for events in the text area we're interested in.private static class
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
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
FieldsModifier and TypeFieldDescriptionprivate Map
<?, ?> private int
private int
private int
private int
private Color
The color of current line number.static final Color
static final LineNumberFormatter
private LineNumberList.Listener
Listens for events from the current text area.private int
private int
private LineNumberFormatter
Formats line numbers into a string to be displayed.private int
The index at which line numbering should start.private int
private Insets
Used inpaintComponent(Graphics)
to prevent reallocation on each paint.private Rectangle
Used inpaintComponent(Graphics)
to prevent reallocation on each paint.Fields inherited from class org.fife.ui.rtextarea.AbstractGutterComponent
currentLineCount, textArea
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
ConstructorsConstructorDescriptionLineNumberList
(RTextArea textArea) Constructs a newLineNumberList
using default values for line number color (gray) and highlighting the current line.LineNumberList
(RTextArea textArea, Color numberColor) Constructs a newLineNumberList
.LineNumberList
(RTextArea textArea, Color numberColor, Color currentLineNumberColor) Constructs a newLineNumberList
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Overridden to set width of this component correctly when we are first displayed (as keying off of the RTextArea gives us (0,0) when it isn't yet displayed.private int
Calculates the last line number index painted in this component.Returns the color to use when painting the current line's line number.Returns the line number formatter.int
Returns the starting line's line number.private int
Returns the width of the empty border on this component's right-hand side (or left-hand side, if the orientation is RTL).(package private) void
Called when text is inserted to or removed from the text area.protected void
init()
Called by the constructor before the text area is set.(package private) void
Called when the line heights of the text area change.void
void
void
void
void
void
void
protected void
Paints this component.private void
paintWrappedLineNumbers
(Graphics g, Rectangle visibleRect) Paints line numbers for text areas with line wrap enabled.void
Called when this component is removed from the view hierarchy.private void
repaintLine
(int line) Repaints a single line in this list.void
setCurrentLineNumberColor
(Color color) Sets the color to use when painting the current line's line number.void
Overridden to ensure line number cell sizes are updated with the font size change.void
setLineNumberFormatter
(LineNumberFormatter formatter) Sets a custom line number formatter.void
setLineNumberingStartIndex
(int index) Sets the starting line's line number.void
setTextArea
(RTextArea textArea) Sets the text area being displayed.private void
Changes the height of the cells in the JList so that they are as tall as font.(package private) void
Changes the width of the cells in the JList so you can see every digit of each.Methods inherited from class org.fife.ui.rtextarea.AbstractGutterComponent
getChildViewBounds, getGutter
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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
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, 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
-
Field Details
-
currentLine
private int currentLine -
lastY
private int lastY -
lastVisibleLine
private int lastVisibleLine -
cellHeight
private int cellHeight -
cellWidth
private int cellWidth -
ascent
private int ascent -
aaHints
-
mouseDragStartOffset
private int mouseDragStartOffset -
l
Listens for events from the current text area. -
textAreaInsets
Used inpaintComponent(Graphics)
to prevent reallocation on each paint. -
visibleRect
Used inpaintComponent(Graphics)
to prevent reallocation on each paint. -
lineNumberingStartIndex
private int lineNumberingStartIndexThe index at which line numbering should start. The default value is1
, but applications can change this if, for example, they are displaying a subset of lines in a file. -
lineNumberFormatter
Formats line numbers into a string to be displayed. -
currentLineNumberColor
The color of current line number. -
DEFAULT_LINE_NUMBER_COLOR
-
DEFAULT_LINE_NUMBER_FORMATTER
-
-
Constructor Details
-
LineNumberList
Constructs a newLineNumberList
using default values for line number color (gray) and highlighting the current line.- Parameters:
textArea
- The text component for which line numbers will be displayed.
-
LineNumberList
Constructs a newLineNumberList
.- Parameters:
textArea
- The text component for which line numbers will be displayed.numberColor
- The color to use for the line numbers. If this isnull
, gray will be used.
-
LineNumberList
Constructs a newLineNumberList
.- Parameters:
textArea
- The text component for which line numbers will be displayed.numberColor
- The color to use for the line numbers. If this isnull
, gray will be used.currentLineNumberColor
- The color to use for the current line number. If this isnull
, the current line's number will not have a special color.
-
-
Method Details
-
addNotify
public void addNotify()Overridden to set width of this component correctly when we are first displayed (as keying off of the RTextArea gives us (0,0) when it isn't yet displayed.- Overrides:
addNotify
in classAbstractGutterComponent
-
calculateLastVisibleLineNumber
private int calculateLastVisibleLineNumber()Calculates the last line number index painted in this component.- Returns:
- The last line number index painted in this component.
-
getCurrentLineNumberColor
Returns the color to use when painting the current line's line number.- Returns:
- The color to use when painting the current line's line
number. If this is
null
, the regular line number color will be used. - See Also:
-
getLineNumberingStartIndex
public int getLineNumberingStartIndex()Returns the starting line's line number. The default value is1
.- Returns:
- The index
- See Also:
-
getLineNumberFormatter
Returns the line number formatter. The default value isDEFAULT_LINE_NUMBER_FORMATTER
- Returns:
- The formatter
- See Also:
-
getPreferredSize
- Overrides:
getPreferredSize
in classJComponent
-
getRhsBorderWidth
private int getRhsBorderWidth()Returns the width of the empty border on this component's right-hand side (or left-hand side, if the orientation is RTL).- Returns:
- The border width.
-
handleDocumentEvent
Description copied from class:AbstractGutterComponent
Called when text is inserted to or removed from the text area. Implementations can take this opportunity to repaint, revalidate, etc.- Specified by:
handleDocumentEvent
in classAbstractGutterComponent
- Parameters:
e
- The document event.
-
init
protected void init()Description copied from class:AbstractGutterComponent
Called by the constructor before the text area is set. This is a hook to allow subclasses to do any needed initialization. The default implementation does nothing.- Overrides:
init
in classAbstractGutterComponent
-
lineHeightsChanged
void lineHeightsChanged()Description copied from class:AbstractGutterComponent
Called when the line heights of the text area change. This is usually the result of one or more of the fonts in the editor changing.- Specified by:
lineHeightsChanged
in classAbstractGutterComponent
-
mouseClicked
- Specified by:
mouseClicked
in interfaceMouseListener
-
mouseDragged
- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
-
mouseMoved
- Specified by:
mouseMoved
in interfaceMouseMotionListener
-
mousePressed
- Specified by:
mousePressed
in interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleased
in interfaceMouseListener
-
paintComponent
Paints this component.- Overrides:
paintComponent
in classJComponent
- Parameters:
g
- The graphics context.
-
paintWrappedLineNumbers
Paints line numbers for text areas with line wrap enabled.- Parameters:
g
- The graphics context.visibleRect
- The visible rectangle of these line numbers.
-
removeNotify
public void removeNotify()Called when this component is removed from the view hierarchy.- Overrides:
removeNotify
in classAbstractGutterComponent
-
repaintLine
private void repaintLine(int line) Repaints a single line in this list.- Parameters:
line
- The line to repaint.
-
setCurrentLineNumberColor
Sets the color to use when painting the current line's line number.- Parameters:
color
- The color to use. If this isnull
, the current line's line number will be painted just like any other.- See Also:
-
setFont
Overridden to ensure line number cell sizes are updated with the font size change.- Overrides:
setFont
in classJComponent
- Parameters:
font
- The new font to use for line numbers.
-
setLineNumberingStartIndex
public void setLineNumberingStartIndex(int index) Sets the starting line's line number. The default value is1
. Applications can call this method to change this value if they are displaying a subset of lines in a file, for example.- Parameters:
index
- The new index.- See Also:
-
setLineNumberFormatter
Sets a custom line number formatter. Can be called when other number formats are needed like hindu-arabic numerals.- Parameters:
formatter
- The new line number formatter- See Also:
-
setTextArea
Sets the text area being displayed.- Overrides:
setTextArea
in classAbstractGutterComponent
- Parameters:
textArea
- The text area.
-
updateCellHeights
private void updateCellHeights()Changes the height of the cells in the JList so that they are as tall as font. This function should be called whenever the user changes the Font oftextArea
. -
updateCellWidths
void updateCellWidths()Changes the width of the cells in the JList so you can see every digit of each.
-