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.obex.demo;
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.lcdui.List;
039: import javax.microedition.midlet.MIDlet;
040:
041: /**
042: * @version
043: */
044: public final class ObexDemoMIDlet extends MIDlet implements
045: CommandListener {
046: /** A list of menu items */
047: private static final String[] elements = { "Send Image",
048: "Receive Image" };
049:
050: /** Soft button for exiting the demo. */
051: private Command exitCommand = new Command("Exit", Command.EXIT, 1);
052:
053: /** Soft button for launching a sender or receiver of images . */
054: private Command startCommand = new Command("Start", Command.ITEM, 1);
055:
056: /** A menu list instance */
057: private final List menuList = new List("OBEX Demo", List.IMPLICIT,
058: elements, null);
059:
060: /** A GUI part of OBEX client which send image to server */
061: private GUIImageSender imageSender = null;
062:
063: /** A GUI part of OBEX server which receive image from client */
064: private GUIImageReceiver imageReceiver = null;
065:
066: /** Shows that demo was paused */
067: private boolean isPaused;
068:
069: public ObexDemoMIDlet() {
070: menuList.setCommandListener(this );
071: menuList.addCommand(exitCommand);
072: menuList.addCommand(startCommand);
073: }
074:
075: public boolean isPaused() {
076: return isPaused;
077: }
078:
079: public void startApp() {
080: isPaused = false;
081: show();
082: }
083:
084: public void pauseApp() {
085: isPaused = true;
086: }
087:
088: public void destroyApp(boolean unconditional) {
089: if (imageReceiver != null) {
090: imageReceiver.stop();
091: }
092:
093: if (imageSender != null) {
094: imageSender.stop();
095: }
096: }
097:
098: public void commandAction(Command c, Displayable s) {
099: if (c == exitCommand) {
100: destroyApp(true);
101: notifyDestroyed();
102: } else if ((c == startCommand) || (c == List.SELECT_COMMAND)) {
103: switch (menuList.getSelectedIndex()) {
104: case 0:
105: imageSender = new GUIImageSender(this );
106:
107: break;
108:
109: case 1:
110: imageReceiver = new GUIImageReceiver(this );
111:
112: break;
113:
114: default:
115: System.err.println("Unexpected choice...");
116:
117: break;
118: }
119: }
120: }
121:
122: /**
123: * Shows main menu of MIDlet on the screen.
124: */
125: void show() {
126: Display.getDisplay(this).setCurrent(menuList);
127: }
128: }
|