JIDE 3.5.15

com.jidesoft.diff
Class CodeEditorMergePane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.diff.AbstractDiffPane
                      extended by com.jidesoft.diff.AbstractMergePane
                          extended by com.jidesoft.diff.CodeEditorMergePane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CodeEditorMergePane
extends AbstractMergePane

CodeEditorMergePane is a merge pane based on CodeEditor component in JIDE Code Editor product. It can be used to compare three block of multiple line texts. The text will be displayed in a CodeEditor to have syntax coloring. It also uses the highlight features provided by CodeEditor to make it easy to see the differences and let user do the merging.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  com.jidesoft.diff.DiffMargin _fromDiffMargin
           
protected  CodeEditor _fromEditor
           
protected  com.jidesoft.diff.DiffMargin _otherDiffMargin
           
protected  CodeEditor _otherEditor
           
protected  CodeEditor _toEditor
           
protected  int GAP_TITLE_PANE
           
 
Fields inherited from class com.jidesoft.diff.AbstractMergePane
_conflictedColor, COMMAND_ACCEPT
 
Fields inherited from class com.jidesoft.diff.AbstractDiffPane
_actions, _changedColor, _deletedColor, _insertedColor, COMMAND_FIRST, COMMAND_LAST, COMMAND_NEXT, COMMAND_PREVIOUS
 
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
CodeEditorMergePane()
           
CodeEditorMergePane(String fromText, String toText, String otherText)
           
 
Method Summary
protected  List<Conflict> acceptConflict(List<Conflict> conflicts, Difference c)
           
protected  List<Conflict> acceptDocumentChange(List<Conflict> conflicts, DocumentEvent e)
           
 void acceptNonConflicts()
           
protected  void adjustDividerOffset(DiffDivider divider, int index)
          Adjusts the DiffDivider's left and right offset.
 void clearMerge()
          Clears the merge results.
 DiffDivider createDivider(int index)
          Subclass implements it to create a DiffDivider that appears between the panes.
protected  CodeEditor createEditor()
           
protected  CodeEditor createEditor(int index)
          Creates the code editor.
protected  DiffDivider.RowConverter createFromRowConverter()
           
protected  JComponent createFromTitle()
           
protected  CharSequence createLineCharSequence(CodeEditor editor, int lineIndex)
          Creates the line char sequence for the code editor in the designated line.
protected  Merge<CharSequence> createMerge()
          Creates the merge.
protected  DiffDivider.RowConverter createOtherRowConverter()
           
protected  JComponent createOtherTitle()
           
 JComponent createPane(Object item, int index)
          Subclass implements it to use a different component to display the objects to be compared.
protected  DiffDivider.RowConverter createToRowConverter()
           
protected  JComponent createToTitle()
           
protected  void customizeDivider(DiffDivider divider, int index)
          Customizes the newly created DiffDivider.
protected  void customizeEditor(CodeEditor editor, int index)
           
 void delete(int line, int numberOfLines, boolean runMergeAfterward)
           
protected  void firstChange()
          Goes to the first change.
 List<Conflict> getConflicts()
           
 CodeEditor getFromEditor()
          Gets the from code editor.
 CharSequence[] getFromItems()
          Gets the from items to compare.
 String getFromText()
           
 String getFromTitle()
           
protected  List<Difference> getFromToDifferences(List<Conflict> conflicts)
           
 CodeEditor getOtherEditor()
          Gets the other code editor.
 CharSequence[] getOtherItems()
          Gets the other items to compare.
 String getOtherText()
           
 String getOtherTitle()
           
 CodeEditor getToEditor()
          Gets the to code editor.
 CharSequence[] getToItems()
          Gets the to items to compare.
protected  List<Difference> getToOtherDifferences(List<Conflict> conflicts)
           
 String getToText()
           
 String getToTitle()
           
protected  List<Conflict> ignoreConflict(List<Conflict> conflicts, Difference c)
           
 void insert(CodeEditor codeEditor, int line, int fromLine, int fromNumberOfLines, boolean runMergeAfterward)
           
