|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JMenuBar
com.ccg.swing.RMenuBar
public class RMenuBar
Not ready for prime time - please ignore for now.
class Example {
public void main(String[] args) {
com.ccg.swing.RMenuBar o = new com.ccg.swing.RMenuBar();
System.out.println(o);
}
}
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JMenuBar |
|---|
JMenuBar.AccessibleJMenuBar |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
(package private) Lookup |
_Lookup
|
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
RMenuBar(ResourceBundle rb)
Initializes object to... |
|
| Method Summary | |
|---|---|
JMenu |
addMainMenu(String id)
One line summary... |
void |
addMenuAction(JMenu addTo,
AbstractAction a,
String id)
One line summary... |
static JMenu |
createMenu(TagLookup tl)
|
static JMenuItem |
createMenuItem(TagLookup tl)
|
Hashtable |
getMenuItemMap()
Allows one to retrieve a "menu item" map for all of the menu actions available throughout the main menu bar. |
JMenu |
getTopMenu(String name)
Locate top level menu by its generic name. |
void |
load(String tag,
Object o)
Builds the menu bar by loading it from the resource file. |
| Methods inherited from class javax.swing.JMenuBar |
|---|
add, addNotify, getAccessibleContext, getComponent, getComponentAtIndex, getComponentIndex, getHelpMenu, getMargin, getMenu, getMenuCount, getSelectionModel, getSubElements, getUI, getUIClassID, isBorderPainted, isSelected, menuSelectionChanged, paintBorder, paramString, processKeyBinding, processKeyEvent, processMouseEvent, removeNotify, setBorderPainted, setHelpMenu, setMargin, setSelected, setSelectionModel, setUI, updateUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
Lookup _Lookup
| Constructor Detail |
|---|
public RMenuBar(ResourceBundle rb)
| Method Detail |
|---|
public JMenu addMainMenu(String id)
arg1 - arg1-describearg2 - arg2-describe
exc - Why thrownpublic static JMenu createMenu(TagLookup tl)
public JMenu getTopMenu(String name)
All graphical components have a "name" value which is not displayed to the user but can be used for internal purposes. This method attempts to lookup a top level menu by its internal name which should remain the same across ALL locales (whereas the text actually displayed to the user may vary based upon locale).
name - Name of the top level menu on the menu bar to locate (NOTE:
this is the NAME of the menu, and not the actual text which
appears on the menu bar).
public void addMenuAction(JMenu addTo,
AbstractAction a,
String id)
arg1 - arg1-describearg2 - arg2-describe
exc - Why thrownpublic static JMenuItem createMenuItem(TagLookup tl)
public Hashtable getMenuItemMap()
Since the main menu bar can be difficult to navigate via code (its dynamically built at run time), it can be very difficult to enable/disable certain menu items depending upon the state of you system. This method allows one to retrieve ANY menu item based upon its generic "name" (as set via the ".name" attribute).
public void load(String tag,
Object o)
This method builds the entire menu-bar and installs callbacks to your object based upon the contents of the resource file. To use this method effectively, you:
This is a powerful way to build menus, and separates the layout and text from the code. Take a look at the following three files (MyClass.java, msgs/MyClass.properties, and msgs/MyClass_en_PL.properties):
import com.ccg.swing.*;
import javax.swing.*;
public class MyClass extends RFrame {
private boolean _Enabled;
public void setShowEnabled(boolean v) { _Enabled = v; }
public boolean isShowEnabled() { return _Enabled; }
private String _Mode;
public void setMode(String v) { _Mode = v; }
public String getMode() { return _Mode; }
public void showState() {
Object args[] = { new Boolean(isShowEnabled()), getMode() };
showMessage("showMsg",args);
}
public void exit() {
System.exit(0);
}
public static void main(String[] args) {
if (args.length == 2) try {
java.util.Locale.setDefault(new java.util.Locale(args[0],args[1]));
} catch (Exception e) { e.printStackTrace(); }
MyClass mc = new MyClass();
// create Menu bar
RMenuBar rb = new RMenuBar(mc.getResourceBundle());
rb.load("rb",mc); // load from resource file
mc.setJMenuBar(rb); // and install in frame
// when using RFrame, you can use the
// following instead of the above
// three lines
// mc.createMenuBar("rb",mc);
mc.pack();
mc.init("main");
mc.show();
}
}
Now, to use the above class, we will create a default language file "msgs/MyClass.properties" with the contents necessary to define the menu-bar and the sub components. The property file will also make use of the "show()", "exit()", "setEnabled()" and "setMode()" methods which our class defines. The resource file looks like:
# # Main title # main.title=RMenuBar Test # # Entries for Menu Bar (a "File", "Properties" and "Help") # Use the "hglue" option on the Help menu to move to right # rb.0=file rb.1=props rb.2=help rb.2.option=hglue # # File menu # file.text=File file.mnemonic=f file.0=show file.1=sep file.2=exit show.text=Show show.mnemonic=s show.type=action show.action=showState sep.type=sep exit.text=Exit exit.mnemonic=x exit.type=action exit.action=exit help.text=Help help.mnemonic=h help.type=action help.action=exit # # Properties menu # props.text=Properties props.mnemonic=p props.0=mode props.1=sep props.2=enable mode.text=Mode mode.mnemonic=m mode.type=sub mode.0=cmode cmode.type=choose cmode.choices=fast normal slow cmode.choose=1 cmode.action=setMode enable.text=Enable enable.mnemonic=e enable.type=bool enable.action=setShowEnabled # # Pop-up dialog box # showMsg.title=Current Values showMsg.type=info showMsg.text=You specified the following:\n\ ShowEnabled:{0}\n\ Mode:{1}
Now, if we want to create a menu bar in a different language, we can overide the text values in the default property file. The following demonstrates this programmers attempt to create a "pig-latin" version of the application (demonstrating this programmer's failure at learning other spoken languages):
# # A "pig-latin" version of the resource file # Save as: msgs/MyClass_en_PL.properties # # To use: java MyClass en PL # main.title=MenuBarRay estTay file.text=ileFay file.mnemonic=i show.text=howSay show.mnemonic=h exit.text=xitEay exit.mnemonic=x props.text=ropertiesPay props.mnemonic=r mode.text=odeMay mode.mnemonic=o cmode.choices=fast normal slow enable.text=nableEay enable.mnemonic=n showMsg.title=urrentCay aluesVay showMsg.text=ouYay pecifiedSay hetay ollowingfay:\n\ howEnabledSay:{0}\n\ odeMay:{1}
tag - The "tag" identifier which is used to specify the initial list
of menu entries on the menu bar (we start looking for "tag.0",
then "tag.1" and so on until we run out - see preceding example).o - The object which has the necessary callback handlers you want
invoked when the user selects something (see the "ID.action"
handlers in the preceding examples).RFrame.createMenuBar(java.lang.String, java.lang.Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||