Source Code Cross Referenced for SqlPopupMenu.java in  » Database-Client » SQLMinus » isql » 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 » Database Client » SQLMinus » isql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package isql;
002:
003:        import javax.swing.*;
004:        import javax.swing.text.*;
005:        import javax.swing.event.*;
006:        import java.util.*;
007:        import java.awt.event.*;
008:        import java.awt.Component;
009:
010:        // currently each time constrcutor is called and cache is set. would
011:        // like to do this once and call only show and match method
012:        /** Pops up with a list which user can select from. If user enters
013:         * characters or backspace then the search result changes accordingly.
014:         * HOwever, if you use anythig other than arrow keys then the list loses
015:         * keyboard focus.
016:         * @author rahul kumar 2001, $Author
017:         * $Id: SqlPopupMenu.java,v 1.1 2001/12/31 19:51:37 rahul_kumar Exp $
018:         */
019:
020:        public class SqlPopupMenu {
021:
022:            JPopupMenu jp; // that which will popup
023:            JTextComponent _jt;
024:            ActionListener alis;
025:            JMenuItem ji;
026:            String[] cache; // list of words to search in
027:            String _patt; // current pattern
028:            String originalpatt; // required for knowing length of what we are replacing
029:
030:            public SqlPopupMenu(JTextComponent jt) {
031:
032:                _jt = jt;
033:                jp = new JPopupMenu();
034:                jp.addKeyListener(new PopupKeyListener(this ));
035:                alis = new ActionListener() {
036:                    public void actionPerformed(ActionEvent event) {
037:                        if (_jt instanceof  JTextArea) {
038:                            // replace current word with what user selected
039:                            ((JTextArea) _jt).replaceRange(event
040:                                    .getActionCommand(), _jt.getCaretPosition()
041:                                    - originalpatt.length(), _jt
042:                                    .getCaretPosition());
043:                            _jt.requestFocus(); // return focus back to caller
044:                        } else
045:                            System.out.println("selected: "
046:                                    + event.getActionCommand());
047:                    }
048:                };
049:
050:            }
051:
052:            public JTextComponent getTextComponent() {
053:                return _jt;
054:            }
055:
056:            public void show(int x, int y) {
057:                if (ji == null)
058:                    return;
059:                jp.show(_jt, x, y);
060:                jp.requestFocus();
061:            }
062:
063:            public void show() {
064:                if (ji == null)
065:                    return;
066:                jp.show(_jt, 0, 0);
067:                jp.requestFocus();
068:            }
069:
070:            public void set(Collection coll) {
071:                cache = new String[coll.size()];
072:                coll.toArray(cache);
073:            }
074:
075:            public void set(String[] arr) {
076:                // we need to clear the jmenu also
077:                cache = arr;
078:            }
079:
080:            public void setMatching(String patt) {
081:                if (cache == null || cache.length == 0)
082:                    return;
083:                int len = patt.length();
084:                if (len == 0)
085:                    return;
086:                if (_patt == null) // otherwise replace will not work QUICK DIRTY
087:                    originalpatt = patt;
088:                _patt = patt;
089:                // clean out existing elements
090:                Component comps[] = jp.getComponents();
091:                for (int i = 0; i < comps.length; i++) {
092:                    jp.remove(comps[i]);
093:                }
094:                for (int i = 0; i < cache.length; i++) {
095:                    // check if patt is not longer than array else subst throws
096:                    // up
097:                    if (patt.length() <= cache[i].length()
098:                            && cache[i].substring(0, len).equals(patt)) {
099:                        ji = jp.add(cache[i]);
100:                        /*
101:                        if (len < cache[i].length())
102:                            ji.setMnemonic(cache[i].toUpperCase().charAt(len));
103:                         */
104:                        ji.addActionListener(alis);
105:                        ji.addKeyListener(new PopupKeyListener(this ));
106:                    }//if matching
107:
108:                } // for
109:
110:            } // setMatching
111:
112:            public String getPattern() {
113:                return _patt;
114:            }
115:
116:            public JPopupMenu getPopupMenu() {
117:                return jp;
118:            }
119:        } // class SqlPopupMenu
120:
121:        // 
122:        class PopupKeyListener implements  KeyListener {
123:            private SqlPopupMenu jp;
124:
125:            public PopupKeyListener(SqlPopupMenu jpm) {
126:                jp = jpm;
127:            }
128:
129:            public void keyTyped(KeyEvent e) {
130:            }
131:
132:            public void keyPressed(KeyEvent e) {
133:                char ch = e.getKeyChar();
134:                String patt = jp.getPattern(); // could be done once in constructor
135:                String oldpatt = patt;
136:                if (Character.isJavaIdentifierPart(ch))
137:                    patt += ch;
138:                if (e.getKeyCode() == java.awt.event.KeyEvent.VK_BACK_SPACE)
139:                    patt = patt.substring(0, patt.length() - 2);
140:                if (!oldpatt.equals(patt)) {
141:                    System.out.println("patt:" + patt);
142:                    jp.setMatching(patt);
143:                    jp.getPopupMenu().pack();
144:                    jp.getPopupMenu().invalidate();
145:                    jp.getPopupMenu().revalidate();
146:                    jp.getPopupMenu().repaint();
147:                    jp.getPopupMenu().requestFocus();
148:                    //jp.getPopupMenu().grabFocus();
149:                    try {
150:                        //jp.getPopupMenu().getComponentAtIndex(0).requestFocus();
151:                        //((JComponent)jp.getPopupMenu().getComponentAtIndex(0)).grabFocus();
152:                        jp.getPopupMenu().setSelected(
153:                                jp.getPopupMenu().getComponentAtIndex(0));
154:                    } catch (Exception exc) {
155:                    }
156:                }
157:
158:            }
159:
160:            public void keyReleased(KeyEvent e) {
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.