Source Code Cross Referenced for ImageItemLFImpl.java in  » 6.0-JDK-Modules » j2me » javax » 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 » 6.0 JDK Modules » j2me » javax.microedition.lcdui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        /**
030:         * Platform widget look and feel of <code>ImageItem</code>.
031:         */
032:        class ImageItemLFImpl extends ItemLFImpl implements  ImageItemLF {
033:
034:            /**
035:             * Creates look &amp; feel for an <code>ImageItem</code>.
036:             *
037:             * @param imageItem the <code>ImageItem</code> associated with this 
038:             *                  look &amp; feel
039:             */
040:            ImageItemLFImpl(ImageItem imageItem) {
041:                super (imageItem);
042:
043:                ImageData imageData = null;
044:                if (imageItem != null) {
045:                    Image image = imageItem.immutableImg;
046:                    if (image != null) {
047:                        imageData = image.getImageData();
048:                    }
049:                }
050:
051:                this .imgItem = imageItem;
052:
053:                this .itemImageData = imageData;
054:
055:                // when no commands are added, the actual appearance
056:                // is PLAIN; the actual appearance will be the same
057:                // as appearance set in ImageItem if a command is added
058:                // to this ImageItem
059:                appearanceMode = Item.PLAIN;
060:            }
061:
062:            // *****************************************************
063:            //  Public methods (ImageItemLF impl)
064:            // *****************************************************
065:
066:            /**
067:             * Notifies L&amp;F of an image change in the corresponding 
068:             * <code>ImageItem</code>.
069:             *
070:             * @param img the new image set in the <code>ImageItem</code>
071:             */
072:            public void lSetImage(Image img) {
073:                // Only update native resource if it exists.
074:                if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
075:                    ImageData imageData = null;
076:                    if (img != null) {
077:                        imageData = img.getImageData();
078:                    }
079:                    setContent0(nativeId, imageData, imgItem.altText,
080:                            appearanceMode);
081:                }
082:                lRequestInvalidate(true, true);
083:            }
084:
085:            /**
086:             * Notifies L&amp;F of an alternative text change
087:             * in the corresponding <code>ImageItem</code>.
088:             *
089:             * @param altText the new alternative text set in the 
090:             *                <code>ImageItem</code>
091:             */
092:            public void lSetAltText(String altText) {
093:                // Only update native resource if it exists.
094:                if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
095:                    setContent0(nativeId, itemImageData, altText,
096:                            appearanceMode);
097:                }
098:                lRequestInvalidate(true, true);
099:            }
100:
101:            /**
102:             * Notifies L&amp;F of a command addition in the corresponding 
103:             * <code>ImageItem</code>.
104:             *
105:             * @param cmd the newly added command
106:             * @param i the index of the added command in the <code>ImageItem</code>'s
107:             *        commands[] array
108:             */
109:            public void lAddCommand(Command cmd, int i) {
110:                super .lAddCommand(cmd, i);
111:
112:                if ((imgItem.numCommands >= 1)
113:                        && (appearanceMode == Item.PLAIN)) {
114:                    appearanceMode = imgItem.appearanceMode == Item.BUTTON ? Item.BUTTON
115:                            : Item.HYPERLINK;
116:                    if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
117:                        setContent0(nativeId, itemImageData, imgItem.altText,
118:                                appearanceMode);
119:                    }
120:                    lRequestInvalidate(true, true);
121:                }
122:            }
123:
124:            /**
125:             * Notifies L&amp;F of a command removal in the corresponding 
126:             * <code>ImageItem</code>.
127:             *
128:             * @param cmd the newly removed command
129:             * @param i the index of the removed command in the 
130:             *          <code>ImageItem</code>'s commands[] array
131:             */
132:            public void lRemoveCommand(Command cmd, int i) {
133:                super .lRemoveCommand(cmd, i);
134:
135:                // restore the value of the original appearanceMode
136:                if (imgItem.numCommands < 1) {
137:                    appearanceMode = Item.PLAIN;
138:                    if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
139:                        setContent0(nativeId, itemImageData, imgItem.altText,
140:                                appearanceMode);
141:                    }
142:                    lRequestInvalidate(true, true);
143:                }
144:            }
145:
146:            // *****************************************************
147:            //  Package private methods
148:            // *****************************************************
149:            /**
150:             * Create native resource for current <code>ImageItem</code>.
151:             * Override function in <code>ItemLFImpl</code>.
152:             *
153:             * @param ownerId Owner screen's native resource id
154:             */
155:            void createNativeResource(int ownerId) {
156:                nativeId = createNativeResource0(ownerId, imgItem.label,
157:                        imgItem.layout, itemImageData, imgItem.altText,
158:                        appearanceMode);
159:            }
160:
161:            // *****************************************************
162:            //  Private methods
163:            // *****************************************************
164:
165:            /**
166:             * Determine if this <code>Item</code> should have a newline before it.
167:             *
168:             * @return <code>true</code> if it should have a newline before
169:             */
170:            boolean equateNLB() {
171:                // MIDP1.0 already had an ability to set LAYOUT_NEWLINE_BEFORE.
172:                // Hence there is no need to check for LAYOUT_2 (as in StringItem)
173:                if (super .equateNLB()) {
174:                    return true;
175:                }
176:
177:                // LAYOUT_NEWLINE_BEFORE is not set but LAYOUT_2 is set
178:                // which means that items could be positioned side by side
179:                if ((imgItem.layout & Item.LAYOUT_2) == Item.LAYOUT_2) {
180:                    return false;
181:                }
182:
183:                // LAYOUT_2 was not set, hence we need to provide backward 
184:                // compatibility with MIDP1.0 where any ImageItem with a 
185:                // non-null label would go on a new line.
186:                return imgItem.label != null && imgItem.label.length() > 0;
187:            }
188:
189:            /**
190:             * Called by event delivery to notify an ItemLF in current FormLF
191:             * of a change in its peer state.
192:             * Handle special gesture of default command.
193:             *
194:             * @param hint <code>-1</code> signals that user performed 
195:             *             the special gesture of default command
196:             *
197:             * @return always <code>false</code> so <code>ItemStateListener</code> 
198:             *         will not be notified
199:             */
200:            boolean uCallPeerStateChanged(int hint) {
201:                // activate default command if hint is -1
202:                if (hint == -1) {
203:
204:                    Command defaultCommand;
205:                    ItemCommandListener commandListener;
206:
207:                    synchronized (Display.LCDUILock) {
208:
209:                        defaultCommand = imgItem.defaultCommand;
210:                        commandListener = imgItem.commandListener;
211:                    }
212:
213:                    if (defaultCommand != null && commandListener != null) {
214:
215:                        // Protect from any unexpected application exceptions
216:                        try {
217:                            synchronized (Display.calloutLock) {
218:                                commandListener.commandAction(defaultCommand,
219:                                        imgItem);
220:                            }
221:                        } catch (Throwable thr) {
222:                            Display.handleThrowable(thr);
223:                        }
224:                    }
225:                }
226:
227:                // Indicate to Form to not notify ItemStateListener
228:                return false;
229:            }
230:
231:            /**
232:             * KNI function that creates native resource for current 
233:             * <code>ImageItem</code>.
234:             *
235:             * @param ownerId Owner screen's native resource id 
236:             *                (<code>MidpDisplayable *</code>)
237:             * @param label label to be used for this <code>Item</code>
238:             * @param layout layout directive associated with this <code>Item</code>
239:             * @param imageData ImageData to be used for this <code>ImageItem</code>
240:             * @param altText alternative text to be used for this 
241:             *                <code>ImageItem</code>
242:             * @param appearanceMode should be <code>PLAIN</code>, 
243:             *                       <code>HYPERLINK</code> or <code>BUTTON</code>
244:             *
245:             * @return native resource id (<code>MidpItem *</code>) of this 
246:             *         <code>ImageItem</code>
247:             */
248:            private native int createNativeResource0(int ownerId, String label,
249:                    int layout, ImageData imageData, String altText,
250:                    int appearanceMode);
251:
252:            /**
253:             * KNI function that sets image on the native resource corresponding
254:             * to the current <code>ImageItem</code>.
255:             *
256:             * @param nativeId native resource id for this item
257:             * @param imgData <code>ImageData</code> instance associated with 
258:             *        a new <code>Image</code> set on the current 
259:             *        <code>ImageItem</code>
260:             * @param text new alternative text set on the current 
261:             *             <code>ImageItem</code>
262:             * @param appearanceMode the actual appearance mode to be used
263:             */
264:            private native void setContent0(int nativeId, ImageData imageData,
265:                    String text, int appearanceMode);
266:
267:            /** 
268:             * The <code>ImageItem</code> associated with this view.
269:             */
270:            private final ImageItem imgItem;
271:
272:            /** 
273:             * The <code>ImageData</code> associated with the item.
274:             */
275:            private final ImageData itemImageData;
276:
277:            /**
278:             * Appearance mode.
279:             * The actual appearance of an <code>ImageItem</code> could be different to
280:             * the one set in <code>ImageItem</code>. An <code>ImageItem</code> 
281:             * created with <code>PLAIN</code> appearance will look like a 
282:             * <code>HYPERLINK</code> if commands were added. 
283:             */
284:            private int appearanceMode;
285:
286:        } // ImageItemLFImpl
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.