|
|||||||||
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.
Field Summary | |
---|---|
int |
SHIFT
|
Constructor Summary | |
---|---|
ProgramMenuBar(Program owner)
ProgramMenuBar . |
Method Summary | |
---|---|
JMenuItem |
createFocusedItem(String action)
|
JMenuItem |
createFocusedItem(String action,
int key)
|
JMenuItem |
createProgramItem(String action)
|
JMenuItem |
createProgramItem(String action,
int key)
|
JMenuItem |
createStandardItem(String action)
ProgramMenuBar class. |
boolean |
fireAccelerator(KeyEvent e)
|
void |
fireActionListeners(ActionEvent e)
|
boolean |
getMacMenuBarFlag()
|
Program |
getProgram()
Program object associated with this menu. |
void |
install(Component comp)
JFrame or Program
object enclosing the component comp . |
boolean |
isFocusedItem(JMenuItem item)
true if the item is a focused item. |
Iterator<JMenuItem> |
iterator()
|
void |
setAccelerator(JMenuItem item,
int key)
|
void |
setEnabled(String action,
boolean flag)
|
void |
setFocusedListener(ActionListener listener)
|
void |
setMacMenuBarFlag(boolean flag)
|
Field Detail |
---|
public static final int SHIFT
Constructor Detail |
---|
public ProgramMenuBar(Program owner)
ProgramMenuBar
.
Usage: | ProgramMenuBar mbar = new ProgramMenuBar(owner); | ||
Parameter: |
|
Method Detail |
---|
public JMenuItem createFocusedItem(String action)
Usage: | JMenuItem item = createFocusedItem(action); | ||
Parameter: |
|
public JMenuItem createFocusedItem(String action,
int key)
Usage: | JMenuItem item = createFocusedItem(action, key); | ||||
Parameters: |
|
public JMenuItem createProgramItem(String action)
setName
on the item.
Usage: | JMenuItem item = createProgramItem(action); | ||
Parameter: |
|
public JMenuItem createProgramItem(String action,
int key)
Usage: | JMenuItem item = createProgramItem(action, key); | ||||
Parameters: |
|
public JMenuItem createStandardItem(String action)
ProgramMenuBar
class. The menu item is identified
by its action command.
Usage: | JMenuItem item = mbar.createStandardItem(action); | ||
Parameter: |
|
public boolean fireAccelerator(KeyEvent e)
true
if such an accelerator exists.
public void fireActionListeners(ActionEvent e)
public boolean getMacMenuBarFlag()
Usage: | boolean flag = getMacMenuBarFlag(); |
Returns: | true if Mac menu style is supported; false otherwise
|
public Program getProgram()
Program
object associated with this menu.
Usage: | Program program = mbar.getProgram(); |
Returns: | The program associated with this menu bar |
public void install(Component comp)
JFrame
or Program
object enclosing the component comp
.
Usage: | mbar.install(comp); | ||
Parameter: |
|
public boolean isFocusedItem(JMenuItem item)
true
if the item is a focused item.
Usage: | if (mbar.isFocusedItem(item)) . . . | ||
Parameter: |
| ||
Returns: | true if the item is a program item
|
public Iterator<JMenuItem> iterator()
Usage: | Iterator |
iterator
in interface Iterable<JMenuItem>
public void setAccelerator(JMenuItem item,
int key)
Usage: | mbar.setAccelerator(item, key); | ||||
Parameters: |
|
public void setEnabled(String action,
boolean flag)
Usage: | mbar.setEnabled(action, flag); | ||||
Parameters: |
|
public void setFocusedListener(ActionListener listener)
null
when it loses it.
Usage: | setFocusedListener(listener); | ||
Parameter: |
|
public 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.
Usage: | setMacMenuBarFlag(flag); | ||
Parameter: |
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |