org.browsecode.helpers.reorderablelistpanel
Class ReorderableListPanel<T>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.browsecode.helpers.reorderablelistpanel.ReorderableListPanel<T>
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, Uninitializable
Direct Known Subclasses:
AbstractPartListPanel, PagesListPanel, QuestionListPanel, RadioButtonListPanel

public class ReorderableListPanel<T>
extends javax.swing.JComponent
implements java.awt.event.ActionListener, Uninitializable

See Also:
Serialized Form

Nested Class Summary
static interface ReorderableListPanel.GetDoubleClicks
          If an image icon is set for the items to show on the left, then this will be called whenever a user double-clicks on it.
static interface ReorderableListPanel.ItemActionListener<T2>
           
 class ReorderableListPanel.MyReorderableChangeListener
           
static interface ReorderableListPanel.NewItemListener<T2>
          Called whenever a new item is inserted from the GUI.
static interface ReorderableListPanel.RunnableWithSuccessNotification<T2>
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 boolean debug
           
 
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
protected ReorderableListPanel(boolean trash)
          Trash constructor!
  ReorderableListPanel(ReorderableListModel<T> listModel, ReorderableListModelRenderer<T> renderer, java.awt.Insets imageBorderInsets, java.lang.String itemsName)
           
  ReorderableListPanel(ReorderableListModel<T> listModel, ReorderableListModelRenderer<T> renderer, java.awt.Insets imageBorderInsets, java.lang.String itemsName, boolean horizontal)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent action)
           
protected  void addItem(java.awt.Component c, javax.swing.ImageIcon icon, java.lang.String name, int index, T reorderableListItem)
           
 void addNewListItemFromData(java.lang.Object data, int oldIndex, int newIndex)
          Add this chunk of data to this list.
 javax.swing.JMenuItem addPopupMenuItem(java.lang.String name, javax.swing.ImageIcon icon, ReorderableListPanel.ItemActionListener<T> action)
           
 boolean canAddNewListItemFromData(java.lang.Object data)
          Whether or not this chunk of data can be added to this list.
protected  FocusOtherListener getFocusOtherListener()
           
 ReorderableListPanel.GetDoubleClicks getGetDoubleClicks()
           
 java.awt.Component getItem(int i)
           
 int getItemCount()
           
 java.lang.String getItemName()
           
 ReorderableListPanel.NewItemListener getNewItemListener()
           
static ReorderableListPanel getTrashList()
           
 boolean isCompressionButtonVisible()
           
 boolean isItemCompressed(int i)
           
static void main(java.lang.String[] args)
           
 void makeNewItemAndDragIt(java.awt.Component c, java.lang.String name, java.awt.event.MouseEvent e, QuestionDragStarterImage thisQuestionDragStarterImage, ReorderableListPanel.RunnableWithSuccessNotification<T> runnable, T reorderableItem)
          TODO both makeNewItemAndDragIt are wrong -- they have Component passed in, when we also need the ReorderableListItem
 void makeNewItemAndDragIt(java.awt.Component c, java.lang.String name, java.awt.event.MouseEvent e, QuestionDragStarterImage thisQuestionDragStarterImage, T reorderableItem)
          Use this only if, for example, you are creating an object outside and you want to let it be dragged around in this panel.
 void removeItem(int index)
           
 void removeItem(ReorderableListItemPanel rItem)
           
protected  void renderListToGUI(boolean loadList)
          This can be overridden to use a custom rendering technique or to delay the time that this list is loaded.
 void scrollToShowItem(int i)
           
 void setAlwaysShowNewButton(boolean alwaysShowNew)
           
 void setCompressionButtonVisible(boolean b)
           
 void setFocusOtherListener(FocusOtherListener focusOtherListener)
           
 void setGetDoubleClicks(ReorderableListPanel.GetDoubleClicks getDoubleClicks)
           
 void setItemCompressed(int i, boolean compressed)
           
 void setNewItemListener(ReorderableListPanel.NewItemListener<T> newItemListener)
           
 void setRefreshComponent(java.awt.Component c)
          The refreshComponent will be repainted and re-laid out every time something changes.
protected  void setReorderableListModel(ReorderableListModel<T> listModel, ReorderableListModelRenderer<T> renderer)
           
static void showDemoPanel(boolean horizontal)
           
 void uninitialize()
          Uninitialize the component.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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

debug

public boolean debug
Constructor Detail

ReorderableListPanel

public ReorderableListPanel(ReorderableListModel<T> listModel,
                            ReorderableListModelRenderer<T> renderer,
                            java.awt.Insets imageBorderInsets,
                            java.lang.String itemsName)

ReorderableListPanel

public ReorderableListPanel(ReorderableListModel<T> listModel,
                            ReorderableListModelRenderer<T> renderer,
                            java.awt.Insets imageBorderInsets,
                            java.lang.String itemsName,
                            boolean horizontal)

ReorderableListPanel

protected ReorderableListPanel(boolean trash)
Trash constructor! Placeholder for a trash can.

Method Detail

