001: /*
002: *
003: * Copyright (c) 2007, Sun Microsystems, Inc.
004: *
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * * Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * * Neither the name of Sun Microsystems nor the names of its contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032: package example.chooser;
033:
034: import javax.microedition.lcdui.Command;
035: import javax.microedition.lcdui.CommandListener;
036: import javax.microedition.lcdui.Display;
037: import javax.microedition.lcdui.Displayable;
038: import javax.microedition.midlet.MIDlet;
039:
040: /**
041: * A Color chooser MIDlet.
042: */
043: public class Color extends MIDlet implements CommandListener {
044: /** This MIDlets Display object */
045: private Display display; // Our display
046:
047: /** The Color chooser */
048: private ColorChooser chooser;
049:
050: /** The Exit Command */
051: private Command exitCommand = new Command("Exit", Command.EXIT, 1);
052:
053: /** The Decimal Command */
054: private Command decimalCommand = new Command("Decimal",
055: Command.SCREEN, 7);
056:
057: /** The Hexadecimal Command */
058: private Command hexCommand = new Command("Hexadecimal",
059: Command.SCREEN, 7);
060:
061: /** The Coarse command */
062: private Command coarseCommand = new Command("Coarse",
063: Command.SCREEN, 8);
064:
065: /** The Fine command */
066: private Command fineCommand = new Command("Fine", Command.SCREEN, 8);
067:
068: /**
069: * Construct a new Color MIDlet and initialize.
070: */
071: public Color() {
072: display = Display.getDisplay(this );
073: chooser = new ColorChooser(display.isColor());
074:
075: chooser.addCommand(exitCommand);
076: chooser.addCommand(hexCommand);
077: chooser.addCommand(fineCommand);
078: chooser.setCommandListener(this );
079:
080: chooser.setColor(0xffff00);
081: }
082:
083: /**
084: * Create the ColorChooser and make it current
085: */
086: public void startApp() {
087: display.setCurrent(chooser);
088: }
089:
090: /**
091: * Pause
092: */
093: public void pauseApp() {
094: }
095:
096: /**
097: * Destroy must cleanup everything.
098: * @param unconditional true if must destroy
099: */
100: public void destroyApp(boolean unconditional) {
101: }
102:
103: /**
104: * Respond to a commands issued on any Screen.
105: * @param c Command invoked
106: * @param s Displayable on which the command was invoked
107: */
108: public void commandAction(Command c, Displayable s) {
109: if (c == exitCommand) {
110: destroyApp(true);
111: notifyDestroyed();
112: } else if (c == decimalCommand) {
113: chooser.setRadix(10);
114: chooser.removeCommand(decimalCommand);
115: chooser.addCommand(hexCommand);
116: } else if (c == hexCommand) {
117: chooser.setRadix(16);
118: chooser.removeCommand(hexCommand);
119: chooser.addCommand(decimalCommand);
120: } else if (c == fineCommand) {
121: chooser.setDelta(4);
122: chooser.removeCommand(fineCommand);
123: chooser.addCommand(coarseCommand);
124: } else if (c == coarseCommand) {
125: chooser.setDelta(32);
126: chooser.removeCommand(coarseCommand);
127: chooser.addCommand(fineCommand);
128: }
129: }
130: }
|