ucot.ui.gui
Class GUIUtils

java.lang.Object
  extended by ucot.ui.gui.GUIUtils

public class GUIUtils
extends java.lang.Object

Miscallaneous utils used by the grapical userinterface.

Author:
ilanliuk

Field Summary
protected static java.lang.String DEFAULT_ERROR_HEADER
           
protected static java.lang.String DEFAULT_QUESTION_HEADER
           
protected static java.lang.String DEFAULT_WARNING_HEADER
           
protected static java.lang.String OK_CAPTION
           
 
Constructor Summary
GUIUtils()
           
 
Method Summary
static void centerDialog(javax.swing.JDialog dialog)
           This method centers a given dialog to the center of the screen.
static javax.swing.DefaultCellEditor createComboBoxCellEditor(java.lang.String[] values, java.lang.String self, java.lang.String selfPointer, boolean allowSelf, boolean addEmpty)
           This method creates a new JComboBox Cell Editor for a JTable element from the given String array.
static void printError(java.awt.Window win, java.lang.String errorMessage)
           Method for spawning error dialog with default header String
static void printError(java.awt.Window win, java.lang.String errorMessage, java.lang.String header)
           Method for spawning error dialog.
static void printInfo(java.awt.Window win, java.lang.String info, java.lang.String header)
           Method for spawning info dialog.
static void printWarning(java.awt.Window win, java.lang.String warning)
           Method for spawning warning dialog with dafault header String.
static void printWarning(java.awt.Window win, java.lang.String warning, java.lang.String header)
           Method for spawning warning dialog.
static int questionDialog(java.awt.Window win, java.lang.String question)
           Method for spawning question dialog.
static int questionDialog(java.awt.Window win, java.lang.String question, java.lang.String header)
           Method for spawning question dialog with YES_NO_OPTION-option.
static int questionDialog(java.awt.Window win, java.lang.String question, java.lang.String header, int options)
           Method for spawning question dialog with wanted options.
static int showDialog(java.awt.Window parent, int messageType, java.lang.String message, java.lang.String header, int options)
           Dialog spawner for warnings, errors and questions.
static java.net.URL showOpenFileDialog(java.awt.Component owner, java.util.Vector<CustomFileFilter> fileFilters)
           Default open dialog spawner which assumes that all file types are not required to be shown when any file filters are manually defined.
static java.net.URL showOpenFileDialog(java.awt.Component owner, java.util.Vector<CustomFileFilter> fileFilters, boolean acceptAllFileFiltersUsed)
           Method for spawning a file chooser dialog.
static ChoosedFile showSaveFileDialog(java.awt.Component owner, java.util.Vector<CustomFileFilter> fileFilters)
           Method for spawning a save file chooser dialog.
static ChoosedFile showSaveFileDialog(java.awt.Component owner, java.util.Vector<CustomFileFilter> fileFilters, int fileSelectionMode)
           Method for spawning a file save dialog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ERROR_HEADER

protected static final java.lang.String DEFAULT_ERROR_HEADER
See Also:
Constant Field Values

DEFAULT_QUESTION_HEADER

protected static final java.lang.String DEFAULT_QUESTION_HEADER
See Also:
Constant Field Values

DEFAULT_WARNING_HEADER

protected static final java.lang.String DEFAULT_WARNING_HEADER
See Also:
Constant Field Values

OK_CAPTION

protected static final java.lang.String OK_CAPTION
See Also:
Constant Field Values
Constructor Detail

GUIUtils

public GUIUtils()
Method Detail

showOpenFileDialog

public static java.net.URL showOpenFileDialog(java.awt.Component owner,
                                              java.util.Vector<CustomFileFilter> fileFilters,
                                              boolean acceptAllFileFiltersUsed)

Method for spawning a file chooser dialog.

Parameters:
owner - Parent of this dialog.
fileFilters - Allowed file extensions.
acceptAllFileFiltersUsed - Defines whether all file types are allowed or not when any file filters are manually defined.
Returns:
The selected file as an URL or null if no file was selected.

showOpenFileDialog

public static java.net.URL showOpenFileDialog(java.awt.Component owner,
                                              java.util.Vector<CustomFileFilter> fileFilters)

Default open dialog spawner which assumes that all file types are not required to be shown when any file filters are manually defined.

Parameters:
owner - Parent of this dialog.
fileFilters - Allowed file extensions.
Returns:
The selected file as an URL or null if no file was selected.

