upidiff.gui
Class VisualDiff

java.lang.Object
  |
  +--upidiff.gui.VisualDiff

public class VisualDiff
extends Object

This class represents the visualation for two compared files

Author:
Alexander Jung

Field Summary
private  Catalog catalog
          I18n Catalog
private  Change currentChange
          The actual Change-Object to work with.
private  DebugGraphics debugGraphics
          Object to handel graphics and to get the FontMetiric of the Textpanes
private  SimpleAttributeSet deletedCharAttribute
          AttributeSet for the Backgroundcolor of a deleted Char
private  SimpleAttributeSet deletedLineAttribute
          AttributeSet for the Backgroundcolor of a deleted Line
private  JScrollPane externScrollPaneNew
          extern object to handel scrolling of the new text
private  JScrollPane externScrollPaneOld
          extern object to handel scrolling of the old texts
private  JLabel externStatusBarLabel
          extern object to be labeled with Information about the Changes
private  FileChange fileChange
          The container with all needed information about the compared Documents
private  FontMetrics fontMetrics
          Object for the FontMetric of the Textpanes
private  SimpleAttributeSet insertedCharAttribute
          AttributeSet for the Backgroundcolor of an inserted Char
private  SimpleAttributeSet insertedLineAttribute
          AttributeSet for the Backgroundcolor of an inserted Line
private  SimpleAttributeSet invertedAttribute
          AttributeSet for highlighting the linenumbers
private  Merge merge
          Object to handel the merging of the two files
private  SimpleAttributeSet mergedAttribute
          AttributeSet for the backgroundcolor of allready merged changes
private  StyledDocument newFile
          The container for the newFile Text and its Style
static int NEWFILE
          A constant definde to name the new file
private  StyledDocument newFileLinenumbers
          The container for the newFile Linenumbers and its Style
private  LineOffset newFileOffset
          Object to contain the Line/Char Offset for the new file The inner Vector contains a LineElement for each line
private  String newLine
          Contains the NextLine String of the current running operatingsystem
private  SimpleAttributeSet noneLineAttribute
          AttributeSet for none Backgroundcolor
private  StyledDocument oldFile
          The container for the oldFile Text and its Style
static int OLDFILE
          A constant defined to name the old file
private  StyledDocument oldFileLinenumbers
          The container for the oldFile Linenumbers and its Style
private  LineOffset oldFileOffset
          Object to contain the Line/Char Offset for the old file The inner Vector contains a LineElement for each line
private  UserPreferences prefs
          Reference to the User-Preferences
private  SimpleAttributeSet updatedLineAttribute
          AttributeSet for the Backgroundcolor of an updated Line
 
Constructor Summary
VisualDiff(FileChange fileChange, JLabel externStatusBarLabel, Catalog catalog)
          Constructs a new Object of this class
 
Method Summary
 boolean addChangeToMerge(int version)
          This method adds the current Change-Object to the merged document in the given Version
private  void addEmtyLine(int whichFile, Change change)
          method to add an emty line to the text
private  void addLine(int whichFile, String insert, int orgLinenum, Change change)
          method to add a line to the text
private  void createDocument(int lineOldFile, int lineNewFile)
          This method sets or resets the StyledDocument
 Change getCurrentChange()
          This method queries the current change
 FileChange getFileChange()
          This method Querries the FileChange object
 Merge getMerge()
          This method queries the Merge-Object
 StyledDocument getNewFile()
          Queries the newFile StyledDocument
 StyledDocument getNewFileLinenumbers()
          Queries the newFileLinenumber StyledDocument
 StyledDocument getOldFile()
          Queries the oldFile StyledDocument
 StyledDocument getOldFileLinenumbers()
          Queries the oldFileLinenumber StyledDocument
 void jumpToNext()
          This method sets the focus and the highlight on the next change.
 void jumpToPrev()
          This method sets the focus and the highlight on the prev
 void recalculate(int lineOldFile, int lineNewFile)
          This method manages the changing of the Styles in case of a recalculation
 void resetColors()
          This method resets the colors in the document
private  void scrollToLine(int linenumber)
          This method scrolls the extern JScrollpanes, if they are not null, to the given Line
 void setCloserLook()
          This method sets the next subchangeclass of currentChange visibel, if currentChange has such changes
 void setColors()
          This method sets the Backroundcolors in the Text according to the userpreference
 void setExternScrollPaneNew(JScrollPane externScrollPaneNew)
          This method sets the extern JScrollPane to handel the scrolling of the Text
 void setExternScrollPaneOld(JScrollPane externScrollPaneOld)
          This method sets the extern JScrollPane to handel the scrolling of the Text
 void setExternStatusBarLabel(JLabel externStatusBarLabel)
          This method sets the extern JLabel to show information about the curren Change
 void setHighlight()
          This method sets a highlight on the current change.
