kawigi.editor
Class LineNumbers

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--kawigi.editor.LineNumbers
All Implemented Interfaces:
javax.swing.event.CaretListener, javax.swing.event.DocumentListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.beans.PropertyChangeListener, java.io.Serializable

public class LineNumbers
extends javax.swing.JComponent
implements javax.swing.event.DocumentListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.beans.PropertyChangeListener, javax.swing.event.CaretListener

A custom widgets creating line numbers to the side of a JTextPane that also provides some interaction with the text pane. It will use the same font (but bolded) as the JText pane and the same colors. By clicking or clicking and dragging on numbers, you can select lines of text in the text pane.

See Also:
Serialized Form

Field Summary
 
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
LineNumbers(javax.swing.JTextPane textarea)
          Creates an instance of LineNumbers to go next to textarea.
 
Method Summary
 void caretUpdate(javax.swing.event.CaretEvent e)
          Listens for changes in caret position on the text pane.
 void changedUpdate(javax.swing.event.DocumentEvent e)
          Listens for changes on the Document in its associated text pane.
protected  void checkLines(java.lang.String text)
          Called by the DocumentListener methods to check if the number of lines has changed, and if it has, it updates the display.
protected  void doSelection()
          Handles selection in the text pane due to gestures on the line numbers.
 void insertUpdate(javax.swing.event.DocumentEvent e)
          Listens for changes on the Document in its associated text pane.
 void mouseClicked(java.awt.event.MouseEvent e)
          Empty - part of the MouseListener interface.
 void mouseDragged(java.awt.event.MouseEvent e)
          Temporarily moves the end anchor of the current selection.
 void mouseEntered(java.awt.event.MouseEvent e)
          Empty - part of the MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent e)
          Empty - part of the MouseListener interface.
 void mouseMoved(java.awt.event.MouseEvent e)
          Empty - part of the MouseMotionListener interface.
 void mousePressed(java.awt.event.MouseEvent e)
          Selects the number that was clicked on and sets it as an "anchor" for dragging.
 void mouseReleased(java.awt.event.MouseEvent e)
          Sets the end anchor and updates the state of the widget to reflect that the click-and-drag gesture has ended.
 void paint(java.awt.Graphics g)
          Draws the old line numbers.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Listens for property changes on the text pane, specifically to its document (so I can become a DocumentListener on the new Document).
 void removeUpdate(javax.swing.event.DocumentEvent e)
          Listens for changes on the Document in its associated text pane.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Constructor Detail

LineNumbers

public LineNumbers(javax.swing.JTextPane textarea)
Creates an instance of LineNumbers to go next to textarea. It still needs to be put next to textarea to be fully useful, I recommend making a JPanel with both components on a BorderLayout, with this object using the BorderLayout.WEST constraint.

Method Detail

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
Listens for changes on the Document in its associated text pane. If the number of lines has changed, it updates its view.

Specified by:
changedUpdate in interface javax.swing.event.DocumentListener

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
Listens for changes on the Document in its associated text pane. If the number of lines has changed, it updates its view.

Specified by:
insertUpdate in interface javax.swing.event.DocumentListener

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
Listens for changes on the Document in its associated text pane. If the number of lines has changed, it updates its view.

Specified by:
removeUpdate in interface javax.swing.event.DocumentListener

checkLines

protected void checkLines(java.lang.String text)
Called by the DocumentListener methods to check if the number of lines has changed, and if it has, it updates the display.


paint

public void paint(java.awt.Graphics g)
Draws the old line numbers.

Overrides:
paint in class javax.swing.JComponent

doSelection

protected void doSelection()
Handles selection in the text pane due to gestures on the line numbers.


mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Selects the number that was clicked on and sets it as an "anchor" for dragging.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Sets the end anchor and updates the state of the widget to reflect that the click-and-drag gesture has ended.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Temporarily moves the end anchor of the current selection.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Empty - part of the MouseMotionListener interface.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Empty - part of the MouseListener interface.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Empty - part of the MouseListener interface.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Empty - part of the MouseListener interface.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Listens for property changes on the text pane, specifically to its document (so I can become a DocumentListener on the new Document).

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

caretUpdate

public void caretUpdate(javax.swing.event.CaretEvent e)
Listens for changes in caret position on the text pane. Updates the code block display and stuff

Specified by:
caretUpdate in interface javax.swing.event.CaretListener