|
|||||||||
| 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
acm.program.ProgramMenuBar
public class ProgramMenuBar
This class standardizes the menu bars used in the ACM program package. The fundamental principles behind the design of this package are:
These goals turn out to be difficult to achieve simultaneously. In
particular, supporting both Macintosh-style and Windows-style menu bars
requires creating a parallel MenuBar structure behind the
underlying JMenuBar, which accounts for much of the complexity
in this implementation.
Using the ProgramMenuBar class
The ProgramMenuBar class supports two distinct disciplines
for listening for menu actions:
createFocusedItem.
Activating a focused item passes an action event to the listener set by calling
setFocusedListener,
which should be called whenever a component interested in responding to menu
actions gains the keyboard focus.
createProgramItem.
Activating a program item passes an action event to the menuAction
method in the Program object that created the menu bar.
| 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 | |
|---|---|
static int |
SHIFT
Constant indicating that an accelerator key requires the SHIFT modifier. |
| 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 | |
|---|---|
ProgramMenuBar(Program owner)
Creates an empty ProgramMenuBar. |
|
| Method Summary | |
|---|---|
protected void |
addEditMenu()
Installs the Edit menu. |
protected void |
addEditMenuItems(JMenu menu)
Adds the standard Edit items to the specified menu. |
protected void |
addFileMenu()
Installs the File menu. |
protected void |
addFileMenuItems(JMenu menu)
Adds the standard File items to the specified menu. |
protected void |
addMenus()
Adds menus to the menu bar. |
JMenuItem |
createFocusedItem(String action)
Creates a focused menu item with the specified action command. |
JMenuItem |
createFocusedItem(String action,
int key)
Creates a focused menu item with the specified action command and accelerator key. |
JMenuItem |
createProgramItem(String action)
Creates a program menu item with the specified action command. |
JMenuItem |
createProgramItem(String action,
int key)
Creates a program menu item with the specified action command and accelerator key. |
JMenuItem |
createStandardItem(String action)
Creates one of the standard menu items implemented by the ProgramMenuBar class. |
boolean |
fireAccelerator(KeyEvent e)
Triggers the accelerator associated with the keystroke implied by the key event. |
void |
fireActionListeners(ActionEvent e)
Fires the action listeners responsible for handling the specified event. |
boolean |
getMacMenuBarFlag()
Retrieves the setting of the Mac menu bar flag. |
Program |
getProgram()
Returns the Program object associated with this menu. |
void |
install(Component comp)
Installs the menu bar in the JFrame or Program
object enclosing the component comp. |
boolean |
isFocusedItem(JMenuItem item)
Returns true if the item is a focused item. |
Iterator<JMenuItem> |
iterator()
Returns an iterator that enumerates the individual menu items under the control of the menu bar. |
void |
setAccelerator(JMenuItem item,
int key)
Sets the accelerator for the item as appropriate to the operating system conventions. |
void |
setEnabled(String action,
boolean flag)
Enables or disables any menu items that generate the specified action command. |
void |
setFocusedListener(ActionListener listener)
Registers a listener that responds while the caller holds the keyboard focus. |
void |
setMacMenuBarFlag(boolean flag)
Sets a flag indicating whether applications running on the Macintosh should use standard Mac menus. |
| 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 |
|---|
public static final int SHIFT
| Constructor Detail |
|---|
public ProgramMenuBar(Program owner)
ProgramMenuBar.
owner - The Program that owns this menu bar.| Method Detail |
|---|
protected void addEditMenu()
Edit menu.
protected void addEditMenuItems(JMenu menu)
Edit items to the specified menu. Subclasses
can override this method to change the list of items.
menu - The menu to which the Edit items are addedprotected void addFileMenu()
File menu.
protected void addFileMenuItems(JMenu menu)
File items to the specified menu. Subclasses
can override this method to change the list of items.
menu - The menu to which the File items are addedprotected void addMenus()
File and Edit
menus should override this method with one that adds the desired menus.
public JMenuItem createFocusedItem(String action)
action - The action command generated by this menu item
public JMenuItem createFocusedItem(String action,
int key)
action - The action command generated by this menu itemkey - The integer value of the keystroke acceleratorpublic JMenuItem createProgramItem(String action)
setName on the item.
action - The action command generated by this menu item
public JMenuItem createProgramItem(String action,
int key)
action - The action command generated by this menu itemkey - The integer value of the keystroke acceleratorpublic JMenuItem createStandardItem(String action)
ProgramMenuBar class. The menu item is identified
by its action command.
action - The action command identifying the menu item to be createdpublic boolean fireAccelerator(KeyEvent e)
true if such an accelerator exists.
public void fireActionListeners(ActionEvent e)
public boolean getMacMenuBarFlag()
true if Mac menu style is supported; false otherwisepublic Program getProgram()
Program object associated with this menu.
public void install(Component comp)
JFrame or Program
object enclosing the component comp.
comp - A descendant of the frame in which the menu is to be installedpublic boolean isFocusedItem(JMenuItem item)
true if the item is a focused item.
item - A menu item installed in the menu bar
true if the item is a program itempublic Iterator<JMenuItem> iterator()
iterator in interface Iterable<JMenuItem>
public void setAccelerator(JMenuItem item,
int key)
item - The menu item triggered by this acceleratorkey - The integer value of the keystroke accelerator
public void setEnabled(String action,
boolean flag)
action - The action command triggered by the menu itemflag - true to enable the item, false to disable itpublic void setFocusedListener(ActionListener listener)
null when it loses it.
listener - An ActionListener that responds to focused itemspublic void setMacMenuBarFlag(boolean flag)
true.
Setting this value to false means that Mac programs
use the same in-window JMenuBar approach used on other
platforms.
flag - true to use Mac menu style; false otherwise
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||