com.ccg.swing
Class Resources

java.lang.Object
  extended by com.ccg.swing.Resources

public class Resources
extends Object

A standard way to associate resource bundles with classes.

Often when creating GUI components, it is desirable to have the text string and messages which appear to come from a resource bundle. This class helps to facilitate this.

To use this class, you need to follow a certain convention with the design of your objects. The basic convention is if you create a "x.y.Class", there should be a "x.y.msgs.Class" property file to go with it.

For example, lets say you were working on a class called: "com.ccg.swing.Foo" and the source file was located at: "$HOME/com/ccg/swing/Foo.java", the resource file to associate with this class should then exist as: "$HOME/com/ccg/swing/msgs/Foo.properties". You can create different variants of the Foo resources for the languages you want to support (if you understand how resource bundles work).

If you follow this procedure, then the following code fragment could be used to load the resource bundle for your class:

 ResourceBundle rb =
   com.ccg.swing.Resources.getBundle(com.ccg.swing.Foo.class);
 

Since:
1.0
Version:
$Revision: 1.13 $
Author:
$Author: pkb $ #see #getBundle(Class)

Constructor Summary
Resources(Class cl)
          Create a object with a assoicated ResourceBundle.
Resources(Lookup l)
          Create a resource repository using a lookup object.
Resources(ResourceBundle rb)
          Create a object with a assoicated ResourceBundle.
 
Method Summary
 JComponent createButtonGrid(String tag, Object callback)
          Creates an entire "grid" of buttons AND registers callbacks.
static JComponent createButtonGrid(TagLookup tl, Object callback, ImageHolder ih)
          Creates an entire "grid" of buttons AND registers callbacks.
 JDialog createDialog(String tag, JComponent top, Component owner, Object callback)
          Creates a JDialog box from resources.
 JPanel createLabeledFields(String tag, JComponent[] fields)
          Layout a set of components with labels from our resources.
static ResourceBundle getBundle(Class cl)
          Fetch a resource bundle that is associated with the class.
static ResourceBundle getBundle(Class cl, Locale locale)
          Fetch a resource bundle that is associated with the class.
static ResourceBundle getBundle(Class cl, Locale locale, ClassLoader loader)
          Fetch a resource bundle that is associated with the class.
static String getBundleName(Class c)
          Determine the resource bundle name to associate with a class.
 ImageHolder getImageHolder()
          Get the ImageHolder used to fetch image data from.
static int getKeyCode(String s)
          Convert a resource string to a keycode mnemonic.
static Object getObject(ResourceBundle rb, String key, Object def)
          Safely retrieve a Object.
static String getString(ResourceBundle rb, String key, String def)
          Safely retrieve a String.
 String getString(String keyName)
          Fetch a string resource by key value.
 String getString(String keyName, String defValue)
          Fetch a string resource by key value.
static TagLookup getTagLookup(ResourceBundle rb, String tag)
          Get a TagLookup object from your ResourceBundle.
 TagLookup getTagLookup(String tag)
          Get a TagLookup object for a particular resource.
 void setButtonValues(String tag, AbstractButton b)
          Set the properties for a JButton object.
static void setButtonValues(TagLookup tl, AbstractButton b, ImageHolder ih)
          Set the properties for a JButton object.
 void setFrameValues(String tag, JFrame jf)
          Set the common basic properties shared by all JFrames.
static void setFrameValues(TagLookup tl, JFrame jf, ImageHolder ih)
          Set the common basic properties shared by all JFrames.
 void setImageHolder(ImageHolder val)
          Set the ImageHolder used to fetch image data from.
 void setMenuItemValues(String tag, JMenuItem jc)
          Set the common basic properties shared by all JComponents.
static void setMenuItemValues(TagLookup tl, JMenuItem mi, ImageHolder ih)
          Set the common basic properties shared by all JComponents.
 void setValues(String tag, JComponent jc)
          Set the common basic properties shared by all JComponents.
static void setValues(TagLookup tl, JComponent jc)
          Set the common basic properties shared by all JComponents.
 int showConfirmDialog(Component parent, Object contents, String tag, Object[] args, int optionType)
          Present a confirmation dialog to the user and wait for user response.
 String showInputDialog(Component parent, String tag, Object[] args)
          Present a input dialog to the user and wait for user response.
 void showMessage(Component parent, String tag, Object[] args)
          Present a message to the user and wait for them to acknowledge it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resources

