Source Code Cross Referenced for SearchableListBox.java in  » Portal » Open-Portal » ob » listbox » 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 » Portal » Open Portal » ob.listbox 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Stingray Software Objective Blend
003:         * Copyright (C) 1997 Stingray Software, Inc.
004:         * All Rights Reserved
005:         *
006:         * This source code is only intended as a supplement to
007:         * the Stingray Objective Blend product.  See the Objective
008:         * Blend html help documentation for detailed information regarding
009:         * using OB classes.
010:         *
011:         * Author : Kerry Smith
012:         * Description : SearchableListBox.java - list box
013:         *
014:         * CHANGELOG:
015:         * 7/09/96 	LFW	Created
016:         * 3/12/97  JDK1.1
017:         *
018:         */
019:
020:        /**
021:         * SearchableListBox provides the ability to dynamically search for a particular
022:         * element of the listbox.  By invoking some of its data members, you can perform
023:         * partial key searches (that is, if you had a very long listbox with many data members
024:         * that is pre-sorted, you can enter in the first few characters of the search string to
025:         * be able to quickly jump to the location you wish to fine tune your search in).  The
026:         * SearchableListBox derives from the SortableListBox since it uses many of the routines
027:         * of sorting and depends on a presorted list to be able to search for items.
028:         * @see ob.listbox.SortableListBox
029:         * @see ob.listbox.ListBox
030:         */package ob.listbox;
031:
032:        import java.awt.event.*;
033:        import com.sun.portal.log.common.PortalLogger;
034:
035:        public class SearchableListBox extends ob.listbox.SortableListBox {
036:            String m_strCurrentSearchString = "";
037:
038:            /**
039:             * constructor
040:             * @param bMultipleSelections whether multiple selections are allowed
041:             */
042:            public SearchableListBox(boolean bMultipleSelections) {
043:                super (bMultipleSelections);
044:            }
045:
046:            /**
047:             * default constructor
048:             */
049:            public SearchableListBox() {
050:                this (false);
051:            }
052:
053:            /**
054:             * sets the string to search on
055:             * @param newSearch the text to search for as type String
056:             */
057:            public void setSearchString(String newSearch) {
058:                m_strCurrentSearchString = newSearch;
059:            }
060:
061:            /**
062:             * search for a particular piece of text.  If list is not sorted, will automatically
063:             * sort the list.
064:             * @param strSearch string to search on
065:             * @return the first ListItem (row) instance which matches the search criterea, as type int
066:             */
067:
068:            public int search(String strSearch) {
069:                if (m_nColumnSorted != 0)
070:                    sort();
071:
072:                if (strSearch == null || strSearch.length() == 0)
073:                    return 0;
074:                int nSearchLength = strSearch.length();
075:                int maximumLocation = m_arrItems.size() - 1;
076:                int minimumLocation = 0;
077:
078:                while (maximumLocation > minimumLocation) {
079:                    int middle = (maximumLocation + minimumLocation) / 2;
080:                    ListItem currentItem = (ListItem) m_arrItems
081:                            .elementAt(middle);
082:                    String currentString = (currentItem.getText())
083:                            .toUpperCase();
084:
085:                    if (currentString.startsWith(strSearch.toUpperCase())) {
086:                        int tempMiddle = middle;
087:                        while (currentString
088:                                .startsWith(strSearch.toUpperCase())
089:                                && tempMiddle >= 0) {
090:                            if (--tempMiddle != -1)
091:                                currentString = ((ListItem) m_arrItems
092:                                        .elementAt(tempMiddle)).getText()
093:                                        .toUpperCase();
094:                        }
095:
096:                        return tempMiddle + 1;
097:                    } else if (currentString.compareTo(strSearch.toUpperCase()) > 0)
098:                        maximumLocation = middle - 1;
099:                    else
100:                        minimumLocation = middle + 1;
101:                }
102:
103:                if ((((ListItem) m_arrItems.elementAt(minimumLocation))
104:                        .getText()).toUpperCase().startsWith(
105:                        strSearch.toUpperCase())) { //System.out.println("here");
106:                    return minimumLocation;
107:                } else
108:                    return search(strSearch
109:                            .substring(0, strSearch.length() - 1)); //0;
110:            }
111:
112:            protected void changeItemText() {
113:                super .changeItemText();
114:                m_nColumnSorted = -1;
115:            }
116:
117:            protected void processKeyEvent(KeyEvent e) {
118:
119:                int key = e.getKeyCode();
120:
121:                String keyChar = e.getKeyText(key);
122:                if (e.getID() == KeyEvent.KEY_PRESSED) {
123:                    if (!e.isActionKey() && key != KeyEvent.VK_BACK_SPACE
124:                            && keyChar.length() == 1) {
125:                        //System.out.println(keyChar);
126:                        m_strCurrentSearchString = m_strCurrentSearchString
127:                                .concat(keyChar);
128:                        int searchIndex = search(m_strCurrentSearchString);
129:                        //System.out.println(searchIndex + "  search index");
130:                        //    select(searchIndex);
131:                        prev = searchIndex;
132:                        selected = new int[0];
133:                        select(searchIndex, false);
134:                        scrollToView(searchIndex);
135:                        update();
136:                        processItemEvent(new ItemEvent(this ,
137:                                ItemEvent.ITEM_STATE_CHANGED,
138:                                getItem(searchIndex), ItemEvent.SELECTED));
139:
140:                    } else if (key == KeyEvent.VK_BACK_SPACE) {
141:                        int nIndex = m_strCurrentSearchString.length() - 1;
142:                        if (nIndex < 0)
143:                            nIndex = 0;
144:
145:                        m_strCurrentSearchString = m_strCurrentSearchString
146:                                .substring(0, nIndex);
147:                        int searchIndex = search(m_strCurrentSearchString);
148:                        prev = searchIndex;
149:                        selected = new int[0];
150:                        select(searchIndex);
151:                        scrollToView(searchIndex);
152:                        update();
153:                        processItemEvent(new ItemEvent(this,
154:                                ItemEvent.ITEM_STATE_CHANGED,
155:                                getItem(searchIndex), ItemEvent.SELECTED));
156:                    }
157:
158:                }
159:
160:                super.processKeyEvent(e);
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.