Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jsource.gui
Class Gutter  view Gutter download Gutter.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JLabel
                  extended byjsource.gui.Gutter
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.swing.SwingConstants

public class Gutter
extends javax.swing.JLabel
implements javax.swing.SwingConstants

Gutter is the component that displays line numbers to the left of the text area. Based on jEdit's Gutter component by Mike Dillon and Slava Pestov.


Nested Class Summary
(package private)  class Gutter.MouseHandler
           
 
Nested classes inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  int alignment
           
private  int baseline
           
private  boolean collapsed
           
private  java.awt.Dimension collapsedSize
           
private  javax.swing.JPopupMenu context
           
private  java.awt.Color currentLineHighlight
           
private  boolean currentLineHighlightEnabled
           
(package private) static java.awt.Color DEFAULT_BG_COLOUR
          Internal Gutter color constants
(package private) static java.awt.Color DEFAULT_CURRENT_LINE_COLOUR
           
(package private) static java.awt.Color DEFAULT_DIVIDER_COLOUR
           
(package private) static java.awt.Color DEFAULT_FG_COLOUR
           
(package private) static java.awt.Color DEFAULT_INTERVAL_COLOUR
           
private  java.awt.Color dividerColour
           
private  JSEditor editor
          A reference to the JSEditor object where the Gutter is attached
private  java.awt.FontMetrics fm
           
private  java.awt.Dimension gutterSize
           
private  int ileft
           
private  int interval
           
private  java.awt.Color intervalHighlight
           
private  boolean lineNumberingEnabled
           
private  int mMinWidth
           
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Gutter(JSEditor editor)
           
 
Method Summary
 javax.swing.JPopupMenu getContextMenu()
           
 java.awt.Color getCurrentLineForeground()
           
 java.awt.Color getDividerColour()
           
 int getGutterWidth()
          Get the width of the expanded gutter
 java.awt.Color getHighlightedForeground()
          Get the foreground color for highlighted line numbers
 int getHighlightInterval()
          Sets the number of lines between highlighted line numbers.
 int getLineNumberAlignment()
          Identifies whether the horizontal alignment of the line numbers.
 java.awt.Dimension getMinimumSize()
          Get the component's minimum size.
 java.awt.Dimension getPreferredSize()
          Get the component's preferred size.
 void invalidateLine(int line)
          Marks a line as needing a repaint.
 void invalidateLineRange(int firstLine, int lastLine)
          Marks a range of lines as needing a repaint.
 boolean isCollapsed()
          Identifies whether the gutter is collapsed or expanded.
 boolean isCurrentLineHighlightEnabled()
           
 boolean isLineNumberingEnabled()
          Identifies whether or not the line numbers are drawn in the gutter
 void paint(java.awt.Graphics gfx)
          Paint the component.
 void paintComponent(java.awt.Graphics gfx)
          Paint the component's body.
private  void paintLineNumbers(java.awt.Graphics gfx)
           
 void setCollapsed(boolean collapsed)
          Sets whether the gutter is collapsed or expanded and force the text area to update its layout if there is a change.
 void setContextMenu(javax.swing.JPopupMenu context)
           
 void setCurrentLineForeground(java.awt.Color highlight)
           
 void setCurrentLineHighlightEnabled(boolean enabled)
           
 void setDividerColour(java.awt.Color c)
           
 void setFont(java.awt.Font font)
          This method overrides setFont so that we can call for a repaint after the font is changed.
 void setGutterWidth(int width)
          Set the width of the expanded gutter
 void setHighlightedForeground(java.awt.Color highlight)
           
 void setHighlightInterval(int interval)
          Sets the number of lines between highlighted line numbers.
 void setLineNumberAlignment(int alignment)
          Sets the horizontal alignment of the line numbers.
 void setLineNumberingEnabled(boolean enabled)
          Turns the line numbering on or off and causes the gutter to be repainted.
 void toggleCollapsed()
          Toggles whether the gutter is collapsed or expanded.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BG_COLOUR

static final java.awt.Color DEFAULT_BG_COLOUR
Internal Gutter color constants


DEFAULT_FG_COLOUR

static final java.awt.Color DEFAULT_FG_COLOUR

DEFAULT_DIVIDER_COLOUR

static final java.awt.Color DEFAULT_DIVIDER_COLOUR

DEFAULT_CURRENT_LINE_COLOUR

static final java.awt.Color DEFAULT_CURRENT_LINE_COLOUR

DEFAULT_INTERVAL_COLOUR

static final java.awt.Color DEFAULT_INTERVAL_COLOUR

editor

private JSEditor editor
A reference to the JSEditor object where the Gutter is attached


context

private javax.swing.JPopupMenu context

baseline

private int baseline

ileft

private int ileft

mMinWidth

private int mMinWidth

gutterSize

private java.awt.Dimension gutterSize

collapsedSize

private java.awt.Dimension collapsedSize

intervalHighlight

private java.awt.Color intervalHighlight

currentLineHighlight

private java.awt.Color currentLineHighlight

dividerColour

private java.awt.Color dividerColour

fm

private java.awt.FontMetrics fm

alignment

private int alignment

interval

private int interval

lineNumberingEnabled

private boolean lineNumberingEnabled

currentLineHighlightEnabled