protected  void installListeners()
          Installs the listeners.
 boolean isConflicted()
          Checks if there is any conflicting changes during the merging process.
 boolean isIgnoreLeadingTrailingSpaces()
          Gets the flag indicating if the leading and trailing spaces should be ignored when comparing two texts.
 boolean isReadOnly()
          Checks if the diff pane is read only.
protected  void lastChange()
          Goes to the last change.
 List<Conflict> merge()
           
protected  List<Conflict> merge(String fromText, String toText, String otherText)
          Deprecated. replaced by createMerge().
protected  void nextChange()
          Goes to the next change.
protected  void previousChange()
          Goes to the previous change.
 void replace(CodeEditor codeEditor, int line, int numberOfLines, int fromLine, int fromNumberOfLines, boolean runMergeAfterward)
           
 void setChangedColor(Color changedColor)
           
 void setConflictedColor(Color conflictedColor)
           
 void setDeletedColor(Color deletedColor)
           
 void setFromText(String fromText)
          Sets the text for the from editor.
 void setFromTitle(String title)
           
 void setIgnoreLeadingTrailingSpaces(boolean ignoreLeadingTrailingSpaces)
          Sets the flag indicating if the leading and trailing spaces should be ignored when comparing two texts.
 void setInsertedColor(Color insertedColor)
           
 void setOtherText(String otherText)
          Sets the text for the other editor.
 void setOtherTitle(String title)
           
 void setReadOnly(boolean readOnly)
          Sets the read only flag.
 void setToText(String toText)
          Sets the text for the to editor.
 void setToTitle(String title)
           
protected  String[] splitString(String string, String lineBreak)
          Deprecated. replaced by createLineCharSequence(com.jidesoft.editor.CodeEditor, int).
protected  void synchronizeViewport(DiffDivider diffDivider, CodeEditor firstEditor, CodeEditor secondEditor, boolean changeFromFirst)
           
protected  void updateActions(int index)
          Updates the enable/disable states of the actions on the toolbar buttons.
 
Methods inherited from class com.jidesoft.diff.AbstractMergePane
createActions, createLegendBar, customizeToolBar, getConflictedColor
 
Methods inherited from class com.jidesoft.diff.AbstractDiffPane
createButton, createContentArea, createStatusBar, createToolBar, customizeAction, customizePane, customizePanes, flip, getChangedColor, getDeletedColor, getInsertedColor, getMessage, getResourceString, initLayout, setMessage, uninstallListeners
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GAP_TITLE_PANE

protected final int GAP_TITLE_PANE
See Also:
Constant Field Values

_fromEditor

protected CodeEditor _fromEditor

_toEditor

protected CodeEditor _toEditor

_otherEditor

protected CodeEditor _otherEditor

_fromDiffMargin

protected com.jidesoft.diff.DiffMargin _fromDiffMargin

_otherDiffMargin

protected com.jidesoft.diff.DiffMargin _otherDiffMargin
Constructor Detail

CodeEditorMergePane

public CodeEditorMergePane()

CodeEditorMergePane

public CodeEditorMergePane(String fromText,
                           String toText,
                           String otherText)
Method Detail

createPane

public JComponent createPane(Object item,
                             int index)
Description copied from class: AbstractDiffPane
Subclass implements it to use a different component to display the objects to be compared.

Specified by:
createPane in class AbstractDiffPane
Parameters:
item - item to be compared. The component should be able to display the item.
index - the index of the pane. For example, for a type diff pane to compare two items before and after modification, the index 0 will be the original item before modification, the index 1 will be the item after modification.
Returns:
the component to display the item to be compared.

createDivider

public DiffDivider createDivider(int index)
Description copied from class: AbstractDiffPane
Subclass implements it to create a DiffDivider that appears between the panes.

Specified by:
createDivider in class AbstractDiffPane
Parameters:
index - the index of the DiffDivider
Returns:
the DiffDivider.

customizeDivider

protected void customizeDivider(DiffDivider divider,
                                int index)
Description copied from class: AbstractDiffPane
Customizes the newly created DiffDivider.

Overrides:
customizeDivider in class AbstractDiffPane
Parameters:
divider - the diff divider
index - the index of the diff divider

setChangedColor

