Source Code Cross Referenced for WbCellEditor.java in  » Database-Client » SQL-Workbench » workbench » gui » components » 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 » SQL Workbench » workbench.gui.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * WbCellEditor.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.gui.components;
013:
014:        import java.awt.Component;
015:        import java.awt.EventQueue;
016:        import java.awt.Font;
017:        import java.awt.event.ActionEvent;
018:        import java.awt.event.InputEvent;
019:        import java.awt.event.KeyEvent;
020:        import java.awt.event.MouseEvent;
021:        import java.awt.event.MouseListener;
022:        import java.util.Collections;
023:        import java.util.EventObject;
024:        import javax.swing.AbstractAction;
025:        import javax.swing.AbstractCellEditor;
026:        import javax.swing.InputMap;
027:        import javax.swing.JComponent;
028:        import javax.swing.JScrollPane;
029:        import javax.swing.JTable;
030:        import javax.swing.JTextArea;
031:        import javax.swing.KeyStroke;
032:        import javax.swing.table.TableCellEditor;
033:        import workbench.gui.WbSwingUtilities;
034:        import workbench.gui.WbSwingUtilities;
035:
036:        public class WbCellEditor extends AbstractCellEditor implements 
037:                TableCellEditor, MouseListener {
038:            private TextAreaEditor editor;
039:            private WbTable parentTable;
040:            private JScrollPane scroll;
041:
042:            public WbCellEditor(WbTable parent) {
043:                parentTable = parent;
044:                editor = new TextAreaEditor();
045:                setDefaultCopyPasteKeys(editor);
046:                setFont(parent.getFont());
047:                scroll = new TextAreaScrollPane(editor);
048:                scroll
049:                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
050:                scroll
051:                        .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
052:                editor.setLineWrap(false);
053:                editor.setWrapStyleWord(true);
054:                editor.setBorder(WbSwingUtilities.EMPTY_BORDER);
055:                scroll.setBorder(WbSwingUtilities.EMPTY_BORDER);
056:                editor.addMouseListener(new TextComponentMouseListener());
057:                editor.addMouseListener(this );
058:            }
059:
060:            protected void setDefaultCopyPasteKeys(JComponent editor) {
061:                InputMap im = editor.getInputMap();
062:                KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_C,
063:                        InputEvent.CTRL_MASK);
064:                KeyStroke ksnew = KeyStroke.getKeyStroke(KeyEvent.VK_INSERT,
065:                        InputEvent.CTRL_MASK);
066:
067:                Object cmd = im.get(ks);
068:                im.put(ksnew, cmd);
069:
070:                ks = KeyStroke
071:                        .getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK);
072:                ksnew = KeyStroke.getKeyStroke(KeyEvent.VK_INSERT,
073:                        InputEvent.SHIFT_MASK);
074:
075:                cmd = im.get(ks);
076:                im.put(ksnew, cmd);
077:
078:                ks = KeyStroke
079:                        .getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK);
080:                ksnew = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,
081:                        InputEvent.SHIFT_MASK);
082:
083:                cmd = im.get(ks);
084:                im.put(ksnew, cmd);
085:            }
086:
087:            public void setFont(Font aFont) {
088:                this .editor.setFont(aFont);
089:            }
090:
091:            public Component getComponent() {
092:                return scroll;
093:            }
094:
095:            public Object getCellEditorValue() {
096:                return editor.getText();
097:            }
098:
099:            public boolean isCellEditable(EventObject anEvent) {
100:                boolean result = true;
101:                if (anEvent instanceof  MouseEvent) {
102:                    result = ((MouseEvent) anEvent).getClickCount() >= 2;
103:                }
104:                if (result) {
105:                    EventQueue.invokeLater(new Runnable() {
106:                        public void run() {
107:                            editor.requestFocus();
108:                        }
109:                    });
110:                }
111:                return result;
112:            }
113:
114:            public Component getTableCellEditorComponent(JTable table,
115:                    Object value, boolean isSelected, int row, int column) {
116:                editor.setText((value != null) ? value.toString() : "");
117:                return scroll;
118:            }
119:
120:            public boolean shouldSelectCell(EventObject anEvent) {
121:                return true;
122:            }
123:
124:            public boolean isManagingFocus() {
125:                return false;
126:            }
127:
128:            public void mouseClicked(MouseEvent evt) {
129:                if (evt.getClickCount() == 2
130:                        && evt.getButton() == MouseEvent.BUTTON1
131:                        && this .parentTable != null) {
132:                    parentTable.openEditWindow();
133:                }
134:            }
135:
136:            public void mousePressed(MouseEvent evt) {
137:            }
138:
139:            public void mouseReleased(MouseEvent evt) {
140:            }
141:
142:            public void mouseEntered(MouseEvent evt) {
143:            }
144:
145:            public void mouseExited(MouseEvent evt) {
146:            }
147:
148:            class TextAreaEditor extends JTextArea {
149:                public TextAreaEditor() {
150:                    super ();
151:                    this .setFocusCycleRoot(false);
152:                    this .setFocusTraversalKeys(WHEN_FOCUSED,
153:                            Collections.EMPTY_SET);
154:
155:                    Object tabAction = this .getInputMap().get(
156:                            WbSwingUtilities.TAB);
157:
158:                    this .getInputMap().put(WbSwingUtilities.TAB,
159:                            "wb-do-nothing-at-all");
160:
161:                    if (tabAction != null) {
162:                        this .getInputMap().put(WbSwingUtilities.CTRL_TAB,
163:                                tabAction);
164:                    }
165:
166:                    Object enterAction = this .getInputMap().get(
167:                            WbSwingUtilities.ENTER);
168:
169:                    this .getInputMap().put(WbSwingUtilities.ENTER,
170:                            "wb-stop-editing");
171:
172:                    this .getActionMap().put("stopEditing",
173:                            new AbstractAction("wb-stop-editing") {
174:                                public void actionPerformed(ActionEvent e) {
175:                                    stopCellEditing();
176:                                }
177:                            });
178:                    if (enterAction != null) {
179:                        this .getInputMap().put(WbSwingUtilities.CTRL_ENTER,
180:                                enterAction);
181:                        this .getInputMap().put(WbSwingUtilities.ALT_ENTER,
182:                                enterAction);
183:                    }
184:                }
185:
186:                public boolean isManagingFocus() {
187:                    return false;
188:                }
189:            }
190:
191:            public class TextAreaScrollPane extends JScrollPane {
192:                TextAreaEditor editor;
193:
194:                public TextAreaScrollPane(TextAreaEditor content) {
195:                    super (content);
196:                    this .setFocusCycleRoot(false);
197:                    this .setFocusTraversalKeys(WHEN_FOCUSED,
198:                            Collections.EMPTY_SET);
199:                    editor = content;
200:                }
201:
202:                public boolean isManagingFocus() {
203:                    return false;
204:                }
205:
206:                public boolean requestFocus(boolean temp) {
207:                    return editor.requestFocus(temp);
208:                }
209:
210:                public void requestFocus() {
211:                    this .editor.requestFocus();
212:                }
213:
214:                public boolean requestFocusInWindow() {
215:                    return this .editor.requestFocusInWindow();
216:                }
217:
218:                public boolean requestFocusInWindow(boolean temp) {
219:                    return this.editor.requestFocusInWindow();
220:                }
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.