Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.greenstone.gatherer.undo
Class UndoManager  view UndoManager download UndoManager.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.AbstractButton
                  extended byjavax.swing.JButton
                      extended byorg.greenstone.gatherer.undo.UndoManager
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, org.greenstone.gatherer.util.DragComponent, java.awt.dnd.DropTargetListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, javax.swing.SwingConstants

public class UndoManager
extends javax.swing.JButton
implements java.awt.event.ActionListener, org.greenstone.gatherer.util.DragComponent, java.awt.dnd.DropTargetListener

Manages the rather complex task of undoing and redoing actions. It does this by storing two queues, undo and redo, containing undo jobs which encapsulate all the information needed to undo or redo an action. It is also important to note that the manage creates a temporary directory, and then places any deleted files in this directory, and saves their associated metadata with them, for the life of the session. This is to facilitate the restoring of deleted files.

Version:
2.3c

Nested Class Summary
private  class UndoManager.UndoJob
           
private  class UndoManager.UndoJobAdder
           
private  class UndoManager.UndoStack
           
 
Nested classes inherited from class javax.swing.JButton
javax.swing.JButton.AccessibleJButton
 
Nested classes inherited from class javax.swing.AbstractButton
javax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListener
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  int drag_action
          What sort of action should a drag resemble.
private  java.awt.dnd.DropTarget drop_target
          In order to make this button a drop target we have to create a DropTarget instance with the button as its target.
static int FILE_COPY
           
static int FILE_DELETE
           
static int FILE_MOVE
           
private  org.greenstone.gatherer.file.FileQueue file_queue
           
private  org.greenstone.gatherer.util.DragGroup group
          The group encompasses all of the objects you plan to drag and drop within, and ensures that only one has focus (as clearly identified by the colour of the selection field or, in this particular case, the background) and that actions only occur between components in the same group.
private  boolean ignore
           
private  boolean ignore_next
           
private  org.greenstone.gatherer.file.FileSystemModel model
           
private  org.greenstone.gatherer.msm.GDMDocument obsolete_metadata
           
private  java.awt.Point pt_last
          The last point the mouse was at.
private  java.awt.Rectangle ra_ghost
          The area covered by the drag ghost, our custom drag icon.
private  UndoManager.UndoStack redo
           
private  java.util.ArrayList redo_sources
           
private  UndoManager.UndoStack undo
           
private  java.util.ArrayList undo_sources
           
 
Fields inherited from class javax.swing.JButton
 
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
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.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
UndoManager()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          This method is invoked when an action occurs.
 void addMetadata(java.io.File file, java.util.ArrayList metadatum)
           
 void addUndo(long id, int type, org.greenstone.gatherer.util.DragComponent source_model, org.greenstone.gatherer.file.FileNode source_parent, org.greenstone.gatherer.util.DragComponent target_model, org.greenstone.gatherer.file.FileNode record, boolean undo_event)
           
 void clear()
           
 void clearGhost()
          In order for the appearance to be consistant, given we may be in the situation where the pointer has left our focus but the ghost remains, this method allows other members of the GGroup to tell this component to repair the 'spoilt' region left by its ghost.
 void destroy()
           
 void dragEnter(java.awt.dnd.DropTargetDragEvent event)
          Any implementation of DropTargetListener must include this method so we can be notified when the drag focus enters this component.
 void dragExit(java.awt.dnd.DropTargetEvent event)
          Any implementation of DropTargetListener must include this method so we can be notified when the drag focus leaves this component.
 void dragOver(java.awt.dnd.DropTargetDragEvent event)
          Any implementation of DropTargetListener must include this method so we can be notified when the drag moves in this component.
 void drop(java.awt.dnd.DropTargetDropEvent event)
          Any implementation of DropTargetListener must include this method so we can be notified when the drag ends, ie the transferable is dropped.
 void dropActionChanged(java.awt.dnd.DropTargetDragEvent event)
          Any implementation of DropTargetListener must include this method so we can be notified when the action to be taken upon drop changes.
 void fileCopied(long id, org.greenstone.gatherer.util.DragComponent target_model, org.greenstone.gatherer.file.FileNode target_parent, org.greenstone.gatherer.file.FileNode record, boolean undo_event)
           
 void fileMoved(long id, org.greenstone.gatherer.util.DragComponent source_model, org.greenstone.gatherer.file.FileNode source_parent, org.greenstone.gatherer.util.DragComponent target_model, org.greenstone.gatherer.file.FileNode target_parent, org.greenstone.gatherer.file.FileNode record, boolean undo_event)
           
 void gainFocus()
          Used to notify this component that it has gained focus by some method other that mouse focus.
 java.util.ArrayList getMetadata(java.io.File file)
           
 org.greenstone.gatherer.file.FileSystemModel getTreeModel()
          Any implementation of DragComponent must include this method so that a outsider can get at the underlying tree model behind the component.
 boolean ignore()
           
 void loseFocus()
          This method is used to inform this component when it loses focus by means other than a drag mouse event, and should indicate this somehow.
 void registerRedoSource(javax.swing.AbstractButton source)
           
 void registerUndoSource(javax.swing.AbstractButton source)
           
 void setGroup(org.greenstone.gatherer.util.DragGroup group)
          Set the components group.
private  void showTree()
           
 void undoAll()
           
 
Methods inherited from class javax.swing.JButton
configurePropertiesFromAction, getAccessibleContext, getSelectedObjects, getUIClassID, isDefaultButton, isDefaultCapable, paramString, removeNotify, setDefaultCapable, updateUI
 
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, swapComponents, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.greenstone.gatherer.util.DragComponent
addFocusListener
 

Field Detail

redo_sources

private java.util.ArrayList redo_sources

undo_sources

private java.util.ArrayList undo_sources

ignore

