ARoad0.Gui1
Class DialogBox

java.lang.Object
  extended by ARoad0.Gui1.DialogBox
All Implemented Interfaces:
Singleton, java.util.EventListener, javax.swing.event.TreeSelectionListener

public class DialogBox
extends java.lang.Object
implements Singleton, javax.swing.event.TreeSelectionListener

This class is responsible to built up the short dialog boxes in the desktop. According to the Model-View-Controller pattern, it is a View used by BeamerManager, CommonPropertyEditor and its subclasses, BadseObjectHandler, and numerous Action classes. The main methods are:

- showListDialog() to display a list where the user clicks on its choices

- showSimpleSelectionDialog() does the same job with check boxes

- showSingleEditor() to display a field where the user enters one text then returns

- showExplorerSelection Dialog() is a powerfull method to select objects in the explorer

- showBackedJComponents() to display complex panels managed by the caller

- showBackedJLists() to display a set of lists for an user choice

- showImmutableStringMap() to display a String map without action on it

- several methods to display a message

Since:
0.5.0

Nested Class Summary
(package private) static class DialogBox.KeyListSelectionListener
          nested static class for showImmutableStringMap()
 
Field Summary
protected static javax.swing.JDesktopPane desk__
           
protected static boolean hasHandlerDialog__
           
private static int INITIAL_CAPACITY
           
private static DialogBox instance__
           
protected static javax.swing.JList keyList__
          handled by showImmutableStringMap() and the static nested class KeyListSelectionListener.
protected static java.util.Map<java.lang.String,java.util.List<java.lang.String>> m_values__
           
protected static boolean onlyOneSelectionAllowed__
           
protected static int selectedObjectsCount__
           
protected static java.util.Map selectedObjectsSetMap__
          updated by showExplorerSelectionDialog() and used by valueChanged() map of Class (as key, instance of BaseObject) and JList (as value).
protected static javax.swing.DefaultListModel valuesModel__
           
protected static boolean waitClickInExplorer__
           
 
Constructor Summary
DialogBox()
          only one private constructor
 
Method Summary
static DialogBox getInstance()
          Only method to get an instance.
static boolean onGoingObjectSelectionOrUserDialog()
          .
static void setHasHandlerDialog(boolean _b)
          Called by BaseObjectHandler and CollectionPropertyEditor.actionPerformed() to indicate the start and the end of an user dialog.
static void showAlarmMessage(java.lang.String _msg)
          Displays an OK alarm message following the Access Road standard.
static void showBackedJComponents(CreationDialogListener _controller, java.lang.String _request, javax.swing.JPanel _panel)
          Displays a JInternalFrame with several JComponents to be edited by the user, where the components and the frame are closed AFTER the reading of the properties in the components by the controller.
static void showBackedJLists(CreationDialogListener _controller, java.lang.String _request, javax.swing.JList[] _l_lists, java.lang.String[] _l_titles, boolean _verticalDisplay, javax.swing.JTextField _field, boolean _textBeforeLists)
          Displays several String/BaseObject lists and a text field for selecting one item or more in each.
static boolean[] showClosingAndSavingDialog(ImmutableName _name)
          Display a confirm dialog for closing and saving operations on a base object.
static boolean showConfirmDialog(java.lang.String _question, java.lang.String _comment)
          Displays a question to the user in a modal window.
static void showErrorMessage(java.lang.String _msg)
          Displays an OK error message following the Access Road standard.
 void showExplorerSelectionDialog(SelectionDialogListener _caller, java.lang.String _message, java.util.Set _objectsTypes, java.util.Map _selectedObjectsSetMap, boolean _oneSelection)
          Displays a powerful dialog for selecting from the Explorer some instances of n specified BaseObject classes (n from 1 to 4, inclusively) in a gBase package.
static void showImmutableStringMap(java.lang.String _title, java.util.Map<java.lang.String,java.util.List<java.lang.String>> _m_values)
          Show a map of Strings to read, without action on it.
static javax.swing.JDialog showListDialog(java.lang.String _title, javax.swing.JList _list)
          Displays an OK_CANCEL dialog box with a list and BoxLayout.Y_AXIS, following the Access Road standard.
