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 javax.microedition.lcdui.*;
030:
031: import com.sun.midp.chameleon.ChamDisplayTunnel;
032: import com.sun.midp.chameleon.CLayer;
033:
034: import com.sun.midp.chameleon.skins.*;
035:
036: /**
037: * AlertLayer
038: */
039: public class AlertLayer extends BodyLayer {
040:
041: /**
042: * The AlertLayer constructor. Initializes background image if
043: * there is one set in AlertSkin.
044: * @param tunnel - The ChamDisplayTunnel to do paint calls
045: */
046: public AlertLayer(ChamDisplayTunnel tunnel) {
047: super (AlertSkin.IMAGE_BG, AlertSkin.COLOR_BG, tunnel);
048: setVisible(false);
049: }
050:
051: /**
052: * Sets content to be displayed in the Alert Layer.
053: * This AlertLayer will be made visible if <code>alertVisible</code>
054: * is true and will be hidden - otherwise.
055: * @param alertVisible - true if the AlertLayer should be shown,
056: * and false - otherwise
057: * @param alert - The <code>Alert</code> instance that is currently
058: * visible
059: * @param height the preferred height for the Alert. This is accepted
060: * as long as it is less than AlertSkin.HEIGHT
061: */
062: public void setAlert(boolean alertVisible, Alert alert, int height) {
063: this .alert = alert;
064: setDirty();
065: setVisible(alertVisible);
066: }
067:
068: /**
069: * Toggle the visibility state of Alert layer within its containing
070: * window.
071: *
072: * @param visible if alert should be visible, false otherwise
073: */
074: public void setVisible(boolean visible) {
075: super .setVisible(visible);
076: setSupportsInput(visible);
077: }
078:
079: /**
080: * Initialize the bounds of this AlertLayer. Overrides
081: * initialize in superclasses. The dimensions of the
082: * specific AlertLayer are specified in AlertSkin.
083: *
084: * The X and Y coordinates represent the upper left position
085: * of this CLayer in the physical display's coordinate space.
086: */
087: protected void initialize() {
088: super .initialize();
089: setAnchor();
090: }
091:
092: /**
093: * Align alert depend on skin
094: */
095: public void setAnchor() {
096:
097: bounds[W] = AlertSkin.WIDTH;
098: bounds[H] = AlertSkin.HEIGHT;
099:
100: switch (AlertSkin.ALIGN_X) {
101: case Graphics.LEFT:
102: bounds[X] = 0;
103: break;
104: case Graphics.RIGHT:
105: bounds[X] = ScreenSkin.WIDTH - bounds[W];
106: break;
107: case Graphics.HCENTER:
108: default:
109: bounds[X] = (ScreenSkin.WIDTH - bounds[W]) / 2;
110: break;
111: }
112: switch (AlertSkin.ALIGN_Y) {
113: case Graphics.TOP:
114: bounds[Y] = 0;
115: break;
116: case Graphics.VCENTER:
117: bounds[Y] = (ScreenSkin.HEIGHT - SoftButtonSkin.HEIGHT - bounds[H]) / 2;
118: if (alert != null && alert.getTicker() != null) {
119: bounds[Y] -= TickerSkin.HEIGHT;
120: }
121: break;
122: case Graphics.BOTTOM:
123: default:
124: bounds[Y] = ScreenSkin.HEIGHT - SoftButtonSkin.HEIGHT
125: - bounds[H];
126: if (alert != null && alert.getTicker() != null) {
127: bounds[Y] -= TickerSkin.HEIGHT;
128: }
129: break;
130: }
131: }
132:
133: /** The Alert instance which content is currently visible */
134: private Alert alert;
135:
136: /**
137: * Update bounds of layer
138: *
139: * @param layers - current layer can be dependant on this parameter
140: */
141: public void update(CLayer[] layers) {
142: setAnchor();
143: if (visible) {
144: addDirtyRegion();
145: }
146: if (scrollInd != null) {
147: scrollInd.update(layers);
148: if (scrollInd.isVisible()) {
149: bounds[W] -= scrollInd.bounds[W];
150: }
151: }
152: }
153: }
|