com.bluemarsh.jswat.view
Class SourceViewTextArea

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.bluemarsh.jswat.view.SourceViewTextArea
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable, com.bluemarsh.jswat.view.SourceViewArea

public class SourceViewTextArea
extends javax.swing.JComponent
implements javax.swing.Scrollable, com.bluemarsh.jswat.view.SourceViewArea

Class SourceViewTextArea is a quasi-text component that implements the SourceViewArea interface for easily getting the line number that corresponds to a view coordinate.

In addition, this class has the ability to interpret the value of the string under the mouse pointer. That is, it will read the string and assume it is a variable reference. If it is a variable, the value is displayed in the form of a tooltip.

Author:
Nathan Fiedler, David Taylor
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  SourceContent content
          Content that contains the text.
protected static boolean DEBUG
          If true, does additional debugging output to console.
protected  com.bluemarsh.adt.PriorityList drawLayersList
          Draw layers in priority order.
protected static java.awt.Color gutterColor
          Color for the gutter background.
protected  com.bluemarsh.adt.PriorityList gutterLayersList
          Draw layers in priority order.
protected  int gutterWidth
          Width of the gutter.
protected static Category logCategory
          Debug reporting category.
protected  SelectionDrawLayer selectionDrawLayer
          Draw layer for drawing the current text selection.
 
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
SourceViewTextArea(char[] buf)
          Constructs a SourceViewTextArea for the given text.
 
Method Summary
 void addDrawLayer(DrawLayer layer, int prio)
          Adds the given draw layer to this text area.
 void addGutterLayer(GutterDrawLayer layer, int prio)
          Adds the given draw layer to this text area.
 SourceContent getContent()
          Returns the source view text area content object.
 java.awt.Dimension getPreferredScrollableViewportSize()
          Returns the preferred size of the viewport for a view component.
 java.awt.Dimension getPreferredSize()
          Calculates and returns the preferred size of the text area.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.
 boolean getScrollableTracksViewportHeight()
          Return true if a viewport should always force the height of this Scrollable to match the height of the viewport.
 boolean getScrollableTracksViewportWidth()
          Return true if a viewport should always force the width of this Scrollable to match the width of the viewport.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation.
 int getSelectionEnd()
          Returns the selected text's end position.
 int getSelectionStart()
          Returns the selected text's start position.
 java.lang.String getToolTipText(java.awt.event.MouseEvent event)
          Checks to see if the mouse if hovering over a variable; if so, attempts to find the value of that variable and set the tooltip text.
 void paint(java.awt.Graphics g)
          Invoked by Swing to draw components.
protected  void paintGutter(java.awt.Graphics g)
          Draws the line numbers in the gutter area.
protected  void paintText(java.awt.Graphics g)
          Draws the text of the text area.
 void select(int selectionStart, int selectionEnd)
          Selects the text found between the specified start and end locations.
 void setContent(SourceContent content)
          Sets the source view text area content object to the one given.
 int viewToLine(java.awt.Point pt)
          Turns a view coordinate into a one-based line number.
 int viewToModel(java.awt.Point pt)
          Turns a view coordinate into a zero-based character offset.
 
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, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

protected static final boolean DEBUG
If true, does additional debugging output to console.

logCategory

protected static Category logCategory
Debug reporting category.

gutterColor

protected static java.awt.Color gutterColor
Color for the gutter background.

content

protected SourceContent content
Content that contains the text.

selectionDrawLayer

protected SelectionDrawLayer selectionDrawLayer
Draw layer for drawing the current text selection.

drawLayersList

protected com.bluemarsh.adt.PriorityList drawLayersList
Draw layers in priority order.

gutterLayersList

protected com.bluemarsh.adt.PriorityList gutterLayersList
Draw layers in priority order.

gutterWidth

protected int gutterWidth
Width of the gutter.
Constructor Detail

SourceViewTextArea

public SourceViewTextArea(char[] buf)
Constructs a SourceViewTextArea for the given text.
Parameters:
buf - array of text, sized to fit.
Method Detail

addDrawLayer

public void addDrawLayer(DrawLayer layer,
                         int prio)
