ca.sqlpower.architect.swingui
Class ContainerPane<T,C>

java.lang.Object
  extended by ca.sqlpower.architect.swingui.PlayPenComponent
      extended by ca.sqlpower.architect.swingui.ContainerPane<T,C>
Type Parameters:
T - Class of the model
C - Class of the an item.
All Implemented Interfaces:
LayoutNode, Selectable, java.awt.dnd.DragSourceListener, java.util.EventListener
Direct Known Subclasses:
OLAPPane, TablePane

public abstract class ContainerPane<T,C>
extends PlayPenComponent
implements java.awt.dnd.DragSourceListener, LayoutNode

A playpen component that represents a model with a list of individually selectable items.


Field Summary
static int ITEM_INDEX_NONE
          A special item index that means "no location."
static int ITEM_INDEX_TITLE
          A special item index that represents the titlebar area.
protected  java.awt.Insets margin
          How many pixels should be left between the surrounding box and the item name labels.
protected  T model
           
protected  java.util.Set<C> selectedItems
          Tracks which items in this container are currently selected.
 
Fields inherited from class ca.sqlpower.architect.swingui.PlayPenComponent
backgroundColor, componentPreviouslySelected, foregroundColor, selected
 
Constructor Summary
protected ContainerPane(PlayPenContentPane parent)
           
 
Method Summary
 void addItemSelectionListener(ItemSelectionListener<T,C> listener)
           
 java.awt.datatransfer.DataFlavor bestImportFlavor(javax.swing.JComponent c, java.awt.datatransfer.DataFlavor[] flavors)
          Chooses the best import flavour from the flavors array for importing into c.
abstract  java.awt.datatransfer.Transferable createTransferableForSelection()
          Creates a Transferable representation of the currently-selected items.
protected  void deSelectEverythingElse(java.awt.event.MouseEvent evt)
          Deselects everything except the selected item.
 void deselectItem(C item)
          Deselects the given item.
 void deselectItem(int i)
          Deselects the item, if i < 0, selectNone() is called.
 void dragDropEnd(java.awt.dnd.DragSourceDropEvent dsde)
           
 void dragEnter(java.awt.dnd.DragSourceDragEvent dsde)
           
 void dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
          Called while a drag operation is ongoing, when the mouse pointer enters the operable part of the drop site for the DropTarget registered with this listener.
 void dragExit(java.awt.dnd.DragSourceEvent dse)
           
 void dragExit(java.awt.dnd.DropTargetEvent dte)
          Called while a drag operation is ongoing, when the mouse pointer has exited the operable part of the drop site for the DropTarget registered with this listener.
 void dragOver(java.awt.dnd.DragSourceDragEvent dsde)
           
 void dragOver(java.awt.dnd.DropTargetDragEvent dtde)
          Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site for the DropTarget registered with this listener.
 void drop(java.awt.dnd.DropTargetDropEvent dtde)
          Called when the drag operation has terminated with a drop on the operable part of the drop site for the DropTarget registered with this listener.
 void dropActionChanged(java.awt.dnd.DragSourceDragEvent dsde)
           
 void dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)
          Called if the user has modified the current drop gesture.
protected  void fireItemsDeselected(java.util.Set<C> items)
           
protected  void fireItemsSelected(java.util.Set<C> items)
           
protected abstract  java.util.List<C> getItems()
          Returns a list of the items to be displayed with the model.
 java.awt.Point getLocationOnScreen()
           
 java.awt.Insets getMargin()
          Gets the value of margin
 T getModel()
           
 java.lang.String getNodeName()
          Simple implementation for LayoutNode interface.
 int getSelectedItemIndex()
          Returns the index of the first selected item, or ITEM_INDEX_NONE if there are no selected items.
 java.util.List<C> getSelectedItems()
          Returns a list of the items that are currently in the selection that also currently exist in the model.
 void handleMouseEvent(java.awt.event.MouseEvent evt)
          Performs the component specific actions for the given MouseEvent.
 boolean isDashed()
          Indicates whether the lines are dashed/normal.
 boolean isItemSelected(C item)
          Returns true if the given item was selected in this container pane since the last time selectNone() was called, even if it has subsequently been removed from the model.
 boolean isItemSelected(int i)
          Returns true if the item at the given index is selected.
 boolean isRounded()
          Indicates whether the corners are rounded.
