edu.rice.cs.util.swing
Class ScrollableListDialog<T>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Dialog
                  extended by javax.swing.JDialog
                      extended by edu.rice.cs.util.swing.ScrollableListDialog<T>
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class ScrollableListDialog<T>
extends JDialog

The ScrollableListDialog is a popup dialog with a message and a scrollable list of items. A ScrollableListDialog should be used when a message may need to display a variable number of items, for example, when reporting missing files.

The message (also know as the leader text) is displayed above the items with an optional icon. The items are displayed in a scrollable list. Buttons are added below the list of items.

This dialog is somewhat styled after JOptionPane and uses the message-type constants from JOptionPane.

Since:
2007-03-06
Version:
$Id: ScrollableListDialog.java 5544 2012-04-27 15:22:12Z rcartwright $
Author:
Chris Warrington
See Also:
Serialized Form

Nested Class Summary
static class ScrollableListDialog.Builder<T>
          Factory design pattern.
 
Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityType
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  int _buttonPressed
          The number of the button that was pressed to close the dialog.
private static int DEFAULT_HEIGHT
          The default height for this dialog.
private static int DEFAULT_WIDTH
          The default width for this dialog.
private static double HEIGHT_RATIO
          The ratio of the screen height to use by default.
protected   list
          The list of items displayed.
protected  List<T> listItems
          The list of items being listed.
private static double WIDTH_RATIO
          The ratio of the screen width to use by default.
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPE
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
private ScrollableListDialog(Frame owner, String dialogTitle, String leaderText, List<T> listItems, List<T> selItems, int messageType, int width, int height, Icon icon, boolean fitToScreen, List<JButton> buttons, List<JComponent> additional, boolean selectable)
          Creates a new ScrollableListDialog with the given title, leader text, items, message type, width, height, and icon.
 
Method Summary
protected  void _addAdditionalComponents(JPanel buttonPanel, List<JComponent> additional)
          Adds additional components to the bottom of the dialog.
protected  void _addButtons(JPanel buttonPanel, List<JButton> buttons)
          Adds buttons to the bottom of the dialog.
private  Icon _getIcon(int messageType)
          Lookup the icon associated with the given messageType.
private  boolean _isknownMessageType(int messageType)
          A method to check if they given message type is a know message type.
protected  void closeDialog()
          Should be called when the dialog should be closed.
 int getButtonPressed()
          Return the number of the button that was pressed to close the dialog.
 List<T> getSelectedItems()
          Return a list of the selected items.
static void main(String[] args)
          A simple main method for testing purposes.
 void showDialog()
          Shows the dialog.
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setModalityType, setResizable, setTitle, setUndecorated, setVisible, show, toBack
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_WIDTH

private static final int DEFAULT_WIDTH
The default width for this dialog.

See Also:
Constant Field Values

DEFAULT_HEIGHT

private static final int DEFAULT_HEIGHT
The default height for this dialog.

See Also:
Constant Field Values

WIDTH_RATIO

private static final double WIDTH_RATIO
The ratio of the screen width to use by default.

See Also:
Constant Field Values

HEIGHT_RATIO

private static final double HEIGHT_RATIO
The ratio of the screen height to use by default.

See Also:
Constant Field Values

list

protected final  list
The list of items displayed.


_buttonPressed

protected int _buttonPressed
The number of the button that was pressed to close the dialog.


listItems

protected List<T> listItems
The list of items being listed.

Constructor Detail

ScrollableListDialog

private ScrollableListDialog(Frame owner,
                             String dialogTitle,
                             String leaderText,
                             List<T> listItems,
                             List<T> selItems,
                             int messageType,
                             int width,
                             int height,
                             Icon icon,
                             boolean fitToScreen,
                             List<JButton> buttons,
                             List<JComponent> additional,
                             boolean selectable)

Creates a new ScrollableListDialog with the given title, leader text, items, message type, width, height, and icon. The list of items is used to construct an internal string list that is not backed by the original list. Changes made to the list or items after dialog construction will not be reflected in the dialog.

The message type must be one of the message types from JOptionPane. The message type controlls which default icon is used. If icon is non-null, it is used instead of the default icon.

Parameters:
owner - The frame that owns this dialog. May be null.
dialogTitle - The text to use as the dialog title.
leaderText - Text to display before the list of items.
listItems - The items to display in the list.
selItems - The items selected at the beginning.
messageType - The type of dialog message.
width - The width of the dialog box.
height - The height of the dialog box.
icon - The icon to display. May be null.
fitToScreen - If true, the width and height of the dialog will be calculated using the screen dimensions, WIDTH_RATIO, and HEIGHT_RATIO. If false, the provided width and height will be used.
buttons - The list of buttons to display
additional - The list of additional components to display
selectable - true if items can be selected
Throws:
IllegalArgumentException - if listItems is null.
IllegalArgumentException - if the message type is unknown or listItems is null.
Method Detail

_isknownMessageType

private boolean _isknownMessageType(int messageType)
A method to check if they given message type is a know message type.

Parameters:
messageType - The message type to check
Returns:
true if the message type is known, false otherwise

_getIcon

private Icon _getIcon(int messageType)
Lookup the icon associated with the given messageType. The message type must be one of the message types from JOptionPane.

Parameters:
messageType - The message for which the icon is requested.
Returns:
The message's icon or null is no icon was found.

_addButtons

protected void _addButtons(JPanel buttonPanel,
                           List<JButton> buttons)
Adds buttons to the bottom of the dialog. By default, a single "OK" button is added that calls closeDialog(). It is also set as the dialog's default button. Inheritors should feel free the change settings of the panel such as the layout manager. However, no guarantees are made that every change will work with every version of this class.

Parameters:
buttonPanel - The JPanel that should contain the buttons.
buttons - The list of buttons

_addAdditionalComponents

protected void _addAdditionalComponents(JPanel buttonPanel,
                                        List<JComponent> additional)
Adds additional components to the bottom of the dialog.

Parameters:
buttonPanel - The JPanel that should contain the components.
additional - The list of components

showDialog

public void showDialog()
Shows the dialog.


closeDialog

protected void closeDialog()
Should be called when the dialog should be closed. The default implementation simply hides the dialog.


getButtonPressed

public int getButtonPressed()
Return the number of the button that was pressed to close the dialog.


getSelectedItems

public List<T> getSelectedItems()
Return a list of the selected items.


main

public static void main(String[] args)
A simple main method for testing purposes.

Parameters:
args - Not used.