Source Code Cross Referenced for AbstractInfoScreen.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » microedition » lcdui » 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 » vmd.analyzer » org.netbeans.microedition.lcdui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        /*
043:         * AbstractInfoScreen.java
044:         *
045:         * Created on August 26, 2005, 1:53 PM
046:         *
047:         */
048:
049:        package org.netbeans.microedition.lcdui;
050:
051:        import javax.microedition.lcdui.Alert;
052:        import javax.microedition.lcdui.Canvas;
053:        import javax.microedition.lcdui.CommandListener;
054:        import javax.microedition.lcdui.Display;
055:        import javax.microedition.lcdui.Displayable;
056:        import javax.microedition.lcdui.Font;
057:        import javax.microedition.lcdui.Graphics;
058:        import javax.microedition.lcdui.Image;
059:        import org.netbeans.microedition.lcdui.laf.ColorSchema;
060:        import org.netbeans.microedition.lcdui.laf.SystemColorSchema;
061:
062:        /**
063:         * 
064:         * An abstract class serving as a parent for SplashScreen and WaitScreen. This class provides
065:         * the basic visualization of the screen. 
066:         * 
067:         * When this screen is displayed, it can display either supplied text or image. The current implementation
068:         * shows both, text and image, centered in the middle of the display. 
069:         * 
070:         * > Please note, in previous version this component automatically switched to displayables
071:         * specified by setNextDisplayable() method, but this approach has been deprecated in favor
072:         * of using static command and calling CommandListener's commandAction() method when an action
073:         * happens. This gives the developer much higher flexibility for processing the action - it
074:         * is no longer limited to switching to another displayable, but it can do whatever developer wants.
075:         *
076:         * @author breh
077:         */
078:        public abstract class AbstractInfoScreen extends Canvas {
079:
080:            private Display display;
081:
082:            private Image image;
083:            private String text;
084:
085:            private static Font DEFAULT_TEXT_FONT = Font
086:                    .getFont(Font.FONT_STATIC_TEXT);
087:            private Font textFont = DEFAULT_TEXT_FONT;
088:
089:            private Displayable nextDisplayable;
090:            private Alert nextAlert;
091:
092:            private Displayable previousDisplayable;
093:
094:            private CommandListener commandListener;
095:
096:            private ColorSchema colorSchema;
097:
098:            /**
099:             * Creates a new instance of AbstractInfoScreen
100:             * @param display display parameter. Cannot be null
101:             * @throws java.lang.IllegalArgumentException if the display parameter is null
102:             */
103:            public AbstractInfoScreen(Display display)
104:                    throws IllegalArgumentException {
105:                this (display, null);
106:            }
107:
108:            /**
109:             * Creates a new instance of AbstractInfoScreen
110:             * @param display display parameter. Cannot be null
111:             * @param colorSchema color schema to be used for this component. If null, SystemColorSchema is used.
112:             * @throws java.lang.IllegalArgumentException if the display parameter is null
113:             */
114:            public AbstractInfoScreen(Display display, ColorSchema colorSchema) {
115:                if (display == null)
116:                    throw new IllegalArgumentException(
117:                            "Display parameter cannot be null."); // NOI18N
118:                this .display = display;
119:                setColorSchemaImpl(display, colorSchema);
120:            }
121:
122:            // properties
123:
124:            /**
125:             * Gets ColorSchema currently in use
126:             */
127:            public ColorSchema getColorSchema() {
128:                return colorSchema;
129:            }
130:
131:            /**
132:             * Sets ColorSchema
133:             */
134:            public void setColorSchema(ColorSchema colorSchema) {
135:                setColorSchemaImpl(getDisplay(), colorSchema);
136:                repaint();
137:            }
138:
139:            /**
140:             * Sets the text to be painted on the screen.
141:             * @param text text to be painter, or null if no text should be shown
142:             */
143:            public void setText(String text) {
144:                this .text = text;
145:                repaint();
146:            }
147:
148:            /**
149:             * Gets the text to be painted on the screen.
150:             * @return text
151:             */
152:            public String getText() {
153:                return this .text;
154:            }
155:
156:            /**
157:             * Gets the image to be painted on the screen.
158:             * @return image
159:             */
160:            public Image getImage() {
161:                return image;
162:            }
163:
164:            /**
165:             * Sets image to be painted on the screen. If set to null, no image
166:             * will be painted
167:             * @param image image to be painted. Can be null.
168:             */
169:            public void setImage(Image image) {
170:                this .image = image;
171:                repaint();
172:            }
173:
174:            /**
175:             * Sets the font to be used to paint the specified text. If set
176:             * to null, the default font (Font.STATIC_TEXT_FONT) will be used.
177:             * @param font font to be used to paint the text. May be null.
178:             */
179:            public void setTextFont(Font font) {
180:                if (font != null) {
181:                    this .textFont = font;
182:                } else {
183:                    this .textFont = DEFAULT_TEXT_FONT;
184:                }
185:                repaint();
186:            }
187:
188:            /**
189:             * Gets the current font used to paint the text.
190:             * @return text font
191:             */
192:            public Font getTextFont() {
193:                return textFont;
194:            }
195:
196:            /**
197:             * Gets command listener assigned to this displayable
198:             * @return command listener assigned to this component or null if there is no command listener assigned
199:             */
200:            protected final CommandListener getCommandListener() {
201:                return this .commandListener;
202:            }
203:
204:            /**
205:             * Sets command listener to this component
206:             * @param commandListener - command listener to be used
207:             */
208:            public void setCommandListener(CommandListener commandListener) {
209:                super .setCommandListener(commandListener);
210:                this .commandListener = commandListener;
211:            }
212:
213:            /**
214:             * 
215:             * Sets the displayable to be used to switch when the screen is being dismissed.
216:             *
217:             * @param nextDisplayable displayable, or null if the component should switch back
218:             * to the screen from which was displayed prior showing this component.
219:             * 
220:             * @deprecated - use static Commands and CommandListener from the actual implementation 
221:             */
222:            public void setNextDisplayable(Displayable nextDisplayable) {
223:                this .nextDisplayable = nextDisplayable;
224:            }
225:
226:            /**
227:             * Requests that the specified Alert is going to be shown in the case of
228:             * screen dismiss, and nextDisplayable be made current after the Alert is dismissed.
229:             *  <p/>
230:             * The nextDisplayable parameter cannot be Alert and in the case
231:             * nextAlert is not null, it also cannot be null.
232:             * @param nextAlert alert to be shown, or null if the component should return back to the original screen
233:             * @param nextDisplayable a displayable to be shown after the alert is being dismissed. This displayable
234:             * cannot be null if the <code>nextAlert</code> is not null and it also cannot be
235:             * Alert.
236:             * @throws java.lang.IllegalArgumentException If the nextAlert is not null and nextDisplayable is null at the same time, or
237:             * if the nextDisplayable is instance of <code>Alert</code>
238:             *
239:             * @deprecated - use static Commands and CommandListener pattern from the actual implementation class
240:             */
241:            public void setNextDisplayable(Alert nextAlert,
242:                    Displayable nextDisplayable)
243:                    throws IllegalArgumentException {
244:                if ((nextAlert != null) && (nextDisplayable == null))
245:                    throw new IllegalArgumentException(
246:                            "A nextDisplayable parameter cannot be null if the nextAlert parameter is not null.");
247:                if (nextDisplayable instanceof  Alert)
248:                    throw new IllegalArgumentException(
249:                            "nextDisplayable paremter cannot be Alert.");
250:                this .nextAlert = nextAlert;
251:                this .nextDisplayable = nextDisplayable;
252:            }
253:
254:            // protected methods
255:
256:            /**
257:             * implementation of abstract method
258:             * @param g
259:             */
260:            protected void paint(Graphics g) {
261:                // paint background based on color schema
262:                getColorSchema().paintBackground(g, true);
263:                //g.setColor(getColorSchema().getColor(Display.COLOR_BACKGROUND));
264:                //g.fillRect(0,0,g.getClipWidth(), g.getClipHeight());
265:                g.setColor(getColorSchema().getColor(Display.COLOR_FOREGROUND));
266:                g.setFont(getTextFont());
267:                final int centerX = g.getClipWidth() / 2 + g.getClipX();
268:                final int centerY = g.getClipHeight() / 2 + g.getClipY();
269:                if (image != null) {
270:                    g.drawImage(image, centerX, centerY, Graphics.HCENTER
271:                            | Graphics.VCENTER);
272:                }
273:                if (text != null) {
274:                    g.drawString(text, centerX, centerY, Graphics.HCENTER
275:                            | Graphics.BASELINE);
276:                }
277:            }
278:
279:            /**
280:             * repaints the screen whem a size has changed.
281:             */
282:            protected void sizeChanged(int w, int h) {
283:                repaint();
284:            }
285:
286:            /**
287:             * Gets the used display object
288:             * @return display object
289:             */
290:            protected Display getDisplay() {
291:                return display;
292:            }
293:
294:            /**
295:             * Gets the next displayable
296:             * @return next displayable
297:             * @deprecated - use static Commands and CommandListener pattern from the actual implementation class
298:             */
299:            protected Displayable getNextDisplayable() {
300:                return nextDisplayable;
301:            }
302:
303:            /**
304:             * gets the next alert
305:             * @return next alert
306:             * @deprecated - use static Commands and CommandListener pattern from the actual implementation class
307:             */
308:            protected Alert getNextAlert() {
309:                return nextAlert;
310:            }
311:
312:            /**
313:             * switch to the next displayable (or alert)
314:             * @deprecated - use static Commands and CommandListener pattern from the actual implementation class
315:             */
316:            protected void switchToNextDisplayable() {
317:                if (nextDisplayable != null) {
318:                    switchToDisplayable(display, nextAlert, nextDisplayable);
319:                } else if (previousDisplayable != null) {
320:                    display.setCurrent(previousDisplayable);
321:                }
322:            }
323:
324:            /**
325:             * Switch to the given displayable and alert
326:             * @param display
327:             * @param alert
328:             * @param displayable
329:             *
330:             * @deprecated - use SplashScreen.DISMISS_COMMAND or WaitScreen.SUCCESS_COMMAND in CommandListener.commandAction()
331:             * to handle this event for specific implementation of the info screen.
332:             */
333:            protected static void switchToDisplayable(Display display,
334:                    Alert alert, Displayable displayable) {
335:                if (displayable != null) {
336:                    if (alert != null) {
337:                        display.setCurrent(alert, displayable);
338:                    } else {
339:                        display.setCurrent(displayable);
340:                    }
341:                }
342:            }
343:
344:            /**
345:             * sets value of previous displayable. Implementation should always
346:             * call this super implementation when overriding this method
347:             *
348:             */
349:            protected void showNotify() {
350:                previousDisplayable = getDisplay().getCurrent();
351:                super .showNotify();
352:            }
353:
354:            /**
355:             * Sets color schema. If null, creates a new SystemColorSchema based on the display
356:             */
357:            private void setColorSchemaImpl(Display display,
358:                    ColorSchema colorSchema) {
359:                if (colorSchema != null) {
360:                    this.colorSchema = colorSchema;
361:                } else {
362:                    this.colorSchema = SystemColorSchema.getForDisplay(display);
363:                }
364:            }
365:
366:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.