Source Code Cross Referenced for Listitem.java in  » Ajax » zk » org » zkoss » mil » 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 » Ajax » zk » org.zkoss.mil 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Listitem.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Jun 15, 2007 10:17:32 AM, Created by henrichen
010:        }}IS_NOTE
011:
012:        Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:
020:        package org.zkoss.mil;
021:
022:        import org.zkoss.lang.Objects;
023:        import org.zkoss.lang.Strings;
024:        import org.zkoss.xml.HTMLs;
025:        import org.zkoss.zk.ui.Component;
026:        import org.zkoss.zk.ui.Desktop;
027:        import org.zkoss.zk.ui.UiException;
028:
029:        /**
030:         * The Listitem that can be located under Listbox only.
031:         * 
032:         * @author henrichen
033:         */
034:        public class Listitem extends MilComponent {
035:            private static final long serialVersionUID = 200706151103L;
036:
037:            private boolean _selected;
038:            private String _label;
039:            private Object _value;
040:            private String _src;
041:            /** The image. If not null, _src is generated automatically. */
042:            private org.zkoss.image.Image _image;
043:            /** Count the version of {@link #_image}. */
044:            private int _imgver;
045:
046:            public Listitem() {
047:            }
048:
049:            public Listitem(String label) {
050:                setLabel(label);
051:            }
052:
053:            public Listitem(String label, Object value) {
054:                setLabel(label);
055:                setValue(value);
056:            }
057:
058:            /** Returns the list box that it belongs to.
059:             */
060:            public Listbox getListbox() {
061:                return (Listbox) getParent();
062:            }
063:
064:            /** 
065:             * Get the label of this Item.
066:             * 
067:             * @return the label of this Item.
068:             */
069:            public String getLabel() {
070:                return _label;
071:            }
072:
073:            /**
074:             * Set the new label of this Item.
075:             * @param label the new label of this Item.
076:             */
077:            public void setLabel(String label) {
078:                if (label != null && label.length() == 0) {
079:                    label = null;
080:                }
081:                if (!Objects.equals(_label, label)) {
082:                    _label = label;
083:                    smartUpdate("lb", encodeString(label));
084:                }
085:            }
086:
087:            /** Sets whether it is selected.
088:             */
089:            public void setSelected(boolean selected) {
090:                if (_selected != selected) {
091:                    final Listbox listbox = (Listbox) getParent();
092:                    if (listbox != null) {
093:                        //Note: we don't update it here but let its parent does the job
094:                        listbox.toggleItemSelection(this );
095:                    } else {
096:                        _selected = selected;
097:                    }
098:                }
099:            }
100:
101:            public boolean isSelected() {
102:                return _selected;
103:            }
104:
105:            /*package*/void setSelectedDirectly(boolean b) {
106:                _selected = b;
107:            }
108:
109:            public void setValue(Object value) {
110:                _value = value;
111:            }
112:
113:            public Object getValue() {
114:                return _value;
115:            }
116:
117:            /** Returns the image source of this Listitem, or null if no image.
118:             */
119:            public String getSrc() {
120:                return _src;
121:            }
122:
123:            /** Sets theimage soruce of this Listitem.
124:             * @param src the image source
125:             */
126:            public void setSrc(String src) {
127:                setImage(src);
128:            }
129:
130:            /** Returns the image source of this Listitem, or null if no image.
131:             */
132:            public String getImage() {
133:                return _src;
134:            }
135:
136:            /** Sets the image source of this Listitem.
137:             * @param image the image source
138:             */
139:            public void setImage(String image) {
140:                if (image != null && image.length() == 0)
141:                    image = null;
142:
143:                if (!Objects.equals(_src, image)) {
144:                    _src = image;
145:                    if (_image == null) {
146:                        smartUpdate("im", getEncodedSrc());
147:                    }
148:                    //_src is meaningful only if _image is null
149:                }
150:            }
151:
152:            /** Returns the encoded src ({@link #getSrc}).
153:             */
154:            private String getEncodedSrc() {
155:                final Desktop dt = getDesktop(); //it might not belong to any desktop
156:                return _image != null ? getContentSrc() : //already encoded
157:                        dt != null ? dt.getExecution().encodeURL(
158:                                _src != null ? _src : "~./img/spacer.gif") : "";
159:            }
160:
161:            /** Sets the content directly.
162:             * Default: null.
163:             *
164:             * @param image the image to display. If not null, it has higher
165:             * priority than {@link #getSrc}.
166:             */
167:            public void setImageContent(org.zkoss.image.Image image) {
168:                if (image != _image) {
169:                    _image = image;
170:                    if (_image != null)
171:                        ++_imgver; //enforce browser to reload image
172:                    smartUpdate("im", getEncodedSrc());
173:                }
174:            }
175:
176:            /** Returns the content set by {@link #setImageContent}.
177:             * <p>Note: it won't fetch what is set thru by {@link #setSrc}.
178:             * It simply returns what is passed to {@link #setImageContent}.
179:             */
180:            public org.zkoss.image.Image getImageContent() {
181:                return _image;
182:            }
183:
184:            /** Returns the encoded URL for the current image content.
185:             * Don't call this method unless _image is not null;
186:             *
187:             * <p>Used only for component template, not for application developers.
188:             */
189:            private String getContentSrc() {
190:                final Desktop desktop = getDesktop();
191:                if (desktop == null)
192:                    return ""; //no avail at client
193:
194:                final StringBuffer sb = new StringBuffer(64).append('/');
195:                Strings.encode(sb, _imgver);
196:                final String name = _image.getName();
197:                final String format = _image.getFormat();
198:                if (name != null || format != null) {
199:                    sb.append('/');
200:                    boolean bExtRequired = true;
201:                    if (name != null && name.length() != 0) {
202:                        sb.append(name);
203:                        bExtRequired = name.lastIndexOf('.') < 0;
204:                    } else {
205:                        sb.append(getId());
206:                    }
207:                    if (bExtRequired && format != null)
208:                        sb.append('.').append(format);
209:                }
210:                return desktop.getDynamicMediaURI(this , sb.toString()); //already encoded
211:            }
212:
213:            //--Component--//
214:            public void setParent(Component parent) {
215:                if (parent != null
216:                        && !(parent instanceof  org.zkoss.mil.Listbox)) {
217:                    throw new UiException("Unsupported parent for Listitem: "
218:                            + this  + ", parent: " + parent);
219:                }
220:                super .setParent(parent);
221:            }
222:
223:            /** Not childable. */
224:            public boolean isChildable() {
225:                return false;
226:            }
227:
228:            public String getInnerAttrs() {
229:                final StringBuffer sb = new StringBuffer(64);
230:                if (getLabel() != null) {
231:                    HTMLs.appendAttribute(sb, "lb", getLabel());
232:                }
233:                if (getImage() != null) {
234:                    HTMLs.appendAttribute(sb, "im", getEncodedSrc());
235:                }
236:                return sb.toString();
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.