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


001:        /* LabelImageElement.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Tue Jul 12 12:09:00     2005, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2005 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:        package org.zkoss.zul.impl;
020:
021:        import org.zkoss.lang.Objects;
022:        import org.zkoss.util.media.Media;
023:        import org.zkoss.image.Image;
024:
025:        import org.zkoss.zk.ui.Execution;
026:        import org.zkoss.zk.ui.Desktop;
027:        import org.zkoss.zk.ui.UiException;
028:        import org.zkoss.zk.ui.ext.render.DynamicMedia;
029:
030:        /**
031:         * A HTML element with a label ({@link #getLabel})and an image ({@link #getImage}).
032:         * 
033:         * @author tomyeh
034:         */
035:        public class LabelImageElement extends LabelElement {
036:            private String _src = null;
037:            /** The image. If not null, _src is generated automatically. */
038:            private Image _image;
039:            /** Count the version of {@link #_image}. */
040:            private int _imgver;
041:
042:            /** Returns the image URI.
043:             * <p>Default: null.
044:             * <p>The same as {@link #getSrc}.
045:             */
046:            public String getImage() {
047:                return _src;
048:            }
049:
050:            /** Sets the image URI.
051:             * <p>If src is changed, the component's inner is invalidate.
052:             * Thus, you want to smart-update, you have to override this method.
053:             * <p>The same as {@link #setSrc}.
054:             */
055:            public void setImage(String src) {
056:                if (src != null && src.length() == 0)
057:                    src = null;
058:                if (!Objects.equals(_src, src)) {
059:                    _src = src;
060:                    if (_image == null)
061:                        invalidate();
062:
063:                    //_src is meaningful only if _image is null
064:                    //NOTE: Tom Yeh: 20051222
065:                    //It is possible to use smartUpdate if we always generate
066:                    //an image (with an ID) in getImgTag.
067:                    //However, it is too costly by making HTML too big, so
068:                    //we prefer to invalidate (it happens rarely)
069:                }
070:            }
071:
072:            /** Returns the src (an image URI).
073:             * <p>Default: null.
074:             * <p>The same as {@link #getImage}.
075:             */
076:            public String getSrc() {
077:                return getImage();
078:            }
079:
080:            /** Sets the src (the image URI).
081:             * <p>If src is changed, the component's inner is invalidate.
082:             * Thus, you want to smart-update, you have to override this method.
083:             * <p>The same as {@link #setImage}.
084:             */
085:            public void setSrc(String src) {
086:                setImage(src);
087:            }
088:
089:            /** Sets the content directly.
090:             * Default: null.
091:             *
092:             * @param image the image to display. If not null, it has higher
093:             * priority than {@link #getSrc}.
094:             */
095:            public void setImageContent(Image image) {
096:                if (image != _image) {
097:                    _image = image;
098:                    if (_image != null)
099:                        ++_imgver; //enforce browser to reload image
100:                    invalidate();
101:                }
102:            }
103:
104:            /** Returns the content set by {@link #setImageContent}.
105:             * <p>Note: it won't fetch what is set thru by {@link #setSrc}.
106:             * It simply returns what is passed to {@link #setImageContent}.
107:             */
108:            public Image getImageContent() {
109:                return _image;
110:            }
111:
112:            /** Returns whether the image is available.
113:             * In other words, it return true if {@link #setImage} or
114:             * {@link #setImageContent} is called with non-null.
115:             */
116:            public boolean isImageAssigned() {
117:                return _src != null || _image != null;
118:            }
119:
120:            /** Returns the HTML IMG tag for the image part, or null
121:             * if no image is assigned ({@link #isImageAssigned})
122:             *
123:             * <p>Used only for component template, not for application developers.
124:             *
125:             * <p>Note: the component template shall use this method to
126:             * generate the HTML tag, instead of using {@link #getImage}.
127:             */
128:            public String getImgTag() {
129:                if (_src == null && _image == null)
130:                    return null;
131:
132:                final StringBuffer sb = new StringBuffer(64).append(
133:                        "<img src=\"").append(_image != null ? getContentSrc() : //already encoded
134:                        getDesktop().getExecution().encodeURL(_src)).append(
135:                        "\" align=\"absmiddle\"/>");
136:
137:                final String label = getLabel();
138:                if (label != null && label.length() > 0)
139:                    sb.append(' ');
140:
141:                return sb.toString(); //keep a space
142:            }
143:
144:            /** Returns the encoded URL for the current image content.
145:             * Don't call this method unless _image is not null;
146:             *
147:             * <p>Used only for component template, not for application developers.
148:             */
149:            private String getContentSrc() {
150:                return Utils.getDynamicMediaURI(this , _imgver,
151:                        _image.getName(), _image.getFormat());
152:            }
153:
154:            //-- ComponentCtrl --//
155:            protected Object newExtraCtrl() {
156:                return new ExtraCtrl();
157:            }
158:
159:            /** A utility class to implement {@link #getExtraCtrl}.
160:             * It is used only by component developers.
161:             */
162:            protected class ExtraCtrl extends LabelElement.ExtraCtrl implements 
163:                    DynamicMedia {
164:                //-- DynamicMedia --//
165:                public Media getMedia(String pathInfo) {
166:                    return _image;
167:                }
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.