Source Code Cross Referenced for KeySequenceInputPanel.java in  » Swing-Library » abeille-forms-designer » org » netbeans » editor » 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 » abeille forms designer » org.netbeans.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *                 Sun Public License Notice
003:         * 
004:         * The contents of this file are subject to the Sun Public License
005:         * Version 1.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://www.sun.com/
008:         * 
009:         * The Original Code is NetBeans. The Initial Developer of the Original
010:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011:         * Microsystems, Inc. All Rights Reserved.
012:         */
013:
014:        package org.netbeans.editor;
015:
016:        import java.awt.Dimension;
017:        import java.awt.event.KeyEvent;
018:        import java.util.Vector;
019:
020:        import javax.swing.KeyStroke;
021:
022:        /**
023:         * This class could be used as input of sequence of KeyStrokes.
024:         * {@link #getKeySequence} One instance could be reused. {@link #clear} When
025:         * actual keySequence changes, it fires PropertyChangeEvent of property
026:         * {@link #PROP_KEYSEQUENCE}. There is additional label on the bottom, which
027:         * could be set with {@link #setInfoText} to pass some information to user.
028:         * 
029:         * @author David Konecny
030:         */
031:
032:        public class KeySequenceInputPanel extends javax.swing.JPanel {
033:
034:            public static String PROP_KEYSEQUENCE = "keySequence"; // NOI18N
035:            private Vector strokes = new Vector();
036:            private StringBuffer text = new StringBuffer();
037:
038:            /** Creates new form KeySequenceInputPanel with empty sequence */
039:            public KeySequenceInputPanel() {
040:                initComponents();
041:
042:                keySequenceLabel.setDisplayedMnemonic(LocaleSupport.getString(
043:                        "LBL_KSIP_Sequence_Mnemonic").charAt(0)); // NOI18N
044:                keySequenceInputField.getAccessibleContext()
045:                        .setAccessibleDescription(
046:                                LocaleSupport
047:                                        .getString("ACSD_LBL_KSIP_Sequence")); // NOI18N
048:                getAccessibleContext().setAccessibleName(
049:                        LocaleSupport.getString("MSP_AddTitle")); // NOI18N
050:                getAccessibleContext().setAccessibleDescription(
051:                        LocaleSupport.getString("ACSD_KSIP")); // NOI18N
052:            }
053:
054:            /**
055:             * Clears actual sequence of KeyStrokes
056:             */
057:            public void clear() {
058:                strokes.clear();
059:                text.setLength(0);
060:                keySequenceInputField.setText(text.toString());
061:                firePropertyChange(PROP_KEYSEQUENCE, null, null);
062:            }
063:
064:            /*
065:             * Sets the text of JLabel locaten on the bottom of this panel
066:             */
067:            public void setInfoText(String s) {
068:                collisionLabel.setText(s + ' '); // NOI18N
069:            }
070:
071:            /**
072:             * Returns sequence of completed KeyStrokes as KeyStroke[]
073:             */
074:            public KeyStroke[] getKeySequence() {
075:                return (KeyStroke[]) strokes.toArray(new KeyStroke[0]);
076:            }
077:
078:            /**
079:             * Makes it trying to be bigger
080:             */
081:            public Dimension getPreferredSize() {
082:                Dimension dim = super .getPreferredSize();
083:
084:                if (dim.width < 400)
085:                    dim.width = 400;
086:
087:                return dim;
088:            }
089:
090:            /**
091:             * We're redirecting our focus to proper component.
092:             */
093:            public void requestFocus() {
094:                keySequenceInputField.requestFocus();
095:            }
096:
097:            /**
098:             * Visual part and event handling:
099:             */
100:            private void initComponents() {// GEN-BEGIN:initComponents
101:                java.awt.GridBagConstraints gridBagConstraints;
102:
103:                keySequenceLabel = new javax.swing.JLabel();
104:                keySequenceInputField = new javax.swing.JTextField();
105:                collisionLabel = new javax.swing.JTextArea();
106:
107:                setLayout(new java.awt.GridBagLayout());
108:
109:                setBorder(new javax.swing.border.EmptyBorder(
110:                        new java.awt.Insets(12, 12, 11, 11)));
111:                keySequenceLabel.setText(LocaleSupport
112:                        .getString("LBL_KSIP_Sequence"));
113:                keySequenceLabel.setBorder(new javax.swing.border.EmptyBorder(
114:                        new java.awt.Insets(0, 0, 0, 8)));
115:                keySequenceLabel.setLabelFor(keySequenceInputField);
116:                gridBagConstraints = new java.awt.GridBagConstraints();
117:                gridBagConstraints.gridx = 0;
118:                gridBagConstraints.gridy = 0;
119:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
120:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
121:                add(keySequenceLabel, gridBagConstraints);
122:
123:                keySequenceInputField
124:                        .addKeyListener(new java.awt.event.KeyAdapter() {
125:                            public void keyTyped(java.awt.event.KeyEvent evt) {
126:                                keySequenceInputFieldKeyTyped(evt);
127:                            }
128:
129:                            public void keyPressed(java.awt.event.KeyEvent evt) {
130:                                keySequenceInputFieldKeyPressed(evt);
131:                            }
132:
133:                            public void keyReleased(java.awt.event.KeyEvent evt) {
134:                                keySequenceInputFieldKeyReleased(evt);
135:                            }
136:                        });
137:
138:                gridBagConstraints = new java.awt.GridBagConstraints();
139:                gridBagConstraints.gridx = 1;
140:                gridBagConstraints.gridy = 0;
141:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
142:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
143:                gridBagConstraints.weightx = 1.0;
144:                add(keySequenceInputField, gridBagConstraints);
145:
146:                collisionLabel.setLineWrap(true);
147:                collisionLabel.setEditable(false);
148:                collisionLabel.setRows(2);
149:                collisionLabel.setForeground(java.awt.Color.red);
150:                collisionLabel.setBackground(getBackground());
151:                collisionLabel.setDisabledTextColor(java.awt.Color.red);
152:                collisionLabel.setEnabled(false);
153:                gridBagConstraints = new java.awt.GridBagConstraints();
154:                gridBagConstraints.gridx = 0;
155:                gridBagConstraints.gridy = 1;
156:                gridBagConstraints.gridwidth = 2;
157:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
158:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
159:                gridBagConstraints.weightx = 1.0;
160:                gridBagConstraints.weighty = 1.0;
161:                gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
162:                add(collisionLabel, gridBagConstraints);
163:
164:            }// GEN-END:initComponents
165:
166:            private void keySequenceInputFieldKeyTyped(
167:                    java.awt.event.KeyEvent evt) {// GEN-FIRST:event_keySequenceInputFieldKeyTyped
168:                evt.consume();
169:            }// GEN-LAST:event_keySequenceInputFieldKeyTyped
170:
171:            private void keySequenceInputFieldKeyReleased(
172:                    java.awt.event.KeyEvent evt) {// GEN-FIRST:event_keySequenceInputFieldKeyReleased
173:                evt.consume();
174:                keySequenceInputField.setText(text.toString());
175:            }// GEN-LAST:event_keySequenceInputFieldKeyReleased
176:
177:            private void keySequenceInputFieldKeyPressed(
178:                    java.awt.event.KeyEvent evt) {// GEN-FIRST:event_keySequenceInputFieldKeyPressed
179:                evt.consume();
180:
181:                String modif = KeyEvent.getKeyModifiersText(evt.getModifiers());
182:                if (isModifier(evt.getKeyCode())) {
183:                    keySequenceInputField
184:                            .setText(text.toString() + modif + '+'); // NOI18N
185:                } else {
186:                    KeyStroke stroke = KeyStroke.getKeyStrokeForEvent(evt);
187:                    strokes.add(stroke);
188:                    text.append(Utilities.keyStrokeToString(stroke));
189:                    text.append(' ');
190:                    keySequenceInputField.setText(text.toString());
191:                    firePropertyChange(PROP_KEYSEQUENCE, null, null);
192:                }
193:            }// GEN-LAST:event_keySequenceInputFieldKeyPressed
194:
195:            private boolean isModifier(int keyCode) {
196:                return (keyCode == KeyEvent.VK_ALT)
197:                        || (keyCode == KeyEvent.VK_ALT_GRAPH)
198:                        || (keyCode == KeyEvent.VK_CONTROL)
199:                        || (keyCode == KeyEvent.VK_SHIFT)
200:                        || (keyCode == KeyEvent.VK_META);
201:            }
202:
203:            // Variables declaration - do not modify//GEN-BEGIN:variables
204:            private javax.swing.JLabel keySequenceLabel;
205:            private javax.swing.JTextArea collisionLabel;
206:            private javax.swing.JTextField keySequenceInputField;
207:            // End of variables declaration//GEN-END:variables
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.