JIDE 3.5.15

com.jidesoft.diff
Class AbstractDiffPane

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
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
AbstractMergePane, BasicDiffPane

public abstract class AbstractDiffPane
extends JPanel

AbstractDiffPane is the base for the diff/merge panes. We introduced this level of abstraction so that we can support different kinds of diff components, to compare string arrays, folders etc.

The methods that subclass can override are

 
 

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  Map<String,Action> _actions
           
protected  Color _changedColor
           
protected  Color _deletedColor
           
protected  Color _insertedColor
           
static String COMMAND_FIRST
           
static String COMMAND_LAST
           
static String COMMAND_NEXT
           
static String 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
AbstractDiffPane(Object... items)
          Creates an AbstractDiffPane.
 
Method Summary
protected  void adjustDividerOffset(DiffDivider divider, int index)
          Adjusts the DiffDivider's left and right offset.
protected  void createActions()
          Creates the actions used by the diff pane.
protected  AbstractButton createButton(Action action)
          Creates the button.
protected  JComponent createContentArea(JComponent... panes)
          Creates the content area.
abstract  DiffDivider createDivider(int index)
          Subclass implements it to create a DiffDivider that appears between the panes.
protected  JComponent createLegendBar()
          Creates the legend area which shows the meaning of the colors used by the diff pane.
abstract  JComponent createPane(Object item, int index)
          Subclass implements it to use a different component to display the objects to be compared.
protected  JComponent createStatusBar()
          Creates the status bar component.
protected  JComponent createToolBar()
          Creates the toolbar component for the DiffPane.
protected  Action customizeAction(Action action, String command)
          Customizes the action for a command string by getting the text, tooltip, mnemonic, icon etc from the resource file.
protected  void customizeDivider(DiffDivider divider, int i)
          Customizes the newly created DiffDivider.
protected  void customizePane(JComponent pane, int index)
          Customizes the pane.
protected  void customizePanes(JComponent[] panes)
          Customizes the components after the panes are created.
protected  void customizeToolBar(JComponent toolBar)
          Adds components to the toolbar.
protected  void firstChange()
          Goes to the first change.
 void flip()
          Flips the from to the to and vice versa.
 Color getChangedColor()
           
 Color getDeletedColor()
           
 Color getInsertedColor()
           
 String getMessage()
          Get the message.
protected  String getResourceString(String key)
          Gets the localized string from resource bundle.
protected  void initLayout(JComponent contentArea, JComponent toolBar, JComponent statusBar)
          Initialize the layout.
protected  void installListeners()
          Installs the listeners.
protected  void lastChange()
          Goes to the last change.
protected  void nextChange()
          Goes to the next change.
protected  void previousChange()
          Goes to the previous change.
 void setChangedColor(Color changedColor)
           
 void setDeletedColor(Color deletedColor)
           
 void setInsertedColor(Color insertedColor)
           
 void setMessage(String message)
          Changes the message.
protected  void uninstallListeners()
          Uninstalls the listeners.
protected  void updateActions(int index)
          Updates the enable/disable states of the actions on the toolbar buttons.
 
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

_insertedColor

protected Color _insertedColor

_changedColor

protected Color _changedColor

_deletedColor

protected Color _deletedColor

_actions

protected Map<String,Action> _actions

COMMAND_FIRST

public static final String COMMAND_FIRST
See Also:
Constant Field Values

COMMAND_PREVIOUS

public static final String COMMAND_PREVIOUS
See Also:
Constant Field Values

COMMAND_NEXT

public static final String COMMAND_NEXT
See Also:
Constant Field Values

COMMAND_LAST

public static final String COMMAND_LAST
See Also:
Constant Field Values
Constructor Detail

AbstractDiffPane

public AbstractDiffPane(Object... items)
Creates an AbstractDiffPane.

Parameters:
items - items to be compared.
Method Detail

flip

public void flip()
Flips the from to the to and vice versa.

Since:
3.4.2

initLayout

protected void initLayout(JComponent contentArea,
                          JComponent toolBar,
                          JComponent statusBar)
Initialize the layout. This method will arrange the layout of the split pane, the tool bar and the status bar. By default, we use a BorderLayout with split pane at the center, toolbar and status bar on the north and south side respectively.

Parameters:
contentArea - the content area. It is a JideSplitPane by default.
toolBar - the tool bar.
statusBar - the status bar.

createContentArea

protected JComponent createContentArea(JComponent... panes)
Creates the content area. By default, it is a JideSplitPane and each pane contains a component that displays one item to be compared.

Parameters:
panes - the panes. Each pane contains a component that displays one item to be compared.
Returns:
the content area of the diff pane.

