Source Code Cross Referenced for FilePropertyEditor.java in  » Swing-Library » l2fprod-common » com » l2fprod » common » beans » 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 » l2fprod common » com.l2fprod.common.beans.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * L2FProd.com Common Components 7.3 License.
003:         *
004:         * Copyright 2005-2007 L2FProd.com
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */package com.l2fprod.common.beans.editor;
018:
019:        import com.l2fprod.common.swing.ComponentFactory;
020:        import com.l2fprod.common.swing.LookAndFeelTweaks;
021:        import com.l2fprod.common.swing.PercentLayout;
022:        import com.l2fprod.common.swing.UserPreferences;
023:        import com.l2fprod.common.util.ResourceManager;
024:
025:        import java.awt.datatransfer.DataFlavor;
026:        import java.awt.datatransfer.Transferable;
027:        import java.awt.event.ActionEvent;
028:        import java.awt.event.ActionListener;
029:        import java.io.File;
030:        import java.util.List;
031:
032:        import javax.swing.JButton;
033:        import javax.swing.JComponent;
034:        import javax.swing.JFileChooser;
035:        import javax.swing.JPanel;
036:        import javax.swing.JTextField;
037:        import javax.swing.TransferHandler;
038:
039:        /**
040:         * FilePropertyEditor. <br>
041:         *  
042:         */
043:        public class FilePropertyEditor extends AbstractPropertyEditor {
044:
045:            protected JTextField textfield;
046:            private JButton button;
047:            private JButton cancelButton;
048:
049:            public FilePropertyEditor() {
050:                this (true);
051:            }
052:
053:            public FilePropertyEditor(boolean asTableEditor) {
054:                editor = new JPanel(new PercentLayout(PercentLayout.HORIZONTAL,
055:                        0)) {
056:                    public void setEnabled(boolean enabled) {
057:                        super .setEnabled(enabled);
058:                        textfield.setEnabled(enabled);
059:                        button.setEnabled(enabled);
060:                        cancelButton.setEnabled(enabled);
061:                    }
062:                };
063:                ((JPanel) editor).add("*", textfield = new JTextField());
064:                ((JPanel) editor).add(button = ComponentFactory.Helper
065:                        .getFactory().createMiniButton());
066:                if (asTableEditor) {
067:                    textfield.setBorder(LookAndFeelTweaks.EMPTY_BORDER);
068:                }
069:                button.addActionListener(new ActionListener() {
070:                    public void actionPerformed(ActionEvent e) {
071:                        selectFile();
072:                    }
073:                });
074:                ((JPanel) editor).add(cancelButton = ComponentFactory.Helper
075:                        .getFactory().createMiniButton());
076:                cancelButton.setText("X");
077:                cancelButton.addActionListener(new ActionListener() {
078:                    public void actionPerformed(ActionEvent e) {
079:                        selectNull();
080:                    }
081:                });
082:                textfield.setTransferHandler(new FileTransferHandler());
083:            }
084:
085:            class FileTransferHandler extends TransferHandler {
086:                public boolean canImport(JComponent comp,
087:                        DataFlavor[] transferFlavors) {
088:                    for (int i = 0, c = transferFlavors.length; i < c; i++) {
089:                        if (transferFlavors[i]
090:                                .equals(DataFlavor.javaFileListFlavor)) {
091:                            return true;
092:                        }
093:                    }
094:                    return false;
095:                }
096:
097:                public boolean importData(JComponent comp, Transferable t) {
098:                    try {
099:                        List list = (List) t
100:                                .getTransferData(DataFlavor.javaFileListFlavor);
101:                        if (list.size() > 0) {
102:                            File oldFile = (File) getValue();
103:                            File newFile = (File) list.get(0);
104:                            String text = newFile.getAbsolutePath();
105:                            textfield.setText(text);
106:                            firePropertyChange(oldFile, newFile);
107:                        }
108:                    } catch (Exception e) {
109:                        e.printStackTrace();
110:                    }
111:                    return true;
112:                }
113:            }
114:
115:            public Object getValue() {
116:                if ("".equals(textfield.getText().trim())) {
117:                    return null;
118:                } else {
119:                    return new File(textfield.getText());
120:                }
121:            }
122:
123:            public void setValue(Object value) {
124:                if (value instanceof  File) {
125:                    textfield.setText(((File) value).getAbsolutePath());
126:                } else {
127:                    textfield.setText("");
128:                }
129:            }
130:
131:            protected void selectFile() {
132:                ResourceManager rm = ResourceManager
133:                        .all(FilePropertyEditor.class);
134:
135:                JFileChooser chooser = UserPreferences.getDefaultFileChooser();
136:                chooser.setDialogTitle(rm
137:                        .getString("FilePropertyEditor.dialogTitle"));
138:                chooser.setApproveButtonText(rm
139:                        .getString("FilePropertyEditor.approveButtonText"));
140:                chooser.setApproveButtonMnemonic(rm
141:                        .getChar("FilePropertyEditor.approveButtonMnemonic"));
142:                customizeFileChooser(chooser);
143:
144:                if (JFileChooser.APPROVE_OPTION == chooser
145:                        .showOpenDialog(editor)) {
146:                    File oldFile = (File) getValue();
147:                    File newFile = chooser.getSelectedFile();
148:                    String text = newFile.getAbsolutePath();
149:                    textfield.setText(text);
150:                    firePropertyChange(oldFile, newFile);
151:                }
152:            }
153:
154:            /**
155:             * Placeholder for subclasses to customize the JFileChooser shown to select a
156:             * file.
157:             * 
158:             * @param chooser
159:             */
160:            protected void customizeFileChooser(JFileChooser chooser) {
161:            }
162:
163:            protected void selectNull() {
164:                Object oldFile = getValue();
165:                textfield.setText("");
166:                firePropertyChange(oldFile, null);
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.