Java Reference
In-Depth Information
action.home: home();
action.home.label: Home
action.home.description: Go to home page
action.oreilly: displayPage("http://www.oreilly.com");
action.oreilly.label: O'Reilly
action.oreilly.description: O'Reilly & Associates home page
These properties describe two actions, one named by the key “action.home” and
the other by “action.oreilly”.
Example 10•24: CommandParser.java
package com.davidflanagan.examples.gui;
import com.davidflanagan.examples.reflect.Command;
/**
* This class parses a Command object from a GUIResourceBundle. It uses
* the Command.parse() method to perform all the actual parsing work.
**/
public class CommandParser implements ResourceParser {
static final Class[] supportedTypes = new Class[] { Command.class };
public Class[] getResourceTypes() { return supportedTypes;}
public Object parse(GUIResourceBundle bundle, String key, Class type)
throws java.util.MissingResourceException, java.io.IOException
{
String value = bundle.getString(key); // look up the command text
return Command.parse(bundle.getRoot(), value); // parse it!
}
}
Example 10•25: ActionParser.java
package com.davidflanagan.examples.gui;
import com.davidflanagan.examples.reflect.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
/**
* This class parses an Action object from a GUIResourceBundle.
* The specified key is used to look up the Command string for the action.
* The key is also used as a prefix for other resource names that specify
* other attributes (such as the label and icon) associated with the Action.
* An action named "zoomOut" might be specified like this:
*
*
zoomOut: zoom(0.5);
*
zoomOut.label: Zoom Out
*
zoomOut.description: Zoom out by a factor of 2
*
* Because Action objects are often reused by an application (for example
* in a toolbar and a menu system, this ResourceParser caches the Action
* objects it returns. By sharing Action objects, you can disable and enable
* an action and that change will affect the entire GUI.
**/
public class ActionParser implements ResourceParser {
static final Class[] supportedTypes = new Class[] { Action.class };
public Class[] getResourceTypes() { return supportedTypes; }
HashMap bundleToCacheMap = new HashMap();
Search WWH ::




Custom Search