Source Code Cross Referenced for StringListModel.java in  » Source-Control » gruntspud » gruntspud » 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 » Source Control » gruntspud » gruntspud 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Gruntspud
003:         *
004:         *  Copyright (C) 2002 Brett Smith.
005:         *
006:         *  Written by: Brett Smith <t_magicthize@users.sourceforge.net>
007:         *
008:         *  This program is free software; you can redistribute it and/or
009:         *  modify it under the terms of the GNU Library General Public License
010:         *  as published by the Free Software Foundation; either version 2 of
011:         *  the License, or (at your option) any later version.
012:         *  This program is distributed in the hope that it will be useful,
013:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         *  GNU Library General Public License for more details.
016:         *
017:         *  You should have received a copy of the GNU Library General Public
018:         *  License along with this program; if not, write to the Free Software
019:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020:         */
021:
022:        package gruntspud;
023:
024:        import java.util.StringTokenizer;
025:        import java.util.Vector;
026:
027:        import javax.swing.AbstractListModel;
028:        import javax.swing.ComboBoxModel;
029:
030:        /**
031:         *  Description of the Class
032:         *
033:         *@author     magicthize
034:         *@created    26 May 2002
035:         */
036:        public class StringListModel extends AbstractListModel implements 
037:                ComboBoxModel {
038:            //
039:            private Object sel;
040:            private Vector strings;
041:            private boolean adjusting;
042:
043:            /**
044:             *  Constructor for the StringListModel object
045:             *
046:             *@param  stringList  Description of the Parameter
047:             */
048:            public StringListModel(String stringList, boolean noSelection) {
049:                strings = new Vector();
050:
051:                StringTokenizer t = new StringTokenizer(stringList, "|");
052:
053:                while (t.hasMoreTokens()) {
054:                    String r = t.nextToken();
055:
056:                    if (r.startsWith("&")) {
057:                        r = r.substring(1);
058:
059:                        if (!noSelection) {
060:                            sel = r;
061:                        }
062:                    }
063:
064:                    addString(r, noSelection);
065:                }
066:
067:                if ((sel == null) && (getSize() > 0) && !noSelection) {
068:                    sel = getElementAt(0);
069:                }
070:            }
071:
072:            /**
073:             * DOCUMENT ME!
074:             *
075:             * @param s DOCUMENT ME!
076:             *
077:             * @return DOCUMENT ME!
078:             */
079:            public boolean containsString(String s) {
080:                return indexOfString(s) != -1;
081:            }
082:
083:            /**
084:             * DOCUMENT ME!
085:             *
086:             * @param s DOCUMENT ME!
087:             *
088:             * @return DOCUMENT ME!
089:             */
090:            public int indexOfString(String s) {
091:                int z = getSize();
092:
093:                for (int i = 0; i < z; i++) {
094:                    if (s.equals(strings.elementAt(i).toString())) {
095:                        return i;
096:                    }
097:                }
098:
099:                return -1;
100:            }
101:
102:            /**
103:             * DOCUMENT ME!
104:             *
105:             * @return DOCUMENT ME!
106:             */
107:            public String getListAsPropertyString() {
108:                StringBuffer buf = new StringBuffer();
109:
110:                for (int i = getSize() - 1; i >= 0; i--) {
111:                    if (i != (getSize() - 1)) {
112:                        buf.append('|');
113:
114:                    }
115:                    String string = (String) getElementAt(i);
116:
117:                    if (sel == string) {
118:                        buf.append('&');
119:
120:                    }
121:                    buf.append(string);
122:                }
123:
124:                return buf.toString();
125:            }
126:
127:            /**
128:             * DOCUMENT ME!
129:             *
130:             * @param i DOCUMENT ME!
131:             *
132:             * @return DOCUMENT ME!
133:             */
134:            public Object getElementAt(int i) {
135:                return strings.elementAt(i);
136:            }
137:
138:            /**
139:             * DOCUMENT ME!
140:             *
141:             * @param string DOCUMENT ME!
142:             */
143:            public void addString(String string) {
144:                addString(string, false);
145:            }
146:
147:            /**
148:             * DOCUMENT ME!
149:             *
150:             * @param string DOCUMENT ME!
151:             * @param noSelection DOCUMENT ME!
152:             */
153:            public void addString(String string, boolean noSelection) {
154:                for (int i = 0; i < getSize(); i++) {
155:                    if (getElementAt(i).equals(string)) {
156:                        strings.removeElementAt(i);
157:
158:                        break;
159:                    }
160:                }
161:
162:                strings.insertElementAt(string, 0);
163:
164:                while (strings.size() > 20) {
165:                    strings.removeElementAt(20);
166:
167:                }
168:                if ((sel == null) && !noSelection) {
169:                    sel = (strings.size() > 0) ? getElementAt(0) : null;
170:
171:                }
172:                fireContentsChanged(this , 0, getSize());
173:            }
174:
175:            /**
176:             * DOCUMENT ME!
177:             *
178:             * @param string DOCUMENT ME!
179:             */
180:            public void removeString(String string) {
181:                int idx = indexOfString(string);
182:
183:                if (idx != -1) {
184:                    strings.removeElementAt(idx);
185:                    fireIntervalRemoved(this , idx, idx);
186:
187:                    if ((getSelectedItem() != null)
188:                            && getSelectedItem().equals(string)
189:                            && (getSize() > 0)) {
190:                        setSelectedItem(getElementAt(0));
191:                    }
192:                }
193:            }
194:
195:            /**
196:             * DOCUMENT ME!
197:             *
198:             * @return DOCUMENT ME!
199:             */
200:            public int getSize() {
201:                return strings.size();
202:            }
203:
204:            /**
205:             * DOCUMENT ME!
206:             *
207:             * @return DOCUMENT ME!
208:             */
209:            public Object getSelectedItem() {
210:                return sel;
211:            }
212:
213:            /**
214:             * DOCUMENT ME!
215:             *
216:             * @param o DOCUMENT ME!
217:             */
218:            public void setSelectedItem(Object o) {
219:                Object old = sel;
220:                this .sel = o;
221:
222:                if (sel != old) {
223:                    adjusting = true;
224:                    fireContentsChanged(this , 0, getSize());
225:                    adjusting = false;
226:                }
227:            }
228:
229:            public boolean isAdjusting() {
230:                return adjusting;
231:            }
232:
233:            /**
234:             * DOCUMENT ME!
235:             *
236:             * @param stringListPropertyString DOCUMENT ME!
237:             *
238:             * @return DOCUMENT ME!
239:             */
240:            public static String getSelectedItemForStringListPropertyString(
241:                    String stringListPropertyString) {
242:                return (String) (new StringListModel(stringListPropertyString,
243:                        false).getSelectedItem());
244:            }
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.