public Resources(Lookup l)
Create a resource repository using a lookup object.

Parameters:
l - Standard Lookup object used to retreive resource information from.
Since:
1.0
See Also:
getTagLookup(java.util.ResourceBundle, java.lang.String)

Resources

public Resources(Class cl)
Create a object with a assoicated ResourceBundle.

Use this method to create a resource collection using a standard ResourceBundle which is associated with a specific class.

For example, if your class were: com.ccg.swing.ColorChoices, then you could invoke this method via:

 Resources r = new Resources(com.ccg.swing.ColorChoices.class);
 

NOTE: To use the example shown above, the resource file "com/ccg/swing/msgs/ColorChoices.properties" must exist in the CLASSPATH.

Parameters:
cl - The class which you want to load the resources for - must not be null.
Since:
1.0
See Also:
getBundle(Class)

Resources

public Resources(ResourceBundle rb)
Create a object with a assoicated ResourceBundle.

Use this method to create a resource collection using a standard ResourceBundle from which to pull information from.

This constructor allows one to use ANY resource bundle object.

Parameters:
rb - The resources to use - must not be null.
Since:
1.0
See Also:
getBundle(Class)
Method Detail

getBundle

public static ResourceBundle getBundle(Class cl,
                                       Locale locale,
                                       ClassLoader loader)
Fetch a resource bundle that is associated with the class.

Parameters:
cl - The class you want to retrieve the resources for (must not be null).
locale - The locale you want to retreive the resource bundle for.
loader - The class loader to use to retreive the resources.
Since:
1.0
See Also:
ResourceBundle.getBundle(String,Locale,ClassLoader), getBundleName(java.lang.Class)

getBundle

public static ResourceBundle getBundle(Class cl,
                                       Locale locale)
Fetch a resource bundle that is associated with the class.

Parameters:
cl - The class you want to retrieve the resources for (must not be null).
locale - The locale you want to retreive the resource bundle for.
Since:
1.0
See Also:
ResourceBundle.getBundle(String,Locale), getBundleName(java.lang.Class)

getBundle

public static ResourceBundle getBundle(Class cl)
Fetch a resource bundle that is associated with the class.

Parameters:
cl - The class you want to retrieve the resources for (must not be null).
Since:
1.0
See Also:
ResourceBundle.getBundle(String), getBundleName(java.lang.Class)

getBundleName

public static String getBundleName(Class c)
Determine the resource bundle name to associate with a class.

This method takes a class name and changes it into a string in the form where we expect the resource property files to exist. For example, if you passed this method 'com.ccg.swing.Resources', it will return a string of "com.ccg.swing.msgs.Resources" - you can try this out yourself with the below sample program:


 import com.ccg.swing.*;

 public class T {
 
   static public void main(String args[]) {
     System.out.println(Resources.getBundleName(Resources.class));
   }
 }
 

The ".msgs" prefix was chosen to be consistent with another implementation of this feature.

Parameters:
class - The class you want to fetch the name of the associated resource bundle for (must not be null)
Returns:
The name of the resource bundle that is associated with the class.
Since:
1.0
See Also:
getBundle(Class)

getString

public static String getString(ResourceBundle rb,
                               String key,
                               String def)
Safely retrieve a String.

This method will fetch a string from a resource bundle without throwing an exception. Normally, if you request a string from a resource bundle, you get a MissingResource exception if what you want isn't found. This method catches this exception and returns your default value if what you want isn't found.

