JIDE 3.4.0

com.jidesoft.diff
Class CodeEditorDiffPane

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.BasicDiffPane<String>
                          extended by com.jidesoft.diff.CodeEditorDiffPane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CodeEditorDiffPane
extends BasicDiffPane<String>

CodeEditorDiffPane is a diff pane based on CodeEditor component in JIDE Code Editor product. It can be used to compare two 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.

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  CodeEditor _fromEditor
           
protected  CodeEditor _toEditor
           
 
Fields inherited from class com.jidesoft.diff.BasicDiffPane
_diffed, _differences, _fromComponent, _fromDiffLineNumberMargin, _fromDiffMargin, _fromMarginArea, _fromMarkerArea, _fromRowMarginSupport, _fromScrollPane, _fromTitle, _fromToDivider, _toComponent, _toDiffLineNumberMargin, _toDiffMargin, _toMarginArea, _toMarkerArea, _toRowMarginSupport, _toScrollPane, _toTitle, GAP_TITLE_PANE, POSITION_AFTER_LAST, POSITION_BEFORE_FIRST, POSITION_IN_THE_MIDDLE, POSITION_ON_FIRST, POSITION_ON_FIRST_AND_LAST, POSITION_ON_LAST
 
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
CodeEditorDiffPane()
          Creates a CodeEditorDiffPane.
CodeEditorDiffPane(String fromText, String toText)
           
 
Method Summary
protected  List<Difference> acceptDifference(List<Difference> differences, Difference c)
          Accepts the specified Difference and return a new list of Differences.
protected  void adjustDividerOffset(DiffDivider divider, int index)
          Adjusts the DiffDivider's left and right offset.
 void clearHighlights()
           
 JComponent createComponent(Object item, int index)
          Creates the component to display the content for the diff.
protected  CodeEditor createEditor()
           
protected  CodeEditor createEditor(int index)
          Creates the code editor.
 Diff<?> createLinesDiff(int fromStartOffset, int fromEndOffset, int toStartOffset, int toEndOffset)
          Creates multiple lines diff.
protected  MarkerSupport createMarkerSupport(JComponent component)
           
 JComponent createPane(Object item, int index)
          Subclass implements it to use a different component to display the objects to be compared.
protected  RowMarginSupport createRowMarginSupport(JComponent component, JScrollPane scrollPane)
           
protected  void customizeEditor(CodeEditor editor, int index)
           
protected  void customizePane(JComponent pane, int index)
          Customizes the pane.
 boolean delete(int line, int numberOfLines, boolean runDiffAfterward)
          Deletes number of lines from the specified started line in the toEditor.
 void endHighlights()
           
 String[] getFromItems()
           
 String getFromText()
           
protected  int getSelectedIndex(int paneIndex)
           
 String[] getToItems()
           
 String getToText()
           
 void highlightChanged(int fromStartOffset, int fromEndOffset, int toStartOffset, int toEndOffset, Color c, Color separatorColor, String changeToolTip)
           
 void highlightChangedExactly(List<Difference> lineDiff, int fromStartOffset, int fromEndOffset, int toStartOffset, int toEndOffset, Color c, Color separatorColor, String changeToolTip)
           
 void highlightDeleted(int fromStartLine, int fromEndLine, int toStartLine, Color c, Color separatorColor, String changeToolTip)
           
 void highlightInserted(int fromStartLine, int toStartLine, int toEndLine, Color c, Color separatorColor, String changeToolTip)
           
 boolean insert(int line, int fromLine, int fromNumberOfLines, boolean runDiffAfterward)
          Inserts some lines from the fromEditor to the toEditor.
protected  void installListeners()
          Installs the listeners.
 void setFromText(String fromText)
          Sets the text for the from editor.
 void setReadOnly(boolean readOnly)
          Sets the read only flag.
 void setToText(String toText)
          Sets the text for the to editor.
protected  String[] splitString(String string, String lineBreak)
           
 void startHighlights()
           
protected  void synchronizeViewport(DiffDivider diffDivider, boolean startFrom)
           
 
Methods inherited from class com.jidesoft.diff.BasicDiffPane
binarySearchAdded, binarySearchDeleted, clearDiff, createDivider, createFromRowConverter, createFromTitle, createLineDiff, createToRowConverter, createToTitle, customizeLinesDiff, diff, diff, firstChange, getCaretPosition, getDifferences, getFromMatchingRow, getFromTitle, getToMatchingRow, getToTitle, isHighlightExactChange, isReadOnly, isSelectOnNavigation, lastChange, nextChange, previousChange, replace, runDiff, setChangedColor, setDeletedColor, setFromTitle, setHighlightExactChange, setInsertedColor, setSelectOnNavigation, setToTitle, synchronizeViewport, updateActions
 
Methods inherited from class com.jidesoft.diff.AbstractDiffPane
createActions, createButton, createContentArea, createLegendBar, createStatusBar, createToolBar, customizeAction, customizePanes, customizeToolBar, getChangedColor, getDeletedColor, getInsertedColor, getMessage, getResourceString, initLayout, setMessage
 
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

_fromEditor

protected CodeEditor _fromEditor

_toEditor

protected CodeEditor _toEditor
Constructor Detail

CodeEditorDiffPane

public CodeEditorDiffPane()
Creates a CodeEditorDiffPane. The text to be compared can be set using setFromText(String) and setToText(String) methods.


CodeEditorDiffPane

public CodeEditorDiffPane(String fromText,
                          String toText)
Method Detail

createComponent

public JComponent createComponent(Object item,
                                  int index)