public void setChangedColor(Color changedColor)
Overrides:
setChangedColor in class AbstractDiffPane

setInsertedColor

public void setInsertedColor(Color insertedColor)
Overrides:
setInsertedColor in class AbstractDiffPane

setDeletedColor

public void setDeletedColor(Color deletedColor)
Overrides:
setDeletedColor in class AbstractDiffPane

setConflictedColor

public void setConflictedColor(Color conflictedColor)
Overrides:
setConflictedColor in class AbstractMergePane

adjustDividerOffset

protected void adjustDividerOffset(DiffDivider divider,
                                   int index)
Description copied from class: AbstractDiffPane
Adjusts the DiffDivider's left and right offset.

Overrides:
adjustDividerOffset in class AbstractDiffPane
Parameters:
divider - the DiffDivider.
index - the index of the DiffDivider.

createFromTitle

protected JComponent createFromTitle()

createToTitle

protected JComponent createToTitle()

createOtherTitle

protected JComponent createOtherTitle()

getFromTitle

public String getFromTitle()

setFromTitle

public void setFromTitle(String title)

getToTitle

public String getToTitle()

setToTitle

public void setToTitle(String title)

getOtherTitle

public String getOtherTitle()

setOtherTitle

public void setOtherTitle(String title)

createEditor

protected CodeEditor createEditor(int index)
Creates the code editor.

By default, it invokes createEditor() to create a CodeEditor instance.

Parameters:
index - the code editor index
Returns:
the CodeEditor instance.
Since:
3.4.1

createEditor

protected CodeEditor createEditor()

customizeEditor

protected void customizeEditor(CodeEditor editor,
                               int index)

getFromEditor

public CodeEditor getFromEditor()
Gets the from code editor.

Returns:
the from code editor.
Since:
3.4.1

getToEditor

public CodeEditor getToEditor()
Gets the to code editor.

Returns:
the to code editor.
Since:
3.4.1

getOtherEditor

public CodeEditor getOtherEditor()
Gets the other code editor.

Returns:
the other code editor.
Since:
3.4.1

getFromItems

public CharSequence[] getFromItems()
Gets the from items to compare.

Returns:
the CharSequence array from the from editor.
Since:
3.4.1

getToItems

public CharSequence[] getToItems()
Gets the to items to compare.

Returns:
the CharSequence array from the to editor.
Since:
3.4.1

getOtherItems

public CharSequence[] getOtherItems()
Gets the other items to compare.

Returns:
the CharSequence array from the other editor.
Since:
3.4.1

createLineCharSequence

protected CharSequence createLineCharSequence(CodeEditor editor,
                                              int lineIndex)
Creates the line char sequence for the code editor in the designated line.

By default, a CodeEditorCharSequence is created.

Parameters:
editor - the code editor
lineIndex - the line number
Returns:
the CharSequence instance.
Since:
3.4.1

setFromText

public void setFromText(String fromText)
Sets the text for the from editor.

Parameters:
fromText - the new text for the from editor.

getFromText

public String getFromText()

setToText

public void setToText(String toText)
Sets the text for the to editor.

Parameters:
toText - the new text for the to editor.

getToText

public String getToText()

setOtherText

public void setOtherText(String otherText)
Sets the text for the other editor.

Parameters:
otherText - the new text for the other editor.

getOtherText

public String getOtherText()

createFromRowConverter

protected DiffDivider.RowConverter createFromRowConverter()

createToRowConverter

protected DiffDivider.RowConverter createToRowConverter()

createOtherRowConverter

protected DiffDivider.RowConverter createOtherRowConverter()

synchronizeViewport

protected void synchronizeViewport(DiffDivider diffDivider,
                                   CodeEditor firstEditor,
                                   CodeEditor secondEditor,
                                   boolean changeFromFirst)

updateActions

protected void updateActions(int index)
Description copied from class: AbstractDiffPane
Updates the enable/disable states of the actions on the toolbar buttons.

Overrides:
updateActions in class AbstractDiffPane
Parameters:
index - the pane index. This is the pane that triggers the update.

installListeners

protected void installListeners()
Description copied from class: AbstractDiffPane
Installs the listeners. Subclass can override this method to install the necessary listeners. This method is called only in the constructor.