customizeDivider

protected void customizeDivider(DiffDivider divider,
                                int i)
Customizes the newly created DiffDivider.

Parameters:
divider - the diff divider
i - the index of the diff divider
Since:
3.4.2

adjustDividerOffset

protected void adjustDividerOffset(DiffDivider divider,
                                   int index)
Adjusts the DiffDivider's left and right offset.

Parameters:
divider - the DiffDivider.
index - the index of the DiffDivider.

customizePane

protected void customizePane(JComponent pane,
                             int index)
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 customizePanes(JComponent[]).

Parameters:
pane - the pane.
index - the index of the pane.

customizePanes

protected void customizePanes(JComponent[] panes)
Customizes the components after the panes are created. You can override this method to do customization that involves all the panes.

Parameters:
panes - the panes.

createToolBar

protected JComponent createToolBar()
Creates the toolbar component for the DiffPane.

Returns:
a JToolBar. You can subclass it to create a CommandBar if you have JIDE Action Framework.

createButton

protected AbstractButton createButton(Action action)
Creates the button. Our default code is
 protected AbstractButton createButton(Action action) {
     AbstractButton button = new JideButton(action);
     button.setName("" + action.getValue(Action.ACTION_COMMAND_KEY));
     button.setDisabledIcon((Icon) action.getValue("disabledIcon"));
     button.setRequestFocusEnabled(false);
     AutoRepeatButtonUtils.install(button, 50, 200);
     return button;
 }
 

Parameters:
action - the action for the button.
Returns:
a button.

getResourceString

protected String getResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in grids.properties that begin with "Pane.".

Parameters:
key - the key
Returns:
the localized string.

createActions

protected void createActions()
Creates the actions used by the diff pane. We kept map of actions on field _actions. All actions used by the tool bar buttons are added to this map. Each action has a name. We will use this name to find out the text, tooltip and icon from diff.properties. By default, the text is empty and the icon is getting from the icon files under icons folder. You can follow the same pattern if you want to add more buttons to the tool bar.


customizeAction

protected Action customizeAction(Action action,
                                 String command)
Customizes the action for a command string by getting the text, tooltip, mnemonic, icon etc from the resource file.

Parameters:
action - the action.
command - the command string.
Returns:
the action.

customizeToolBar

protected void customizeToolBar(JComponent toolBar)
Adds components to the toolbar. By default, we added four buttons to the tool bar.

Parameters:
toolBar - the tool bar where we will add the buttons.

createStatusBar

protected JComponent createStatusBar()
Creates the status bar component. The status bar appears on the bottom of the diff pane by default. It has a message label which shows the status. You can call setMessage(String) to change the status. It also has a legend area which shows the meaning of the colors used by the diff pane. The legend component can be customized by overriding createLegendBar().

Returns:
a status bar component.

createLegendBar

protected JComponent createLegendBar()
Creates the legend area which shows the meaning of the colors used by the diff pane. By default, it appears on the bottom right of the diff pane on the same line as the status label.

Returns:
the legend area.

getInsertedColor

public Color getInsertedColor()

setInsertedColor

public void setInsertedColor(Color insertedColor)

getChangedColor

public Color getChangedColor()

setChangedColor

public void setChangedColor(Color changedColor)

getDeletedColor

public Color getDeletedColor()

setDeletedColor

public void setDeletedColor(Color deletedColor)

createPane

public abstract JComponent createPane(Object item,
                                      int index)
Subclass implements it to use a different component to display the objects to be compared.

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 abstract DiffDivider createDivider(int index)
Subclass implements it to create a DiffDivider that appears between the panes.

Parameters:
index - the index of the DiffDivider
Returns:
the DiffDivider.

setMessage

public void setMessage(String message)
Changes the message.

Parameters:
message - the new message.

getMessage

public String getMessage()
Get the message.

Returns:
the message.

updateActions

protected void updateActions(int index)
Updates the enable/disable states of the actions on the toolbar buttons.

Parameters:
index - the pane index. This is the pane that triggers the update.

firstChange

protected void firstChange()
Goes to the first change.


previousChange

protected void previousChange()
Goes to the previous change.


nextChange

protected void nextChange()
Goes to the next change.


lastChange

protected void lastChange()
Goes to the last change.


installListeners

protected void installListeners()
Installs the listeners. Subclass can override this method to install the necessary listeners. This method is called only in the constructor.


uninstallListeners

protected void uninstallListeners()
Uninstalls the listeners. Subclass can override this method to uninstall the necessary listeners. This method has to be invoked explicitly by customers to uninstall all the listeners installed by installListeners()

Since:
3.4.9

JIDE 3.5.15