private  void setLineHighlight(int linenumber)
          This method sets a highlight on a line
private  void setLineStyle(int linenumber)
          method to set the style of a line
 void setStatus()
          This method sets the text on the statuslabel with information about the current ChangeObject
 void setStyle(Change change)
          This method sets a style on a change
 void setUndoCloserLook()
          This method sets the current visible subchangeclass of currentChange invisibel.
 void startMerge()
          This method creates the Merge-Object
private  void unsetHighlight(Change change)
          This method unsets the highlight on a change
private  void unsetLineStyle(int linenumber)
          Method to set the the style of a line to normal
private  void usetStyle(Change change)
          This method unsets the style of a change
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OLDFILE

public static final int OLDFILE
A constant defined to name the old file

See Also:
Constant Field Values

NEWFILE

public static final int NEWFILE
A constant definde to name the new file

See Also:
Constant Field Values

fileChange

private FileChange fileChange
The container with all needed information about the compared Documents


oldFile

private StyledDocument oldFile
The container for the oldFile Text and its Style


oldFileLinenumbers

private StyledDocument oldFileLinenumbers
The container for the oldFile Linenumbers and its Style


newFile

private StyledDocument newFile
The container for the newFile Text and its Style


newFileLinenumbers

private StyledDocument newFileLinenumbers
The container for the newFile Linenumbers and its Style


currentChange

private Change currentChange
The actual Change-Object to work with.


oldFileOffset

private LineOffset oldFileOffset
Object to contain the Line/Char Offset for the old file The inner Vector contains a LineElement for each line

See Also:
LineElement

newFileOffset

private LineOffset newFileOffset
Object to contain the Line/Char Offset for the new file The inner Vector contains a LineElement for each line

See Also:
LineElement

merge

private Merge merge
Object to handel the merging of the two files


externScrollPaneOld

private JScrollPane externScrollPaneOld
extern object to handel scrolling of the old texts


externScrollPaneNew

private JScrollPane externScrollPaneNew
extern object to handel scrolling of the new text


externStatusBarLabel

private JLabel externStatusBarLabel
extern object to be labeled with Information about the Changes


debugGraphics

private DebugGraphics debugGraphics
Object to handel graphics and to get the FontMetiric of the Textpanes


fontMetrics

private FontMetrics fontMetrics
Object for the FontMetric of the Textpanes


newLine

private String newLine
Contains the NextLine String of the current running operatingsystem


prefs

private UserPreferences prefs
Reference to the User-Preferences


catalog

private Catalog catalog
I18n Catalog


deletedLineAttribute

private SimpleAttributeSet deletedLineAttribute
AttributeSet for the Backgroundcolor of a deleted Line


insertedLineAttribute

private SimpleAttributeSet insertedLineAttribute
AttributeSet for the Backgroundcolor of an inserted Line


deletedCharAttribute

private SimpleAttributeSet deletedCharAttribute
AttributeSet for the Backgroundcolor of a deleted Char


insertedCharAttribute

private SimpleAttributeSet insertedCharAttribute
AttributeSet for the Backgroundcolor of an inserted Char


updatedLineAttribute

private SimpleAttributeSet updatedLineAttribute
AttributeSet for the Backgroundcolor of an updated Line


noneLineAttribute

private SimpleAttributeSet noneLineAttribute
AttributeSet for none Backgroundcolor


invertedAttribute

private SimpleAttributeSet invertedAttribute
AttributeSet for highlighting the linenumbers


mergedAttribute

private SimpleAttributeSet mergedAttribute
AttributeSet for the backgroundcolor of allready merged changes

Constructor Detail

VisualDiff

public VisualDiff(FileChange fileChange,
                  JLabel externStatusBarLabel,
                  Catalog catalog)
Constructs a new Object of this class

Parameters:
fileChange - contains the two files with their offset an the Changelist
externStatusBarLabel - extern Label to show information about the current change
catalog - The languagecatalog
Method Detail

createDocument

private void createDocument(int lineOldFile,
                            int lineNewFile)
This method sets or resets the StyledDocument

Parameters:
lineOldFile - The line to start with in the old file
lineNewFile - The line to start with in the new file

addEmtyLine

private void addEmtyLine(int whichFile,
                         Change change)
method to add an emty line to the text

