public class SoftKeyBar extends Object implements EventListener, HasProperties
SoftKeyBars provide two types of controls - buttons which simply fire an action when the associated softkey is pressed, or menus which display a general Menu when pressed.
The SoftKeyBar is not a UI Control since it may actually be implemented using the system's native UI system - but it is fully responsible for configuring the appearance on screen and handling the softkey presses. The only thing an application has to do is to trap the events sent out by the SoftKeyBar or override the event handling of the SoftKeyBar.
Because only one SoftKeyBar can be displayed at a time, you display it by calling Window.setSoftKeyBar() on the containing Window.
Modifier and Type | Field and Description |
---|---|
static int |
ALLOW_ALL_OVERLAYS
This allows full merging of this bar with any other bar.
|
static int |
ALLOW_HIGHER_OVERLAY_OVER_THIS
This allows a higher level bar to be merged with this one.
|
static int |
ALLOW_OVERLAY_THIS_OVER_LOWER
This allows this bar to be merged with a lower level one.
|
int |
barModifiersToClear |
int |
barModifiersToSet |
static Color |
defaultBackgroundColor
The default background color for the soft keys.
|
static Font |
defaultFont
This is the default font.
|
static Color |
defaultTextColor |
boolean |
dontClosePopupsOnPress
If the SoftKeyBar is being used by a Popup Form, then set this true,
otherwise the Popup Form will be closed with IDCANCEL when either of the keys is pressed.
|
static SoftKeyBar |
empty |
static boolean |
hideRemovesSoftKeyBar
This is false by default and if you set it true, then a hide() will cause
the SoftKeyBar to disappear entirely, instead of just becoming empty - which
is the default.
|
String |
name
You can use this as an identifier for bar.
|
protected int |
overlayOptions |
static int |
preferredBarHeight
This is the preferred height of the softkey bar.
|
static boolean |
showMenuNumbers
Set this to false if you do not want numbers to appear
in the Menus within SoftKeys.
|
static int |
TYPE_DOUBLE
A return value for getType() - indicates that two softkeys exists and either
can be a button or a menu.
|
static int |
TYPE_MENU
A return value for getType() - indicates that only a single MENU softkey
is available (e.g. on an Android platform).
|
static int |
TYPE_NONE
A return value for getType() - indicates that the system does not use
softkeys.
|
static int |
TYPE_SINGLE
A return value for getType() - indicates that only one softkey exists but
it is visible and can be a button or a menu.
|
Constructor and Description |
---|
SoftKeyBar() |
SoftKeyBar(EventListener listener) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(EventListener el) |
void |
addTo(SingleContainer sc) |
void |
clearKeys() |
Menu |
createMenuFor(Object obj)
Create a Menu for a specific set of Objects, placed in a Vector, or a Container or an Object
array.
|
MenuItem |
createMenuItem(Button button)
Return a MenuItem that will be used as a proxy for a specific buton.
|
MenuItem |
createMenuItem(String label,
String action,
IImage icon)
Create a MenuItem suitable for use in a menu assigned to the SoftKeyBar.
|
MenuItem |
createMenuItemFor(Object obj)
Create a MenuItem for a particular Object.
|
boolean |
display()
Display the SoftKeyBar in the global SoftKeyBar location.
|
static Menu |
fixMenu(Menu m)
Fix a Menu for use with the SoftKeyBar.
|
static SoftKeyBar |
getDisplayed() |
FontMetrics |
getFontMetrics() |
Control |
getKey(int whichKey)
Return the Control the SoftKey is set for.
|
Control |
getKey(int whichKey,
boolean baseKeyOnly)
Return the Control the SoftKey is set for.
|
int |
getOverlayOptions() |
PropertyList |
getProperties()
Get the PropertyList object associated with this object.
|
static int |
getType()
Determine the type of SoftKeys available.
|
boolean |
handleKey(KeyEvent ev) |
static void |
hide()
Hide any visible SoftKeyBar.
|
static Menu |
insertAsSubMenu(Menu mainMenu,
String asName,
String items) |
static Menu |
insertAsSubMenu(Menu mainMenu,
String asName,
Vector menuItems) |
static boolean |
isSingleMenuOnly()
Some platforms have only one softkey that always brings up a Menu (like
Android).
|
protected Control |
make() |
static int |
numberOfKeys()
Returns the number of keys supported by the system.
|
void |
onEvent(Event ev) |
static boolean |
onKeyEvent(KeyEvent ev) |
static SoftKeyBar |
overlay(SoftKeyBar higher,
SoftKeyBar lower) |
static void |
pop()
Display the keybar that was displayed before the last push() call.
|
static void |
push(SoftKeyBar skb)
Display a new keybar, but save the old keybar.
|
void |
removeListener(EventListener el) |
static boolean |
reveal()
Reveal a hidden SoftKeyBar.
|
protected void |
sendToListeners(Event ev) |
void |
setFont(Font f)
Set the Font to be used by the bar if possible.
|
SoftKeyBar |
setKey(int which,
Button button)
Set one of the SoftKeyBar keys to be a proxy for an existing Button.
|
SoftKeyBar |
setKey(int which,
IImage image,
Menu menu) |
SoftKeyBar |
setKey(int which,
Object obj,
String label)
Set one of the SoftKeys to be a button or a Menu, depending on the type of the obj
parameter.
|
SoftKeyBar |
setKey(int which,
String text,
IImage icon,
Menu menu) |
SoftKeyBar |
setKey(int which,
String text,
Menu menu) |
SoftKeyBar |
setMenu(int which,
String name,
IImage icon,
String items)
Set a particular softkey to be a Menu, specifying the menu as a String.
|
int |
setOverlayOptions(int toSet,
int toClear)
Change or get the overlay options.
|
static void |
setupIn(Panel c)
Setup the global location for the SoftKeyBar.
|
static void |
setupScreen(int options)
This is called by the GUI system when running on a Smartphone.
|
static boolean |
supportsImages()
Returns true if the softkey displays on screen supports the display of images, false if not.
|
static boolean |
usingSoftKeys()
This returns true if SoftKeys are under this platform.
|
public String name
public static boolean showMenuNumbers
public static int preferredBarHeight
public static Color defaultBackgroundColor
public static Color defaultTextColor
public static boolean hideRemovesSoftKeyBar
public int barModifiersToSet
public int barModifiersToClear
public static final SoftKeyBar empty
public boolean dontClosePopupsOnPress
public static final int ALLOW_HIGHER_OVERLAY_OVER_THIS
public static final int ALLOW_OVERLAY_THIS_OVER_LOWER
public static final int ALLOW_ALL_OVERLAYS
protected int overlayOptions
public static Font defaultFont
public static final int TYPE_MENU
public static final int TYPE_SINGLE
public static final int TYPE_DOUBLE
public static final int TYPE_NONE
public SoftKeyBar()
public SoftKeyBar(EventListener listener)
public int setOverlayOptions(int toSet, int toClear)
toSet
- overlay options to set. Any combination of the ALLOW_XXX values.toClear
- overlay options to clear. Any combination of the ALLOW_XXX valuespublic final int getOverlayOptions()
public void addListener(EventListener el)
public void removeListener(EventListener el)
protected void sendToListeners(Event ev)
public void clearKeys()
public void setFont(Font f)
f
- the Font to use if this is allowed by the system. If setting of the Font is not allowed,
then this method will have no effect.public static boolean supportsImages()
public static int numberOfKeys()
public static boolean isSingleMenuOnly()
public static int getType()
public void onEvent(Event ev)
public FontMetrics getFontMetrics()
public static SoftKeyBar overlay(SoftKeyBar higher, SoftKeyBar lower)
public MenuItem createMenuItem(String label, String action, IImage icon)
label
- the display text for the item.action
- an action String assigned to the item. The handleAction()
method will be called on the Form with this value when the item is selected.icon
- an optional icon to be displayed next to the item.public MenuItem createMenuItem(Button button)
public SoftKeyBar setKey(int which, Button button)
which
- the key to set, either 1 (left) or 2 (right).button
- the button that will be activated by the Soft Key.public Control getKey(int whichKey, boolean baseKeyOnly)
whichKey
- either 1 or 2.baseKeyOnly
- set true to get the buttons in the SoftKeyBar only, false
to get the Menu if either of the Buttons activates a Menu.public Control getKey(int whichKey)
whichKey
- either 1 or 2.public MenuItem createMenuItemFor(Object obj) throws IllegalArgumentException
obj
- - this can be a String or an Button, each of which creates a normal MenuItem,
or it can be a Menu or Vector or Object[] or a Container, in which case a MenuItem that has
a sub-menu will be created.IllegalArgumentException
public Menu createMenuFor(Object obj) throws IllegalArgumentException
IllegalArgumentException
public SoftKeyBar setKey(int which, Object obj, String label) throws IllegalArgumentException
which
- the key to set, either 1 (left) or 2 (right.obj
- this can be either a String or Button (either of which creates a single
button for the Soft Key) or a Vector or Object[] or Container or Menu - in which
case a Menu will be created for the Soft Key.label
- if the obj parameter gets converted to a Menu, then this parameter will
be the label for the menu.IllegalArgumentException
public SoftKeyBar setKey(int which, IImage image, Menu menu) throws IllegalArgumentException
which
- The key to set, starting from 1.image
- The image to use for the key.menu
- An optional menu to display when the key is pressed. If this is null the key
will just be treated as a button.IllegalArgumentException
- if the system does not support displaying images on the
soft keys.public SoftKeyBar setKey(int which, String text, IImage icon, Menu menu) throws IllegalArgumentException
which
- The key to set, starting from 1.text
- The text for the key. If this is in the form "Text_1|Text_2" then "Text_1" is used
as the text for the key and "Text_2" is used as the action for the key.icon
- An image to display as an icon next to the text if possible. If this is not possible
then the icon is ignored.menu
- An optional menu to display when the key is pressed. If this is null the key
will just be treated as a button.IllegalArgumentException
- if the system does not support displaying images on the
soft keys.public SoftKeyBar setKey(int which, String text, Menu menu)
which
- The key to set, starting from 1.text
- The text for the key. If this is in the form "Text_1|Text_2" then "Text_1" is used
as the text for the key and "Text_2" is used as the action for the key.menu
- An optional menu to display when the key is pressed. If this is null the key
will just be treated as a button with the Text and action for the button being the same.IllegalArgumentException
- if the system does not support displaying images on the
soft keys.public SoftKeyBar setMenu(int which, String name, IImage icon, String items)
which
- The key to set, starting from 1.name
- The name of the menu.icon
- An optional icon for the menu.items
- The items for the menu. This should be specified either as a
comma separted list of item names (e.g. "Item 1,Item 2,Item 3") or as a '|' separated list of
item name and action pairs (e.g. "Item 1|ACTION_1|Item 2|ACTION_2|Item 3|ACTION_3").protected Control make()
public boolean handleKey(KeyEvent ev)
public static boolean onKeyEvent(KeyEvent ev)
public void addTo(SingleContainer sc)
public static boolean usingSoftKeys()
public static void setupIn(Panel c)
public boolean display()
public static SoftKeyBar getDisplayed()
public static void setupScreen(int options)
public static void hide()
public static boolean reveal()
public static void push(SoftKeyBar skb)
public static void pop()
public static Menu fixMenu(Menu m)
public PropertyList getProperties()
HasProperties
getProperties
in interface HasProperties