Description copied from class: BasicDiffPane
Creates the component to display the content for the diff.

Specified by:
createComponent in class BasicDiffPane<String>
Parameters:
item - the content to be displayed in the component.
index - the index of the component.
Returns:
the component.

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.

Overrides:
createPane in class BasicDiffPane<String>
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.

customizePane

protected void customizePane(JComponent pane,
                             int index)
Description copied from class: AbstractDiffPane
Customizes the pane. The index will tell you which pane to customize. Subclass can override this method to customize the pane. Please limit the customization to this pane only because at this point, depending on the order, other panes may not be created yet. If a customization involves several panes, please do it in the overridden AbstractDiffPane.customizePanes(JComponent[]).

Overrides:
customizePane in class AbstractDiffPane
Parameters:
pane - the pane.
index - the index of the pane.

createMarkerSupport

protected MarkerSupport createMarkerSupport(JComponent component)
Specified by:
createMarkerSupport in class BasicDiffPane<String>

createRowMarginSupport

protected RowMarginSupport createRowMarginSupport(JComponent component,
                                                  JScrollPane scrollPane)
Specified by:
createRowMarginSupport in class BasicDiffPane<String>

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 BasicDiffPane<String>
Parameters:
divider - the DiffDivider.
index - the index of the DiffDivider.

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.0

createEditor

protected CodeEditor createEditor()

customizeEditor

protected void customizeEditor(CodeEditor editor,
                               int index)

getFromItems

public String[] getFromItems()
Specified by:
getFromItems in class BasicDiffPane<String>

getToItems

public String[] getToItems()
Specified by:
getToItems in class BasicDiffPane<String>

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()

createLinesDiff

public Diff<?> createLinesDiff(int fromStartOffset,
                               int fromEndOffset,
                               int toStartOffset,
                               int toEndOffset)
Creates multiple lines diff.

The string inside the diff instance is only the related rows. The method highlightChangedExactly(java.util.List, int, int, int, int, java.awt.Color, java.awt.Color, String) will consider the offset and get the correct position

Overrides:
createLinesDiff in class BasicDiffPane<String>
Parameters:
fromStartOffset - from start offset
fromEndOffset - from end offset
toStartOffset - to start offset
toEndOffset - to end offset
Returns:
the Diff instance.
Since:
3.4.0

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()

synchronizeViewport

protected void synchronizeViewport(DiffDivider diffDivider,
                                   boolean startFrom)

getSelectedIndex

protected int getSelectedIndex(int paneIndex)
Specified by:
getSelectedIndex in class BasicDiffPane<String>

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 BasicDiffPane<String>

splitString

protected String[] splitString(String string,
                               String lineBreak)

setReadOnly

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

Overrides:
setReadOnly in class BasicDiffPane<String>
Parameters:
readOnly - the new read only flag.

clearHighlights

public void clearHighlights()
Overrides:
clearHighlights in class BasicDiffPane<String>

startHighlights

public void startHighlights()
Overrides:
startHighlights in class BasicDiffPane<String>

endHighlights

public void endHighlights()
Overrides:
endHighlights in class BasicDiffPane<String>

highlightChangedExactly

public void highlightChangedExactly(List<Difference> lineDiff,
                                    int fromStartOffset,
                                    int fromEndOffset,
                                    int toStartOffset,
                                    int toEndOffset,
                                    Color c,
                                    Color separatorColor,
                                    String changeToolTip)
Overrides:
highlightChangedExactly in class BasicDiffPane<String>

highlightChanged

public void highlightChanged(int fromStartOffset,
                             int fromEndOffset,
                             int toStartOffset,
                             int toEndOffset,
                             Color c,
                             Color separatorColor,
                             String changeToolTip)
Overrides:
highlightChanged in class BasicDiffPane<String>

highlightInserted

public void highlightInserted(int fromStartLine,
                              int toStartLine,
                              int toEndLine,
                              Color c,
                              Color separatorColor,
                              String changeToolTip)
Overrides:
highlightInserted in class BasicDiffPane<String>

highlightDeleted

public void highlightDeleted(int fromStartLine,
                             int fromEndLine,
                             int toStartLine,
                             Color c,
                             Color separatorColor,
                             String changeToolTip)
Overrides:
highlightDeleted in class BasicDiffPane<String>

acceptDifference

protected List<Difference> acceptDifference(List<Difference> differences,
                                            Difference c)
Accepts the specified Difference and return a new list of Differences.

Overrides:
acceptDifference in class BasicDiffPane<String>
Parameters:
differences - the list of Differences.
c - the Difference to be accepted.
Returns:
a new list of Differences.

delete

public boolean delete(int line,
                      int numberOfLines,
                      boolean runDiffAfterward)
Deletes number of lines from the specified started line in the toEditor.

Specified by:
delete in class BasicDiffPane<String>
Parameters:
line - the starting line
numberOfLines - the number of lines to be deleted.
runDiffAfterward - true of run the diff() again after deleting the lines.
Returns:
true or false. True means the operation is successful.

insert

public boolean insert(int line,
                      int fromLine,
                      int fromNumberOfLines,
                      boolean runDiffAfterward)
Inserts some lines from the fromEditor to the toEditor.

Specified by:
insert in class BasicDiffPane<String>
Parameters:
line - the insersion line in the toEditor
fromLine - the starting line in the fromEditor
fromNumberOfLines - the number of lines in the fromEditor to be inserted to the toEditor.
runDiffAfterward - true of run the diff() again after inserting the lines.
Returns:
true or false. True means the operation is successful.

JIDE 3.4.0