beowulf.gui
Class DraggableContainer

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bybeowulf.gui.DraggableContainer
All Implemented Interfaces:
EventListener, ImageObserver, MenuContainer, MouseListener, Serializable
Direct Known Subclasses:
JGraph

public class DraggableContainer
extends JComponent
implements MouseListener

This class extends the functionality of a basic JComponent so that when other swing components are added to this container, they can be dragged around according to how the user wants them positioned. The only real code in this class simply assures that all components added to this draggable container are instances of DraggableComponent (which can wrap any swing component), and to handle some of the default behaviors of the mouse to allow for dragging. The DraggableContainer also keeps track of the currently selected component.

Version:
1.0, 6/9/2003
Author:
Andy Scukanec (ags at cs dot cornell dot edu)
See Also:
Serialized Form

Nested Class Summary
 
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
protected  DraggableComponent currentComponent
          The currently selected component.
protected  EventListenerList listenerList
          This list contains references to all interested listeners.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
DraggableContainer()
          The default (and only) constructor for a DraggableContainer.
 
Method Summary
 Component add(Component comp)
          Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent.
 Component add(Component comp, int index)
          Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent.
 void add(Component comp, Object constraints)
          Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent.
 void add(Component comp, Object constraints, int index)
          Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent.
 Component add(String name, Component comp)
          Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent.
 void addDraggableComponentSelectionListener(DraggableComponentSelectionListener l)
          This method adds a DraggableComponentSelectionListener as an interested listener of events to this DraggableContainer.
protected  void fireComponentDeselected(DraggableComponent component)
          This method must be called by all subclasses after a component is deselected.
protected  void fireComponentSelected(DraggableComponent component)
          This method must be called any time a component is selected.
 DraggableComponent getCurrentComponent()
          Returns the currently selected component.
 void mouseClicked(MouseEvent me)
          Part of the default highlighting/selecting handling.
 void mouseEntered(MouseEvent me)
          Part of the default highlighting/selecting handling.
 void mouseExited(MouseEvent me)
          Part of the default highlighting/selecting handling.
 void mousePressed(MouseEvent me)
          Part of the default highlighting/selecting handling.
 void mouseReleased(MouseEvent me)
          Part of the default highlighting/selecting handling.
 void removeDraggableComponentSelectionListener(DraggableComponentSelectionListener l)
          This method removes the DraggableComponentSelectionListener as an interested listener of events to this DraggableContainer.
 void setCurrentComponent(DraggableComponent dc)
          Sets the currently selected component.
 void setLayout(LayoutManager lm)
          Overridden setLayout method to force a null layout for any instance of DraggableComponent.
 
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, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, updateUI
 
Methods inherited from class java.awt.Container
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, 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, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentComponent

protected DraggableComponent currentComponent
The currently selected component.


listenerList

protected EventListenerList listenerList
This list contains references to all interested listeners.

Constructor Detail

DraggableContainer

public DraggableContainer()
The default (and only) constructor for a DraggableContainer.

Method Detail

getCurrentComponent

public DraggableComponent getCurrentComponent()
Returns the currently selected component.

Returns:
The currently selected component.

setCurrentComponent

public void setCurrentComponent(DraggableComponent dc)
Sets the currently selected component.

Parameters:
dc - The new currently selected component.

addDraggableComponentSelectionListener

public void addDraggableComponentSelectionListener(DraggableComponentSelectionListener l)
This method adds a DraggableComponentSelectionListener as an interested listener of events to this DraggableContainer.

Parameters:
l - The draggable component selection listener to add.

removeDraggableComponentSelectionListener

public void removeDraggableComponentSelectionListener(DraggableComponentSelectionListener l)
This method removes the DraggableComponentSelectionListener as an interested listener of events to this DraggableContainer.

Parameters:
l - The draggable component selection listener to remove.

fireComponentSelected

protected void fireComponentSelected(DraggableComponent component)
This method must be called any time a component is selected.

Parameters:
component - The component that was selected.

fireComponentDeselected

protected void fireComponentDeselected(DraggableComponent component)
This method must be called by all subclasses after a component is deselected.

Parameters:
component - The component that was deselected.

mouseEntered

public void mouseEntered(MouseEvent me)
Part of the default highlighting/selecting handling.

Specified by:
mouseEntered in interface MouseListener
Parameters:
me - The mouse event that supplies extra parameters.

mouseExited

public void mouseExited(MouseEvent me)
Part of the default highlighting/selecting handling.

Specified by:
mouseExited in interface MouseListener
Parameters:
me - The mouse event that supplies extra parameters.

mousePressed

public void mousePressed(MouseEvent me)
Part of the default highlighting/selecting handling.

Specified by:
mousePressed in interface MouseListener
Parameters:
me - The mouse event that supplies extra parameters.

mouseReleased

public void mouseReleased(MouseEvent me)
Part of the default highlighting/selecting handling.

Specified by:
mouseReleased in interface MouseListener
Parameters:
me - The mouse event that supplies extra parameters.

mouseClicked

public void mouseClicked(MouseEvent me)
Part of the default highlighting/selecting handling.

Specified by:
mouseClicked in interface MouseListener
Parameters:
me - The mouse event that supplies extra parameters.

setLayout

public final void setLayout(LayoutManager lm)
Overridden setLayout method to force a null layout for any instance of DraggableComponent. This method cannot be overridden.

Parameters:
lm - The new layout manager (no effect).

add

public Component add(Component comp)
Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent. If it is not, the component is not added. All other functionality remains the same. For details on how this method works, see the identical method in the superclass.

Parameters:
comp - The component to be added - must be a DraggableComponent.

add

public Component add(String name,
                     Component comp)
Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent. If it is not, the component is not added. All other functionality remains the same. For details on how this method works, see the identical method in the superclass.

Parameters:
comp - The component to be added - must be a DraggableComponent.

add

public Component add(Component comp,
                     int index)
Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent. If it is not, the component is not added. All other functionality remains the same. For details on how this method works, see the identical method in the superclass.

Parameters:
comp - The component to be added - must be a DraggableComponent.

add

public void add(Component comp,
                Object constraints)
Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent. If it is not, the component is not added. All other functionality remains the same. For details on how this method works, see the identical method in the superclass.

Parameters:
comp - The component to be added - must be a DraggableComponent.

add

public void add(Component comp,
                Object constraints,
                int index)
Overridden version of the add method to ensure that the incoming component is an instance of DraggableComponent. If it is not, the component is not added. All other functionality remains the same. For details on how this method works, see the identical method in the superclass.

Parameters:
comp - The component to be added - must be a DraggableComponent.