|
MIDP3.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface CommandLayoutPolicy
This interface is used to implement exact placement of commands.
Example:
class MyCanvas extends Canvas implements CommandLayoutPolicy {
MyCanvas() {
setCommandLayoutPolicy(this);
}
void sort(Command[] commands, int[] positions) {
// sort the commands in the correct order depending on the positions available.
// Implementation can use Display's getCommandPreferredPlacements to get the recommended
// placement for each Command.
}
public void onCommandLayout(Displayable displayable) {
Display display = displayable.getCurrentDisplay();
final int border = Display.SOFTKEY_BOTTOM;
int[] positions = display.getExactPlacementPositions(border);
int numOfPositions = positions.length;
Command[] cmd = displayable.getCommands();
sort(cmd, positions);
if (cmd.length <= numOfPositions) {
for (int i = 0; i < cmd.length; ++i) {
displayable.setCommand(cmd[i], positions[i]);
}
} else {
for (int i = 0; i < numOfPositions ; ++i) {
displayable.setCommand(cmd[i], positions[i]);
}
int[] menuSupportedPlmts = display.getMenuSupportedPlacements();
if( menuSupportedPlmts != null ) {
Menu options = new Menu("More", null, null);
// first add the remaining commands in the Menu
for (int i = numOfPositions; i < cmd.length; ++i) {
options.append(cmd[i]);
}
// Get the first preferred placement of Menu
int menuPlmt = menuSupportedPlmts[0];
// check if this placement already occupied by Command
if( displayable.getCommand(menuPlmt) != null ) {
//add the existing Command in Menu, otherwise the existing
// Command will be removed from the Displayable according to
//setMenu() method
//
options.append(displayable.getCommand(menuPlmt));
}
displayable.setMenu(options, menuPlmt);
}
}
}
}
| Method Summary | |
|---|---|
void |
onCommandLayout(Displayable displayable)
Method called when a new layout is needed. |
| Method Detail |
|---|
void onCommandLayout(Displayable displayable)
Command
or Menu not explicitly set at a placement (via
Displayable.setCommand(Command, int),
Displayable.setMenu(Menu, int), or
Item.setCommand(Command, int)) in the
CommandLayoutPolicy implementation will be ignored and not displayed.
displayable - The Displayable that holds the commands that should be updated. If
displayable is a TabbedPane, it is the
CommandLayoutPolicy implementation's responsibility to update
commands depending on the active tab etc. If
displayable is a Form, it is the
CommandLayoutPolicy implementation's responsibility to update
commands depending on the active item etc.
|
MIDP3.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||