static javax.swing.JDialog showOkCancelDialog(java.lang.String _title, javax.swing.JPanel _panel)
          Displays an OK_CANCEL dialog box with BoxLayout.Y_AXIS, following the Access Road standard, in a modal window.
static void showOkMessage(java.lang.String _msg)
          Displays an OK information message following the Access Road standard.
static int showOneSelectionOneDialog(java.lang.String _displayName, java.lang.Object[] _l_values)
          Displays one list for selecting one item.
static javax.swing.JPanel showSelectionsInOneDialog(java.lang.String _displayName, java.lang.Object[] _l_values)
          Displays one list for selecting several items.
static java.util.List<java.lang.String> showSimpleSelectionsInOneDialog(java.lang.String _displayName, java.lang.Object[] _l_values)
          Displays one list for selecting several items.
static java.lang.String showSingleEditor(java.lang.String _request)
          Displays a request text to the user for entering a short answer.
static javax.swing.JDialog showYesNoCancelDialog(java.lang.String _title, javax.swing.JPanel _panel)
          Displays an YES_NO_CANCEL dialog box with BoxLayout.Y_AXIS, following the Access Road standard.
 void valueChanged(javax.swing.event.TreeSelectionEvent _evt)
          For implementing the user selection of items in the Explorer, implement a continous TreeSelectionListener which is used only when the showExplorerSelectionDialog() method is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

private static final int INITIAL_CAPACITY
See Also:
Constant Field Values

instance__

private static DialogBox instance__

desk__

protected static javax.swing.JDesktopPane desk__

waitClickInExplorer__

protected static boolean waitClickInExplorer__

hasHandlerDialog__

protected static boolean hasHandlerDialog__

selectedObjectsSetMap__

protected static final java.util.Map selectedObjectsSetMap__
updated by showExplorerSelectionDialog() and used by valueChanged() map of Class (as key, instance of BaseObject) and JList (as value). each JList is associated to a DefaultListModel.


selectedObjectsCount__

protected static int selectedObjectsCount__

onlyOneSelectionAllowed__

protected static boolean onlyOneSelectionAllowed__

keyList__

protected static javax.swing.JList keyList__
handled by showImmutableStringMap() and the static nested class KeyListSelectionListener.


valuesModel__

protected static javax.swing.DefaultListModel valuesModel__

m_values__

protected static java.util.Map<java.lang.String,java.util.List<java.lang.String>> m_values__
Constructor Detail

DialogBox

public DialogBox()
only one private constructor

Method Detail

getInstance

public static DialogBox getInstance()
Only method to get an instance.

Returns:
DialogBox

showOkMessage

public static void showOkMessage(java.lang.String _msg)
Displays an OK information message following the Access Road standard.

Parameters:
_msg - message to display

showSingleEditor

public static java.lang.String showSingleEditor(java.lang.String _request)
Displays a request text to the user for entering a short answer. The request must have a lenght lesser than 300 characters. Called by ActionNewACSyst.selectACSType(), CollectionPropertyEditor.addOneStringOrNameElements(), StringMapPropertyEditor.addKeyElement(), ActionImportACS. Calls showOkCancelDialog().

Parameters:
_request - explains the data to enter. Displayed to the user without adding. Returns null if _request is null or superior to 300.
Returns:
the text the user has entered, or null.

showErrorMessage

public static void showErrorMessage(java.lang.String _msg)
Displays an OK error message following the Access Road standard. The message may have a length superior to 100.

Parameters:
_msg - String message

showAlarmMessage

public static void showAlarmMessage(java.lang.String _msg)
Displays an OK alarm message following the Access Road standard.

Parameters:
_msg - String message

showOkCancelDialog

public static javax.swing.JDialog showOkCancelDialog(java.lang.String _title,
                                                     javax.swing.JPanel _panel)
Displays an OK_CANCEL dialog box with BoxLayout.Y_AXIS, following the Access Road standard, in a modal window. See also showConfirmDialog(), which is simpler to use. If the user enters a "return" in an editable field of _panel, it is also processed as OK_OPTION in the JDialog JOptionPane. To display long texts, use one JLabel per line. Called by showOneSelectionOneDialog() and showImmutableStringMap().

