Source Code Cross Referenced for SComboBox.java in  » Swing-Library » Swinglets » com » javelin » swinglets » 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 » Swing Library » Swinglets » com.javelin.swinglets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Javelin Software, All rights reserved.
003:         */
004:
005:        package com.javelin.swinglets;
006:
007:        import java.awt.*;
008:        import java.awt.event.*;
009:        import java.util.*;
010:        import java.io.*;
011:
012:        import javax.swing.*;
013:
014:        import com.javelin.swinglets.plaf.*;
015:
016:        /**
017:         * SComboBox defines a drop down list of options. Initially no
018:         * option is selected. Only one option can be selected.
019:         * <P>
020:         * The SComboBox uses the Swing ComboBoxModel.
021:         * 
022:         * @author Robin Sharp
023:         */
024:
025:        public class SComboBox extends SComponent {
026:            /**
027:             * Creates a SComboBox using the ComboBoxModel.
028:             */
029:            public SComboBox(ComboBoxModel model) {
030:                if (model != null)
031:                    setModel(model);
032:            }
033:
034:            /**
035:             * Creates a SComboBox that contains the elements in the specified array.
036:             */
037:            public SComboBox(final Object[] array) {
038:                this (new DefaultComboBoxModel(array));
039:            }
040:
041:            /**
042:             * Creates a SComboBox that contains the elements in the specified vector.
043:             */
044:            public SComboBox(Vector vector) {
045:                this (new DefaultComboBoxModel(vector));
046:            }
047:
048:            /**
049:             * Creates a SComboBox unslected.
050:             */
051:            public SComboBox() {
052:                this (new DefaultComboBoxModel());
053:            }
054:
055:            /**
056:             * Returns the name of the L&F class that renders this component.
057:             */
058:            public Class getUIClass() {
059:                return SComboBox.class;
060:            }
061:
062:            /**
063:             * Sets the data model that the SComboBox uses to obtain the list of items.
064:             */
065:            public SComboBox setModel(ComboBoxModel model) {
066:                firePropertyChange("model", this .model, this .model = model);
067:                return this ;
068:            }
069:
070:            /**
071:             * Returns the data model currently used by the SComboBox.
072:             */
073:            public ComboBoxModel getModel() {
074:                return model;
075:            }
076:
077:            /** 
078:             * Sets the selected item in the JComboBox by specifying the object in the list.
079:             */
080:            public SComboBox setSelectedItem(Object selectedItem) {
081:                model.setSelectedItem(selectedItem);
082:                return this ;
083:            }
084:
085:            /**
086:             * Returns the currently selected item.
087:             */
088:            public Object getSelectedItem() {
089:                return model.getSelectedItem();
090:            }
091:
092:            /**
093:             * Selects the item at index index.
094:             */
095:            public SComboBox setSelectedIndex(int index) {
096:                int size = model.getSize();
097:
098:                if (index == -1) {
099:                    setSelectedItem(null);
100:                } else if (index >= size || index < -1) {
101:                    throw new IllegalArgumentException("setSelectedIndex: "
102:                            + index + " out of bounds");
103:                } else {
104:                    setSelectedItem(model.getElementAt(index));
105:                }
106:
107:                return this ;
108:            }
109:
110:            /**
111:             * Returns the index of the currently selected item in the list.
112:             */
113:            public int getSelectedIndex() {
114:                Object selectedObject = model.getSelectedItem();
115:                Object object;
116:
117:                for (int index = 0, size = model.getSize(); index < size; index++) {
118:                    object = model.getElementAt(index);
119:                    if (object.equals(selectedObject)) {
120:                        return index;
121:                    }
122:                }
123:                return -1;
124:            }
125:
126:            /**
127:             * Returns the number of items in the list.
128:             */
129:            public int getItemCount() {
130:                return model.getSize();
131:            }
132:
133:            /**
134:             * Returns the list item at the specified index.
135:             */
136:            public Object getItemAt(int index) {
137:                return model.getElementAt(index);
138:            }
139:
140:            /** 
141:             * Adds an item to the item list.
142:             */
143:            public void addItem(Object object) {
144:                checkMutableComboBoxModel();
145:                ((MutableComboBoxModel) model).addElement(object);
146:            }
147:
148:            /** 
149:             * Inserts an item into the item list at a given index. 
150:             */
151:            public void insertItemAt(Object object, int index) {
152:                checkMutableComboBoxModel();
153:                ((MutableComboBoxModel) model).insertElementAt(object, index);
154:            }
155:
156:            /** 
157:             * Removes an item from the item list.
158:             */
159:            public void removeItem(Object object) {
160:                checkMutableComboBoxModel();
161:                ((MutableComboBoxModel) model).removeElement(object);
162:            }
163:
164:            /**  
165:             * Removes the item at index.
166:             */
167:            public void removeItemAt(int index) {
168:                checkMutableComboBoxModel();
169:                ((MutableComboBoxModel) model).removeElementAt(index);
170:            }
171:
172:            /** 
173:             * Removes all items from the item list.
174:             */
175:            public void removeAllItems() {
176:                checkMutableComboBoxModel();
177:                MutableComboBoxModel mutableModel = (MutableComboBoxModel) model;
178:                int size = mutableModel.getSize();
179:
180:                if (mutableModel instanceof  DefaultComboBoxModel) {
181:                    ((DefaultComboBoxModel) mutableModel).removeAllElements();
182:                } else {
183:                    for (int index = 0; index < size; ++index) {
184:                        Object element = mutableModel.getElementAt(0);
185:                        mutableModel.removeElement(element);
186:                    }
187:                }
188:            }
189:
190:            /**
191:             * Set the value as Text. This sets the text  property. It is
192:             * assumes that the text is the index.
193:             */
194:            public SComponent setValueAsText(String text) {
195:                try {
196:                    setSelectedIndex(Integer.parseInt(text));
197:                } catch (Exception e) {
198:                    //Fail silently
199:                }
200:
201:                return this ;
202:            }
203:
204:            // DISPATCH & EVENTS //////////////////////////////////////////////////////
205:
206:            /**
207:             * Adds the specified text event listener to recieve text events 
208:             * from this textcomponent.
209:             */
210:            public SComboBox addTextListener(TextListener listener) {
211:                getUI().addListener(listener);
212:                return this ;
213:            }
214:
215:            /**
216:             * Removes the specified text event listener so that it no longer
217:             * receives text events from this textcomponent.
218:             */
219:            public SComboBox removeTextListener(TextListener listener) {
220:                getUI().removeListener(listener);
221:                return this ;
222:            }
223:
224:            // PRIVATE /////////////////////////////////////////////////////////////
225:
226:            protected void checkMutableComboBoxModel() {
227:                if (!(model instanceof  MutableComboBoxModel)) {
228:                    throw new RuntimeException(
229:                            "Cannot use this method with a non-Mutable data model.");
230:                }
231:            }
232:
233:            protected ComboBoxModel model;
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.