Source Code Cross Referenced for ComboBoxSearchable.java in  » Swing-Library » jide-common » com » jidesoft » swing » 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 » jide common » com.jidesoft.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)${NAME}
003:         *
004:         * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
005:         */
006:        package com.jidesoft.swing;
007:
008:        import com.jidesoft.swing.event.SearchableEvent;
009:
010:        import javax.swing.*;
011:        import javax.swing.event.ListDataEvent;
012:        import javax.swing.event.ListDataListener;
013:        import java.awt.*;
014:        import java.beans.PropertyChangeEvent;
015:        import java.beans.PropertyChangeListener;
016:
017:        /**
018:         * <code>ComboBoxSearchable</code> is an concrete implementation of {@link Searchable}
019:         * that enables the search function in non-editable JComboBox.
020:         * <p>It's very simple to use it. Assuming you have a JComboBox, all you need to do is to
021:         * call
022:         * <code><pre>
023:         * JComboBox comboBox = ....;
024:         * ComboBoxSearchable searchable = new ComboBoxSearchable(comboBox);
025:         * </pre></code>
026:         * Now the JComboBox will have the search function.
027:         * <p/>
028:         * There is very little customization you need to do to ComboBoxSearchable. The only thing you might
029:         * need is when the element in the JComboBox needs a special conversion to convert to string. If so, you can overide
030:         * convertElementToString() to provide you own algorithm to do the conversion.
031:         * <code><pre>
032:         * JComboBox comboBox = ....;
033:         * ComboBoxSearchable searchable = new ComboBoxSearchable(comboBox) {
034:         *      protected String convertElementToString(Object object) {
035:         *          ...
036:         *      }
037:         * };
038:         * </pre></code>
039:         * <p/>
040:         * Additional customization can be done on the base Searchable class such as background and foreground color, keystrokes,
041:         * case sensitivity,
042:         */
043:        public class ComboBoxSearchable extends Searchable implements 
044:                ListDataListener, PropertyChangeListener {
045:
046:            private boolean _showPopupDuringSearching = true;
047:
048:            public ComboBoxSearchable(JComboBox comboBox) {
049:                super (comboBox);
050:
051:                // to avoid conflict with default type-match feature of JComboBox.
052:                comboBox
053:                        .setKeySelectionManager(new JComboBox.KeySelectionManager() {
054:                            public int selectionForKey(char aKey,
055:                                    ComboBoxModel aModel) {
056:                                return -1;
057:                            }
058:                        });
059:                comboBox.getModel().addListDataListener(this );
060:                comboBox.addPropertyChangeListener("model", this );
061:            }
062:
063:            @Override
064:            public void uninstallListeners() {
065:                super .uninstallListeners();
066:                if (_component instanceof  JComboBox) {
067:                    ((JComboBox) _component).getModel().removeListDataListener(
068:                            this );
069:                }
070:                _component.removePropertyChangeListener("model", this );
071:            }
072:
073:            /**
074:             * Checks if the popup is showing during searching.
075:             *
076:             * @return true if popup is visible during searching.
077:             * @deprecated misspelled. Use {@link #isShowPopupDuringSearching()}.
078:             */
079:            public boolean isShowPopupDuringSeaching() {
080:                return _showPopupDuringSearching;
081:            }
082:
083:            /**
084:             * Sets the property which determines if the popup should be shown during searching.
085:             *
086:             * @param showPopupDuringSeaching
087:             * @deprecated misspelled. Use {@link #setShowPopupDuringSearching(boolean)}
088:             */
089:            public void setShowPopupDuringSeaching(
090:                    boolean showPopupDuringSeaching) {
091:                _showPopupDuringSearching = showPopupDuringSeaching;
092:            }
093:
094:            /**
095:             * Checks if the popup is showing during searching.
096:             *
097:             * @return true if popup is visible during searching.
098:             */
099:            public boolean isShowPopupDuringSearching() {
100:                return _showPopupDuringSearching;
101:            }
102:
103:            /**
104:             * Sets the property which determines if the popup should be shown during searching.
105:             *
106:             * @param showPopupDuringSearching
107:             */
108:            public void setShowPopupDuringSearching(
109:                    boolean showPopupDuringSearching) {
110:                _showPopupDuringSearching = showPopupDuringSearching;
111:            }
112:
113:            @Override
114:            protected void setSelectedIndex(int index, boolean incremental) {
115:                if (isShowPopupDuringSearching()) {
116:                    try {
117:                        ((JComboBox) _component).showPopup();
118:                    } catch (IllegalComponentStateException e) {
119:                    }
120:                }
121:                if (((JComboBox) _component).getSelectedIndex() != index) {
122:                    ((JComboBox) _component).setSelectedIndex(index);
123:                }
124:            }
125:
126:            @Override
127:            protected int getSelectedIndex() {
128:                return ((JComboBox) _component).getSelectedIndex();
129:            }
130:
131:            @Override
132:            protected Object getElementAt(int index) {
133:                ComboBoxModel comboBoxModel = ((JComboBox) _component)
134:                        .getModel();
135:                return comboBoxModel.getElementAt(index);
136:            }
137:
138:            @Override
139:            protected int getElementCount() {
140:                ComboBoxModel comboBoxModel = ((JComboBox) _component)
141:                        .getModel();
142:                return comboBoxModel.getSize();
143:            }
144:
145:            /**
146:             * Converts the element in Jcombobox to string. The returned value will be the
147:             * <code>toString()</code> of whatever element that returned from <code>list.getModel().getElementAt(i)</code>.
148:             *
149:             * @param object
150:             * @return the string representing the element in the JComboBox.
151:             */
152:            @Override
153:            protected String convertElementToString(Object object) {
154:                if (object != null) {
155:                    return object.toString();
156:                } else {
157:                    return "";
158:                }
159:            }
160:
161:            public void contentsChanged(ListDataEvent e) {
162:                if (e.getIndex0() == -1 && e.getIndex1() == -1) {
163:                } else {
164:                    hidePopup();
165:                    fireSearchableEvent(new SearchableEvent(this ,
166:                            SearchableEvent.SEARCHABLE_MODEL_CHANGE));
167:                }
168:            }
169:
170:            public void intervalAdded(ListDataEvent e) {
171:                hidePopup();
172:                fireSearchableEvent(new SearchableEvent(this ,
173:                        SearchableEvent.SEARCHABLE_MODEL_CHANGE));
174:            }
175:
176:            public void intervalRemoved(ListDataEvent e) {
177:                hidePopup();
178:                fireSearchableEvent(new SearchableEvent(this ,
179:                        SearchableEvent.SEARCHABLE_MODEL_CHANGE));
180:            }
181:
182:            public void propertyChange(PropertyChangeEvent evt) {
183:                if ("model".equals(evt.getPropertyName())) {
184:                    hidePopup();
185:
186:                    if (evt.getOldValue() instanceof  ComboBoxModel) {
187:                        ((ComboBoxModel) evt.getOldValue())
188:                                .removeListDataListener(this );
189:                    }
190:
191:                    if (evt.getNewValue() instanceof  ComboBoxModel) {
192:                        ((ComboBoxModel) evt.getNewValue())
193:                                .addListDataListener(this );
194:                    }
195:                }
196:                fireSearchableEvent(new SearchableEvent(this,
197:                        SearchableEvent.SEARCHABLE_MODEL_CHANGE));
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.