Parameters:
_title - displayed to the user without adding
_panel - JPanel to be displayed
Returns:
JDialog displayed, with a JOptionPane as unique component in its contentPane.

showYesNoCancelDialog

public static javax.swing.JDialog showYesNoCancelDialog(java.lang.String _title,
                                                        javax.swing.JPanel _panel)
Displays an YES_NO_CANCEL dialog box with BoxLayout.Y_AXIS, following the Access Road standard. See also showConfirmDialog(), which is simpler to use. If the user enters a "return" in an editable field of _panel, it is also processed as OK_OPTION in the JDialog JOptionPane. To display long texts, use one JLabel per line.

Parameters:
_title - of the dialog box
_panel - JPanel to be displayed
Returns:
displayed JDialog with a JOptionPane as unique component in its contentPane.

showListDialog

public static javax.swing.JDialog showListDialog(java.lang.String _title,
                                                 javax.swing.JList _list)
Displays an OK_CANCEL dialog box with a list and BoxLayout.Y_AXIS, following the Access Road standard. Called by ActionOpenACSyst, ActionOpenGraphicView and ActionRemove.

Parameters:
_title - String for the dialog box
_list - JList to be displayed
Returns:
JDialog displayed, with a JOptionPane as unique component in its contentPane.

showExplorerSelectionDialog

public void showExplorerSelectionDialog(SelectionDialogListener _caller,
                                        java.lang.String _message,
                                        java.util.Set _objectsTypes,
                                        java.util.Map _selectedObjectsSetMap,
                                        boolean _oneSelection)
                                 throws SmallError
Displays a powerful dialog for selecting from the Explorer some instances of n specified BaseObject classes (n from 1 to 4, inclusively) in a gBase package.

The objects of each type are displayed in a dedicated list in the dialog panel. The number of possible user-selected objects is limited to 15. The number of selected object in each BaseObject classes may be limited to one. For selection from a list already known, use showListDialog().

This method sends always a return value through the call to _caller.handleSelectionDialog(Map). Each JList is associated to a DefaultListModel. If _selectedObjectsSetMap is null or empty, this method displays initial empty jlists. If the user clicks on the 'OK' button when one JList is empty, or if it clicks on a value with a forbidden type, or if it is the second selection when only one is expected, an error message is displayed. If the user clicks on the 'Cancel' button, the method calls the caller with a 'null' argument. Called by ActionNewView, SimplePropertyEditor, CollectionPropertyEditor, BaseObjectHandler, ActionNewACS. Use valueChanged().

Parameters:
_caller - which calls this method. Its handleSelectionDialog() method is called by this method when the user valids the selection inputs.
_message - is the title after completed by ' selection'. Its length has to be inferior to 15. May be null.
_objectsTypes - is the set of the n required classes implementing the BaseObject interface in a gBase package (n between 1 and 4, inclusively).
_selectedObjectsSetMap - is the map where: - the key is an _objectsTypes item - the value is a JList of objects that are instances of the key. May be null or empty.
_oneSelection - is true if only one selected object is allowed for all BaseObject classes
Throws:
SmallError - if a parameter is not a BaseObject instance, or if types are not matched, or if there are more than 4 _objectTypes.

showConfirmDialog

public static boolean showConfirmDialog(java.lang.String _question,
                                        java.lang.String _comment)
Displays a question to the user in a modal window. Does not use '\n' as line separation.

Parameters:
_question - displayed, with a lenght limited to 200. If null or empty, return false.
_comment - to the question, , with a lenght limited to 200. May be null.
Returns:
boolean true only if the user answers yes to the question.

showSelectionsInOneDialog

public static javax.swing.JPanel showSelectionsInOneDialog(java.lang.String _displayName,
                                                           java.lang.Object[] _l_values)
Displays one list for selecting several items. For selecting one item, see showOneSelectionDialog(). For selecting several items in several lists, see showBackedJLists(). The list size is limited to 32 items. The minimal size is 1. The first item type is detected to display the list, and the type must be String, ImmutableName or BaseObject. For a BaseObject, getName().toString() is used to display the item, and it is the same for ImmutableName. result.getComponents() is an array of JCheckBox which are selected or not. Called by showSimpleSelectionDialog() and CollectionPropertyEditor.

