com.ccg.swing
Class RMenuBar

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JMenuBar
                  extended by com.ccg.swing.RMenuBar
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, MenuElement

public class RMenuBar
extends JMenuBar

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);
   }
 }
 

Since:
1.0
Version:
$Revision: 1.6 $
Author:
$Author: pkb $ #see [class][#method]|Text
See Also:
Serialized Form

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 javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_Lookup

Lookup _Lookup
Constructor Detail

RMenuBar

public RMenuBar(ResourceBundle rb)
Initializes object to... It performs the following tasks:

Since:
1.0 #see [class][#meth]|Text
Method Detail

addMainMenu

public JMenu addMainMenu(String id)
One line summary... Describe...

Parameters:
arg1 - arg1-describe
arg2 - arg2-describe
Returns:
null if you passed a null ID or no text string was found for the menu in the resource bundle.
Throws:
exc - Why thrown
Since:
1.0 #see [class][#meth]|Text

createMenu

public static JMenu createMenu(TagLookup tl)

getTopMenu

public JMenu getTopMenu(String name)
Locate top level menu by its generic 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).

Parameters:
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).
Returns:
Top level menu with specified name - or null if doesn't exist.
Since:
1.0

addMenuAction

public void addMenuAction(JMenu addTo,
                          AbstractAction a,
                          String id)
One line summary... Describe...

Parameters:
arg1 - arg1-describe
arg2 - arg2-describe
Throws:
exc - Why thrown
Since:
1.0 #see [class][#meth]|Text

createMenuItem

public static JMenuItem createMenuItem(TagLookup tl)

getMenuItemMap

public Hashtable getMenuItemMap()
Allows one to retrieve a "menu item" map for all of the menu actions available throughout the main menu bar.

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).

Returns:
Newly created Hashtable of ("name",JMenuItem) pairs for each "name"d menu item.
Since:
1.0

load

public void load(String tag,
                 Object o)
Builds the menu bar by loading it from the resource file.

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=fastnormalslow
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=fastnormalslow

enable.text=nableEay
enable.mnemonic=n

showMsg.title=urrentCay aluesVay
showMsg.text=ouYay pecifiedSay hetay ollowingfay:\n\
howEnabledSay:{0}\n\
odeMay:{1}
 

Parameters:
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).
Since:
1.0
See Also:
RFrame.createMenuBar(java.lang.String, java.lang.Object)


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