AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
JPopupMenu typedict
 
A JPopupMenu is the interface to the Java Swing JPopupMenu 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 JPopupMenu fields:
autotrim An int that is 1 when white space is automatically trimmed from both ends of every string read from or written to the text field, and 0 otherwise.
background The Color that is used to paint the background of the popupmenu. It is also the default background color assigned to components in the items array that do not pick their own. The default value is NULL, which means use the background color of the component owns the popupmenu. Reading returns a snapshot of the current color. Writing immediately sets the popupmenu's background, and the background of components contained in the popupmenu that do not pick their own, to the new color.
border An Object that should be a Border, Insets, Number, or String that describes the border that is drawn around this popupmenu. A NULL value, which is the default, means no border. A border that is an Insets or Number is an easy way to describe margins (i.e., an EmptyBorder), in units of 72 dots per inch, that are left around the sides of this popupmenu. A border that is a String is a quick way to surround this popupmenu with a border that uses the String as its title. Reading returns a snapshot of the current border. Writing immediately sets the popupmenu's border to the new value.
components A Dictionary maintained by the interpreter that maps tag fields to actual menu components; every menu component contained in the popupmenu has an entry in the dictionary.
cursor An Object that should be an int, Image, or String that selects the cursor shown when the pointer is over the popupmenu. A cursor that is an int should be one of the cursors defined in the yoix.awt.Cursor dictionary. A cursor that is an Image can describe the cursor using its size and hotspot fields and often draws it using its paint function. A cursor that is a String should be the name of a cursor that is already defined in yoix.awt.Cursor or the name a local a file or URL that contains a GIF or JPEG image that will be used as the cursor.

Reading returns the current cursor. Writing immediately sets the popupmenu's cursor to the new value. A popupmenu that does not set its own cursor uses DEFAULT_CURSOR.

doublebuffered An int that is 1 when the popupmenu uses double-buffering to draw itself, 0 when it does not, and starts with a default value that is selected by Java for the popupmenu. Reading returns the current double-buffering behavior. Writing immediately sets the popupmenu's double-buffering behavior to the new value. Note that double-buffering may be required when transparent components are used.
dragenabled An int that should be set to 1 when this popupmenu wants to use the automatic drag handling that Swing provides for some components, and 0 (the default) when it does not. Components that do not provide automatic drag handling always return 0 when their dragenabled field is read, so storing 1 in dragenabled should only be viewed as a request for a service that may not be available. Swing components can always take complete control of their drag and drop handling using their transferhandler field or special drag and drop event handlers.
enabled An int that is 1 when the popupmenu can respond to user input, and 0 when it can not. The top-level application window that contains the popupmenu always gets the final say, so disabling that window always disables the popupmenu. Reading returns the current state. Writing immediately sets the popupmenu's state to the new value.
focusable An int that is non-zero (the default) when the popupmenu can accept the keyboard focus and zero when it can not. Reading returns the popupmenu's current focusable state. Writing immediately changes the popupmenu's focusable state to the new value, which means the focus is automatically transferred if the new value is zero and the popupmenu is the current focus owner.
focusowner A read-only int that is non-zero when the popupmenu has the focus.
font The Font, or font name if it is a String, that is used as the default font assigned to popupmenu and the components in the items array that do not pick their own. The default value is NULL, which means use the font selected by the component that owns the popupmenu. Reading returns a snapshot of the current font. Writing immediately changes the popupmenu's font, and the font used by all components contained in the popupmenu that do not pick their own, to the new font.
foreground The Color that is used as the default foreground color assigned to the popupmenu and components in the items array that do not pick their own. The default value is NULL, which means use the foreground color of the component that owns the popupmenu. Reading returns a snapshot of the current color. Writing immediately sets the popupmenu's foreground, and the foreground of components contained in the popupmenu that do not pick their own, to the new color.
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 or radiobutton 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 that describes the popupmenu configuration or an Array of the JMenu or JMenuItem objects that are actually in the popupmenu. Writing causes the new Array or Menu to be parsed and if there are no errors immediately resets the menu's contents.
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.
nextfocus An Object that identifies the component that receives the focus after this popupmenu when the focus traverses from one component to the next (usually by means of the keyboard TAB character). When nextfocus is a String it is assumed to be the tag associated with the target component, which must belong to the same top-level container (e.g., the same JFrame) as this popupmenu. A NULL value means the component that gets the focus after this popupmenu will be selected by Java's default focus traversal policy. Reading returns the value last stored or NULL if the value was a String that did not reference a component. Writing immediately changes the component that gets the focus after this popupmenu.
preferredsize A Dimension that is used by layout managers when they need to know the popupmenu's preferred size in units of 72 dots per inch. A NULL value means the popupmenu has no preference. A non-positive height or width is allowed and simply means the popupmenu has no preference for that dimension. Reading returns the current preferred size. Writing changes the preferred size and immediately notifies root.layoutmanager, which means the components contained in root may be repositioned and resized.
root An Object that is automatically updated by the interpreter so it always references the component that currently owns the popupmenu. A NULL value means the popupmenu is not currently attached to a component.
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 or radiobutton 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.
showing A read-only int that is non-zero when the popupmenu is showing on the screen.
size A Dimension that determines the size of the popupmenu in units of 72 dots per inch. Reading returns a snapshot of the current size. Writing is allowed, but layout managers usually get the final say, so setting size should be viewed as a request that may not be honored.
text A String of characters that labels the popupmenu. Reading returns the current text. Writing immediately paints the new text.
tooltiptext A String of characters that is displayed in a tightly sized pop-up window that appears near the cursor whenever the cursor lingers over the popupmenu. Setting this value to NULL (the default) disables the tooltip mechanism. Reading returns the current tooltip text. Writing immediately sets the new tooltip text.
transferhandler An Object that should be a TransferHandler or String that determines how the popupmenu handles data transfer operations like drag and drop. A value that is a String but not "" means the field named by the String should be used as the source and sink of the data that is transferred by the popupmenu. The result is the same as assigning the String to the property field in a TransferHandler and then assigning that TransferHandler to transferhandler. The empty String "" is special and refers to the TransferHandler that Swing uses for automatic drag handling, if there is one.

