com.bluemarsh.jswat.view
Class SourceView

java.lang.Object
  |
  +--com.bluemarsh.jswat.view.JSwatView
        |
        +--com.bluemarsh.jswat.view.BasicView
              |
              +--com.bluemarsh.jswat.view.SourceView
All Implemented Interfaces:
BreakpointListener, com.bluemarsh.config.ConfigureListener, ContextListener, java.util.EventListener, SessionListener

public class SourceView
extends BasicView
implements BreakpointListener, ContextListener, com.bluemarsh.config.ConfigureListener, SessionListener

Defines the SourceView class which will be responsible for displaying the source file on the screen. This class displays a row header down the left side of the source view, indicating the line numbers. A popup menu is attached to the view for setting breakpoints.

Author:
Nathan Fiedler

Field Summary
protected  SourceViewPopup headerPopup
          Popup menu for managing breakpoints.
protected  Session owningSession
          Session to which we belong.
protected  java.io.File sourceFile
          Source file we read from.
protected  int tabSize
          Width of tabs in characters.
protected  SourceViewPopup textPopup
          Popup menu for managing breakpoints.
protected  com.bluemarsh.jswat.view.SourceViewHeader viewHeader
          Row header that is usually on the left side of the source window.
protected  javax.swing.JScrollPane viewScroller
          Scrollable component for text component.
 
Fields inherited from class com.bluemarsh.jswat.view.BasicView
highlightTag, logCategory, textComponent, textHighlightPainter, viewContent, viewTitle
 
Constructor Summary
SourceView(java.io.File source)
          Creates a SourceView object.
 
Method Summary
 void activate(Session session)
          Called when the Session is about to begin an active debugging session.
 void breakpointAdded(BreakpointEvent be)
          Invoked when a breakpoint has been added.
 void breakpointModified(BreakpointEvent be)
          Invoked when a breakpoint has been modified.
 void breakpointRemoved(BreakpointEvent be)
          Invoked when a breakpoint has been removed.
 void close(Session session)
          Called when the Session is about to close down.
 void configurationChanged()
          Called then the prefernces change.
 void contextChanged(ContextChangeEvent cce)
          Invoked when the current context has changed.
protected  javax.swing.text.Document createDefaultDocument()
          Creates a Document with all of the necessary styles.
protected  javax.swing.text.JTextComponent createTextComponent()
          Create the text component with the default document.
 void deactivate(Session session)
          Called when the Session is about to end an active debugging session.
protected static java.awt.Color getBreakpointColor(Breakpoint bp)
          Returns the color that best represents the state of this breakpoint.
 int getLineCount()
          Returns the number of lines in this document.
protected  int getLineEndOffset(int line)
          Get the offset of the end of the given line.
protected  int getLineOfOffset(int offset)
          Find the line containing the given offset.
protected  int getLineStartOffset(int line)
          Get the offset of the start of the given line.
protected  int getTabSize()
          Gets the number of characters used to expand tabs.
 javax.swing.JComponent getUI()
          Returns a reference to the UI component.
 void init(Session session)
          Called after the Session has added this listener to the Session listener list.
protected  boolean matches(Breakpoint bp)
          Check if the breakpoint is in the source we are displaying.
protected  boolean matches(com.sun.jdi.Location location)
          Check if the Location is in the same source file as the file we are displaying.
protected  void parseClassDefs()
          Reads the class definition information from the source file using the JavaParser class.
 boolean refresh(java.io.InputStream input, int line)
          Read the input stream text into the text component.
 boolean refresh(int line)
          Read the input stream text into the text component.
protected  void setBreakpoint(Breakpoint bp)
          Adds a line attribute to the source row header, appropriate for the given breakpoint.
protected  void setBreakpoints()
          Iterate all existing breakpoints and create row header attributes as appropriate.
protected  void setPreferences()
          Called to update this view's preferences, either when this object is constructed or when the preferences change.
protected  void setTabSize(int size)
          Sets the tab width of the source document.
protected  void setTextContent()
          Set the content of the text component using the String defined by viewContent.
 
Methods inherited from class com.bluemarsh.jswat.view.BasicView
findString, foundString, removeHighlight, scrollToLine, setTextComponent, showHighlight
 
Methods inherited from class com.bluemarsh.jswat.view.JSwatView
refresh
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceFile

protected java.io.File sourceFile
Source file we read from.

viewScroller

protected javax.swing.JScrollPane viewScroller
Scrollable component for text component.

viewHeader

protected com.bluemarsh.jswat.view.SourceViewHeader viewHeader
Row header that is usually on the left side of the source window. It provides line numbers and breakpoint indicators.

textPopup

protected SourceViewPopup textPopup
Popup menu for managing breakpoints. Listens to text component.

headerPopup

protected SourceViewPopup headerPopup
Popup menu for managing breakpoints. Listens to view header.

owningSession

protected Session owningSession
Session to which we belong. Set in init().

tabSize

protected int tabSize
Width of tabs in characters. Defaults to 8.
Constructor Detail

SourceView

public SourceView(java.io.File source)
Creates a SourceView object.
Parameters:
source - source code file to display
Method Detail

activate

public void activate(Session session)
Called when the Session is about to begin an active debugging session. That is, JSwat is about to debug a debuggee VM.
Specified by:
activate in interface SessionListener
Parameters:
session - Session being activated.

