gov.nih.nlm.swing
Class CutandPasteDNDTable

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JTable
                  extended bygov.nih.nlm.swing.CutandPasteDNDTable
All Implemented Interfaces:
Accessible, Autoscroll, CellEditorListener, DragGestureListener, DragSourceListener, DropTargetListener, EventListener, ImageObserver, ListSelectionListener, MenuContainer, Scrollable, Serializable, TableColumnModelListener, TableModelListener

public class CutandPasteDNDTable
extends JTable
implements DropTargetListener, DragSourceListener, DragGestureListener, Autoscroll

A type of JTable that supports cut-and-paste and drag-and-drop operations for reordering rows.

The Cut-and-paste mechanism allows users to select rows, Use the -X key to remove the rows from the table, and finally the -V key to paste the rows back in to the table above the current first selected row.

The Drag-and-drop mechanism allows users to select rows, and then drag those rows and drop them to another place in the table.

Using this class requires the use of a CutandPasteDNDTableModel.

Author:
Deborah Shapiro
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JTable
JTable.AccessibleJTable
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
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
CutandPasteDNDTable()
          Instantiates a CutandPasteDNDTable without a model.
CutandPasteDNDTable(CutandPasteDNDTableModel table_model)
          Instantiates a CutandPasteDNDTable from the specified model.
 
Method Summary
 void addCutandPasteModeListener(CutandPasteModeListener cpml)
          Adds a CutandPasteModeListener.
 void addFocusListener(FocusListener cpml)
          Adds a CutandPasteModeListener.
 void autoscroll(Point p)
          Provides the auto scrolling functionality during a drag.
 void dragDropEnd(DragSourceDropEvent event)
          Event handler for when dragging ends.
 void dragEnter(DragSourceDragEvent event)
          Event handler for when dragging enters the drag source component.
 void dragEnter(DropTargetDragEvent event)
          Event handler for when a drag enters the drop component.
 void dragExit(DragSourceEvent event)
          Event handler for when dragging exits the drag source component.
 void dragExit(DropTargetEvent event)
          Event handler for when a drag exits the drop component.
 void dragGestureRecognized(DragGestureEvent event)
          Event handler for recognizing that a drag has started.
 void dragOver(DragSourceDragEvent event)
          Event handler for when dragging passes over the drag source component.
 void dragOver(DropTargetDragEvent event)
          Event handler for when a drag is over the drop component.
 void drop(DropTargetDropEvent event)
          Event handler when a drop occurs in the drop component.
 void dropActionChanged(DragSourceDragEvent event)
          Event handler for when the drop action changes.
 void dropActionChanged(DropTargetDragEvent event)
          Event handler for when a drop action is changed.
protected  void fireCutDoneinCutMode()
          Informs listeners that a cut was appropriately done in cut mode.
protected  void fireCutDoneinPasteMode()
          Informs listeners that a cut was illegally attempted in paste mode.
protected  void firePasteDoneinCutMode()
          Informs listeners that a paste was illegally attempted in cut mode
protected  void firePasteDoneinPasteMode()
          Informs listeners that a paste was appropriately done in paste mode
 Insets getAutoscrollInsets()
          Provides insets that delineate the area of the table in which autoscrolling should take place.
 boolean getCutMode()
          Returns the cut mode.
 boolean isCutDone()
          Returns true if a cut has been completed, false otherwise
 boolean isPasteDone()
          Returns true if a cut has been completed, false otherwise
protected  void processKeyEvent(KeyEvent e)
          Event handler for -X and -V key presses.
protected  void processMouseEvent(MouseEvent e)
          Event handler for mouse events.
 void removeCutandPasteModeListener(CutandPasteModeListener cpml)
          Removes a CutandPasteModeListener.
 void removeFocusListener(FocusListener cpml)
          Removes a CutandPasteModeListener.
 void setCutMode(boolean mode)
          Sets the cut mode.
 void setModel(CutandPasteDNDTableModel table_model)
          Sets the table model.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditingRow, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getValueAt, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setValueAt, sizeColumnsToFit, sizeColumnsToFit, tableChanged, unconfigureEnclosingScrollPane, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, 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, setEnabled, 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, 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, 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, imageUpdate, 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, processMouseWheelEvent, remove, removeComponentListener, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CutandPasteDNDTable

public CutandPasteDNDTable(CutandPasteDNDTableModel table_model)
Instantiates a CutandPasteDNDTable from the specified model.

Parameters:
table_model - the CutandPasteDNDTableModel

CutandPasteDNDTable

public CutandPasteDNDTable()
Instantiates a CutandPasteDNDTable without a model.

Method Detail

setModel

public void setModel(CutandPasteDNDTableModel table_model)
Sets the table model.

Parameters:
table_model - the CutandPasteDNDTableModel

setCutMode

public void setCutMode(boolean mode)
Sets the cut mode. This programatically allows the user to change the mode of the table.

Parameters:
mode - the new cut mode

getCutMode

public boolean getCutMode()
Returns the cut mode.

Returns:
true if a cut has been completed false if a paste has been completed

isCutDone

public boolean isCutDone()
Returns true if a cut has been completed, false otherwise