showSaveFileDialog

public static ChoosedFile showSaveFileDialog(java.awt.Component owner,
                                             java.util.Vector<CustomFileFilter> fileFilters,
                                             int fileSelectionMode)

Method for spawning a file save dialog.

Parameters:
owner - Parent of this dialog.
fileFilters - Allowed file extensions.
fileSelectionMode - defines wether the user can select files, directories or both.
Returns:
The object containing selections.

showSaveFileDialog

public static ChoosedFile showSaveFileDialog(java.awt.Component owner,
                                             java.util.Vector<CustomFileFilter> fileFilters)

Method for spawning a save file chooser dialog.

Parameters:
owner - Parent of this dialog.
fileFilters - Allowed file extensions.
Returns:
The selected file as an URL or null if no file was selected.

showDialog

public static int showDialog(java.awt.Window parent,
                             int messageType,
                             java.lang.String message,
                             java.lang.String header,
                             int options)

Dialog spawner for warnings, errors and questions.

Parameters:
parent - Parent Window for this dialog.
messageType - the type of message to be displayed: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE.
message - Message itself.
header - the String to display in the dialog's title bar
options - the options to display in the pane: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, or OK_CANCEL_OPTION.
Returns:
User's choice.

centerDialog

public static void centerDialog(javax.swing.JDialog dialog)

This method centers a given dialog to the center of the screen.

Parameters:
dialog - JDialog to be centered.

questionDialog

public static int questionDialog(java.awt.Window win,
                                 java.lang.String question)

Method for spawning question dialog.

Parameters:
win - Parent Window for this dialog.
question - The question String to show.
Returns:
User's choice.

printWarning

public static void printWarning(java.awt.Window win,
                                java.lang.String warning,
                                java.lang.String header)

Method for spawning warning dialog.

Parameters:
win - Parent Window for this dialog.
warning - The warning String to show.
header - the String to display in the dialog's title bar

printInfo

public static void printInfo(java.awt.Window win,
                             java.lang.String info,
                             java.lang.String header)

Method for spawning info dialog.

Parameters:
win - Parent Window for this dialog.
info - The info String to show.
header - the String to display in the dialog's title bar

printWarning

public static void printWarning(java.awt.Window win,
                                java.lang.String warning)

Method for spawning warning dialog with dafault header String.

Parameters:
win - Parent Window for this dialog.
warning - The warning String to show.

printError

public static void printError(java.awt.Window win,
                              java.lang.String errorMessage,
                              java.lang.String header)

Method for spawning error dialog.

Parameters:
win - Parent Window for this dialog.
errorMessage - The error String to show.
header - the String to display in the dialog's title bar

printError

public static void printError(java.awt.Window win,
                              java.lang.String errorMessage)

Method for spawning error dialog with default header String

Parameters:
win - Parent Window for this dialog.
errorMessage - The error String to show.

questionDialog

public static int questionDialog(java.awt.Window win,
                                 java.lang.String question,
                                 java.lang.String header,
                                 int options)

Method for spawning question dialog with wanted options.

Options available are: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, or OK_CANCEL_OPTION. Options are defined in JOptionPane-class.

Parameters:
win - Parent Window for this dialog.
question - The question String to show.
header - the String to display in the dialog's title bar
options - The options to display in the pane.
Returns:
User's choise.
See Also:
JOptionPane

questionDialog

public static int questionDialog(java.awt.Window win,
                                 java.lang.String question,
                                 java.lang.String header)

Method for spawning question dialog with YES_NO_OPTION-option.

Parameters:
win - Parent Window for this dialog.
question - The question String to show.
header - the String to display in the dialog's title bar
Returns:
User's choise.

createComboBoxCellEditor

public static javax.swing.DefaultCellEditor createComboBoxCellEditor(java.lang.String[] values,
                                                                     java.lang.String self,
                                                                     java.lang.String selfPointer,
                                                                     boolean allowSelf,
                                                                     boolean addEmpty)

This method creates a new JComboBox Cell Editor for a JTable element from the given String array. Duplicate entries from given array will be filtered and the array is sorted to alphabetical order.

Parameters:
values - Available options in the JComboBox.
allowSelf - Allow self pointer in the list.
self - The name of the self object.
selfPointer - The name of the pointer used to point the self object.
addEmpty - Create an empty item to the beginning of the list.
Returns:
JComboBox table cell editor as a DefaultCellEditor.