breakpointAdded

public void breakpointAdded(BreakpointEvent be)
Invoked when a breakpoint has been added.
Specified by:
breakpointAdded in interface BreakpointListener
Parameters:
be - breakpoint event.

breakpointModified

public void breakpointModified(BreakpointEvent be)
Invoked when a breakpoint has been modified.
Specified by:
breakpointModified in interface BreakpointListener
Parameters:
be - breakpoint event.

breakpointRemoved

public void breakpointRemoved(BreakpointEvent be)
Invoked when a breakpoint has been removed.
Specified by:
breakpointRemoved in interface BreakpointListener
Parameters:
be - breakpoint event.

close

public void close(Session session)
Called when the Session is about to close down. Closes this view, detaching it from all other objects and preparing it for finalization.
Specified by:
close in interface SessionListener
Parameters:
session - Session being closed.

configurationChanged

public void configurationChanged()
Called then the prefernces change.
Specified by:
configurationChanged in interface com.bluemarsh.config.ConfigureListener

contextChanged

public void contextChanged(ContextChangeEvent cce)
Invoked when the current context has changed. The context change event identifies which aspect of the context has changed.
Specified by:
contextChanged in interface ContextListener
Parameters:
cce - context change event

createDefaultDocument

protected javax.swing.text.Document createDefaultDocument()
Creates a Document with all of the necessary styles.
Returns:
document.
See Also:
createTextComponent()

createTextComponent

protected javax.swing.text.JTextComponent createTextComponent()
Create the text component with the default document.
Returns:
text component.
See Also:
createDefaultDocument()

deactivate

public void deactivate(Session session)
Called when the Session is about to end an active debugging session. That is, JSwat is about to terminate the connection with the debuggee VM.
Specified by:
deactivate in interface SessionListener
Parameters:
session - Session being deactivated.

getBreakpointColor

protected static java.awt.Color getBreakpointColor(Breakpoint bp)
Returns the color that best represents the state of this breakpoint. If the breakpoint is diabled, the color would be gray. On the other hand, if the breakpoint is enabled and ready, the color would be red. This is useful for those classes that want to visually represent the breakpoint using some colored object.
Returns:
the breakpoint "color".

getLineCount

public int getLineCount()
Returns the number of lines in this document. Lines are sequences of text separated by carriage return, line feed, or the pair of carriage return and line feed.
Returns:
line count.

getLineEndOffset

protected int getLineEndOffset(int line)
                        throws javax.swing.text.BadLocationException
Get the offset of the end of the given line.
Overrides:
getLineEndOffset in class BasicView
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 int getLineOfOffset(int offset)
                       throws javax.swing.text.BadLocationException
Find the line containing the given offset.
Overrides:
getLineOfOffset in class BasicView
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 int getLineStartOffset(int line)
                          throws javax.swing.text.BadLocationException
Get the offset of the start of the given line.
Overrides:
getLineStartOffset in class BasicView
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.

getTabSize

protected int getTabSize()
Gets the number of characters used to expand tabs. If the document is null or doesn't have a tab setting, return a default of 8.
Returns:
the number of characters.

getUI

public javax.swing.JComponent getUI()
Returns a reference to the UI component.
Overrides:
getUI in class JSwatView
Returns:
UI component object

init

public void init(Session session)
Called after the Session has added this listener to the Session listener list.
Specified by:
init in interface SessionListener
Parameters:
session - Session adding this listener.

matches

protected boolean matches(Breakpoint bp)
Check if the breakpoint is in the source we are displaying.
Parameters:
bp - breakpoint to check against.
Returns:
True if breakpoint source name same as our filename.

matches

protected boolean matches(com.sun.jdi.Location location)
Check if the Location is in the same source file as the file we are displaying.
Parameters:
location - Location to check.
Returns:
True if breakpoint source name same as our filename.

parseClassDefs

protected void parseClassDefs()
Reads the class definition information from the source file using the JavaParser class. Give this information to the text component and row header popup menus.

refresh

public boolean refresh(int line)
Read the input stream text into the text component. The view must be added to the Session as a session listener before calling this method.
Parameters:
line - line to make visible.
Returns:
true if successful, false if error.

refresh

public boolean refresh(java.io.InputStream input,
                       int line)
Read the input stream text into the text component. The view must be added to the Session as a session listener before calling this method.
Parameters:
input - input stream providing source.
line - line to make visible.
Returns:
true if successful, false if error.

setBreakpoint

protected void setBreakpoint(Breakpoint bp)
Adds a line attribute to the source row header, appropriate for the given breakpoint. Checks to make sure the breakpoint is set in our file.
Parameters:
bp - breakpoint.

setBreakpoints

protected void setBreakpoints()
Iterate all existing breakpoints and create row header attributes as appropriate.

setPreferences

protected void setPreferences()
Called to update this view's preferences, either when this object is constructed or when the preferences change.

setTabSize

protected void setTabSize(int size)
Sets the tab width of the source document.
Parameters:
size - number of spaces for a tab character.

setTextContent

protected void setTextContent()
Set the content of the text component using the String defined by viewContent. This implementation applies styles to the Java source to colorize it syntactically.