Adds the given draw layer to this text area.
Parameters:
layer - draw layer to add.
prio - priority for the draw layer.

addGutterLayer

public void addGutterLayer(GutterDrawLayer layer,
                           int prio)
Adds the given draw layer to this text area.
Parameters:
layer - draw layer to add.
prio - priority for the draw layer.

getContent

public SourceContent getContent()
Returns the source view text area content object.
Returns:
content.

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for a view component. For example the preferredSize of a JList component is the size required to acommodate all of the cells in its list however the value of preferredScrollableViewportSize is the size required for JList.getVisibleRowCount() rows. A component without any properties that would effect the viewport size should just return getPreferredSize() here.
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable
Returns:
The preferredSize of a JViewport whose view is this Scrollable.
See Also:
JComponent.getPreferredSize()

getPreferredSize

public java.awt.Dimension getPreferredSize()
Calculates and returns the preferred size of the text area.
Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
the preferred size.

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation. Ideally, components should handle a partially exposed row or column by returning the distance required to completely expose the item.

Scrolling containers, like JScrollPane, will use this method each time the user requests a unit scroll.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "unit" increment for scrolling in the specified direction.
See Also:
JScrollBar.setUnitIncrement(int)

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.

Scrolling containers, like JScrollPane, will use this method each time the user requests a block scroll.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "block" increment for scrolling in the specified direction.
See Also:
JScrollBar.setBlockIncrement(int)

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Return true if a viewport should always force the width of this Scrollable to match the width of the viewport. For example a normal text view that supported line wrapping would return true here, since it would be undesirable for wrapped lines to disappear beyond the right edge of the viewport. Note that returning true for a Scrollable whose ancestor is a JScrollPane effectively disables horizontal scrolling.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable
Returns:
True if a viewport should force the Scrollable's width to match its own.

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Return true if a viewport should always force the height of this Scrollable to match the height of the viewport. For example a columnar text view that flowed text in left to right columns could effectively disable vertical scrolling by returning true here.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable
Returns:
True if a viewport should force the Scrollable's height to match its own.

getSelectionEnd

public int getSelectionEnd()
Returns the selected text's end position. Return 0 if the document is empty, or the value of dot if there is no selection.
Returns:
the end position >= 0

getSelectionStart

public int getSelectionStart()
Returns the selected text's start position. Return 0 if the document is empty, or the value of dot if there is no selection.
Returns:
the start position >= 0

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent event)
Checks to see if the mouse if hovering over a variable; if so, attempts to find the value of that variable and set the tooltip text.
Overrides:
getToolTipText in class javax.swing.JComponent
Parameters:
event - the event that caused the tooltip to appear.
Returns:
the text for the tooltip.

paint

public void paint(java.awt.Graphics g)
Invoked by Swing to draw components.
Overrides:
paint in class javax.swing.JComponent
Parameters:
g - the Graphics context in which to paint.

paintGutter

protected void paintGutter(java.awt.Graphics g)
Draws the line numbers in the gutter area.
Parameters:
g - graphics context to draw to.

paintText

protected void paintText(java.awt.Graphics g)
Draws the text of the text area.
Parameters:
g - graphics context to draw to.

select

public void select(int selectionStart,
                   int selectionEnd)
Selects the text found between the specified start and end locations.
Parameters:
selectionStart - the start position of the text >= 0
selectionEnd - the end position of the text >= 0

setContent

public void setContent(SourceContent content)
Sets the source view text area content object to the one given.
Parameters:
content - new content object.

viewToLine

public int viewToLine(java.awt.Point pt)
Turns a view coordinate into a one-based line number.
Specified by:
viewToLine in interface com.bluemarsh.jswat.view.SourceViewArea
Parameters:
pt - Point within the view coordinates.
Returns:
One-based line number corresponding to the point. If the returned value is -1 then there was an error.

viewToModel

public int viewToModel(java.awt.Point pt)
Turns a view coordinate into a zero-based character offset.
Parameters:
pt - Point within the view coordinates.
Returns:
Zero-based character offset corresponding to the point. If the returned value is -1 then there was an error.