Source Code Cross Referenced for Select.java in  » Sevlet-Container » jetty-modules » org » mortbay » html » 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 » Sevlet Container » jetty modules » org.mortbay.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // $Id: Select.java,v 1.7 2005/08/13 00:01:23 gregwilkins Exp $
003:        // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
004:        // ------------------------------------------------------------------------
005:        // Licensed under the Apache License, Version 2.0 (the "License");
006:        // you may not use this file except in compliance with the License.
007:        // You may obtain a copy of the License at 
008:        // http://www.apache.org/licenses/LICENSE-2.0
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:        // ========================================================================
015:
016:        package org.mortbay.html;
017:
018:        import java.util.Enumeration;
019:
020:        /* -------------------------------------------------------------------- */
021:        /** HTML select Block.
022:         * @see  org.mortbay.html.Block
023:         */
024:        public class Select extends Block {
025:            /* ----------------------------------------------------------------- */
026:            /**
027:             * @param name Name of the form element
028:             * @param multiple Whether multiple selections can be made
029:             */
030:            public Select(String name, boolean multiple) {
031:                super ("select");
032:                attribute("name", name);
033:
034:                if (multiple)
035:                    attribute("multiple");
036:            }
037:
038:            /* ----------------------------------------------------------------- */
039:            /**
040:             * @param name Name of the form element
041:             * @param multiple Whether multiple selections can be made
042:             */
043:            public Select(String name, boolean multiple, String[] options) {
044:                this (name, multiple);
045:
046:                for (int i = 0; i < options.length; i++)
047:                    add(options[i]);
048:            }
049:
050:            /* ----------------------------------------------------------------- */
051:            /** Set the number of options to display at once */
052:            public Select setSize(int size) {
053:                size(size);
054:                return this ;
055:            }
056:
057:            /* ----------------------------------------------------------------- */
058:            public Select add(Enumeration e) {
059:                while (e.hasMoreElements())
060:                    add(e.nextElement().toString());
061:                return this ;
062:            }
063:
064:            /* ----------------------------------------------------------------- */
065:            /** Add option and specify if selected.
066:             */
067:            public Composite add(Object o) {
068:                if (o instanceof  Enumeration)
069:                    this .add((Enumeration) o);
070:                else {
071:                    super .add("<option>");
072:                    super .add(o);
073:                }
074:                return this ;
075:            }
076:
077:            /* ----------------------------------------------------------------- */
078:            /** Add option and specify if selected.
079:             */
080:            public Select add(Object o, boolean selected) {
081:                if (selected)
082:                    super .add("<option selected>");
083:                else
084:                    super .add("<option>");
085:                super .add(o);
086:                return this ;
087:            }
088:
089:            /* ----------------------------------------------------------------- */
090:            /** Add an option.
091:             * @param o The name of the option (displayed in the form)
092:             * @param selected Whether the option is selected
093:             * @param value The value of this option (returned in the form content)
094:             */
095:            public Select add(Object o, boolean selected, String value) {
096:                if (selected)
097:                    super .add("<option selected value=\"" + value + "\">");
098:                else
099:                    super .add("<option value=\"" + value + "\">");
100:
101:                super .add(o);
102:
103:                return this ;
104:            }
105:
106:            /* ----------------------------------------------------------------- */
107:            /** Build a select from the given array of Strings. The values of the
108:             * select are the indexes into the array of the strings, which are used
109:             * as the labels on the selector.
110:             * @param arr The array of strings for labels
111:             * @param selected The index of the selected label, -1 for default
112:             */
113:            public Select add(String arr[], int selected) {
114:                for (int i = 0; i < arr.length; i++) {
115:                    this .add(arr[i], i == selected, Integer.toString(i));
116:                }
117:                return this ;
118:            }
119:
120:            /* ----------------------------------------------------------------- */
121:            /** Build a select from the given array of Strings. The values of the
122:             * select are the indexes into the array of the strings, which are used
123:             * as the labels on the selector.
124:             * @param arr The array of strings for labels
125:             * @param selected The index of the selected label, -1 for default
126:             */
127:            public Select add(String arr[], String selected) {
128:                for (int i = 0; i < arr.length; i++) {
129:                    this .add(arr[i], arr[i].equals(selected));
130:                }
131:                return this ;
132:            }
133:
134:            /* ----------------------------------------------------------------- */
135:            /** Utility function for multi-selectors.
136:             * <p> This function takes the result returned by a multi-select input
137:             * and produces an integer bit-set result of the selections made. It
138:             * assumes the values of the multi-select are all different powers of 2.
139:             */
140:            public static int bitsetFormResult(String result) {
141:                int i;
142:                int from = 0;
143:                int res = 0;
144:                String sres = null;
145:                while ((i = result.indexOf(' ', from)) != -1) {
146:                    sres = result.substring(from, i);
147:                    res = res | Integer.parseInt(sres);
148:                    from = i + 1;
149:                }
150:                sres = result.substring(from);
151:                res = res | Integer.parseInt(sres);
152:                return res;
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.