A
PopupMenu
is the interface to Java's AWT PopupMenu MenuComponent.
Yoix programs normally interact with them by adding event handlers
to the component that owns the popupmenu, and by reading or writing
the following
PopupMenu
fields:
| font |
The
Font,
or font name if it is a
String,
used to draw the text strings in the popupmenu.
Unfortunately Windows seems to ignore all font requests.
| | getEnabled(Object pattern) |
A
Builtin
that finds the first menu item with a command that matches
pattern,
which can be a
String
or
Regexp,
and returns
1
if it is currently enabled (i.e., it will respond when selected by a user),
0
if not, and
-1
if there is no match.
| | getState(Object pattern) |
A
Builtin
that finds the first checkbox menu item with a command that matches
pattern,
which can be a
String
or
Regexp,
and returns
1
if it is currently selected,
0
if not, and
-1
if there is no match.
| | items |
A
Menu
array that completely describes the popupmenu.
| | location |
A
Point
that determines where popupmenu is shown.
Coordinates describe a location in the component that currently owns
the popupmenu in a coordinate system that has its origin at that component's
upper left corner, positive x to the right, positive y down,
and a resolution of 72 dots per inch.
In practice
location
is often set using the
location
that is available in a
MouseEvent.
| | setEnabled(Object pattern, int state) |
A
Builtin
that finds menu items with commands that match
pattern,
which can be a
String
or
Regexp,
and enables them (i.e., they respond when selected by a user) when
state
is non-zero and disables them when
state
is zero.
A return value of
-1
means there were no matches.
| | setState(Object pattern, int state) |
A
Builtin
that finds checkbox menu items with commands that match
pattern,
which can be a
String
or
Regexp,
and selects them when
state
is non-zero and deselects them when
state
is zero.
A return value of
-1
means there were no matches.
| | visible |
A crippled
int
field that only works when you store a non-zero value in
visible.
In other words, you can use this field to show a popupmenu,
but it does not let you hide a popupmenu or determine its current state.
The behavior reflects fundamental limitations of AWT menus,
which means we probably will not be able to improve things.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
A popupmenu can be shown over any component by assigning it to that component's
popup
field.
Only one component can show a popupmenu, so assigning it to a different
component automatically hides the popupmenu if it was being shown over
a different component.
Selecting a regular menu item delivers an
ActionEvent
to the
actionPerformed
event handler defined in the component that currently owns the popupmenu.
Selecting a checkbox menu item delivers an
ItemEvent
to the
itemStateChanged
event handler defined in that same component.
Popup menus are usually shown in response to a
MouseEvent
that has its
popuptrigger
field set to
1.
Unfortunately, the mouse event that serves as a popup trigger
is platform dependent
(e.g., press a button on UNIX and release a button on Windows),
so applications that use popupmenus should check
popuptrigger
in
mousePressed
and
mouseReleased
event handlers.
| |
| Example: |
The program,
import yoix.*.*;
PopupMenu popupmenu = {
Menu items = {
"Line 1", "1",
"Line 2", "2",
"More...", new Menu {
"Line 3", "3",
"Line 4", "4", TRUE,
},
"-", NULL,
"Exit", "exit",
};
};
mouseEventHandler(e) {
if (e.popuptrigger) {
global.popupmenu.location = e.location;
this.popup = global.popupmenu;
}
}
Frame f = {
GridLayout layoutmanager;
Array layout = {
new Label {
String text = "Label 1";
Color background = Color.red;
int alignment = CENTER;
Function mousePressed = mouseEventHandler;
Function mouseReleased = mouseEventHandler;
actionPerformed(e) {
printf("Received: %O\n", e);
if (strcmp(e.command, "exit") == 0)
exit(0);
}
},
new Label {
String text = "Label 2";
Color background = Color.green;
int alignment = CENTER;
Function mousePressed = mouseEventHandler;
Function mouseReleased = mouseEventHandler;
itemStateChanged(e) {
printf("Received: %O\n", e);
}
},
};
};
f.visible = TRUE;
shows how different components can show the same popupmenu,
and how menu selections get back to the
actionPerformed
and
itemStateChanged
event handlers defined in the component that is showing the popupmenu.
| | |
| See Also: |
Button,
Canvas,
Checkbox,
Choice,
Dialog,
FileDialog,
Frame,
Label,
List,
Menu,
MenuBar,
Panel,
ScrollPane,
Scrollbar,
TableColumn,
TableManager,
TextArea,
TextCanvas,
TextField,
TextTerm,
Window
|
|