org.ceryle.ui
Class SelectionDialog

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 org.ceryle.ui.SelectionDialog
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
AddFacetDialog

public class SelectionDialog
extends JDialog

A subclass of JDialog providing a selection list populated by a List. It can also be directly populated by a JList containing its contents. AbstractListModel, Vector, Enumeration or Iterator containing the list contents. This dialog is hidden upon button action and must be disposed of manually. The result is obtained via getSelection():

      SelectionDialog dlog = new SelectionDialog(
              myJFrame,
              "dialog title",
              "dialog message",
              "optional description",
              myList.iterator(),
              SelectionDialog.SINGLE_SELECTION );
      Collection selection = dlog.getSelection();
  

Following use of the dialog, the button pressed can be obtained by calling getSelectedButton(), which returns one of the following JOptionPane values:

If the dialog is closed via its window being closed, JOptionPane.CANCEL_OPTION is returned.

Since:
JDK1.3
Version:
$Id: SelectionDialog.java,v 3.9 2007-06-15 12:09:40 altheim Exp $
Author:
Murray Altheim
See Also:
Serialized Form

Nested Class Summary
 class SelectionDialog.DialogDisposer
           
 
Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JButton btn_all
           
protected  JButton btn_cancel
           
protected  JButton btn_extra
           
protected  JButton btn_help
           
protected  JButton btn_none
           
protected  JButton btn_select
           
static int DEFAULT_COLUMN_WIDTH
          The default column width (in characters) for the display list.
static int DEFAULT_ROW_COUNT
          The default number of rows to show in the display list.
protected  JTextArea help
           
protected  JPanel helpPanel
           
protected  JPanel m_centerPanel
           
protected  JList m_list
           
protected  SetModel m_listModel
           
protected  JPanel m_northPanel
           
protected  JPanel m_southPanel
           
protected  MessageHandler mh
           
static int MIN_HEIGHT
          Minimum window height in pixels.
static int MIN_WIDTH
          Minimum window width in pixels.
static int MULTIPLE_INTERVAL_SELECTION
          A value for the selectionMode property: select one or more contiguous ranges of indices at a time.
protected  int selectedButton
           
static int SINGLE_INTERVAL_SELECTION
          A value for the selectionMode property: select one contiguous range of indices at a time.
static int SINGLE_SELECTION
          A value for the selectionMode property: select one list index at a time.
protected  Services srvs
           
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
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
SelectionDialog(Frame frame, String title, String message, String description, Object contents, ListCellRenderer renderer, int selectionMode)
          Auto-display Constructor.
SelectionDialog(Frame frame, String title, String message, String description, Object contents, ListCellRenderer renderer, int selectionMode, boolean initVisible)
          Constructor for a dialog box containing a selection list.
 
Method Summary
protected  void addNavigationButtons(JPanel panel)
          An extension method that does nothing in this class, permits buttons to be added to the left side of the south button panel.
protected  JPanel createCenterPanel(int selectionMode, String description)
          Returns the center panel containing the selection area(s) and optional help text.
protected  JPanel createNorthPanel(String message)
          Returns the northernmost panel containing the message text.
protected  JPanel createSouthPanel(int selectionMode, boolean includeHelp)
          Returns the southernmost panel containing the submit and cancel buttons.
 JButton getExtraButton()
          Returns the unused 'extra' button so that it can be configured externally.
 int getSelectedButton()
          Returns the value of the selected button as one of the JOptionPane options JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, or JOptionPane.CANCEL_OPTION.
 int getSelectedCount()
          Returns the number of selected items in the list.
 int[] getSelectedIndices()
          Returns the selected indices, an empty array if there is no selection.
 Object getSelectedValue()
          Returns the selected Object, null if there is no selection.
 Collection getSelectedValues()
          Returns the selected Objects as a Collection, null if there is no selection.
 Collection getSelection()
          Returns the selected item(s) of this SelectionList as a Collection of Strings, null if there is no selection or the user cancelled the dialog.
 boolean isHelpVisible()
           
 void removeAllButton()
          Removes the 'All' button.
 void removeNoneButton()
          Removes the 'None' button.
 void setActive(boolean active)
          Sets the active/inactive state of this dialog box, as indicated by the south panel colors.
 void setContents(Object o)
          If provided with a ListModel, sets the list contents to that model, otherwise replaces the existing model with the contents of the provided Object.
 void setHelpText(String content)
          Set the help text to the String content.
 void setListTitle(String title, String message)
          Sets the title of the list to title and message.
 void setSelected(Object o)
          Set the selection to the provided object, which is added to the list if it is not already a member.
protected  void setSelectedButton(int value)
           
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, toBack, 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, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, 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, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, 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, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SINGLE_SELECTION

public static final int SINGLE_SELECTION
A value for the selectionMode property: select one list index at a time.

See Also:
ListSelectionModel.SINGLE_SELECTION, Constant Field Values

SINGLE_INTERVAL_SELECTION

public static final int SINGLE_INTERVAL_SELECTION
A value for the selectionMode property: select one contiguous range of indices at a time.

See Also:
ListSelectionModel.SINGLE_INTERVAL_SELECTION, Constant Field Values

MULTIPLE_INTERVAL_SELECTION

