beowulf.gui
Class DraggableComponent

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JLabel
                  extended bybeowulf.gui.DraggableComponent
All Implemented Interfaces:
Accessible, EventListener, ImageObserver, MenuContainer, MouseListener, MouseMotionListener, Serializable, SwingConstants

public class DraggableComponent
extends JLabel
implements MouseListener, MouseMotionListener

This class is just a wrapper class for any sort of swing component that is to be inserted into a DraggableContainer. The reason one would do this, is that any components inserted into a DraggableContainer must be wrapped in an instance of this class. This class takes care of all of the highlighting stuff via a mouse listener. If a swing component which is not a DraggableComponent is added to an instance of a DraggableContainer, the container will detect this and not add the 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.JLabel
JLabel.AccessibleJLabel
 
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  JComponent c
          The component being wrapped.
protected  DraggableContainer container
          The container to which this Drag.
protected  boolean dragging
          Flag for whether or not this Drag.
protected  boolean hovering
          Flag for whether or not this Drag.
protected  int oldX
          The old x value - used for dragging.
protected  int oldY
          The old y value - used for dragging.
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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 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
DraggableComponent(DraggableContainer container, JComponent c)
          This is the basic constructor for a draggable component.
DraggableComponent(DraggableContainer newContainer, JComponent newC, int x, int y)
          This is the full constructor for a draggable component.
 
Method Summary
 JComponent getComponent()
          Returns the contained swing component.
 DraggableContainer getDraggableContainer()
          Returns the DraggableContainer this DraggableComponent is linked to.
 boolean getDragging()
          Returns whether or not the component is being dragged.
 boolean getHovering()
          Returns whether or not the mouse pointer is hover on the component.
 boolean getSelected()
          Returns whether or not this component is the selected one.
 void mouseClicked(MouseEvent me)
          This method is here as part of the highlight handling.
 void mouseDragged(MouseEvent me)
          This method is here as part of the highlight handling.
 void mouseEntered(MouseEvent me)
          This method is here as part of the highlight handling.
 void mouseExited(MouseEvent me)
          This method is here as part of the highlight handling.
 void mouseMoved(MouseEvent me)
          This method is here as part of the highlight handling.
 void mousePressed(MouseEvent me)
          This method is here as part of the highlight handling.
 void mouseReleased(MouseEvent me)
          This method is here as part of the highlight handling.
 void paintComponent(Graphics g)
          This method tells the draggable component how to paint itself.
 void setDraggableContainer(DraggableContainer newContainer)
          Sets the DraggableContainer this DraggableComponent is linked to.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
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, paintBorder, paintChildren, paintImmediately, paintImmediately, 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
 
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, 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, 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

c

protected JComponent c
The component being wrapped.


container

protected DraggableContainer container
The container to which this Drag. Comp. belongs.


dragging

protected boolean dragging
Flag for whether or not this Drag. Comp. is being dragged.


hovering

protected boolean hovering
Flag for whether or not this Drag. Comp. is under a mouse pointer.


oldX

protected int oldX
The old x value - used for dragging.


oldY

protected int oldY
The old y value - used for dragging.

Constructor Detail

DraggableComponent

public DraggableComponent(DraggableContainer container,
                          JComponent c)
This is the basic constructor for a draggable component. To create a draggable component, one MUST supply a container and a component to wrap.

Parameters:
container - The container that will hold this component.
c - The swing component being wrapped by this draggable component.

DraggableComponent

public DraggableComponent(DraggableContainer newContainer,
                          JComponent newC,
                          int x,
                          int y)
This is the full constructor for a draggable component. The only extra options are to supply an initial location inside the draggable container.

Parameters:
newContainer - The container that will hold this component.
newC - The swing component being wrapped by this draggable component.
x - The initial x location of the component inside the container.
y - The initial y location of the component inside the container.
Method Detail

getComponent

public JComponent getComponent()
Returns the contained swing component.

Returns:
The contained swing component.

getDragging

public boolean getDragging()
Returns whether or not the component is being dragged.

Returns:
Whether or not the component is being dragged.

getHovering

public boolean getHovering()
Returns whether or not the mouse pointer is hover on the component.

Returns:
Whether or not the mouse pointer is hover on the component.

getSelected

public boolean getSelected()
Returns whether or not this component is the selected one.

Returns:
Whether or not this component is the selected one.

getDraggableContainer

public DraggableContainer getDraggableContainer()
Returns the DraggableContainer this DraggableComponent is linked to.

Returns:
The DraggableContainer this DraggableComponent is linked to.

setDraggableContainer

public void setDraggableContainer(DraggableContainer newContainer)
Sets the DraggableContainer this DraggableComponent is linked to.

Parameters:
newContainer - The DraggableContainer this DraggableComponent is linked to.

mouseEntered

public void mouseEntered(MouseEvent me)
This method is here as part of the highlight handling.

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

mouseExited

public void mouseExited(MouseEvent me)
This method is here as part of the highlight handling.

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

mousePressed

public void mousePressed(MouseEvent me)
This method is here as part of the highlight handling.

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

mouseReleased

public void mouseReleased(MouseEvent me)
This method is here as part of the highlight handling.

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

mouseClicked

public void mouseClicked(MouseEvent me)
This method is here as part of the highlight handling.

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

mouseDragged

public void mouseDragged(MouseEvent me)
This method is here as part of the highlight handling.

Specified by:
mouseDragged in interface MouseMotionListener
Parameters:
me - The mouse event supplying extra parameters.

mouseMoved

public void mouseMoved(MouseEvent me)
This method is here as part of the highlight handling.

Specified by:
mouseMoved in interface MouseMotionListener
Parameters:
me - The mouse event supplying extra parameters.

paintComponent

public void paintComponent(Graphics g)
This method tells the draggable component how to paint itself. Most of the work goes on in figuring out what color border to paint around the wrapped swing component.

Parameters:
g - The graphics context on which the component should draw itself.