MIDP3.0

javax.microedition.lcdui
Interface CommandLayoutPolicy


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 getCommandPlacements to get the recommended 
     // placement for each Command.
   }
 
   public boolean onCommandLayout(Displayable displayable) {
     Display display = displayable.getCurrentDisplay();
      
     final int border = Display.SOFTKEY_BOTTOM;
     
     int[] positions = display.getExactPlacementPositions(border);
     
     Command[] cmd = displayable.getCommands();
     
     sort(cmd, positions);
     
     if (cmd.length <= positions.length) {
       
       for (int i = 0; i < cmd.length; ++i) {
         displayable.setCommand(cmd[i], border + positions[i]);
       }
       for (int i = cmd.length; i < positions.length; ++i) {
         //clear all non-used placements
         displayable.removeCommandOrMenu(border + positions[i]);
       }
     } else {
       
       for (int i = 0; i < positions.length - 1; ++i) {
         displayable.setCommand(cmd[i], border + positions[i]);
       }
       
       Menu options = new Menu("More", null, null);
       for (int i = positions.length; i < cmd.length; ++i) {
         options.append(cmd[i]);
       }
       displayable.setMenu(options, positions[positions.length-1]);
     }    
   }
 }
 

Since:
MIDP 3.0

Method Summary
 void onCommandLayout(Displayable displayable)
          Method called when a new layout is needed.
 

Method Detail

onCommandLayout

void onCommandLayout(Displayable displayable)
Method called when a new layout is needed. Any 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.

Parameters:
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.
Since:
MIDP 3.0

MIDP3.0

Send a comment or suggestionVersion 3.0 of Mobile Information Device Profile Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries. Copyright 2002-2009 Motorola Inc. Portions copyright 1993-2002 Sun Microsystems, Inc. and Motorola, Inc. All Rights Reserved.