Overrides:
installListeners in class AbstractDiffPane

splitString

@Deprecated
protected String[] splitString(String string,
                                          String lineBreak)
Deprecated. replaced by createLineCharSequence(com.jidesoft.editor.CodeEditor, int).

Splits the string with the line break.

This method is no longer being invoked since 3.4.1.

Parameters:
string - the string
lineBreak - the line break

merge

@Deprecated
protected List<Conflict> merge(String fromText,
                                          String toText,
                                          String otherText)
Deprecated. replaced by createMerge().

Merges to get the conflicts.

Parameters:
fromText - the from text
toText - the to text
otherText - the other text
Returns:
the list of conflicts.

createMerge

protected Merge<CharSequence> createMerge()
Creates the merge.

By default, it returns new Merge(getFromItems(), getToItems(), getOtherItems()).

Returns:
the Merge instance.
Since:
3.4.1

isReadOnly

public boolean isReadOnly()
Checks if the diff pane is read only. A read only merge pane will not show the buttons to apply changes.

Returns:
true or false.

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the read only flag. A read only merge pane will not show the buttons to apply changes.

Parameters:
readOnly - the new read only flag.

getFromToDifferences

protected List<Difference> getFromToDifferences(List<Conflict> conflicts)

getToOtherDifferences

protected List<Difference> getToOtherDifferences(List<Conflict> conflicts)

getConflicts

public List<Conflict> getConflicts()

acceptConflict

protected List<Conflict> acceptConflict(List<Conflict> conflicts,
                                        Difference c)

ignoreConflict

protected List<Conflict> ignoreConflict(List<Conflict> conflicts,
                                        Difference c)

acceptDocumentChange

protected List<Conflict> acceptDocumentChange(List<Conflict> conflicts,
                                              DocumentEvent e)

merge

public List<Conflict> merge()

clearMerge

public void clearMerge()
Clears the merge results.


delete

public void delete(int line,
                   int numberOfLines,
                   boolean runMergeAfterward)

insert

public void insert(CodeEditor codeEditor,
                   int line,
                   int fromLine,
                   int fromNumberOfLines,
                   boolean runMergeAfterward)

replace

public void replace(CodeEditor codeEditor,
                    int line,
                    int numberOfLines,
                    int fromLine,
                    int fromNumberOfLines,
                    boolean runMergeAfterward)

firstChange

protected void firstChange()
Description copied from class: AbstractDiffPane
Goes to the first change.

Overrides:
firstChange in class AbstractDiffPane

previousChange

protected void previousChange()
Description copied from class: AbstractDiffPane
Goes to the previous change.

Overrides:
previousChange in class AbstractDiffPane

nextChange

protected void nextChange()
Description copied from class: AbstractDiffPane
Goes to the next change.

Overrides:
nextChange in class AbstractDiffPane

lastChange

protected void lastChange()
Description copied from class: AbstractDiffPane
Goes to the last change.

Overrides:
lastChange in class AbstractDiffPane

acceptNonConflicts

public void acceptNonConflicts()
Overrides:
acceptNonConflicts in class AbstractMergePane

isConflicted

public boolean isConflicted()
Checks if there is any conflicting changes during the merging process.

Returns:
true or false. If false, it means all the changes are non-conflicts. You could call acceptNonConflicts() to accept all the changes.

isIgnoreLeadingTrailingSpaces

public boolean isIgnoreLeadingTrailingSpaces()
Gets the flag indicating if the leading and trailing spaces should be ignored when comparing two texts.

Returns:
true if leading and trailing spaces should be ignored. Otherwise false.
Since:
3.4.1
See Also:
setIgnoreLeadingTrailingSpaces(boolean)

setIgnoreLeadingTrailingSpaces

public void setIgnoreLeadingTrailingSpaces(boolean ignoreLeadingTrailingSpaces)
Sets the flag indicating if the leading and trailing spaces should be ignored when comparing two texts.

By default, the value is false to keep the original behavior.

Parameters:
ignoreLeadingTrailingSpaces - the flag
Since:
3.4.1

JIDE 3.5.15