001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.chameleon.layers;
028:
029: import com.sun.midp.chameleon.*;
030: import javax.microedition.lcdui.*;
031:
032: /**
033: * A "Popup" layer is a special kind of layer which can
034: * also have commands associated with it. When a popup
035: * layer is added to a MIDPWindow, its commands (if it has any)
036: * can be accessed through the soft button bar. If a popup layer
037: * does have commands associated with it, any commands on the
038: * current displayable/item are no longer accessible. If
039: * the popup layer does not have its own commands, any
040: * existing commands from the displayable/item remain.
041: *
042: * NOTE: For now, a PopupLayer is also always visible,
043: * that is isVisible() always returns true. To control the
044: * visibility of a PopupLayer, you add it and remove it
045: * from a MIDPWindow. IMPL_NOTE: determine if a relationship between
046: * PopupLayer and MIDPWindow can allow non visible popup layers.
047: */
048: public class PopupLayer extends CLayer {
049:
050: /**
051: * The set of Commands for this PopupLayer
052: */
053: protected Command[] commands;
054:
055: /**
056: * The CommandListener to notify when a Command is selected
057: */
058: protected CommandListener listener;
059:
060: /**
061: * Construct a new PopupLayer. By default, setSupportsInput()
062: * is set to true.
063: */
064: public PopupLayer() {
065: this ((Image) null, -1);
066: }
067:
068: /**
069: * Construct a new PopupLayer, given a background image.
070: * By default, setSupportsInput() is set to true, and so
071: * is setVisible().
072: */
073: public PopupLayer(Image bgImage, int bgColor) {
074: super (bgImage, bgColor);
075: this .supportsInput = true;
076: }
077:
078: /**
079: * Construct a new PopupLayer, given a 9 pc background image.
080: * By default, setSupportsInput() is set to true, and so
081: * is setVisible().
082: */
083: public PopupLayer(Image[] bgImage, int bgColor) {
084: super (bgImage, bgColor);
085: this .supportsInput = true;
086: }
087:
088: /**
089: * The setVisible() method is overridden in PopupLayer
090: * so as not to have any effect. PopupLayers are always
091: * visible by their very nature. In order to hide a
092: * PopupLayer, it should be removed from its containing
093: * MIDPWindow.
094: */
095: public void setVisible(boolean visible) {
096: }
097:
098: /**
099: * Set the set of Commands associated with this PopupLayer.
100: *
101: * @param commands the set of Commands associated with this
102: * PopupLayer. 'null' means there are no Commands
103: */
104: public void setCommands(Command[] commands) {
105: this .commands = commands;
106: }
107:
108: /**
109: * Get the set of Commands associated with this PopupLayer
110: *
111: * @return the set of Commands associated with this PopupLayer.
112: * 'null' means there are no Commands.
113: */
114: public Command[] getCommands() {
115: return commands;
116: }
117:
118: /**
119: * Establish a listener for the commands for this popup layer.
120: * NOTE: When the CommandListener is notified of a command action,
121: * the 'displayable' argument in its commandAction() method will
122: * always be null.
123: *
124: * @param listener the CommandListener to call when a command on
125: * this popup layer is selected
126: */
127: public void setCommandListener(CommandListener listener) {
128: this .listener = listener;
129: }
130:
131: /**
132: * Get the CommandListener associated with this popup layer.
133: * If the listener is null, any commands added to this popup layer
134: * will not be visible when this popup is added to a MIDPWindow.
135: *
136: * @return the CommandListener (if any) associated with this popup
137: */
138: public CommandListener getCommandListener() {
139: return listener;
140: }
141:
142: /**
143: * Returns true for popup layer because almost all pointer events
144: * have to be handled by popup even if it's out of bounds. The most of
145: * popups has to be closed if the pointer event is out of its bounds.
146: * The exception is the pointer is a part of the command layer.
147: *
148: * @param x the "x" coordinate of the point
149: * @param y the "y" coordinate of the point
150: * @return true if the point is handled by this layer
151: */
152: public boolean handlePoint(int x, int y) {
153: boolean ret = true;
154: if (commands != null && commands.length > 0 && owner != null) {
155: ret = !((MIDPWindow) owner).belongToCmdLayers(x, y);
156: }
157: return ret | containsPoint(x, y);
158: }
159:
160: }
|