Parameters:
_displayName - of the element to select. May be null.
_l_values - is the String or BaseObject list of the non-null values to display. Not null, and size has to be from 1 to 22.
Returns:
JPanel where are the selected JCheckBox(s). It is an empty JPanel if _l_values is not correct.

showSimpleSelectionsInOneDialog

public static java.util.List<java.lang.String> showSimpleSelectionsInOneDialog(java.lang.String _displayName,
                                                                               java.lang.Object[] _l_values)
Displays one list for selecting several items. For selecting one item, see showOneSelectionOneDialog(). The list size is limited to 22 items. The minimal size is 1. All the items must have the same type: String, ImmutableName or BaseObject. If it is BaseObject, getName().toString() is used to display the item and it is in the returned set. It is the same for ImmutableName values to select. The order of the items in the argument is kept in the returned list. Wrap showSelectionDialog(). Called by BaseObjectHandler.actionPerformed() and StringMapPropertyEditor.addRestrictedValueElements().

Parameters:
_displayName - of the element to select. May be null.
_l_values - is the String, ImmutableName or BaseObject list of the allowed non-null values to display.
Returns:
the selected Strings, or the String form of the selected values, or an empty set.

showBackedJComponents

public static void showBackedJComponents(CreationDialogListener _controller,
                                         java.lang.String _request,
                                         javax.swing.JPanel _panel)
Displays a JInternalFrame with several JComponents to be edited by the user, where the components and the frame are closed AFTER the reading of the properties in the components by the controller. The components editing by user is done through compoent listeners outside this method, so component states are not changed by this method. The single listener is generally the method caller. An exemple is when _panel contains a JTextField and a JButton 'Select', where the button updates the text after an user selection in the explorer. This method stops the object selection in the explorer. The method calls _controller.handleCreationDialog() when the option pane is updated, and it closes the internal frame before. It is a partially reentrant method since _controller may recalls it from handleCreationDialog(). The frame cannot be closed directly by the user: only OK/CANCEL buttons are active.

Called by BaseObjectHandler.getBaseObjectEditor() for entering the arguments of a new object or a copy, by showBackedJLists() and by showOneSelectionOneDialog() for RightMapPropertyEditor.addKeyElement(). The displayed OK and Cancel buttons have the names ' OK ' and ' Cancel ' in the parent panel of the argument _panel. BaseObjectHandler.actionPerformed() may terminate the dialog through a direct call to one of these buttons.

Parameters:
_controller - handles the operations when the user ends this dialog. May be an indirect caller like when this.showOneSelectionOneDialog() is the direct caller. Must be non-null.
_request - is the question to the user. Must be non-null.
_panel - is a non-null group of JComponents which includes listener links for updating the values displayed in the panels, following the first user choices. The listener is generally _controller.

showOneSelectionOneDialog

public static int showOneSelectionOneDialog(java.lang.String _displayName,
                                            java.lang.Object[] _l_values)
                                     throws SmallError
Displays one list for selecting one item. For selecting several items, see showSimpleSelectionDialog(). For selecting several items in several lists, see showBackedJLists(). All the items must have the same type: String, ImmutableName or a subclass of BaseObject. If it is BaseObject, getName().toString() is used to display the item.

Parameters:
_displayName - of the element to select. May be null.
_l_values - is the String, ImmutableName or BaseObject array of the non-null values to display.
Returns:
index of the selected JRadioButton in _l_values, or '-1' if there is no user choice.
Throws:
SmallError - if the arguments are not correct, or if the number is below 2 or above 30.

showBackedJLists

public static void showBackedJLists(CreationDialogListener _controller,
                                    java.lang.String _request,
                                    javax.swing.JList[] _l_lists,
                                    java.lang.String[] _l_titles,
                                    boolean _verticalDisplay,
                                    javax.swing.JTextField _field,
                                    boolean _textBeforeLists)
                             throws SmallError
