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 javax.microedition.lcdui;
028:
029: import com.sun.midp.configurator.AlertTypeConstants;
030:
031: /**
032: * The <code>AlertType</code> provides an indication of the nature
033: * of alerts.
034: * <code>Alerts</code> are used by an application to present
035: * various kinds of
036: * information to the user.
037: * An <code>AlertType</code> may be used to directly signal the
038: * user without changing
039: * the current <code>Displayable</code>.
040: * The <code>playSound</code> method can be used to spontaneously
041: * generate a sound to alert the user. For example, a game using a
042: * <code>Canvas</code> can use <code>playSound</code> to indicate
043: * success or progress.
044: *
045: * The predefined types are <CODE>INFO</CODE>, <CODE>WARNING</CODE>,
046: * <CODE>ERROR</CODE>, <CODE>ALARM</CODE>, and <CODE>CONFIRMATION</CODE>.
047: * <p>
048: *
049: * @see Alert
050: * @since MIDP 1.0
051: */
052: public class AlertType {
053:
054: /**
055: * An <code>INFO</code> <code>AlertType</code> typically
056: * provides non-threatening information to the
057: * user. For example, a simple splash screen might be an
058: * <code>INFO</code> <code>AlertType</code>.
059: */
060: public static final AlertType INFO = new AlertType(
061: AlertTypeConstants.LCDUI_ALERT_TYPE_INFO);
062:
063: /**
064: * A <code>WARNING</code> <code>AlertType</code> is a hint
065: * to warn the user of a potentially
066: * dangerous operation.
067: * For example, the warning message may contain the message, "Warning:
068: * this operation will erase your data."
069: */
070: public static final AlertType WARNING = new AlertType(
071: AlertTypeConstants.LCDUI_ALERT_TYPE_WARNING);
072:
073: /**
074: * An <code>ERROR</code> <code>AlertType</code> is a hint
075: * to alert the user to an erroneous operation.
076: * For example, an error alert might show the message,
077: * "There is not enough room to install the application."
078: */
079: public static final AlertType ERROR = new AlertType(
080: AlertTypeConstants.LCDUI_ALERT_TYPE_ERROR);
081:
082: /**
083: * An <code>ALARM</code> <code>AlertType</code> is a hint
084: * to alert the user to an event for which
085: * the user has previously requested to be notified.
086: * For example, the message might say, "Staff meeting in five
087: * minutes."
088: */
089: public static final AlertType ALARM = new AlertType(
090: AlertTypeConstants.LCDUI_ALERT_TYPE_ALARM);
091:
092: /**
093: * A <code>CONFIRMATION</code> <code>AlertType</code> is a
094: * hint to confirm user actions.
095: * For example, "Saved!" might be shown to indicate that a Save
096: * operation has completed.
097: */
098: public static final AlertType CONFIRMATION = new AlertType(
099: AlertTypeConstants.LCDUI_ALERT_TYPE_CONFIRMATION);
100:
101: /**
102: * Protected constructor for subclasses.
103: */
104: protected AlertType() {
105: }
106:
107: /**
108: * Alert the user by playing the sound for this
109: * <code>AlertType</code>.
110: * The <code>AlertType</code> instance is used as a hint by the device
111: * to generate an appropriate sound. Instances other than
112: * those predefined above may be ignored.
113: * The actual sound made by the device,
114: * if any, is determined by the device. The device may
115: * ignore the request, use the same sound for
116: * several <code>AlertTypes</code> or use any other means
117: * suitable to alert
118: * the user.
119: *
120: * @param display to which the <code>AlertType's</code> sound
121: * should be played.
122: * @return <code>true</code> if the user was alerted,
123: * <code>false</code> otherwise.
124: * @exception NullPointerException if <code>display</code> is
125: * <code>null</code>
126: */
127: public boolean playSound(Display display) {
128: synchronized (Display.LCDUILock) {
129: return display.playAlertSound(this );
130: }
131: }
132:
133: /**
134: * Create a new AlertType given the type identifier
135: *
136: * @param type The type of the new AlertType
137: */
138: AlertType(int type) {
139: this .type = type;
140: }
141:
142: /**
143: * Get the type of this AlertType
144: *
145: * @return int The typer identifer of this AlertType, one of:
146: * ALERT_INFO, ALERT_WARN, ALERT_ERR, ALERT_ALRM, ALERT_CFM
147: */
148: int getType() {
149: return this .type;
150: }
151:
152: /**
153: * The type of this AlertType
154: */
155: private int type;
156: }
|