Source Code Cross Referenced for ListModelArray.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:        /* ListModelArray.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Mon Feb 26 17:02:14     2007, 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:        package org.zkoss.zul;
020:
021:        import org.zkoss.zul.event.ListDataEvent;
022:        import org.zkoss.zk.ui.UiException;
023:
024:        import org.zkoss.lang.Objects;
025:        import org.zkoss.util.ArraysX;
026:        import java.util.Comparator;
027:        import java.util.Arrays;
028:        import java.util.List;
029:
030:        /**
031:         * <p>This is the {@link ListModel} as an Object array to be used with {@link Listbox}.
032:         * Change the contents of this model as an Object array would cause the associated Listbox to 
033:         * change accordingly.</p> 
034:         *
035:         * @author Henri Chen
036:         * @see ListModel
037:         * @see ListModelList
038:         * @see ListModelMap
039:         */
040:        public class ListModelArray extends AbstractListModel implements 
041:                ListModelExt, java.io.Serializable {
042:            private static final long serialVersionUID = 20070226L;
043:
044:            protected final Object[] _array;
045:
046:            /**
047:             * Creates an instance which accepts a "live" Object array as its inner array.
048:             * @param array the inner array storage
049:             * @deprecated As of release 2.4.0, replaced by {@link #ListModelArray(Object[],boolean)}
050:             */
051:            public static ListModelArray instance(Object[] array) {
052:                return new ListModelArray(array, true);
053:            }
054:
055:            /**
056:             * Constructor
057:             *
058:             * @param array the array to represent
059:             * @param live whether to have a 'live' {@link ListModel} on top of
060:             * the specified array.
061:             * If false, the content of the specified array is copied.
062:             * If true, this object is a 'facade' of the specified array,
063:             * i.e., when you add or remove items from this {@link ListModelArray},
064:             * the inner "live" array would be changed accordingly.
065:             *
066:             * However, it is not a good idea to modify <code>array</code>
067:             * if it is passed to this method with live is true,
068:             * since {@link Listbox} is not smart enough to hanle it.
069:             * Instead, modify it thru this object.
070:             * @since 2.4.0
071:             */
072:            public ListModelArray(Object[] array, boolean live) {
073:                _array = live ? array : (Object[]) ArraysX.clone(array);
074:            }
075:
076:            /**
077:             * Constructor.
078:             * It mades a copy of the specified array (i.e., not live).
079:             * @param src the source array used to initialize this ListModelArray.
080:             */
081:            public ListModelArray(Object[] src) {
082:                _array = (Object[]) ArraysX.clone(src);
083:            }
084:
085:            /**
086:             * Constructor.
087:             * @param size the array size.
088:             */
089:            public ListModelArray(int size) {
090:                _array = new Object[size];
091:            }
092:
093:            /**
094:             * Constructor.
095:             * It mades a copy of the specified list (i.e., not live).
096:             * @since 2.4.1
097:             */
098:            public ListModelArray(List list) {
099:                _array = list.toArray(new Object[list.size()]);
100:            }
101:
102:            /** Get the value of this ListModelArray at specified index.
103:             * @param index the array index to be get value.
104:             */
105:            public Object get(int index) {
106:                return getElementAt(index);
107:            }
108:
109:            /** Change content of the Array at specified index.
110:             * @param index the array index to be set the new value.
111:             */
112:            public void set(int index, Object value) {
113:                _array[index] = value;
114:                fireEvent(ListDataEvent.CONTENTS_CHANGED, index, index);
115:            }
116:
117:            /**
118:             * Get the inner real Object[].
119:             * @since 2.4.0
120:             */
121:            public Object[] getInnerArray() {
122:                return _array;
123:            }
124:
125:            /** Returns the index of the specified element.
126:             */
127:            public int indexOf(Object elm) {
128:                for (int j = 0; j < _array.length; ++j) {
129:                    if (Objects.equals(elm, _array[j])) {
130:                        return j;
131:                    }
132:                }
133:                return -1;
134:            }
135:
136:            //-- ListModel --//
137:            public int getSize() {
138:                return _array.length;
139:            }
140:
141:            public Object getElementAt(int j) {
142:                return _array[j];
143:            }
144:
145:            //-- ListModelExt --//
146:            /** Sorts the data.
147:             *
148:             * @param cmpr the comparator.
149:             * @param ascending whether to sort in the ascending order.
150:             * It is ignored since this implementation uses cmprt to compare.
151:             */
152:            public void sort(Comparator cmpr, final boolean ascending) {
153:                Arrays.sort(_array, cmpr);
154:                fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1);
155:            }
156:
157:            //Object//
158:            public boolean equals(Object o) {
159:                return _array
160:                        .equals(o instanceof  ListModelArray ? ((ListModelArray) o)._array
161:                                : o);
162:            }
163:
164:            public int hashCode() {
165:                return _array.hashCode();
166:            }
167:
168:            public String toString() {
169:                return Objects.toString(_array);
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.