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


001:        /*
002:         * @(#)FileIntelliHints.java 7/24/2005
003:         *
004:         * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005:         */
006:        package com.jidesoft.hints;
007:
008:        import javax.swing.*;
009:        import javax.swing.text.BadLocationException;
010:        import javax.swing.text.JTextComponent;
011:        import java.awt.*;
012:        import java.io.File;
013:        import java.io.FilenameFilter;
014:
015:        /**
016:         * <code>FileIntelliHints</code> is a concrete implementation of {@link com.jidesoft.hints.IntelliHints}.
017:         * It allows user to type in a file patch quickly by providing them the hints based on what
018:         * is existed on file system. You can use {@link #setFolderOnly(boolean)} to control if
019:         * the hints contain only the folders, or folders and files.
020:         */
021:        public class FileIntelliHints extends AbstractListIntelliHints {
022:            private boolean _folderOnly = false;
023:            private boolean _showFullPath = true;
024:
025:            public FileIntelliHints(JTextComponent comp) {
026:                super (comp);
027:            }
028:
029:            /**
030:             * If the hints contain the folder names only.
031:             *
032:             * @return true if the hints contain the folder names only.
033:             */
034:            public boolean isFolderOnly() {
035:                return _folderOnly;
036:            }
037:
038:            /**
039:             * Sets the property of folder only. If true, the hints will only show the folder names.
040:             * Otherwise, both folder and file names will be shown in the hints.
041:             *
042:             * @param folderOnly only provide hints for the folders.
043:             */
044:            public void setFolderOnly(boolean folderOnly) {
045:                _folderOnly = folderOnly;
046:            }
047:
048:            /**
049:             * If the hints contain the full path.
050:             *
051:             * @return true if the hints contain the full path.
052:             */
053:            public boolean isShowFullPath() {
054:                return _showFullPath;
055:            }
056:
057:            /**
058:             * Sets the property of showing full path. If true, the hints will show the full path.
059:             * Otherwise, it will only show the path after user typed in so far.
060:             *
061:             * @param showFullPath whether show the full path.
062:             */
063:            public void setShowFullPath(boolean showFullPath) {
064:                _showFullPath = showFullPath;
065:            }
066:
067:            public boolean updateHints(Object value) {
068:                if (value == null) {
069:                    return false;
070:                }
071:                String s = value.toString();
072:                if (s.length() == 0) {
073:                    return false;
074:                }
075:                int index1 = s.lastIndexOf('\\');
076:                int index2 = s.lastIndexOf('/');
077:                int index = Math.max(index1, index2);
078:                if (index == -1)
079:                    return false;
080:                String dir = s.substring(0, index + 1);
081:                final String prefix = index == s.length() - 1 ? null : s
082:                        .substring(index + 1).toLowerCase();
083:                String[] files = new File(dir).list(new FilenameFilter() {
084:                    public boolean accept(File dir, String name) {
085:                        if (isFolderOnly()) {
086:                            if (new File(dir.getAbsolutePath() + File.separator
087:                                    + name).isFile()) {
088:                                return false;
089:                            }
090:                        }
091:                        return prefix == null
092:                                || name.toLowerCase().startsWith(prefix);
093:                    }
094:                });
095:
096:                if (files == null
097:                        || files.length == 0
098:                        || (files.length == 1 && files[0]
099:                                .equalsIgnoreCase(prefix))) {
100:                    setListData(new String[0]);
101:                    return false;
102:                } else {
103:                    getList().setCellRenderer(
104:                            new PrefixListCellRenderer(isShowFullPath() ? dir
105:                                    : ""));
106:                    setListData(files);
107:                    return true;
108:                }
109:            }
110:
111:            @Override
112:            public void acceptHint(Object selected) {
113:                if (selected == null)
114:                    return;
115:
116:                String selectedValue = "" + selected;
117:
118:                String value = getTextComponent().getText();
119:                int caretPosition = getTextComponent().getCaretPosition();
120:                int index1 = value.lastIndexOf('\\', caretPosition);
121:                int index2 = value.lastIndexOf('/', caretPosition);
122:                int index = Math.max(index1, index2);
123:                if (index == -1) {
124:                    return;
125:                }
126:                int prefixlen = caretPosition - index - 1;
127:                try {
128:                    getTextComponent().getDocument().insertString(
129:                            caretPosition, selectedValue.substring(prefixlen),
130:                            null);
131:                } catch (BadLocationException e) {
132:                    e.printStackTrace();
133:                }
134:            }
135:
136:            private class PrefixListCellRenderer extends
137:                    DefaultListCellRenderer {
138:                private String _prefix;
139:
140:                public PrefixListCellRenderer(String prefix) {
141:                    _prefix = prefix;
142:                }
143:
144:                @Override
145:                public Component getListCellRendererComponent(JList list,
146:                        Object value, int index, boolean isSelected,
147:                        boolean cellHasFocus) {
148:                    return super.getListCellRendererComponent(list, _prefix
149:                            + value, index, isSelected, cellHasFocus);
150:                }
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.