abstract  int pointToItemIndex(java.awt.Point p)
          Deprecated. 
 void removeItemSelectionListener(ItemSelectionListener<T,C> listener)
           
 void selectItem(C item)
          Selects the item, firing an ItemSelectionEvent.
 void selectItem(int i)
          Selects the item, firing an ItemSelectionEvent.
 void selectNone()
          Deselects all items in this ContainerPane.
 void setDashed(boolean isDashed)
          Sets whether the lines are dashed.
 void setMargin(java.awt.Insets argMargin)
          Sets the value of margin
 void setRounded(boolean isRounded)
          Sets whether the corners are rounded.
 void setSelected(boolean isSelected, int multiSelectType)
          Overridden so that the items get deselected when the whole container is deselected.
 
Methods inherited from class ca.sqlpower.architect.swingui.PlayPenComponent
addPropertyChangeListener, addPropertyChangeListener, addSelectionListener, contains, firePropertyChange, firePropertyChange, fireSelectionEvent, getBackgroundColor, getBounds, getBounds, getFont, getFontMetrics, getFontRenderContext, getForegroundColor, getHeight, getInsets, getLocation, getLocation, getName, getParent, getPlayPen, getPopup, getPreferredLocation, getPreferredSize, getSize, getToolTipText, getUI, getWidth, getX, getY, isOpaque, isSelected, paint, removePropertyChangeListener, removeSelectionListener, repaint, repaint, repaint, revalidate, setBackgroundColor, setBounds, setBoundsImpl, setForegroundColor, setInsets, setLocation, setLocation, setOpaque, setSize, setToolTipText, setUI, showPopup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ca.sqlpower.architect.layout.LayoutNode
getBounds, getBounds, getHeight, getInboundEdges, getLocation, getOutboundEdges, getWidth, getX, getY, setBounds, setLocation, setLocation
 

Field Detail

ITEM_INDEX_TITLE

public static final int ITEM_INDEX_TITLE
A special item index that represents the titlebar area.

See Also:
Constant Field Values

ITEM_INDEX_NONE

public static final int ITEM_INDEX_NONE
A special item index that means "no location."

See Also:
Constant Field Values

model

protected T model

margin

protected java.awt.Insets margin
How many pixels should be left between the surrounding box and the item name labels.


selectedItems

protected final java.util.Set<C> selectedItems
Tracks which items in this container are currently selected.

Constructor Detail

ContainerPane

protected ContainerPane(PlayPenContentPane parent)
Method Detail

getModel

public T getModel()
Specified by:
getModel in class PlayPenComponent

handleMouseEvent

public void handleMouseEvent(java.awt.event.MouseEvent evt)
Description copied from class: PlayPenComponent
Performs the component specific actions for the given MouseEvent.

Specified by:
handleMouseEvent in class PlayPenComponent

deSelectEverythingElse

protected void deSelectEverythingElse(java.awt.event.MouseEvent evt)
Deselects everything except the selected item. This method exists to stop multiple selection events from propagating into the CreateRelationshipAction listeners.


getLocationOnScreen

public java.awt.Point getLocationOnScreen()

setMargin

public void setMargin(java.awt.Insets argMargin)
Sets the value of margin

Parameters:
argMargin - Value to assign to this.margin

getMargin

public java.awt.Insets getMargin()
Gets the value of margin

Returns:
the value of margin

getItems

protected abstract java.util.List<C> getItems()
Returns a list of the items to be displayed with the model.


isRounded

public boolean isRounded()
Indicates whether the corners are rounded.


setRounded

public void setRounded(boolean isRounded)
Sets whether the corners are rounded.


isDashed

public boolean isDashed()
Indicates whether the lines are dashed/normal.


setDashed

public void setDashed(boolean isDashed)
Sets whether the lines are dashed.


setSelected

public void setSelected(boolean isSelected,
                        int multiSelectType)
Overridden so that the items get deselected when the whole container is deselected.

Specified by:
setSelected in interface Selectable
Overrides:
setSelected in class PlayPenComponent
Parameters:
isSelected - The new selection state for this component
multiSelectType - One of the type codes from SelectionEvent.

pointToItemIndex

@Deprecated
public abstract int pointToItemIndex(java.awt.Point p)
Deprecated. 


selectNone

public void selectNone()
Deselects all items in this ContainerPane.


deselectItem

public void deselectItem(int i)
Deselects the item, if i < 0, selectNone() is called.

Parameters:
i - index to getItems()

deselectItem

public void deselectItem(C item)
Deselects the given item.

Parameters:
item - the item to deselect.

selectItem

public void selectItem(int i)
Selects the item, firing an ItemSelectionEvent. If i < 0, selectNone() is called.

