com.bluemarsh.jswat.view
Class BasicView

java.lang.Object
  |
  +--com.bluemarsh.jswat.view.JSwatView
        |
        +--com.bluemarsh.jswat.view.BasicView
Direct Known Subclasses:
SourceView

public abstract class BasicView
extends JSwatView

Class BasicView provides the basic support for displaying textual data in a scrollable, searchable area.

Author:
Nathan Fiedler

Field Summary
protected  java.lang.Object highlightTag
          The highlighter's tag that represents the current text highlight.
protected static Category logCategory
          Debug reporting category.
protected  javax.swing.text.JTextComponent textComponent
          Text area for displaying the source.
protected  javax.swing.text.Highlighter.HighlightPainter textHighlightPainter
          Highlighter used to highlight the current stepping line.
protected  java.lang.String viewContent
          Text from the text component.
protected  java.lang.String viewTitle
          The title of our view, used for reporting.
 
Constructor Summary
BasicView(java.lang.String title)
          Creates a BasicView object.
 
Method Summary
 boolean findString(java.lang.String str, boolean ignoreCase)
          Look for the given string in the source view's text area.
protected  void foundString(java.lang.String str, int start)
          Show that we found the string we were looking for.
protected abstract  int getLineEndOffset(int line)
          Get the offset of the end of the given line.
protected abstract  int getLineOfOffset(int offset)
          Find the line containing the given offset.
protected abstract  int getLineStartOffset(int line)
          Get the offset of the start of the given line.
protected  void removeHighlight()
          Removes the highlight from the text area, on the AWT event dispatching thread.
 void scrollToLine(int line)
          Scrolls the source view to the given line, if possible.
 void setTextComponent(javax.swing.text.JTextComponent text)
          Sets the text component for this view.
protected  void showHighlight(int line)
          Highlight the given line in the text area, on the AWT event dispatching thread.
 
Methods inherited from class com.bluemarsh.jswat.view.JSwatView
getUI, refresh
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logCategory

protected static Category logCategory
Debug reporting category.

viewTitle

protected java.lang.String viewTitle
The title of our view, used for reporting.

textComponent

protected javax.swing.text.JTextComponent textComponent
Text area for displaying the source.

viewContent

protected java.lang.String viewContent
Text from the text component. Used in the findString() method.

textHighlightPainter

protected javax.swing.text.Highlighter.HighlightPainter textHighlightPainter
Highlighter used to highlight the current stepping line.

highlightTag

protected java.lang.Object highlightTag
The highlighter's tag that represents the current text highlight. Used to highlight the current stepping line in the text area.
Constructor Detail

BasicView

public BasicView(java.lang.String title)
Creates a BasicView object.
Parameters:
title - title of the view, for reporting purposes.
Method Detail

findString

public boolean findString(java.lang.String str,
                          boolean ignoreCase)
Look for the given string in the source view's text area. Uses the text area's current selection as the starting point. Will wrap around if the string was not found after the current selection.
Parameters:
str - string to look for.
ignoreCase - true to ignore case.
Returns:
true if string was found somewhere, false if string does not exist in this view.

foundString

protected void foundString(java.lang.String str,
                           int start)
Show that we found the string we were looking for.
Parameters:
str - string we were looking for.
start - start offset of matched string.

getLineEndOffset

protected abstract int getLineEndOffset(int line)
                                 throws javax.swing.text.BadLocationException
Get the offset of the end of the given line.
Parameters:
line - zero-based line for which to find the end.
Returns:
offset of end of line.
Throws:
javax.swing.text.BadLocationException - Thrown if line is invalid.

getLineOfOffset

protected abstract int getLineOfOffset(int offset)
                                throws javax.swing.text.BadLocationException
Find the line containing the given offset.
Parameters:
offset - offset within document >= 0.
Returns:
zero-based line containing that offset.
Throws:
javax.swing.text.BadLocationException - Thrown if offset is invalid.

getLineStartOffset

protected abstract int getLineStartOffset(int line)
                                   throws javax.swing.text.BadLocationException
Get the offset of the start of the given line.
Parameters:
line - zero-based line for which to find the start.
Returns:
offset of start of line.
Throws:
javax.swing.text.BadLocationException - Thrown if line is invalid.

removeHighlight

protected void removeHighlight()
Removes the highlight from the text area, on the AWT event dispatching thread.

scrollToLine

public void scrollToLine(int line)
Scrolls the source view to the given line, if possible. Any value less than one is ignored.
Parameters:
line - line to scroll to (1-based).

setTextComponent

public void setTextComponent(javax.swing.text.JTextComponent text)
Sets the text component for this view.
Parameters:
text - text component used to display data.

showHighlight

protected void showHighlight(int line)
Highlight the given line in the text area, on the AWT event dispatching thread.
Parameters:
line - line in text area to be highlighted.