private boolean ignore

ignore_next

private boolean ignore_next

group

private org.greenstone.gatherer.util.DragGroup group
The group encompasses all of the objects you plan to drag and drop within, and ensures that only one has focus (as clearly identified by the colour of the selection field or, in this particular case, the background) and that actions only occur between components in the same group.


drop_target

private java.awt.dnd.DropTarget drop_target
In order to make this button a drop target we have to create a DropTarget instance with the button as its target.


file_queue

private org.greenstone.gatherer.file.FileQueue file_queue

model

private org.greenstone.gatherer.file.FileSystemModel model

obsolete_metadata

private org.greenstone.gatherer.msm.GDMDocument obsolete_metadata

drag_action

private int drag_action
What sort of action should a drag resemble. Not really used as we override with custom drag icon.


pt_last

private java.awt.Point pt_last
The last point the mouse was at. Used to repaint 'spoilt' area.


ra_ghost

private java.awt.Rectangle ra_ghost
The area covered by the drag ghost, our custom drag icon.


redo

private UndoManager.UndoStack redo

undo

private UndoManager.UndoStack undo

FILE_COPY

public static final int FILE_COPY
See Also:
Constant Field Values

FILE_DELETE

public static final int FILE_DELETE
See Also:
Constant Field Values

FILE_MOVE

public static final int FILE_MOVE
See Also:
Constant Field Values
Constructor Detail

UndoManager

public UndoManager()
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Description copied from interface: java.awt.event.ActionListener
This method is invoked when an action occurs.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

addMetadata

public void addMetadata(java.io.File file,
                        java.util.ArrayList metadatum)

addUndo

public void addUndo(long id,
                    int type,
                    org.greenstone.gatherer.util.DragComponent source_model,
                    org.greenstone.gatherer.file.FileNode source_parent,
                    org.greenstone.gatherer.util.DragComponent target_model,
                    org.greenstone.gatherer.file.FileNode record,
                    boolean undo_event)

clear

public void clear()

clearGhost

public void clearGhost()
In order for the appearance to be consistant, given we may be in the situation where the pointer has left our focus but the ghost remains, this method allows other members of the GGroup to tell this component to repair the 'spoilt' region left by its ghost.

Specified by:
clearGhost in interface org.greenstone.gatherer.util.DragComponent

destroy

public void destroy()

dragEnter

public void dragEnter(java.awt.dnd.DropTargetDragEvent event)
Any implementation of DropTargetListener must include this method so we can be notified when the drag focus enters this component. We want to provide some sort of indication whether the current component is an acceptable drop target as well as indicating focus.

Specified by:
dragEnter in interface java.awt.dnd.DropTargetListener

dragExit

public void dragExit(java.awt.dnd.DropTargetEvent event)
Any implementation of DropTargetListener must include this method so we can be notified when the drag focus leaves this component. We need to indicate that we have lost focus.

Specified by:
dragExit in interface java.awt.dnd.DropTargetListener

dragOver

public void dragOver(java.awt.dnd.DropTargetDragEvent event)
Any implementation of DropTargetListener must include this method so we can be notified when the drag moves in this component. This is where we repaint our ghost icon at the tip of the mouse pointer.

Specified by:
dragOver in interface java.awt.dnd.DropTargetListener

drop

public void drop(java.awt.dnd.DropTargetDropEvent event)
Any implementation of DropTargetListener must include this method so we can be notified when the drag ends, ie the transferable is dropped. This in turn triggers a series of add events preceded by a pre() and followed by a post().

Specified by:
drop in interface java.awt.dnd.DropTargetListener

dropActionChanged

public void dropActionChanged(java.awt.dnd.DropTargetDragEvent event)
Any implementation of DropTargetListener must include this method so we can be notified when the action to be taken upon drop changes. We never change so we don't do anything here.

Specified by:
dropActionChanged in interface java.awt.dnd.DropTargetListener

fileCopied

public void fileCopied(long id,
                       org.greenstone.gatherer.util.DragComponent target_model,
                       org.greenstone.gatherer.file.FileNode target_parent,
                       org.greenstone.gatherer.file.FileNode record,
                       boolean undo_event)

fileMoved

public void fileMoved(long id,
                      org.greenstone.gatherer.util.DragComponent source_model,
                      org.greenstone.gatherer.file.FileNode source_parent,
                      org.greenstone.gatherer.util.DragComponent target_model,
                      org.greenstone.gatherer.file.FileNode target_parent,
                      org.greenstone.gatherer.file.FileNode record,
                      boolean undo_event)

gainFocus

public void gainFocus()
Used to notify this component that it has gained focus by some method other that mouse focus.

Specified by:
gainFocus in interface org.greenstone.gatherer.util.DragComponent

getMetadata

public java.util.ArrayList getMetadata(java.io.File file)

getTreeModel

public org.greenstone.gatherer.file.FileSystemModel getTreeModel()
Any implementation of DragComponent must include this method so that a outsider can get at the underlying tree model behind the component.

Specified by:
getTreeModel in interface org.greenstone.gatherer.util.DragComponent

ignore

public boolean ignore()

loseFocus

public void loseFocus()
This method is used to inform this component when it loses focus by means other than a drag mouse event, and should indicate this somehow.

Specified by:
loseFocus in interface org.greenstone.gatherer.util.DragComponent

registerRedoSource

public void registerRedoSource(javax.swing.AbstractButton source)

registerUndoSource

public void registerUndoSource(javax.swing.AbstractButton source)

setGroup

public void setGroup(org.greenstone.gatherer.util.DragGroup group)
Description copied from interface: org.greenstone.gatherer.util.DragComponent
Set the components group.

Specified by:
setGroup in interface org.greenstone.gatherer.util.DragComponent

undoAll

public void undoAll()

showTree

private void showTree()