Parameters:
i - index to getItems()

selectItem

public void selectItem(C item)
Selects the item, firing an ItemSelectionEvent.

Parameters:
item - The item to select.

isItemSelected

public boolean isItemSelected(int i)
Returns true if the item at the given index is selected.

Parameters:
i - index from getItems()

isItemSelected

public boolean isItemSelected(C item)
Returns true if the given item was selected in this container pane since the last time selectNone() was called, even if it has subsequently been removed from the model. This comes in handy in event listeners that want to know if a recently-removed item was selected at the time it was removed.

Parameters:
item - The item to check
Returns:
true if item is currently selected, or was selected at the time it was removed.

getSelectedItems

public java.util.List<C> getSelectedItems()
Returns a list of the items that are currently in the selection that also currently exist in the model. Sometimes, especially when handling remove events, you will want to know if the item that was just removed used to be selected. In that case, use isItemSelected(Object).


getSelectedItemIndex

public int getSelectedItemIndex()
Returns the index of the first selected item, or ITEM_INDEX_NONE if there are no selected items.


fireItemsSelected

protected void fireItemsSelected(java.util.Set<C> items)

fireItemsDeselected

protected void fireItemsDeselected(java.util.Set<C> items)

addItemSelectionListener

public void addItemSelectionListener(ItemSelectionListener<T,C> listener)

removeItemSelectionListener

public void removeItemSelectionListener(ItemSelectionListener<T,C> listener)

dragEnter

public void dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
Called while a drag operation is ongoing, when the mouse pointer enters the operable part of the drop site for the DropTarget registered with this listener.

NOTE: This method is expected to be called from the PlayPen's dragOver method (not directly by Swing), and as such the DropTargetContext (and the mouse co-ordinates) will be of the PlayPen.


dragExit

public void dragExit(java.awt.dnd.DropTargetEvent dte)
Called while a drag operation is ongoing, when the mouse pointer has exited the operable part of the drop site for the DropTarget registered with this listener.

NOTE: This method is expected to be called from the PlayPen's dragOver method (not directly by Swing), and as such the DropTargetContext (and the mouse co-ordinates) will be of the PlayPen.


dragOver

public void dragOver(java.awt.dnd.DropTargetDragEvent dtde)
Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site for the DropTarget registered with this listener.

NOTE: This method is expected to be called from the PlayPen's dragOver method (not directly by Swing), and as such the DropTargetContext (and the mouse co-ordinates) will be of the PlayPen.


drop

public void drop(java.awt.dnd.DropTargetDropEvent dtde)
Called when the drag operation has terminated with a drop on the operable part of the drop site for the DropTarget registered with this listener.

NOTE: This method is expected to be called from the PlayPen's dragOver method (not directly by Swing), and as such the DropTargetContext (and the mouse co-ordinates) will be of the PlayPen.


dropActionChanged

public void dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)
Called if the user has modified the current drop gesture.


bestImportFlavor

public java.awt.datatransfer.DataFlavor bestImportFlavor(javax.swing.JComponent c,
                                                         java.awt.datatransfer.DataFlavor[] flavors)
Chooses the best import flavour from the flavors array for importing into c.

Returns:
The first acceptable DataFlavor in the flavors list, or null if no acceptable flavours are present.

dragEnter

public void dragEnter(java.awt.dnd.DragSourceDragEvent dsde)
Specified by:
dragEnter in interface java.awt.dnd.DragSourceListener

dragOver

public void dragOver(java.awt.dnd.DragSourceDragEvent dsde)
Specified by:
dragOver in interface java.awt.dnd.DragSourceListener

dropActionChanged

public void dropActionChanged(java.awt.dnd.DragSourceDragEvent dsde)
Specified by:
dropActionChanged in interface java.awt.dnd.DragSourceListener

dragExit

public void dragExit(java.awt.dnd.DragSourceEvent dse)
Specified by:
dragExit in interface java.awt.dnd.DragSourceListener

dragDropEnd

public void dragDropEnd(java.awt.dnd.DragSourceDropEvent dsde)
Specified by:
dragDropEnd in interface java.awt.dnd.DragSourceListener

createTransferableForSelection

public abstract java.awt.datatransfer.Transferable createTransferableForSelection()
Creates a Transferable representation of the currently-selected items. If there is nothing transferable selected, returns null.


getNodeName

public java.lang.String getNodeName()
Simple implementation for LayoutNode interface. Simply calls getName().

Specified by:
getNodeName in interface LayoutNode


Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca