Source Code Cross Referenced for AbstractListIntelliHints.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:         * @(#)AbstractListIntelliHints.java 7/24/2005
003:         *
004:         * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005:         */
006:        package com.jidesoft.hints;
007:
008:        import com.jidesoft.swing.JideScrollPane;
009:        import com.jidesoft.swing.Sticky;
010:
011:        import javax.swing.*;
012:        import javax.swing.text.JTextComponent;
013:        import java.awt.*;
014:        import java.awt.event.KeyEvent;
015:        import java.util.Vector;
016:
017:        /**
018:         * <code>AbstractListIntelliHints</code> extends AbstractIntelliHints and further
019:         * implement most of the methods in interface {@link com.jidesoft.hints.IntelliHints}. In this class, it assumes the
020:         * hints can be represented as a JList, so it used JList in the hints popup.
021:         *
022:         * @author Santhosh Kumar T - santhosh@in.fiorano.com
023:         * @author JIDE Software, Inc.
024:         */
025:        public abstract class AbstractListIntelliHints extends
026:                AbstractIntelliHints {
027:            private JList _list;
028:            protected KeyStroke[] _keyStrokes;
029:            private JideScrollPane _scroll;
030:
031:            /**
032:             * Creates a Completion for JTextComponent
033:             *
034:             * @param textComponent
035:             */
036:            public AbstractListIntelliHints(JTextComponent textComponent) {
037:                super (textComponent);
038:            }
039:
040:            public JComponent createHintsComponent() {
041:                JPanel panel = new JPanel(new BorderLayout());
042:
043:                _list = createList();
044:                new Sticky(_list);
045:                _scroll = new JideScrollPane(getList());
046:                getList().setFocusable(false);
047:
048:                _scroll
049:                        .setHorizontalScrollBarPolicy(JideScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
050:                _scroll.setBorder(BorderFactory.createEmptyBorder());
051:                _scroll.getVerticalScrollBar().setFocusable(false);
052:                _scroll.getHorizontalScrollBar().setFocusable(false);
053:
054:                panel.add(_scroll, BorderLayout.CENTER);
055:                return panel;
056:            }
057:
058:            /**
059:             * Creates the list to display the hints. By default, we create a JList using the code below.
060:             * <code><pre>
061:             * return new JList() {
062:             *     public int getVisibleRowCount() {
063:             *         int size = getModel().getSize();
064:             *         return size < super.getVisibleRowCount() ? size : super.getVisibleRowCount();
065:             *     }
066:             * <p/>
067:             *     public Dimension getPreferredScrollableViewportSize() {
068:             *         if (getModel().getSize() == 0) {
069:             *             return new Dimension(0, 0);
070:             *         }
071:             *         else {
072:             *             return super.getPreferredScrollableViewportSize();
073:             *         }
074:             *     }
075:             * };
076:             * </pre></code>
077:             *
078:             * @return the list.
079:             */
080:            protected JList createList() {
081:                return new JList() {
082:                    @Override
083:                    public int getVisibleRowCount() {
084:                        int size = getModel().getSize();
085:                        return size < super .getVisibleRowCount() ? size : super 
086:                                .getVisibleRowCount();
087:                    }
088:
089:                    @Override
090:                    public Dimension getPreferredScrollableViewportSize() {
091:                        if (getModel().getSize() == 0) {
092:                            return new Dimension(0, 0);
093:                        } else {
094:                            return super .getPreferredScrollableViewportSize();
095:                        }
096:                    }
097:                };
098:            }
099:
100:            /**
101:             * Gets the list.
102:             *
103:             * @return the list.
104:             */
105:            protected JList getList() {
106:                return _list;
107:            }
108:
109:            /**
110:             * Sets the list data.
111:             *
112:             * @param objects
113:             */
114:            protected void setListData(Object[] objects) {
115:                resetSelection();
116:                getList().setListData(objects);
117:
118:                // update the view so that isViewSizeSet flag in JViewport is reset to false
119:                if (_scroll != null) {
120:                    _scroll.setViewportView(getList());
121:                }
122:
123:            }
124:
125:            /**
126:             * Sets the list data.
127:             *
128:             * @param objects
129:             */
130:            protected void setListData(Vector<?> objects) {
131:                resetSelection();
132:                getList().setListData(objects);
133:                // update the view so that isViewSizeSet flag in JViewport is reset to false
134:                if (_scroll != null) {
135:                    _scroll.setViewportView(getList());
136:                }
137:            }
138:
139:            private void resetSelection() {
140:                getList().getSelectionModel().setAnchorSelectionIndex(-1); // has to call setAnchor first
141:                getList().getSelectionModel().setLeadSelectionIndex(-1);
142:                getList().getSelectionModel().clearSelection();
143:            }
144:
145:            public Object getSelectedHint() {
146:                return getList().getSelectedValue();
147:            }
148:
149:            @Override
150:            public JComponent getDelegateComponent() {
151:                return getList();
152:            }
153:
154:            /**
155:             * Gets the delegate keystrokes. Since we know the hints popup is a JList, we return eight
156:             * keystrokes so that they can be delegate to the JList. Those keystrokes are
157:             * DOWN, UP, PAGE_DOWN, PAGE_UP, HOME and END.
158:             *
159:             * @return the keystokes that will be delegated to the JList when hints popup is visible.
160:             */
161:            @Override
162:            public KeyStroke[] getDelegateKeyStrokes() {
163:                if (_keyStrokes == null) {
164:                    _keyStrokes = new KeyStroke[6];
165:                    _keyStrokes[0] = KeyStroke
166:                            .getKeyStroke(KeyEvent.VK_DOWN, 0);
167:                    _keyStrokes[1] = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);
168:                    _keyStrokes[2] = KeyStroke.getKeyStroke(
169:                            KeyEvent.VK_PAGE_DOWN, 0);
170:                    _keyStrokes[3] = KeyStroke.getKeyStroke(
171:                            KeyEvent.VK_PAGE_UP, 0);
172:                    _keyStrokes[4] = KeyStroke
173:                            .getKeyStroke(KeyEvent.VK_HOME, 0);
174:                    _keyStrokes[5] = KeyStroke.getKeyStroke(KeyEvent.VK_END, 0);
175:                }
176:                return _keyStrokes;
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.