Source Code Cross Referenced for GUIImageReceiver.java in  » IDE-Netbeans » mobility » example » obex » demo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » mobility » example.obex.demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.Alert;
035:        import javax.microedition.lcdui.Command;
036:        import javax.microedition.lcdui.CommandListener;
037:        import javax.microedition.lcdui.Display;
038:        import javax.microedition.lcdui.Displayable;
039:        import javax.microedition.lcdui.Form;
040:        import javax.microedition.lcdui.Gauge;
041:        import javax.microedition.lcdui.Image;
042:        import javax.microedition.lcdui.ImageItem;
043:        import javax.microedition.lcdui.Item;
044:        import javax.microedition.lcdui.StringItem;
045:
046:        /**
047:         * @version
048:         */
049:        final class GUIImageReceiver implements  CommandListener {
050:            /** Shows if debug prints should be done. */
051:            private static final boolean DEBUG = false;
052:
053:            /** DEBUG only: keeps the class name for debug. */
054:            private static final String cn = "GUIImageReceiver";
055:
056:            /** Keeps a reference to a parent MIDlet. */
057:            private ObexDemoMIDlet parent;
058:
059:            /** Soft button for stopping download and returning to the mane screen. */
060:            private Command stopCommand = new Command("Stop", Command.BACK, 1);
061:
062:            /** Soft button for returning to the main screen of demo. */
063:            private Command backCommand = new Command("Back", Command.STOP, 1);
064:
065:            /** Soft button for confirm Image downloading. */
066:            private Command confirmCommand = new Command("Yes", Command.OK, 1);
067:
068:            /** Soft button for reject Image downloading. */
069:            private Command rejectCommand = new Command("No", Command.CANCEL, 1);
070:
071:            /** StringItem shows string about connection waiting state. */
072:            private StringItem waitingItem = new StringItem(
073:                    "Waiting for connection", "");
074:
075:            /** ImageItem shows image on the screen */
076:            private ImageItem imageItem = new ImageItem("Image ...", null,
077:                    Item.LAYOUT_CENTER, null);
078:
079:            /** Gauge to indicate progress of downloading process. */
080:            private Gauge downloadingItem = new Gauge("Downloading Image ...",
081:                    false, 256, 0);
082:
083:            /** Form to show current state of receiver and to show a picture. */
084:            private Form receiverForm = new Form("Receive Image");
085:
086:            /** synchronization object to prevent downloading during permission alert.*/
087:            private Object alertLock = new Object();
088:
089:            /** Indicate that user choose to download image or not. */
090:            private boolean download = false;
091:
092:            /** Indicate that user has made a choose. */
093:            private boolean choose = false;
094:
095:            /** Reference to Obex receiver part */
096:            private ObexImageReceiver obexReceiver = null;
097:
098:            /** Constructor initialize receiverForm to show states of receiving. */
099:            GUIImageReceiver(ObexDemoMIDlet parent) {
100:                this .parent = parent;
101:                obexReceiver = new ObexImageReceiver(this );
102:                waitingItem.setLayout(Item.LAYOUT_CENTER);
103:                receiverForm.append(waitingItem);
104:                receiverForm.addCommand(backCommand);
105:                receiverForm.setCommandListener(this );
106:                Display.getDisplay(parent).setCurrent(receiverForm);
107:                (new Thread(obexReceiver)).start();
108:            }
109:
110:            /**
111:             * Responds to commands used on this displayable.
112:             *
113:             * @param c command object source of action.
114:             * @param d screen object containing the item the action was performed on.
115:             */
116:            public void commandAction(Command c, Displayable d) {
117:                if (c == stopCommand) {
118:                    obexReceiver.stop(false);
119:
120:                    return;
121:                } else if (c == backCommand) {
122:                    obexReceiver.stop(true);
123:                    parent.show();
124:
125:                    return;
126:                } else if (c == confirmCommand) {
127:                    synchronized (alertLock) {
128:                        download = true;
129:                        choose = true;
130:                        alertLock.notify();
131:                    }
132:                } else if (c == rejectCommand) {
133:                    synchronized (alertLock) {
134:                        download = false;
135:                        choose = true;
136:                        alertLock.notify();
137:                    }
138:                }
139:            }
140:
141:            /** Ascs user to download image. */
142:            boolean askPermission(String imageName, int imageLength) {
143:                boolean download = false;
144:
145:                // ask permission to download image
146:                Alert alert = new Alert("Connected!",
147:                        "Incoming image:\nName   = " + imageName
148:                                + "\nLength = " + imageLength
149:                                + "\nWould you like to receive it ?", null,
150:                        null);
151:                alert.setTimeout(Alert.FOREVER);
152:                alert.addCommand(confirmCommand);
153:                alert.addCommand(rejectCommand);
154:                alert.setCommandListener(this );
155:                Display.getDisplay(parent).setCurrent(alert);
156:
157:                synchronized (alertLock) {
158:                    if (choose == false) {
159:                        try {
160:                            alertLock.wait();
161:                        } catch (InterruptedException ie) {
162:                            // don't wait then
163:                        }
164:                    }
165:
166:                    choose = false;
167:                    download = this .download;
168:                }
169:
170:                Display.getDisplay(parent).setCurrent(receiverForm);
171:
172:                return download;
173:            }
174:
175:            /**
176:             * Shows string with waiting for connection message.
177:             */
178:            void showWaiting() {
179:                receiverForm.set(0, waitingItem);
180:                receiverForm.removeCommand(stopCommand);
181:                receiverForm.addCommand(backCommand);
182:                downloadingItem.setValue(0);
183:            }
184:
185:            /**
186:             * Shows progress bar of image downloading
187:             */
188:            void showProgress(int maxValue) {
189:                downloadingItem.setValue(0);
190:                downloadingItem.setMaxValue(maxValue);
191:                receiverForm.set(0, downloadingItem);
192:                receiverForm.removeCommand(backCommand);
193:                receiverForm.addCommand(stopCommand);
194:            }
195:
196:            /**
197:             * Update progress of image downloading
198:             */
199:            void updateProgress(int value) {
200:                downloadingItem.setValue(value);
201:            }
202:
203:            /**
204:             * Shows downloaded image.
205:             */
206:            void showImage(byte[] imageData) {
207:                Image image = Image.createImage(imageData, 0, imageData.length);
208:                imageItem.setImage(image);
209:                receiverForm.set(0, imageItem);
210:                receiverForm.removeCommand(stopCommand);
211:                receiverForm.addCommand(backCommand);
212:            }
213:
214:            /**
215:             * Shows alert with "not ready" message.
216:             */
217:            void canNotConnectMessage() {
218:                Alert alert = new Alert("Warning",
219:                        "Can not connect to any sender", null, null);
220:                alert.setTimeout(5000);
221:                Display.getDisplay(parent).setCurrent(alert, receiverForm);
222:            }
223:
224:            /**
225:             * Shows alert with "stop" message.
226:             */
227:            void stopMessage() {
228:                Alert alert = new Alert("Warning",
229:                        "Sender stopped image uploading", null, null);
230:                alert.setTimeout(5000);
231:                Display.getDisplay(parent).setCurrent(alert, receiverForm);
232:            }
233:
234:            /**
235:             * Stops receiving process in OBEX part.
236:             */
237:            void stop() {
238:                obexReceiver.stop(true);
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.