Swing components that provide automatic drag handling start out with a transferhandler field that is not NULL, but the automatic drag handling is not enabled until 1 is stored in dragenabled. Swing components that provide their own drag and drop event handlers currently must store NULL in transferhandler before those event handlers will start working.

visible An int that is 1 when the popupmenu is visible, and 0 otherwise. Reading returns the current visibility. Writing immediately sets the popupmenu's visibility to the new state. Setting this field to 0 effectively pops down the popupmenu.
Several permanent fields have not been documented and should not be used in Yoix applications. In addition, even though the layer, opaque, nextfocus, requestfocus, and requestfocusenabled fields are defined, in most situations they have no effect and as a result they have not been documented.

A popupmenu can be shown over any component, except other menus and menu items, 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 or the actionPerformed event handler in the menu item itself. Selecting a checkbox menu item delivers an ItemEvent to the itemStateChanged event handler defined either in the popupmenu owner or the menu item itself.

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.
 
 Event Handlers:   actionPerformed, invocationRun, itemStateChanged
 
 Example:   The program,
import yoix.*.*;

JPopupMenu popupmenu = {
    String text = "Test Popup Menu";
    
    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;
    }
}

JFrame f = {
    GridLayout layoutmanager;

    Array layout = {
        new JLabel {
            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 JLabel {
            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:   appendText, BevelBorder, Border, EmptyBorder, EtchedBorder, invokeLater, JButton, JCanvas, JCheckBox, JCheckBoxMenuItem, JChoice, JColorChooser, JComboBox, JDesktopPane, JDialog, JFileChooser, JFileDialog, JFrame, JInternalFrame, JLabel, JLayeredPane, JList, JMenu, JMenuBar, JMenuItem, JPanel, JPasswordField, JProgressBar, JRadioButton, JRadioButtonMenuItem, JScrollBar, JScrollPane, JSeparator, JSlider, JSplitPane, JTabbedPane, JTable, JTextArea, JTextCanvas, JTextField, JTextPane, JTextTerm, JToggleButton, JToolBar, JTree, JWindow, LineBorder, MatteBorder, Menu, postEvent, SoftBevelBorder, TransferHandler

 

Yoix is a registered trademark of AT&T Inc.