public static final int MULTIPLE_INTERVAL_SELECTION
A value for the selectionMode property: select one or more contiguous ranges of indices at a time.

See Also:
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, Constant Field Values

MIN_WIDTH

public static int MIN_WIDTH
Minimum window width in pixels. This defaults to 400.


MIN_HEIGHT

public static int MIN_HEIGHT
Minimum window height in pixels. This defaults to 200.


DEFAULT_COLUMN_WIDTH

public static int DEFAULT_COLUMN_WIDTH
The default column width (in characters) for the display list.


DEFAULT_ROW_COUNT

public static int DEFAULT_ROW_COUNT
The default number of rows to show in the display list.


srvs

protected Services srvs

mh

protected MessageHandler mh

m_listModel

protected SetModel m_listModel

m_list

protected JList m_list

selectedButton

protected int selectedButton

btn_help

protected JButton btn_help

btn_cancel

protected JButton btn_cancel

btn_all

protected JButton btn_all

btn_none

protected JButton btn_none

btn_extra

protected JButton btn_extra

btn_select

protected JButton btn_select

m_northPanel

protected JPanel m_northPanel

m_centerPanel

protected JPanel m_centerPanel

m_southPanel

protected JPanel m_southPanel

helpPanel

protected JPanel helpPanel

help

protected JTextArea help
Constructor Detail

SelectionDialog

public SelectionDialog(Frame frame,
                       String title,
                       String message,
                       String description,
                       Object contents,
                       ListCellRenderer renderer,
                       int selectionMode)
Auto-display Constructor. (see other constructor for details)


SelectionDialog

public SelectionDialog(Frame frame,
                       String title,
                       String message,
                       String description,
                       Object contents,
                       ListCellRenderer renderer,
                       int selectionMode,
                       boolean initVisible)
Constructor for a dialog box containing a selection list. The list should be supplied as an AbstractListModel or Vector containing a list of values. The result is returned from the the method getSelection(), and is one or more selected values, or null if there isn't a selection. Options for selectionMode are:

Note that even the provided list is optional. If null, the dialog will still be displayed, but with no displayed list.

Parameters:
frame - the parent frame
title - the dialog title
message - the text to display above the list
description - an optional text description
contents - an AbstractListModel, JList, Vector, Enumeration or Iterator containing list contents
selectionMode - a value of JList's selection mode
renderer - an optional cell renderer
initVisible - when true, displays the dialog upon instantiation
Method Detail

createNorthPanel

protected JPanel createNorthPanel(String message)
Returns the northernmost panel containing the message text.


setListTitle

public void setListTitle(String title,
                         String message)
Sets the title of the list to title and message. If provided, the title is bold text preceding the message. If the list title was not initially created, it is added the first time this is called.


createCenterPanel

protected JPanel createCenterPanel(int selectionMode,
                                   String description)
Returns the center panel containing the selection area(s) and optional help text.


setContents

public void setContents(Object o)
If provided with a ListModel, sets the list contents to that model, otherwise replaces the existing model with the contents of the provided Object. Other permitted interfaces/classes: SetModel, List, Collection, Enumeration, or Iterator. A null value clears any existing contents.


setSelectedButton

protected void setSelectedButton(int value)

getSelectedButton

public int getSelectedButton()
Returns the value of the selected button as one of the JOptionPane options JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, or JOptionPane.CANCEL_OPTION.


getExtraButton

public JButton getExtraButton()
Returns the unused 'extra' button so that it can be configured externally. Calling this method will both set the button enabled and visible.


setSelected

public void setSelected(Object o)
Set the selection to the provided object, which is added to the list if it is not already a member. This method should not be called if the originating list is not backed by a SetModel.


setActive

public void setActive(boolean active)
Sets the active/inactive state of this dialog box, as indicated by the south panel colors. This has no effect on the enabled state of any components, just their color.


removeAllButton

public void removeAllButton()
Removes the 'All' button.


removeNoneButton

public void removeNoneButton()
Removes the 'None' button.


createSouthPanel

protected JPanel createSouthPanel(int selectionMode,
                                  boolean includeHelp)
Returns the southernmost panel containing the submit and cancel buttons.


addNavigationButtons

protected void addNavigationButtons(JPanel panel)
An extension method that does nothing in this class, permits buttons to be added to the left side of the south button panel.


isHelpVisible

public boolean isHelpVisible()

setHelpText

public void setHelpText(String content)
Set the help text to the String content.


getSelectedValue

public Object getSelectedValue()
Returns the selected Object, null if there is no selection.


getSelectedValues

public Collection getSelectedValues()
Returns the selected Objects as a Collection, null if there is no selection.


getSelectedIndices

public int[] getSelectedIndices()
Returns the selected indices, an empty array if there is no selection.


getSelection

public Collection getSelection()
Returns the selected item(s) of this SelectionList as a Collection of Strings, null if there is no selection or the user cancelled the dialog. If the SelectionDialog was instantiated with selectionMode as JList.SINGLE_SELECTION (single selection only), the result can be obtained as
      String result = (String)dialog.getSelection().firstElement();
  
I.e., if the supplied values were Strings, and after first checking that the result is non-null.


getSelectedCount

public int getSelectedCount()
Returns the number of selected items in the list.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.