org.freeshell.zs.common
Class SwingManipulator

java.lang.Object
  extended by org.freeshell.zs.common.SwingManipulator

public class SwingManipulator
extends java.lang.Object

Perform Swing-related operations.


Constructor Summary
SwingManipulator()
           
 
Method Summary
static void addStandardEditingPopupMenu(javax.swing.text.JTextComponent[] fields)
          Add a standard editing popup menu (Cut, Copy, Paste, Select All) to the specified text fields.
static char[] getPasswordJPasswordField(javax.swing.JPasswordField f)
          Wrapper for the getPassword() method of a JPasswordField that always returns a char array.
static java.lang.String getTextJTextField(javax.swing.JTextField f)
          Wrapper for the getText() method of a JTextField that always returns a String.
static void showErrorDialog(java.awt.Component parent, java.lang.String title, java.lang.String message)
          Display a modal error dialog.
static void showInfoDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String message, int rows)
          Display a modal information dialog.
static int showOptionTextDialog(java.awt.Component parentComponent, java.lang.String label, java.lang.String text, int rows, java.lang.String title, int optionType, int messageType, javax.swing.Icon icon, java.lang.Object[] options, int initialValue)
          Convenience method to display a JOptionPane option dialog with a label and text area.
static void showWarningDialog(java.awt.Component parent, java.lang.String title, java.lang.String message)
          Display a modal warning dialog.
static void updateLabel(javax.swing.JLabel label, java.lang.String text)
          Update label.
static void updateProgressBar(javax.swing.JProgressBar progress, java.lang.String text, int percent)
          Update progress bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingManipulator

public SwingManipulator()
Method Detail

addStandardEditingPopupMenu

public static void addStandardEditingPopupMenu(javax.swing.text.JTextComponent[] fields)
Add a standard editing popup menu (Cut, Copy, Paste, Select All) to the specified text fields.

Parameters:
fields - array of JTextField's for which to add the popup menu

getTextJTextField

public static java.lang.String getTextJTextField(javax.swing.JTextField f)
Wrapper for the getText() method of a JTextField that always returns a String.

Parameters:
f - JTextField object on which to call getText()
Returns:
String text in the JTextField

getPasswordJPasswordField

public static char[] getPasswordJPasswordField(javax.swing.JPasswordField f)
Wrapper for the getPassword() method of a JPasswordField that always returns a char array.

Parameters:
f - JPasswordField object on which to call getPassword()
Returns:
char array representing the text in the JPasswordField

updateProgressBar

public static void updateProgressBar(javax.swing.JProgressBar progress,
                                     java.lang.String text,
                                     int percent)
Update progress bar. This method can be called from any thread.

Parameters:
progress - JProgressBar object to be updated
text - Text string to be shown on the progress bar
percent - Percentage of the task completed (if less than 0 or more than 100, then indeterminate mode is used)

updateLabel

public static void updateLabel(javax.swing.JLabel label,
                               java.lang.String text)
Update label. This method can be called from any thread.

Parameters:
label - JLabel object to be updated

showOptionTextDialog

public static int showOptionTextDialog(java.awt.Component parentComponent,
                                       java.lang.String label,
                                       java.lang.String text,
                                       int rows,
                                       java.lang.String title,
                                       int optionType,
                                       int messageType,
                                       javax.swing.Icon icon,
                                       java.lang.Object[] options,
                                       int initialValue)
                                throws java.awt.HeadlessException
Convenience method to display a JOptionPane option dialog with a label and text area.

Parameters:
parentComponent - Frame in which the dialog is to be displayed; if null, or if the parentComponent has no Frame, then a default Frame is used
label - Label String to be displayed
text - Text String to be displayed in the text area
rows - Height of the text area in number of rows
title - Title String for the dialog
optionType - Options available for the dialog: JOptionPane.DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, or OK_CANCEL_OPTION
messageType - Type of message; primarily used to determine the icon from the pluggable Look and Feel: JOptionPane.ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
icon - Icon to be displayed
Object[] - options Array of objects indicating the possible choices the user can make; if the objects are components, they are rendered properly; non-String objects are rendered using their toString methods; if this parameter is null, the options are determined by the Look and Feel
initialValue - Index of the default selection for the dialog; meaningful only if options is used; ignored if negative
Returns:
Index of the option chosen by the user, or JOptionPane.CLOSED_OPTION if the user closed the dialog
Throws:
java.awt.HeadlessException

showErrorDialog

public static void showErrorDialog(java.awt.Component parent,
                                   java.lang.String title,
                                   java.lang.String message)
Display a modal error dialog.

Parameters:
parent - Parent component of this dialog
title - Title of dialog
message - Error message to be displayed

showWarningDialog

public static void showWarningDialog(java.awt.Component parent,
                                     java.lang.String title,
                                     java.lang.String message)
Display a modal warning dialog.

Parameters:
parent - Parent component of this dialog
title - Title of dialog
message - Warning message to be displayed

showInfoDialog

public static void showInfoDialog(java.awt.Component parent,
                                  java.lang.String title,
                                  java.lang.String label,
                                  java.lang.String message,
                                  int rows)
Display a modal information dialog.

Parameters:
parent - Parent component of this dialog
title - Title of dialog
label - Label string to be displayed
message - Information message to be displayed
rows - Height of the text area in number of rows