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


001:        /* Menuitem.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Thu Sep 22 10:58:23     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;
020:
021:        import org.zkoss.lang.Objects;
022:
023:        import org.zkoss.xml.HTMLs;
024:        import org.zkoss.zk.ui.Component;
025:        import org.zkoss.zk.ui.UiException;
026:        import org.zkoss.zk.ui.WrongValueException;
027:        import org.zkoss.zk.ui.ext.client.Checkable;
028:
029:        import org.zkoss.zul.impl.LabelImageElement;
030:
031:        /**
032:         * sA single choice in a {@link Menupopup} element.
033:         * It acts much like a button but it is rendered on a menu.
034:         *
035:         * @author tomyeh
036:         */
037:        public class Menuitem extends LabelImageElement {
038:            private String _value = "";
039:            private String _href, _target;
040:            private boolean _autocheck, _checked;
041:            private boolean _disabled = false;
042:
043:            public Menuitem() {
044:            }
045:
046:            public Menuitem(String label) {
047:                setLabel(label);
048:            }
049:
050:            public Menuitem(String label, String src) {
051:                setLabel(label);
052:                setImage(src);
053:            }
054:
055:            public String getSclass() {
056:                String scls = super .getSclass();
057:                if (isDisabled())
058:                    return scls != null && scls.length() > 0 ? scls + " disd"
059:                            : "disd";
060:                return scls;
061:            }
062:
063:            /**
064:             * Sets whether it is disabled.
065:             * @since 3.0.1
066:             */
067:            public void setDisabled(boolean disabled) {
068:                if (_disabled != disabled) {
069:                    _disabled = disabled;
070:                    invalidate();
071:                }
072:            }
073:
074:            /** Returns whether it is disabled.
075:             * <p>Default: false.
076:             * @since 3.0.1
077:             */
078:            public boolean isDisabled() {
079:                return _disabled;
080:            }
081:
082:            /** Returns the value.
083:             * <p>Default: "".
084:             */
085:            public String getValue() {
086:                return _value;
087:            }
088:
089:            /** Sets the value.
090:             */
091:            public void setValue(String value) {
092:                if (value == null)
093:                    value = "";
094:                _value = value; //no need to update client
095:            }
096:
097:            /** Returns whether it is checked.
098:             * <p>Default: false.
099:             */
100:            public boolean isChecked() {
101:                return _checked;
102:            }
103:
104:            /** Sets whether it is checked.
105:             */
106:            public void setChecked(boolean checked) {
107:                if (_checked != checked) {
108:                    _checked = checked;
109:
110:                    final Component parent = getParent();
111:                    if (parent instanceof  Menupopup)
112:                        parent.invalidate();
113:                    //CONSIDER: to use smartUpdate instead of invalidate
114:                    //FUTURE: to support checked for top-level menuitems
115:                }
116:            }
117:
118:            /** Returns whether the menuitem check mark will update each time
119:             * the menu item is selected
120:             * <p>Default: false.
121:             */
122:            public boolean isAutocheck() {
123:                return _autocheck;
124:            }
125:
126:            /** Sets whether the menuitem check mark will update each time
127:             * the menu item is selected
128:             */
129:            public void setAutocheck(boolean autocheck) {
130:                if (_autocheck != autocheck) {
131:                    _autocheck = autocheck;
132:                    invalidate();
133:                }
134:            }
135:
136:            /** Returns the href.
137:             * <p>Default: null. If null, the button has no function unless you
138:             * specify the onClick handler.
139:             */
140:            public String getHref() {
141:                return _href;
142:            }
143:
144:            /** Sets the href.
145:             */
146:            public void setHref(String href) throws WrongValueException {
147:                if (href != null && href.length() == 0)
148:                    href = null;
149:                if (!Objects.equals(_href, href)) {
150:                    _href = href;
151:                    invalidate();
152:                }
153:            }
154:
155:            /** Returns the target frame or window.
156:             *
157:             * <p>Note: it is useful only if href ({@link #setHref}) is specified
158:             * (i.e., use the onClick listener).
159:             *
160:             * <p>Default: null.
161:             */
162:            public String getTarget() {
163:                return _target;
164:            }
165:
166:            /** Sets the target frame or window.
167:             * @param target the name of the frame or window to hyperlink.
168:             */
169:            public void setTarget(String target) {
170:                if (target != null && target.length() == 0)
171:                    target = null;
172:
173:                if (!Objects.equals(_target, target)) {
174:                    _target = target;
175:                    smartUpdate("target", _target);
176:                }
177:            }
178:
179:            /** Returns whether this is an top-level menu, i.e., not owning
180:             * by another {@link Menupopup}.
181:             */
182:            public boolean isTopmost() {
183:                return !(getParent() instanceof  Menupopup);
184:            }
185:
186:            //-- Super --//
187:            public String getOuterAttrs() {
188:                final String attrs = super .getOuterAttrs();
189:                boolean topmost = isTopmost();
190:                if (!topmost && !_autocheck && !_disabled)
191:                    return attrs;
192:
193:                final StringBuffer sb = new StringBuffer(64).append(attrs);
194:                if (topmost)
195:                    sb.append(" z.top=\"true\"");
196:                HTMLs.appendAttribute(sb, "z.disd", isDisabled());
197:                if (_autocheck) {
198:                    sb.append(" z.autock=\"true\"");
199:                    if (_checked)
200:                        sb.append(" z.checked=\"true\"");
201:                }
202:                return sb.toString();
203:            }
204:
205:            protected String getRealStyle() {
206:                final String style = super .getRealStyle();
207:                return isTopmost() ? style
208:                        + "padding-left:4px;padding-right:4px;" : style;
209:            }
210:
211:            //-- Component --//
212:            public void setParent(Component parent) {
213:                if (parent != null && !(parent instanceof  Menupopup)
214:                        && !(parent instanceof  Menubar))
215:                    throw new UiException("Unsupported parent for menuitem: "
216:                            + parent);
217:                super .setParent(parent);
218:            }
219:
220:            /** Not childable. */
221:            public boolean isChildable() {
222:                return false;
223:            }
224:
225:            //-- ComponentCtrl --//
226:            protected Object newExtraCtrl() {
227:                return new ExtraCtrl();
228:            }
229:
230:            /** A utility class to implement {@link #getExtraCtrl}.
231:             * It is used only by component developers.
232:             */
233:            protected class ExtraCtrl extends LabelImageElement.ExtraCtrl
234:                    implements  Checkable {
235:                //-- Checkable --//
236:                public void setCheckedByClient(boolean checked) {
237:                    setChecked(checked);
238:                }
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.