Parameters:
whichFile - To choose a file use the constants OLDFILE or NEWFILE
change - The change of this line or null if there isn't one

addLine

private void addLine(int whichFile,
                     String insert,
                     int orgLinenum,
                     Change change)
method to add a line to the text

Parameters:
whichFile - To choose a file use the constants OLDFILE or NEWFILE
insert - The String to insert in the Text
orgLinenum - The linenumber the String has in the original Text
change - The change-object of the change in this line, or null if ther is no change in this line.

recalculate

public void recalculate(int lineOldFile,
                        int lineNewFile)
This method manages the changing of the Styles in case of a recalculation

Parameters:
lineOldFile - The line to start with in the old file
lineNewFile - The line to start with in the new file

startMerge

public void startMerge()
This method creates the Merge-Object


jumpToNext

public void jumpToNext()
This method sets the focus and the highlight on the next change.


jumpToPrev

public void jumpToPrev()
This method sets the focus and the highlight on the prev


scrollToLine

private void scrollToLine(int linenumber)
This method scrolls the extern JScrollpanes, if they are not null, to the given Line

Parameters:
linenumber - The linenumber to scroll to

setHighlight

public void setHighlight()
This method sets a highlight on the current change.


setLineHighlight

private void setLineHighlight(int linenumber)
This method sets a highlight on a line

Parameters:
linenumber - the number of the line

setStyle

public void setStyle(Change change)
This method sets a style on a change

Parameters:
change - The change to set the style on

setLineStyle

private void setLineStyle(int linenumber)
method to set the style of a line

Parameters:
linenumber - The number of the line to set the style on

usetStyle

private void usetStyle(Change change)
This method unsets the style of a change

Parameters:
change - The change to unset the change on

unsetLineStyle

private void unsetLineStyle(int linenumber)
Method to set the the style of a line to normal

Parameters:
linenumber - The number of the line

unsetHighlight

private void unsetHighlight(Change change)
This method unsets the highlight on a change

Parameters:
change - The change to unset the highlight on

setColors

public void setColors()
This method sets the Backroundcolors in the Text according to the userpreference


resetColors

public void resetColors()
This method resets the colors in the document


setCloserLook

public void setCloserLook()
This method sets the next subchangeclass of currentChange visibel, if currentChange has such changes


setUndoCloserLook

public void setUndoCloserLook()
This method sets the current visible subchangeclass of currentChange invisibel.


addChangeToMerge

public boolean addChangeToMerge(int version)
                         throws Exception
This method adds the current Change-Object to the merged document in the given Version

Parameters:
version - The version in that the Change-Object shout be merged. Use VisualDiff.OLDFILE or VisualDiff.NEWFILE for this parameter
Returns:
If all Changes are merged the return is true, else false.
Throws:
Exception - An exception from the merge.addChange call will be handed over to the GUI

setStatus

public void setStatus()
This method sets the text on the statuslabel with information about the current ChangeObject


getOldFile

public StyledDocument getOldFile()
Queries the oldFile StyledDocument

Returns:
The oldFile StyledDocument

getOldFileLinenumbers

public StyledDocument getOldFileLinenumbers()
Queries the oldFileLinenumber StyledDocument

Returns:
The oldFileLinenumber StyledDocument

getNewFile

public StyledDocument getNewFile()
Queries the newFile StyledDocument

Returns:
The newFile StyledDocument

getNewFileLinenumbers

public StyledDocument getNewFileLinenumbers()
Queries the newFileLinenumber StyledDocument

Returns:
The newFileLinenumber StyledDocument

getCurrentChange

public Change getCurrentChange()
This method queries the current change

Returns:
The current Changeobject

getMerge

public Merge getMerge()
This method queries the Merge-Object

Returns:
the Mergeobject

setExternScrollPaneOld

public void setExternScrollPaneOld(JScrollPane externScrollPaneOld)
This method sets the extern JScrollPane to handel the scrolling of the Text

Parameters:
externScrollPaneOld - The JScrollPane with the Old Text

setExternScrollPaneNew

public void setExternScrollPaneNew(JScrollPane externScrollPaneNew)
This method sets the extern JScrollPane to handel the scrolling of the Text

Parameters:
externScrollPaneNew - The JScrollPane with the New Text

setExternStatusBarLabel

public void setExternStatusBarLabel(JLabel externStatusBarLabel)
This method sets the extern JLabel to show information about the curren Change

Parameters:
externStatusBarLabel - the JLabel of a GUI

getFileChange

public FileChange getFileChange()
This method Querries the FileChange object

Returns:
the FileChange object