upidiff.merge
Class Merge

java.lang.Object
  |
  +--upidiff.merge.Merge

public class Merge
extends Object

This class represents the management for the merged version of two files

Author:
Alexander Jung

Nested Class Summary
(package private)  class Merge.MergeListener
          This class represents the DocumentListener for the MergeDocument After an editing in the document or a merged ChangeObject it calls the method to correct the offset.
 
Field Summary
private  DebugGraphics debugGraphics
          Object to handel graphics and to get the FontMetiric of the Textpanes
private  JScrollPane externScrollPane
          extern object to handel scrolling of the merged text
private  FileChange fileChange
          Container with all collected Information about the two files set to be merged
private  FontMetrics fontMetrics
          Object for the FontMetric of the Textpanes
private  StyledDocument linenumbers
          The container for the linenumbers
private  StyledDocument mergeDoc
          The container for the text and the Interface for the GUI
private  LineOffset mergeOffset
          Object to manage the Line/Char Offset for the Text The information about every singel line are contained in LineElements
static int NEWFILE
          A constant definde to name the new file
private  String newLine
          Contains the NextLine String of the current running operatingsystem
static int OLDFILE
          A constant defined to name the old file
private  String spacer
          Contains the spacer to be inserted in the text in place of the changes to mark their positions
private  VisualDiff visualDiff
          Reference of the parent VisualDiff object
 
Constructor Summary
Merge(FileChange fileChange, VisualDiff visualDiff)
          Constructs a new object of this class
 
Method Summary
 void addChange(Change addChange, int whichFile)
          Method to add a Version of the Change to the file
private  void addCharChange(Change charChange, int linenumber, int whichFile)
          This Method adds a CharChange to the mergeDoc
 void addEditedString(int start, String addedString)
          Method to add a String to the offset of the file Attention: This Method doesn't add the String itself to the file but adds the offset of the string.
private  void addEmtyLine(int linenumber, Change change, boolean addNextLine)
          Method to add an emty line to the text
private  void addLine(String insert, int orgLinenum, Change change)
          Method to add a line to the text
private  void addLineChange(int linenumber, int whichFile)
          This Method adds a LineChange to the mergeDoc
private  void addLinenumber()
          This method adds a line with a linenumber to the linenumber document
 void debugOutput()
          This Method creates an debugoutput.
 StyledDocument getLinenumbers()
          Queries the StyledDocument used for the linenumbers in the text.
 StyledDocument getMergeDoc()
          Queries the StyledDocument used for the merged text
 void recalculate(int lineOldFile, int lineNewFile)
          Method to handel a manual recalculation of the differences
 void removeChange(Change removeChange)
          Method to remove a Version of the Change from the file
 void removeEditedString(int start, int length)
          Method to remove a String from the fileoffset Attention: This Method doesn't remove the String itself to the file but removes the offset of the string.
private  void removeLinenumber()
          This method removes the last linenumber from the Linenumbers Document
private  void removeSpacer(int pos)
          Removes a Spacer in the Text that marks the Positon of a Change
 void scrollToChange(Change change)
          This Method scrolls the externScrollpane to the given ChangeObject
 void setChangeMerged(Change currentChange, int whichVersion)
          This Method sets the Current Change-Object merged If this Object has SubChangeobjects, these will also be set merged
 void setExternScrollPane(JScrollPane externScrollPane)
          This Method set the extern ScrollPane to handel scrolling
private  void setSpacer(int line, int charInLine)
          Sets a Spacer in the Text to mark the Positon of a Change
 void setUnchangedText(int lineOldFile, int lineNewFile)
          Method to take the parts of the text that were unchanged between the two versions of the text in this document and create the offsets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mergeDoc

private StyledDocument mergeDoc
The container for the text and the Interface for the GUI

See Also:
StyledDocument

linenumbers

private StyledDocument linenumbers
The container for the linenumbers


mergeOffset

private LineOffset mergeOffset
Object to manage the Line/Char Offset for the Text The information about every singel line are contained in LineElements

See Also:
LineOffset, LineElement

fileChange

private FileChange fileChange
Container with all collected Information about the two files set to be merged

See Also:
FileChange

visualDiff

private VisualDiff visualDiff
Reference of the parent VisualDiff object


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


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

externScrollPane

private JScrollPane externScrollPane
extern object to handel scrolling of the merged text


newLine

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


spacer

private String spacer
Contains the spacer to be inserted in the text in place of the changes to mark their positions

