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 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);                    
           }
     }    
   }
 }
 

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.