setReorderableListModel

protected void setReorderableListModel(ReorderableListModel<T> listModel,
                                       ReorderableListModelRenderer<T> renderer)
Parameters:
listModel -
renderer -
loadListToGui - whether to load the panels in. Auto-load can be skipped if, for example, a subclass wants to show a progress bar while loading or set the compression options at loading time, etc.

renderListToGUI

protected void renderListToGUI(boolean loadList)
This can be overridden to use a custom rendering technique or to delay the time that this list is loaded. However, since the listeners need to be added here, when you subclass this, you still need to call this superclass, with parameters loadList=false -- so it will add the listeners without actually rendering.


getTrashList

public static ReorderableListPanel getTrashList()

setRefreshComponent

public void setRefreshComponent(java.awt.Component c)
The refreshComponent will be repainted and re-laid out every time something changes. Consider it to be a high level parent of the stuff we're dragging around. This is part of a heinous hack to refreshing parents automatically -- since java doesn't do it properly all the time. I wish there was a better way...

Parameters:
component -

getItemName

public java.lang.String getItemName()

addItem

protected void addItem(java.awt.Component c,
                       javax.swing.ImageIcon icon,
                       java.lang.String name,
                       int index,
                       T reorderableListItem)

setAlwaysShowNewButton

public void setAlwaysShowNewButton(boolean alwaysShowNew)

makeNewItemAndDragIt

public void makeNewItemAndDragIt(java.awt.Component c,
                                 java.lang.String name,
                                 java.awt.event.MouseEvent e,
                                 QuestionDragStarterImage thisQuestionDragStarterImage,
                                 T reorderableItem)
Use this only if, for example, you are creating an object outside and you want to let it be dragged around in this panel.

Parameters:
c -
name -
thisQuestionDragStarterImage -

makeNewItemAndDragIt

public void makeNewItemAndDragIt(java.awt.Component c,
                                 java.lang.String name,
                                 java.awt.event.MouseEvent e,
                                 QuestionDragStarterImage thisQuestionDragStarterImage,
                                 ReorderableListPanel.RunnableWithSuccessNotification<T> runnable,
                                 T reorderableItem)
TODO both makeNewItemAndDragIt are wrong -- they have Component passed in, when we also need the ReorderableListItem


removeItem

public void removeItem(ReorderableListItemPanel rItem)

removeItem

public void removeItem(int index)

getItemCount

public int getItemCount()

getItem

public java.awt.Component getItem(int i)

isItemCompressed

public boolean isItemCompressed(int i)

setItemCompressed

public void setItemCompressed(int i,
                              boolean compressed)

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent action)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

isCompressionButtonVisible

public boolean isCompressionButtonVisible()
Returns:

setCompressionButtonVisible

public void setCompressionButtonVisible(boolean b)
Parameters:
b -

showDemoPanel

public static final void showDemoPanel(boolean horizontal)

canAddNewListItemFromData

public boolean canAddNewListItemFromData(java.lang.Object data)
Whether or not this chunk of data can be added to this list.

Parameters:
data -
Returns:
whether or not the data can be added to the list

addNewListItemFromData

public void addNewListItemFromData(java.lang.Object data,
                                   int oldIndex,
                                   int newIndex)
Add this chunk of data to this list. You must first call canAddNewListItemFromData().

Parameters:
oldIndex - the former index that this was at.
newIndex - the index to add it to the list at (between 0 and getItemCount()).
object - the data to add to this list

setFocusOtherListener

public void setFocusOtherListener(FocusOtherListener focusOtherListener)

getFocusOtherListener

protected FocusOtherListener getFocusOtherListener()

addPopupMenuItem

public javax.swing.JMenuItem addPopupMenuItem(java.lang.String name,
                                              javax.swing.ImageIcon icon,
                                              ReorderableListPanel.ItemActionListener<T> action)

setGetDoubleClicks

public void setGetDoubleClicks(ReorderableListPanel.GetDoubleClicks getDoubleClicks)
Parameters:
getDoubleClicks - The getDoubleClicks to set.

getGetDoubleClicks

public ReorderableListPanel.GetDoubleClicks getGetDoubleClicks()
Returns:
Returns the getDoubleClicks.

getNewItemListener

public ReorderableListPanel.NewItemListener getNewItemListener()
Returns:
Returns the newItemListener.

setNewItemListener

public void setNewItemListener(ReorderableListPanel.NewItemListener<T> newItemListener)
Parameters:
newItemListener - The newItemListener to set.

scrollToShowItem

public void scrollToShowItem(int i)

uninitialize

public void uninitialize()
Description copied from interface: Uninitializable
Uninitialize the component. It should de-register any listeners that will persist into later usage. For improved stability, it is highly recommended that when you call this, you should put a try{}catch(Throwable t){} block around your call, so that any exceptions do not affect the rest of the program. In general, it shouldn't really matter whether uninitialize succeeds -- if it fails, the program should only operate more slowly.

Specified by:
uninitialize in interface Uninitializable

main

public static final void main(java.lang.String[] args)