Constructor Detail

Merge

public Merge(FileChange fileChange,
             VisualDiff visualDiff)
Constructs a new object of this class

Parameters:
fileChange - Container with all information about the two files set to be merged
visualDiff - referenze to the parent VisualDiff object
Method Detail

setUnchangedText

public void setUnchangedText(int lineOldFile,
                             int lineNewFile)
Method to take the parts of the text that were unchanged between the two versions of the text in this document and create the offsets. Changed parts will be marked. This Method is only used in the construktor

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

addEmtyLine

private void addEmtyLine(int linenumber,
                         Change change,
                         boolean addNextLine)
Method to add an emty line to the text

Parameters:
change - The change of this line or null if there isn't one
linenumber - The number of the line to add the emty line to
addNextLine - True adds a lineseparator

addLine

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

Parameters:
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)
Method to handel a manual recalculation of the differences

Parameters:
lineOldFile - The line where the recalculation starts in the old file
lineNewFile - The line where the recalculation starts in the old file

addChange

public void addChange(Change addChange,
                      int whichFile)
               throws Exception
Method to add a Version of the Change to the file

Parameters:
addChange - The Changeobjekt containing the information about the difference
whichFile - The File wich contains the choosen Version. Use the constants OLDFILE and NEWFILE for this parameter
Throws:
Exception - If the handed over Change is not valid or already merged

addLineChange

private void addLineChange(int linenumber,
                           int whichFile)
This Method adds a LineChange to the mergeDoc

Parameters:
linenumber - The number of line to add
whichFile - From which file add the change?

addCharChange

private void addCharChange(Change charChange,
                           int linenumber,
                           int whichFile)
This Method adds a CharChange to the mergeDoc

Parameters:
charChange - The change to add
linenumber - The line that contains the CharChange
whichFile - From which file add the change?

removeChange

public void removeChange(Change removeChange)
Method to remove a Version of the Change from the file

Parameters:
removeChange - The Changeobjekt containing the information about the difference

addEditedString

public void addEditedString(int start,
                            String addedString)
Method to add a String to the offset of the file Attention: This Method doesn't add the String itself to the file but adds the offset of the string. Use it only to add a manual userinput to the offset.

Parameters:
start - the position of the char where the inserted string starts in the file (Use the totalnumber of Chars in text)
addedString - The added String itself.

removeEditedString

public void removeEditedString(int start,
                               int length)
Method to remove a String from the fileoffset Attention: This Method doesn't remove the String itself to the file but removes the offset of the string. Use it only to add a manual userinput to the offset.

Parameters:
start - the position of the char where the inserted string starts in the file (Use the totalnumber of Chars in text)
length - The length of the removed String.

addLinenumber

private void addLinenumber()
This method adds a line with a linenumber to the linenumber document


removeLinenumber

private void removeLinenumber()
This method removes the last linenumber from the Linenumbers Document


setSpacer

private void setSpacer(int line,
                       int charInLine)
Sets a Spacer in the Text to mark the Positon of a Change

Parameters:
line - The Position of the line in the Text where to set the spacer
charInLine - The Positon of the char in the line to set the spacer

removeSpacer

private void removeSpacer(int pos)
Removes a Spacer in the Text that marks the Positon of a Change

Parameters:
pos - The position of the Spacer in the Text

setChangeMerged

public void setChangeMerged(Change currentChange,
                            int whichVersion)
This Method sets the Current Change-Object merged If this Object has SubChangeobjects, these will also be set merged

Parameters:
currentChange - The ChangeObject to be set merged
whichVersion - The merged version. Use OLDFILE or NEWFILE only

scrollToChange

public void scrollToChange(Change change)
This Method scrolls the externScrollpane to the given ChangeObject

Parameters:
change - the Changeobject to scroll to

getMergeDoc

public StyledDocument getMergeDoc()
Queries the StyledDocument used for the merged text

Returns:
the SyledDocument with the merged text

getLinenumbers

public StyledDocument getLinenumbers()
Queries the StyledDocument used for the linenumbers in the text.

Returns:
the StyledDocument with the linenumbers of the merged text

setExternScrollPane

public void setExternScrollPane(JScrollPane externScrollPane)
This Method set the extern ScrollPane to handel scrolling

Parameters:
externScrollPane - The extern ScrollPane

debugOutput

public void debugOutput()
This Method creates an debugoutput. Use it only for debugging!!