Parameters:
rb - The ResourceBundle to fetch the string value from (must not be null).
key - The key of the resource you want to retrieve (must not be null).
def - The default value to return (if resource doesn't have what you want). This can be null if you want.
Returns:
String from resource bundle or your default value
Since:
1.0
See Also:
getObject(java.util.ResourceBundle, java.lang.String, java.lang.Object)

getObject

public static Object getObject(ResourceBundle rb,
                               String key,
                               Object def)
Safely retrieve a Object.

This method will fetch a object from a resource bundle without throwing an exception. Normally, if you request a object from a resource bundle, you get a MissingResource exception if what you want isn't found. This method catches this exception and returns your default value if what you want isn't found.

Parameters:
rb - The ResourceBundle to fetch the object value from (must not be null).
key - The key of the resource you want to retrieve (must not be null).
def - The default value to return (if resource doesn't have what you want). This can be null if you want.
Returns:
Object from resource bundle or your default value
Since:
1.0
See Also:
getObject(java.util.ResourceBundle, java.lang.String, java.lang.Object)

getTagLookup

public static TagLookup getTagLookup(ResourceBundle rb,
                                     String tag)
Get a TagLookup object from your ResourceBundle.

It can often be easier to work with a TagLookup object instead of a ResourceBundle. The main advantages include:

Parameters:
rb - The underlying ResourceBundle you want to retrieve your values from.
tag - The "tag" identifier you would like to prefixed each "key" value you specify with (you can pass null if a prefix doesn't help you).
Returns:
A handy-dandy TagLookup object.
Since:
1.0
See Also:
TagLookup

setValues

public static void setValues(TagLookup tl,
                             JComponent jc)
Set the common basic properties shared by all JComponents.

This method will search the TagLookup object specified (probably created from the getTagLookup method) for the "tagged" properties and then set the components properties. The following properties are recognized:

TAG.name=TEXT
This is the generic name for the component which the application might want access to find the component. This information is not shown to the user (it provides a way to allow the application to locate a GUI component). This is optional.
TAG.background=COLOR
The background color for the component.
TAG.foreground=COLOR
The foreground color for the component.
TAG.font=FONT
The font to use for the component
TAG.tooltip=TEXT
The tool tip to be associated with the component.
TAG.enabled=true|false
Whether the component should be enabled or disable initially (if omitted, we default to true - to create a enabled button).

Parameters:
tl - The TagLookup object to use for fetching values.
jc - The JComponent to be affected.
Since:
1.0
See Also:
getTagLookup(java.util.ResourceBundle, java.lang.String)

setValues

public void setValues(String tag,
                      JComponent jc)
Set the common basic properties shared by all JComponents.

This method will apply various properties to a JComponent which are identified with a particular TAG in the corresponding set of resources.. The following properties are recognized:

TAG.background=COLOR
The background color for the component.
TAG.foreground=COLOR
The foreground color for the component.
TAG.font=FONT
The font to use for the component
TAG.tooltip=TEXT
The tool tip to be associated with the component.

Parameters:
tag - The TAG identifier for the component to be updated (used to retrieve values mentioned above). null is OK if no TAG is used in the resource file.
jc - The JComponent to be affected.
Since:
1.0

setMenuItemValues

public static void setMenuItemValues(TagLookup tl,
                                     JMenuItem mi,
                                     ImageHolder ih)
Set the common basic properties shared by all JComponents.

This method will search the TagLookup object specified (probably created from the getTagLookup method) for the "tagged" properties and then set the components properties. The following properties are recognized:

TAG.name=TEXT
This is the generic name for the component which the application might want access to find the component. This information is not shown to the user (it provides a way to allow the application to locate a GUI component). This is optional.
TAG.text=TEXT
The text to appear on the button.
TAG.mnemonic=KEY
The shortcut MNEMONIC for the button (this isn't supported yet, but will be).
TAG.icon=NAME
The icon image for the normal state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder).
TAG.background=COLOR
The background color for the component.
TAG.foreground=COLOR
The foreground color for the component.
TAG.font=FONT
The font to use for the component
TAG.tooltip=TEXT
The tool tip to be associated with the component.
TAG.enabled=true|false
Whether the component should be enabled or disable initially (if omitted, we default to true - to create a enabled button).

Parameters:
tl - The TagLookup object to use for fetching values.
jc - The JComponent to be affected.
Since:
1.0
See Also:
getTagLookup(java.util.ResourceBundle, java.lang.String)

setMenuItemValues

public void setMenuItemValues(String tag,
                              JMenuItem jc)
Set the common basic properties shared by all JComponents.

This method will apply various properties to a JMenuItem object which are identified with a particular TAG in the corresponding set of resources. The following properties are recognized:

TAG.name=TEXT
This is the generic name for the component which the application might want access to find the component. This information is not shown to the user (it provides a way to allow the application to locate a GUI component). This is optional.
TAG.text=TEXT
The text to appear on the button.
TAG.mnemonic=KEY
The shortcut MNEMONIC for the button (this isn't supported yet, but will be).
TAG.icon=NAME
The icon image for the normal state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder).
TAG.background=COLOR
The background color for the component.
TAG.foreground=COLOR
The foreground color for the component.
TAG.font=FONT
The font to use for the component
TAG.tooltip=TEXT
The tool tip to be associated with the component.
TAG.enabled=true|false
Whether the component should be enabled or disable initially (if omitted, we default to true - to create a enabled button).

Parameters:
tag - The TAG identifier for the component to be updated (used to retrieve values mentioned above). null is OK if no TAG is used in the resource file.
jc - The JComponent to be affected.
Since:
1.0

setFrameValues

public static void setFrameValues(TagLookup tl,
                                  JFrame jf,
                                  ImageHolder ih)
Set the common basic properties shared by all JFrames.

This method will search the TagLookup object specified (probably created from the getTagLookup method) for the "tagged" properties and then set the components properties. The following properties are recognized:

TAG.background=COLOR
The background color for the component. NOTE: The content pane typically wipes this out, so I'd recommend NOT specifying it (you may get flashy frames otherwise).
TAG.foreground=COLOR
The foreground color for the component.
TAG.font=FONT
The font to use for the component
TAG.title=TEXT
The title to use for the frame.
TAG.icon=NAME
The name of the image icon to be used when the frame is minimized (not currently implemented).
TAG.width=VAL
The preferred width (in pixels) for the frame.
TAG.height=VAL
The preferred height (in pixels) for the frame.
TAG.resizable=true|false
Allow the user to resize the frame. NOTE: If set to true, the frame's size can't be adjusted (make sure you "pack" your frame prior to invoking this method).

NOTE: Both width/height must be specified for either of them to be applied.

Parameters:
tl - The TagLookup object to use for fetching values.
jf - The JFrame to be affected.
ih - This is optional, if you pass a non-null value here, we will try and look for the image icons specified.
Since:
1.0
See Also:
getTagLookup(java.util.ResourceBundle, java.lang.String)

setFrameValues

public void setFrameValues(String tag,
                           JFrame jf)
Set the common basic properties shared by all JFrames.

This method will set certain properties for a JFrame object. The following properties are recognized:

TAG.background=COLOR
The background color for the component. NOTE: The content pane typically wipes this out, so I'd recommend NOT specifying it (you may get flashy frames otherwise).
TAG.foreground=COLOR
The foreground color for the component.
TAG.font=FONT
The font to use for the component
TAG.title=TEXT
The title to use for the frame.
TAG.icon=NAME
The name of the image icon to be used when the frame is minimized (not currently implemented).
TAG.resizable=true|false
Allow the user to resize the frame. NOTE: If set to true, the frame's size can't be adjusted (make sure you "pack" your frame prior to invoking this method).

Parameters:
tag - The TAG identifier for the frame (used to retrieve values mentioned above). null is OK if no TAG is used in the resource file.
jf - The JFrame to be affected.
Since:
1.0

setButtonValues

public static void setButtonValues(TagLookup tl,
                                   AbstractButton b,
                                   ImageHolder ih)
Set the properties for a JButton object.

This method will search the TagLookup object specified (probably created from the getTagLookup method) for the "tagged" properties and then set the buttons properties. The following properties are recognized:

General Values
All of the values recognized by setValues(com.ccg.util.TagLookup, javax.swing.JComponent) may be specified (like colors, fonts, etc).
TAG.text=TEXT
The text to appear on the button.
TAG.mnemonic=KEY
The shortcut MNEMONIC for the button (this isn't supported yet, but will be).
TAG.icon=NAME
The icon image for the normal state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.
TAG.pressed=NAME
The icon image for the pressed state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.
TAG.rollover=NAME
The icon image for the rollover state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.
TAG.selected=NAME
The icon image for the selected state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.

Parameters:
tl - The TagLookup object to use for fetching values.
jc - The JComponent to be affected.
ih - This is optional, if you pass a non-null value here, we will try and look for the image icons specified.
Since:
1.0
See Also:
getTagLookup(java.util.ResourceBundle, java.lang.String)

setButtonValues

public void setButtonValues(String tag,
                            AbstractButton b)
Set the properties for a JButton object.

This method will search the TagLookup object specified (probably created from the getTagLookup method) for the "tagged" properties and then set the buttons properties. The following properties are recognized:

General Values
All of the values recognized by setValues(com.ccg.util.TagLookup, javax.swing.JComponent) may be specified (like colors, fonts, etc).
TAG.text=TEXT
The text to appear on the button.
TAG.mnemonic=KEY
The shortcut MNEMONIC for the button (this isn't supported yet, but will be).
TAG.icon=NAME
The icon image for the normal state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.
TAG.pressed=NAME
The icon image for the pressed state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.
TAG.rollover=NAME
The icon image for the rollover state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.
TAG.selected=NAME
The icon image for the selected state (not supported yet - the "NAME" is used to retrieve it from the associated ImageHolder.

Parameters:
tag - The "TAG" which identifies the button in the assoiciated resource properties.
jc - The button to be affected.
Since:
1.0

createButtonGrid

public static JComponent createButtonGrid(TagLookup tl,
                                          Object callback,
                                          ImageHolder ih)
Creates an entire "grid" of buttons AND registers callbacks.

This method will build an entire grid of buttons from a resource file and install the necessary callbacks so that the buttons will invoke various methods on your object. See the MyClass.java and msgs/MyClass.properties for a working example of how to do this.

Basically, it boils down to:

Parameters:
tl - Where to look for the definitions that define the button grid and the buttons which populate it.
callback - The object which has the methods the buttons are allowed to invoke when pressed (see ActionCallback.create(com.ccg.util.Lookup, javax.swing.AbstractButton, java.lang.Object) for more details - or check out the example mentioned above).
ih - A ImageHolder to retrieve icon images for the buttons (when this becomes supported).
Returns:
A new component which has all of the created buttons installed.
Since:
1.0
See Also:
setButtonValues(com.ccg.util.TagLookup, javax.swing.AbstractButton, com.ccg.awt.ImageHolder)

createButtonGrid

public JComponent createButtonGrid(String tag,
                                   Object callback)
Creates an entire "grid" of buttons AND registers callbacks.

This method will build an entire grid of buttons from a resource file and install the necessary callbacks so that the buttons will invoke various methods on your object. See the MyClass.java and msgs/MyClass.properties for a working example of how to do this.

Basically, it boils down to:

Parameters:
tag - The "TAG" which identifies the button in the associated resource properties.
callback - The object which has the methods the buttons are allowed to invoke when pressed (see ActionCallback.create(com.ccg.util.Lookup, javax.swing.AbstractButton, java.lang.Object) for more details - or check out the example mentioned above).
Returns:
A new component which has all of the created buttons installed.
Since:
1.0
See Also:
setButtonValues(String,AbstractButton)

getKeyCode

public static int getKeyCode(String s)
Convert a resource string to a keycode mnemonic.

Some components allow one to assign a keyboard "mnemonic", this method is used to convert the string values (which might appear in a resource file) into their respective mnemonic value).

Parameters:
s - String to convert into a key code mnemonic
Returns:
integer value of the mnemonic key code, or -1 if unable to determine.
Since:
1.0

getTagLookup

public TagLookup getTagLookup(String tag)
Get a TagLookup object for a particular resource.

Parameters:
tag - The "tag" prefix to use when fetching information (or null if you don't want a tag prefix).
Returns:
A nice TagLookup object which you can use to retrieve information with.
Since:
1.0

setImageHolder

public void setImageHolder(ImageHolder val)
Set the ImageHolder used to fetch image data from.

Parameters:
val - New ImageHolder value to assign.
See Also:
getImageHolder()

getImageHolder

public ImageHolder getImageHolder()
Get the ImageHolder used to fetch image data from.

Returns:
Current ImageHolder value assigned - never returns null.
See Also:
setImageHolder(com.ccg.awt.ImageHolder)

createLabeledFields

public JPanel createLabeledFields(String tag,
                                  JComponent[] fields)
Layout a set of components with labels from our resources.

This method provides a handy means to label components using a resource bundle. This implementation places the labels to the left of the fields. The labels and other decorations are pulled from the resources associated with this object (by applying a "tag" to the name). It supports the following:

The following shows a section of a resource bundle that has be "tagged" with "po" that could be used with this method:

po.title=Pizza Order Properties
po.width=7
po.0.label=Name:
po.0.tooltip=Enter you name here
po.1.label=Hungry?:
po.1.tooltip=Are you hungry or not?
po.2.label=Pizza Fetch:
po.2.tooltip=Press here to go order your pizza
# DEPRECATED form of specifying labels
# po.labels=Name:,Hungry?:,Pizza Fetch:
 

The following demonstrates how this method could be used to then label and layout a set of fields:



private JTextField _Text;
private JCheckBox _Choice;
private JButton _Button;
private JComponent _All;

public Component getComponent(Resources r) {
  if (_All == null) {
    JComponent[] fields = {
      _Text = new JTextField("Frankie"),
      _Choice = new JCheckBox(),
      _Button = new JButton("Order")
    };
    _All = r.createLabeledFields("po",fields);
  }
  return _All;
}

 

Parameters:
tag - The TAG ID which will be used to look for text strings that we use to create the panel.
fields - Array of components corresponding to the labels (you can pass null, have null entries in your array, of not match the length of your labels - we'll deal with it as best we can).
Returns:
A panel with your labels and fields installed.
Since:
1.0
See Also:
LayoutUtils

getString

public String getString(String keyName)
Fetch a string resource by key value.

This method looks up the value of a string resource using a key name. If the resource isn't found, null is returned.

Parameters:
key - The "key" used to lookup the resource with - must not be null.
Returns:
The string value associated with the key, or null if not found.
Since:
1.0
See Also:
getString(String,String)

getString

public String getString(String keyName,
                        String defValue)
Fetch a string resource by key value.

This method looks up the value of a string resource using a key name. If the resource isn't found, the default value (which you pass) is returned.

Parameters:
key - The "key" used to lookup the resource with - must not be null.
default_val - The default value to return if resource wasn't found.
Returns:
The string value associated with the key, or the default value you passed if it wasn't found.
Since:
1.0
See Also:
getString(String,String)

createDialog

public JDialog createDialog(String tag,
                            JComponent top,
                            Component owner,
                            Object callback)
Creates a JDialog box from resources.

This method will build a JDialog box for you. It does so in the following manner:

Parameters:
tag - The "TAG" which identifies the button in the associated resource properties.
top - You component to add to the center of the dialog box created - if you pass null, it isn't added.
parent - The component which is the "owner" or "parent" of this object. We will search up its parent chain for a frame or dialog object to which it belongs to (or is).
callback - The object which has the methods the buttons are allowed to invoke when pressed (see ActionCallback.create(com.ccg.util.Lookup, javax.swing.AbstractButton, java.lang.Object) for more details - or check out the example mentioned above).
Returns:
A new JDialog box - (packed, but not yet shown)
Since:
1.0
See Also:
createButtonGrid(String,Object)

showConfirmDialog

public int showConfirmDialog(Component parent,
                             Object contents,
                             String tag,
                             Object[] args,
                             int optionType)
Present a confirmation dialog to the user and wait for user response.

This method is a wrapper around the showConfirmDialog method in the JOptionPane class. This method allows one to "localize" the message which is displayed to construct the dialog.

This method uses the TAG to select properties from the resource bundle. The following are recognized:

TAG.title=TEXT
Text to display on the title line of the frame that pops up.
TAG.text=TEXT
If you will just be displaying a text message (information or question), then you will probably want the message to come from the resource bundle. Use the "TAG.text" property to accomplish this. You MUST pass null for the 'message' parameter to accomplish this.

Assume the following set of properties:

quit.title=Really Quit? quit.text=The time is {0} are you sure you want to quit?

The following code fragment could be used to display a popup confirmation:


 void actionPerformed(ActionEvent ae) {
   if (ae.getSource() instanceof Component) {
     Resources r = getResources();
                                // subsitute for {0} in resource strings
     Object[] args = { new java.util.Date() };
     int rc = 
     r.showConfirmDialog((Component) ae.getSource(),null,"quit",args,
                             JOptionPane.YES_NO_OPTION);

         if (rc == JOptionPane.YES_OPTION) System.exit(0);
   }
 }
 

Parameters:
parent - Parent component for the dialog (see JOptionPane).
message - The contents to be placed in the dialog area that appears. This can be MANY different things (such as a simple String, a full JPanel, etc) - see JOptionPane for more details). It is legal to pass null - in which case we will lookup the "TAG.text" string from the resource and use that value.
tag - The "tag" used to lookup settings
args - Optional set of arguments to be subsituted (using standard MessageFormat rules) into strings retrieved from the resource. You can pass null if you don't need subsitution.
optionType - Specifiews what type of question you want to ask (OK/Cancel, Yes/No/Cancel, etc). See JOptionPane for more details. You will probably pass JOptionPane.OK_CANCEL_OPTION - but you can use any of them.
Returns:
Integer return code as defined by the JOptionPane class (indicating what option the user selected).
Since:
1.0
See Also:
JOptionPane

showInputDialog

public String showInputDialog(Component parent,
                              String tag,
                              Object[] args)
Present a input dialog to the user and wait for user response.

This method is a wrapper around the showInputDialog method in the JOptionPane class. This method allows one to "localize" the message which is displayed to construct the dialog.

This method uses the TAG to select properties from the resource bundle. The following are recognized:

TAG.title=TEXT
Text to display on the title line of the frame that pops up.
TAG.text=TEXT
This is the informational message that will be displayed within the dialog box indicating what you want the user to enter. This MUST be specified in the resource bundle.
TAG.init=TEXT
This is the default value to initialize the selection with (this is optional - you don't have to specify it).

Assume the following set of properties:

name.title=Name Input name.text=Please enter/edit your full name below: name.init={0}

The following code fragment could be used to prompt the user for their name:


 Resources r = getResources();
                                // subsitute for {0} in resource strings
 Object[] args = { "Mek Blankenbaker" };
 String val =
   r.showConfirmDialog(_MyComponent,"name",args);

 if (val == null) System.out.println("User canceled");
 else System.out.println("User name:"+val);
 

Parameters:
parent - Parent component for the dialog (see JOptionPane).
tag - The "tag" used to lookup settings
args - Optional set of arguments to be subsituted (using standard MessageFormat rules) into strings retrieved from the resource. You can pass null if you don't need subsitution - but this is the only way to insert values from your code into the message formed.
Returns:
String value user entered in the input field (if accepted), or null if user canceled.
Since:
1.0
See Also:
JOptionPane

showMessage

public void showMessage(Component parent,
                        String tag,
                        Object[] args)
Present a message to the user and wait for them to acknowledge it.

This method is a wrapper around the showInputDialog method in the JOptionPane class. This method allows one to "localize" the message which is displayed to construct the dialog.

This method uses the TAG to select properties from the resource bundle. The following are recognized:

TAG.title=TEXT
Text to display on the title line of the frame that pops up.
TAG.text=TEXT
This is the informational message that will be displayed within the dialog box indicating what you want the user to enter. This MUST be specified in the resource bundle.
TAG.type=i|w|e|q|p
The type of message to be displayed (we don't care about case and only look at the first character - hence "ERROR" is treated same as 'e'). Values are mapped as follows: i=JOptionPane.INFORMATION_MESSAGE, w=JOptionPane.WARNING_MESSAGE, e=JOptionPane.ERROR_MESSAGE, q=JOptionPane.QUESTION_MESSAGE, p=JOptionPane.PLAIN_MESSAGE. If omitted we default to "i".

Assume the following set of properties:

E100.title=Bad {0} E100.text=The "{1}" error occurred for {0} at {2}. E100.type=error

The following code fragment could be used to prompt the user for their name:


 public void evaluate(String name) {
   try {
     process(name);
   } catch (Exception e) {
     Resources r = getResources();
                                // set subsitution args
     Object[] args = { "Frank", e.getMessage(), new java.util.Date() };
     r.showMessage(_MyComponent,"E100",args);
   }
 }
 

Parameters:
parent - Parent component for the dialog (see JOptionPane).
tag - The "tag" used to lookup settings
args - Optional set of arguments to be subsituted (using standard MessageFormat rules) into strings retrieved from the resource. You can pass null if you don't need subsitution - but this is the only way to insert values from your code into the message formed.
Since:
1.0
See Also:
JOptionPane


Copyright 1998-1998-2006 null. All Rights Reserved.