private boolean currentLineHighlightEnabled

collapsed

private boolean collapsed
Constructor Detail

Gutter

public Gutter(JSEditor editor)
Method Detail

paintComponent

public void paintComponent(java.awt.Graphics gfx)
Description copied from class: javax.swing.JComponent
Paint the component's body. This usually means calling ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)>ComponentUI.update(java.awt.Graphics, javax.swing.JComponent) 55 on the JComponent.ui>JComponent.ui 55 property of the component, if it is non-null. You may override this if you wish to customize the component's body-painting behavior. The component's body is painted first, before the border and children.


paint

public void paint(java.awt.Graphics gfx)
Description copied from class: javax.swing.JComponent

Paint the component. This is a delicate process, and should only be called from the repaint thread, under control of the javax.swing.RepaintManager. Client code should usually call Component.repaint()>Component.repaint() 55 to trigger painting.

The body of the paint call involves calling JComponent.paintComponent(java.awt.Graphics)>JComponent.paintComponent(java.awt.Graphics) 55 , JComponent.paintBorder(java.awt.Graphics)>JComponent.paintBorder(java.awt.Graphics) 55 , and JComponent.paintChildren(java.awt.Graphics)>JComponent.paintChildren(java.awt.Graphics) 55 in order. If you want to customize painting behavior, you should override one of these methods rather than paint.

For more details on the painting sequence, see this article.


paintLineNumbers

private void paintLineNumbers(java.awt.Graphics gfx)

invalidateLine

public final void invalidateLine(int line)
Marks a line as needing a repaint.


invalidateLineRange

public final void invalidateLineRange(int firstLine,
                                      int lastLine)
Marks a range of lines as needing a repaint.


setFont

public void setFont(java.awt.Font font)
Description copied from class: javax.swing.JLabel
This method overrides setFont so that we can call for a repaint after the font is changed.


getHighlightedForeground

public java.awt.Color getHighlightedForeground()
Get the foreground color for highlighted line numbers


setHighlightedForeground

public void setHighlightedForeground(java.awt.Color highlight)

getCurrentLineForeground

public java.awt.Color getCurrentLineForeground()

setCurrentLineForeground

public void setCurrentLineForeground(java.awt.Color highlight)

setGutterWidth

public void setGutterWidth(int width)
Set the width of the expanded gutter


getGutterWidth

public int getGutterWidth()
Get the width of the expanded gutter


getPreferredSize

public java.awt.Dimension getPreferredSize()
Description copied from class: javax.swing.JComponent
Get the component's preferred size. If the JComponent.preferredSize>JComponent.preferredSize 55 property has been explicitly set, it is returned. If the JComponent.preferredSize>JComponent.preferredSize 55 property has not been set but the JComponent.ui>JComponent.ui 55 property has been, the result of ComponentUI.getPreferredSize(javax.swing.JComponent)>ComponentUI.getPreferredSize(javax.swing.JComponent) 55 is returned. If neither property has been set, the result of Container.getPreferredSize()>Container.getPreferredSize() 55 is returned.


getMinimumSize

public java.awt.Dimension getMinimumSize()
Description copied from class: javax.swing.JComponent
Get the component's minimum size. If the JComponent.minimumSize>JComponent.minimumSize 55 property has been explicitly set, it is returned. If the JComponent.minimumSize>JComponent.minimumSize 55 property has not been set but the JComponent.ui>JComponent.ui 55 property has been, the result of ComponentUI.getMinimumSize(javax.swing.JComponent)>ComponentUI.getMinimumSize(javax.swing.JComponent) 55 is returned. If neither property has been set, the result of Container.getMinimumSize()>Container.getMinimumSize() 55 is returned.


isLineNumberingEnabled

public boolean isLineNumberingEnabled()
Identifies whether or not the line numbers are drawn in the gutter


setLineNumberingEnabled

public void setLineNumberingEnabled(boolean enabled)
Turns the line numbering on or off and causes the gutter to be repainted.


getLineNumberAlignment

public int getLineNumberAlignment()
Identifies whether the horizontal alignment of the line numbers.


setLineNumberAlignment

public void setLineNumberAlignment(int alignment)
Sets the horizontal alignment of the line numbers.


isCollapsed

public boolean isCollapsed()
Identifies whether the gutter is collapsed or expanded.


setCollapsed

public void setCollapsed(boolean collapsed)
Sets whether the gutter is collapsed or expanded and force the text area to update its layout if there is a change.


toggleCollapsed

public void toggleCollapsed()
Toggles whether the gutter is collapsed or expanded.


getHighlightInterval

public int getHighlightInterval()
Sets the number of lines between highlighted line numbers.


setHighlightInterval

public void setHighlightInterval(int interval)
Sets the number of lines between highlighted line numbers. Any value less than or equal to one will result in highlighting being disabled.


setDividerColour

public void setDividerColour(java.awt.Color c)

getDividerColour

public java.awt.Color getDividerColour()

isCurrentLineHighlightEnabled

public boolean isCurrentLineHighlightEnabled()

setCurrentLineHighlightEnabled

public void setCurrentLineHighlightEnabled(boolean enabled)

getContextMenu

public javax.swing.JPopupMenu getContextMenu()

setContextMenu

public void setContextMenu(javax.swing.JPopupMenu context)