FileDocCategorySizeDatePackage
DisplayContainer.javaAPI DocphoneME MR2 API (J2ME)5948Wed May 02 18:00:24 BST 2007com.sun.midp.lcdui

DisplayContainer

public class DisplayContainer extends Object
Stores array of active displays that either belong to MIdlets, or dynamically created for display preemption.

Fields Summary
private final int
isolateId
ID of the Isolate this instance is created in
private int
lastLocalDisplayId
Last local Display count used to create Display ID
private Vector
displays
Active displays.
Constructors Summary
public DisplayContainer(com.sun.midp.security.SecurityToken token, int isolateId)
Default constructor.

param
token security token for initilaization
param
isolateId id of the Isolate this instance is created in


                              
         
        token.checkIfPermissionAllowed(Permissions.MIDP);
	this.isolateId = isolateId;
    
Methods Summary
public synchronized voidaddDisplay(DisplayAccess da)
Adds a display object to the container and sets a the display's ID to new unique value for this isolate, as a single atomic operation.

Intended to be called from Display constructor.

param
da display object to add

        if (displays.indexOf(da) == -1) {
            int newId = createDisplayId();
            da.setDisplayId(newId);
            displays.addElement(da);
        }
    
private intcreateDisplayId()
Creates an Display Id that is unique across all Isolates. Graphics subsystem depends on this uniqueness, which allows quick check on whether a Display is in the foreground without having to check Isolate id.

return
a new unique display Id with high 8 bits as Isolate ID, low 24 bits as local display counter.

        int id;
        
        do {
            lastLocalDisplayId++;
	    // [high 8 bits: isolate id][low 24 bits: display id]]
            id = ((isolateId & 0xff)<<24) | (lastLocalDisplayId & 0x00ffffff);
        } while (findDisplayById(id) != null);

        return id;
    
synchronized DisplayAccessfindDisplayById(int displayId)
Find a display by ID.

param
displayId ID of the display
return
a display access object or null if not found

        int size = displays.size();

        for (int i = 0; i < size; i++) {
            DisplayAccess current = (DisplayAccess)displays.elementAt(i);

            if (current.getDisplayId() == displayId) {
                return current;
            }
        }

        return null;
    
public synchronized DisplayAccessfindDisplayByOwner(java.lang.String nameOfOwner)
Find a display by owner.

param
nameOfOwner class name of the MIDlet that owns this display
return
a display access object or null if not found

        int size = displays.size();

        for (int i = 0; i < size; i++) {
            DisplayAccess current = (DisplayAccess)displays.elementAt(i);

            if (current.getNameOfOwner().equals(nameOfOwner)) {
                return current;
            }
        }

        return null;
    
public DisplayEventConsumerfindDisplayEventConsumer(int displayId)
Find a display event consumer by ID.

param
displayId ID of the display
return
a display event consumer object or null if not found

        DisplayAccess da = findDisplayById(displayId);

        if (da == null) {
            return null;
        }

        return da.getDisplayEventConsumer();
    
public ForegroundEventConsumerfindForegroundEventConsumer(int displayId)
Find a foreground event consumer by ID.

param
displayId ID of the display
return
a foreground event consumer object or null if not found

        DisplayAccess da = findDisplayById(displayId);

        if (da == null) {
            return null;
        }

        return da.getForegroundEventConsumer();
    
public synchronized booleanremoveDisplay(java.lang.String nameOfOwner)
Removes display object from the container.

param
nameOfOwner class name of the MIDlet that owns this display
return
true if display has been succcessfully removed, false, if display object has not been found in the container.

        DisplayAccess da = findDisplayByOwner(nameOfOwner);

        return displays.removeElement(da);
    
public voidrequestForegroundForDisplay(java.lang.String nameOfOwner)
Get a display to request the foreground on behalf of the MIDlet.

param
nameOfOwner class name of the MIDlet that owns this display

        DisplayAccess da = findDisplayByOwner(nameOfOwner);

        da.requestForeground();