Returns:
true if a cut has been completed, false otherwise

isPasteDone

public boolean isPasteDone()
Returns true if a cut has been completed, false otherwise

Returns:
true if a cut has been completed, false otherwise

dragEnter

public void dragEnter(DropTargetDragEvent event)
Event handler for when a drag enters the drop component. Accepts or rejects a drag event.

Specified by:
dragEnter in interface DropTargetListener
Parameters:
event - the DropTargetDragEvent

dragExit

public void dragExit(DropTargetEvent event)
Event handler for when a drag exits the drop component.

Specified by:
dragExit in interface DropTargetListener
Parameters:
event - the DropTargetEvent

dragOver

public void dragOver(DropTargetDragEvent event)
Event handler for when a drag is over the drop component.

Specified by:
dragOver in interface DropTargetListener
Parameters:
event - a DropTargetDragEvent

drop

public void drop(DropTargetDropEvent event)
Event handler when a drop occurs in the drop component. Accept the drop.

Specified by:
drop in interface DropTargetListener
Parameters:
event - the DropTargetDragEvent

dropActionChanged

public void dropActionChanged(DropTargetDragEvent event)
Event handler for when a drop action is changed. Currently does nothing.

Specified by:
dropActionChanged in interface DropTargetListener
Parameters:
event - the DropTargetDragEvent

dragGestureRecognized

public void dragGestureRecognized(DragGestureEvent event)
Event handler for recognizing that a drag has started. In the future, we need to refine this to more easily distinguish between a drag gesture and a "select multiple table rows" gesture.

Specified by:
dragGestureRecognized in interface DragGestureListener
Parameters:
event - the DragGestureEvent

dragDropEnd

public void dragDropEnd(DragSourceDropEvent event)
Event handler for when dragging ends. Do nothing.

Specified by:
dragDropEnd in interface DragSourceListener
Parameters:
event - the DragSourceDropEvent

dragEnter

public void dragEnter(DragSourceDragEvent event)
Event handler for when dragging enters the drag source component. Do nothing.

Specified by:
dragEnter in interface DragSourceListener
Parameters:
event - thye DragSourceDragEvent

dragExit

public void dragExit(DragSourceEvent event)
Event handler for when dragging exits the drag source component. Do nothing.

Specified by:
dragExit in interface DragSourceListener
Parameters:
event - the DragSourceEvent

dragOver

public void dragOver(DragSourceDragEvent event)
Event handler for when dragging passes over the drag source component. Set the cursor.

Specified by:
dragOver in interface DragSourceListener
Parameters:
event - the DragSourceDragEvent

dropActionChanged

public void dropActionChanged(DragSourceDragEvent event)
Event handler for when the drop action changes. Do nothing.

Specified by:
dropActionChanged in interface DragSourceListener
Parameters:
event - the DragSourceDragEvent

processKeyEvent

protected void processKeyEvent(KeyEvent e)
Event handler for -X and -V key presses. Calls the respective methods in the table model to execute the cut and paste operations on the selected rows It also manages the cut-mode to only allow cut when cut is allowed, and only allow paste when paste is allowed.

Parameters:
e - the KeyEvent

processMouseEvent

protected void processMouseEvent(MouseEvent e)
Event handler for mouse events. Remove mouse listeners while dragging is taking place to avoid selection of additional rows.

Parameters:
e - the MouseEvent

addCutandPasteModeListener

public void addCutandPasteModeListener(CutandPasteModeListener cpml)
Adds a CutandPasteModeListener.

Parameters:
cpml - the CutandPasteModeListener

removeCutandPasteModeListener

public void removeCutandPasteModeListener(CutandPasteModeListener cpml)
Removes a CutandPasteModeListener.

Parameters:
cpml - the CutandPasteModeListener

addFocusListener

public void addFocusListener(FocusListener cpml)
Adds a CutandPasteModeListener.

Parameters:
cpml - the CutandPasteModeListener

removeFocusListener

public void removeFocusListener(FocusListener cpml)
Removes a CutandPasteModeListener.

Parameters:
cpml - the CutandPasteModeListener

fireCutDoneinCutMode

protected void fireCutDoneinCutMode()
Informs listeners that a cut was appropriately done in cut mode.


fireCutDoneinPasteMode

protected void fireCutDoneinPasteMode()
Informs listeners that a cut was illegally attempted in paste mode.


firePasteDoneinPasteMode

protected void firePasteDoneinPasteMode()
Informs listeners that a paste was appropriately done in paste mode


firePasteDoneinCutMode

protected void firePasteDoneinCutMode()
Informs listeners that a paste was illegally attempted in cut mode


getAutoscrollInsets

public Insets getAutoscrollInsets()
Provides insets that delineate the area of the table in which autoscrolling should take place.

Specified by:
getAutoscrollInsets in interface Autoscroll
Returns:
the Insets

autoscroll

public void autoscroll(Point p)
Provides the auto scrolling functionality during a drag. This method should be repeatedly called during the drag operation if the mouse is within the area defined by getAutoscrollInsets().

Specified by:
autoscroll in interface Autoscroll
Parameters:
p - the starting Point


Copyright ©2005