John W. Campbell
This class provides a button based menu area object with a main menu section
and an optional 'quit' button separated from the main menu.
Class, fields, constructor and methods:
Class Details
Accessible Fields
Constructor
Operational Methods
Standard Positioning and Sizing
Add/Remove Action Listener
Get Returned Data
Overriden Superclass Methods
- Package:
- Jdl.JdlView;
- Class name:
- JdlMenuArea
- Class definition:
- public class JdlMenuArea
- Extends:
- JdlDrawPanel
- Implements:
- ActionListener
MouseListener
JdlViewObject
- Actions:
- An action event will be generated when a menu item or the quit button is
selected. The associated object is the string 'item n' respectively where 'n'
is the selected menu item number from 1 up or 0 if the 'quit' button was
selected.
The following accessible fields have been defined:
- public final static int FULL_WIDTH
- Button width option: use maximum allowed button widths.
- public final static int ITEMS_WIDTH
- Button width option: use button widths based on longest item string in
current set of displayed items.
- static final long serialVersionUID
- public final static int PREFERRED
- Size Constraint: preferred size.
- public final static int FREE
- Size/Location Constraint: free.
A single constructor is available.
Constructor:
Standard constructor
Constructs a JdlMenuArea object with menu items and optional title and 'quit'
button strings. If present the 'quit' button is positioned below the menu
item buttons and is separated from them by a space.
- Constructor Definition:
- public JdlMenuArea(String title, String[] menu_strings, int num_strings, String quit_string, int max_items, int input_string_width, boolean allow_title, boolean allow_quit, int minimum_width, int minimum_height, JdlMenuAreaStyle style, JdlViewOptions view_opts)
- Parameters List:
- title
- The initial menu title, may be null if not required.
- menu_strings
- The menu item strings for the initial menu to be displayed.
- num_strings
- The number of menu item strings in the array menu_strings;
may be input as 0 if the number of strings to be used is the same as the
String array length.
- quit_string
- The initial menu string for the 'quit' button, may be null
if not required.
- max_items
- The maximum number of items for which this menu area may be
used (used in menu area size calculations).
- input_string_width
- A pre-calculated string width (in pixels) to override
the string width calculated from the current set of title/menu/quit strings.
If 0, then ignore this value.
- allow_title
- Allow for a menu title to be displayed (used in menu area
size calculations).
- allow_quit
- Allow for a quit button to be displayed (used in menu area
size calculations).
- minimum_width
- The minimum width requested (only used if greater than
the minimum needed for the layout.
- minimum_height
- The minimum height requested (only used if greater than
the minimum needed for the layout.
- style
- Allows for non-default settings for various button style
parameters (If null, the default values for these will be used).
- view_opts
- Object to set non-default options for borders, active strip,
colours and fonts.
This section has methods to set menu, quit button and title strings.
Methods:
Set menu strings - setMenuStrings
Set quit string - setQuitString
Set title string - setTitleString
Create popup - popupMenu
This method sets new menu strings.
- Method Definition:
- public void setMenuStrings(String[] menu_strings, int num_strings)
- Parameters List:
- menu_strings
- An array of new nenu item strings.
- num_strings
- The number of menu item strings in the array menu_strings;
may be input as 0 if the number of strings to be used is the same as the
String array length. Note: The number of strings must not exceed the maximum
number of menu items defined when the object was created.
This method sets a new quit string.
- Method Definition:
- public void setQuitString(String quit_string)
- Parameters List:
- quit_string
- The quit string.
This method sets a new title string.
- Method Definition:
- public void setTitleString(String title_string)
- Parameters List:
- title_string
- The title string.
Create a popup menu from the current menu area object.
- Method Definition:
- public synchronized int popupMenu(Component parent, int x, int y, boolean mouse_esc, long timeout)
- Parameters List:
- parent
- The parent view object (or Component).
- x
- The 'x' coordinate of the popup relative to the parent.
- y
- The 'y' coordinate of the popup relative to the parent.
- mouse_esc
- Allow for menu escape if mouse clicked outside a button if
true, otherwise an item/quit-item must be selected.
- timeout
- The popup menu will time out after this number of milliseconds
if a value greater than zero is given. If 0, no timeout will occur.
- Method Return:
-
Selected item flag:
> 0, The number of the menu item selected
= 0, The quit item was selected
= -1, Mouse was clicked outside an item (if mouse_esc = true)
= -2, Menu timeout (if timeout > 0)
This section contains the standard methods for positioning and sizing
JdlView objects and getting the current minimum height and width values.
Methods:
Set position constraints - setLocationConstraints
Set size constraints - setSizeConstraints
Set minimum height - setMinimumHeight
Set minimum width - setMinimumWidth
Set constraints on the Jdl object positioning.
- Method Definition:
- public void setLocationConstraints (int constraint_x, int constraint_y)
- Parameters List:
- constraint_x
- Constrain the Jdl Object 'x' position = the required
Jdl Object 'x' position (overrides setLocation method) or FREE if the 'x'
position may be set by the setLocation method and hence possibly by the
layout manager.
- constraint_y
- Constrain the Jdl Object 'y' position = the required
the Jdl Object 'y'position (overrides setLocation method) or FREE if the 'y'
position may be set by the setLocation method and hence possibly by the
layout manager.
Set constraints on the Jdl Object resizing permitted.
- Method Definition:
- public void setSizeConstraints (int constraint_w, int constraint_h)
- Parameters List:
- constraint_w
- Constrain the Jdl Object width = the required
Jdl Object width, or PREFERRED (default) if the width is to be calculated
from the current resources, or FREE if the width may be resized to anything
greater than the minimum width required.
- constraint_h
- Constrain the Jdl Object height = the required
Jdl Object height, or PREFERRED (default) if the height is to be calculated
from the current resources, or FREE if the height may be resized to anything
greater than the minimum height required.
Set the minimum height resource.
- Method Definition:
- public void setMinimumHeight(int minh)
- Parameters List:
- minh
- The minimum height required for the object (ignored if less
than that required by the minimum layout) (default = 0).
Set the minimum width resource.
- Method Definition:
- public void setMinimumWidth(int minw)
- Parameters List:
- minh
- The minimum width required for the object (ignored if less
than that required by the minimum layout) (default = 0).
This section has methods to add or remove an action listener.
Methods:
Add action listener - addActionListener
Remove an action listener. - removeActionListener
This adds the specified action listener to receive action events from this
object.
- Method Definition:
- public void addActionListener(ActionListener listener)
- Parameters List:
- listener
- The action listener to be added.
This removes the specified action listener so that it no longer receives action
events from this menu.
- Method Definition:
- public void removeActionListener(ActionListener listener)
- Parameters List:
- listener
- The action listener to be added.
This section has methods to get data from the object relating to an
action and following that action.
Methods:
Get menu item number - getReturnedData
This method returns the selected menu item number.
- Method Definition:
- public int getReturnedData()
- Parameters List:
- none
- Method Return:
-
Returns the last selected menu item number or 0 if quit item was
selected.
This section contains methods which override the corresponding superclass
methods. These are basically standard for JdlView objects and comprise
methods to set background and foreground colours and to get the minimum
and preferred sizes for the object. (The paintComponent and setSize methods
are also over-ridden but they are not normally called by the user).
Methods:
Set background - setBackground
Set background colours - setBackground
Set foreground - setForeground
Get minimum size - getMinimumSize
Get preferred size - getPreferredSize
This method sets the background colour resource.
- Method Definition:
- public void setBackground (Color c)
- Parameters List:
- c
- The color to become this object's background color.
This method sets the background colour resource and brighter and darker shades
of that colour (e.g. for 3-D frames).
- Method Definition:
- public void setBackground (Color c, Color brighter, Color darker)
- Parameters List:
- c
- The background colour.
- brighter
- A brighter shade of the background colour.
- darker
- A darker shade of the background colour.
This method sets the foreground colour resource.
- Method Definition:
- public void setForeground (Color c)
- Parameters List:
- c
- The color to become this object's foreground color.
This method returns the minimum size of the component.
- Method Definition:
- public Dimension getMinimumSize()
- Parameters List:
- none
This method returns the preferred size of the component.
- Method Definition:
- public Dimension getPreferredSize()
- Parameters List:
- none
⇑ Up 3
⇑ Up 2
⇑ Up 1
⇑ Top of this