Displays several String/BaseObject lists and a text field for selecting one item or more in each. Uses a JInternalFrame which shows the components, where the components and the frame are closed after the reading of the properties in the components by _controller. The components editing by user is done through component listeners outside this method, so component states are not changed by this method. The single listener is generally the method caller. This method calls _controller.handleCreationDialog() after the closing of the internal frame. It is a partially reentrant method since _controller may recalls it from handleCreationDialog().

For selecting one or several items in the same list, see showSimpleSelectionDialog() and showSelectionsInOneDialog(). The lists size is from 1 (inclusive) to 16 (inclusive). One JTextField may be displayed before or after the JLists. All the items must have the same type: String or BaseObject. If it is BaseObject, getName().toString() is used to display the item. Called by RightMapPropertyEditor, ActionMapPropertyEditor, StringTwoKeysMapProppertyEditor.AddKeyElement() and ActionNewACSyst. Calls showBackedJComponents().

Parameters:
_controller - handles the operations when the user ends this dialog. Never null.
_request - text to display at the bottom of the frame. The size is limited to 50. Never null nor empty.
_l_lists - array of String or BaseObject lists for the non-null values to display. Never null nor empty, and the maximal lenght is 4.
_l_titles - titles for each list and test. Never null. The titles order is the _l_lists order. Must have the same lenght than _l_lists, in the same order if _field is null. If not, the lenght is the _l_lists size plus one, and the field title is always put at the end of _l_titles.
_verticalDisplay - true for presenting the lists vertically; false for an horizontal presentation
_field - a text field. If null, no JTextField is added. May be empty.
_textBeforeLists - if _field is not null, true for having it before the JLists in the presentation; if false, _field is put at the end.
Throws:
SmallError - if the arguments are not correct.

showClosingAndSavingDialog

public static boolean[] showClosingAndSavingDialog(ImmutableName _name)
Display a confirm dialog for closing and saving operations on a base object.

Parameters:
_name - of the base object
Returns:
boolean[] with 2 items: first (0) is true if closing is a user request, second is true if closing and saving are user requests.

showImmutableStringMap

public static void showImmutableStringMap(java.lang.String _title,
                                          java.util.Map<java.lang.String,java.util.List<java.lang.String>> _m_values)
Show a map of Strings to read, without action on it. Derived from StringMapPropertyEditor.getCustomEditor(). Uses the static properties m_values__, keyList__ and valueList__, and the static class DialogBox.KeyListSelectionListener. Called by ActionImportACS. Calls showOkCancelDialog().

Parameters:
_title - title of the map
_m_values - map of Strings to display to the user

valueChanged

public void valueChanged(javax.swing.event.TreeSelectionEvent _evt)
For implementing the user selection of items in the Explorer, implement a continous TreeSelectionListener which is used only when the showExplorerSelectionDialog() method is called.

The user selection is put in selectedObjectsSetMap__, in the JList where the key is an interface implemented by the selection class. This method is called by the JTree listener in Explorer, when the user clicks on a node or a leaf. The number of user selections is limited to 20. When the selection class implements several interfaces which are selectedObjectsSetMap__ keys, the selection is put in every associated JList. This method is independant to the beamer listener that listens to the user selection in Explorer (see ActionOpenBeamer.valueChanged() for instance). Calls TreeManager.getTrueUserObjectInTreeExplorer().

Specified by:
valueChanged in interface javax.swing.event.TreeSelectionListener
Parameters:
_evt - from Explorer JTree

setHasHandlerDialog

public static void setHasHandlerDialog(boolean _b)
Called by BaseObjectHandler and CollectionPropertyEditor.actionPerformed() to indicate the start and the end of an user dialog. See onGoingObjectSelectionOrUserDialog().

Parameters:
_b - is the new value to set

onGoingObjectSelectionOrUserDialog

public static boolean onGoingObjectSelectionOrUserDialog()
. Called by ActionOpenBeamer.valueChanged(), BaseObjectHandler, CollectionPropertyEditor.actionPerformed().

Returns:
true if showExplorerSelectionDialog() is activated to select an object in the explorer, or if a beamer dialog is displayed (for creating a new BaseObject, or any other reason)