Source Code Cross Referenced for WbFilePicker.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:         * WbFilePicker.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.beans.PropertyChangeEvent;
015:        import java.beans.PropertyChangeListener;
016:        import java.io.File;
017:        import javax.swing.JFileChooser;
018:        import javax.swing.SwingUtilities;
019:        import javax.swing.filechooser.FileFilter;
020:        import workbench.gui.WbSwingUtilities;
021:        import workbench.log.LogMgr;
022:        import workbench.resource.Settings;
023:        import workbench.util.ExceptionUtil;
024:        import workbench.util.StringUtil;
025:
026:        /**
027:         *
028:         * @author  support@sql-workbench.net
029:         */
030:        public class WbFilePicker extends javax.swing.JPanel {
031:            private String lastDir;
032:            private FileFilter fileFilter;
033:            private boolean allowMultiple;
034:            private File[] selectedFiles;
035:            private String lastDirProperty = null;
036:
037:            public WbFilePicker() {
038:                initComponents();
039:            }
040:
041:            public void setTextFieldPropertyName(String name) {
042:                this .tfFilename.setName(name);
043:            }
044:
045:            public void setTextfieldTooltip(String text) {
046:                tfFilename.setToolTipText(text);
047:            }
048:
049:            public void setButtonTooltip(String text) {
050:                selectFileButton.setToolTipText(text);
051:            }
052:
053:            public void setLastDirProperty(String prop) {
054:                this .lastDirProperty = prop;
055:                this .lastDir = Settings.getInstance().getProperty(prop, null);
056:            }
057:
058:            public void setEnabled(boolean flag) {
059:                super .setEnabled(flag);
060:                this .tfFilename.setEnabled(flag);
061:                this .selectFileButton.setEnabled(flag);
062:            }
063:
064:            /** This method is called from within the constructor to
065:             * initialize the form.
066:             * WARNING: Do NOT modify this code. The content of this method is
067:             * always regenerated by the Form Editor.
068:             */
069:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
070:            private void initComponents() {
071:                java.awt.GridBagConstraints gridBagConstraints;
072:
073:                tfFilename = new StringPropertyEditor();
074:                selectFileButton = new FlatButton();
075:
076:                setLayout(new java.awt.GridBagLayout());
077:
078:                tfFilename.setColumns(10);
079:                tfFilename.setHorizontalAlignment(javax.swing.JTextField.LEFT);
080:                tfFilename.setName("library"); // NOI18N
081:                tfFilename.addMouseListener(new TextComponentMouseListener());
082:                gridBagConstraints = new java.awt.GridBagConstraints();
083:                gridBagConstraints.gridx = 0;
084:                gridBagConstraints.gridy = 0;
085:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
086:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
087:                gridBagConstraints.weightx = 1.0;
088:                gridBagConstraints.weighty = 1.0;
089:                add(tfFilename, gridBagConstraints);
090:
091:                selectFileButton.setText("...");
092:                selectFileButton.setMaximumSize(new java.awt.Dimension(22, 22));
093:                selectFileButton.setMinimumSize(new java.awt.Dimension(22, 22));
094:                selectFileButton
095:                        .setPreferredSize(new java.awt.Dimension(22, 22));
096:                selectFileButton
097:                        .addActionListener(new java.awt.event.ActionListener() {
098:                            public void actionPerformed(
099:                                    java.awt.event.ActionEvent evt) {
100:                                selectFileButtonActionPerformed(evt);
101:                            }
102:                        });
103:                gridBagConstraints = new java.awt.GridBagConstraints();
104:                gridBagConstraints.gridx = 1;
105:                gridBagConstraints.gridy = 0;
106:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
107:                gridBagConstraints.weighty = 1.0;
108:                gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
109:                add(selectFileButton, gridBagConstraints);
110:            }// </editor-fold>//GEN-END:initComponents
111:
112:            private void selectFileButtonActionPerformed(
113:                    java.awt.event.ActionEvent evt)//GEN-FIRST:event_selectFileButtonActionPerformed
114:            {//GEN-HEADEREND:event_selectFileButtonActionPerformed
115:                try {
116:                    JFileChooser jf = new JFileChooser();
117:                    jf.setMultiSelectionEnabled(allowMultiple);
118:                    if (this .lastDir != null) {
119:                        jf.setCurrentDirectory(new File(this .lastDir));
120:                    }
121:                    if (this .fileFilter != null) {
122:                        jf.setFileFilter(this .fileFilter);
123:                    }
124:                    int answer = jf.showOpenDialog(SwingUtilities
125:                            .getWindowAncestor(this ));
126:                    if (answer == JFileChooser.APPROVE_OPTION) {
127:                        if (this .allowMultiple) {
128:                            this .selectedFiles = jf.getSelectedFiles();
129:                        } else {
130:                            this .selectedFiles = new File[1];
131:                            this .selectedFiles[0] = jf.getSelectedFile();
132:                        }
133:
134:                        StringBuilder path = new StringBuilder(
135:                                this .selectedFiles.length * 100);
136:                        for (int i = 0; i < this .selectedFiles.length; i++) {
137:                            if (this .selectedFiles.length > 1 && i > 0) {
138:                                path.append(StringUtil.getPathSeparator());
139:                            }
140:                            path.append(this .selectedFiles[i].getAbsolutePath()
141:                                    .trim());
142:                        }
143:                        String newValue = path.toString();
144:                        String oldValue = tfFilename.getText();
145:                        this .tfFilename.setText(newValue);
146:                        if (this .lastDirProperty != null) {
147:                            Settings.getInstance().setProperty(lastDirProperty,
148:                                    selectedFiles[0].getParent());
149:                        }
150:                        this .firePropertyChange("filename", oldValue, newValue);
151:                    }
152:                } catch (Throwable e) {
153:                    LogMgr.logError(
154:                            "WbFilePicker.selectFileButtonActionPerformed()",
155:                            "Error selecting file", e);
156:                    WbSwingUtilities.showErrorMessage(ExceptionUtil
157:                            .getDisplay(e));
158:                }
159:            }//GEN-LAST:event_selectFileButtonActionPerformed
160:
161:            public String getFilename() {
162:                return tfFilename.getText();
163:            }
164:
165:            public void setFilename(String name) {
166:                this .tfFilename.setText(name != null ? name : "");
167:                this .tfFilename.setCaretPosition(0);
168:            }
169:
170:            public File getSelectedFile() {
171:                if (this .selectedFiles == null) {
172:                    return null;
173:                }
174:                return this .selectedFiles[0];
175:            }
176:
177:            public File[] getSelectedFiles() {
178:                if (!this .allowMultiple) {
179:                    return null;
180:                }
181:                return this .selectedFiles;
182:            }
183:
184:            public void setAllowMultiple(boolean flag) {
185:                this .allowMultiple = flag;
186:            }
187:
188:            public void setFileFilter(FileFilter f) {
189:                this .fileFilter = f;
190:            }
191:
192:            // Variables declaration - do not modify//GEN-BEGIN:variables
193:            private javax.swing.JButton selectFileButton;
194:            private javax.swing.JTextField tfFilename;
195:            // End of variables declaration//GEN-END:variables
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.