Source Code Cross Referenced for FileSelectorPane.java in  » Mail-Clients » pooka » net » suberic » util » gui » propedit » 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 » Mail Clients » pooka » net.suberic.util.gui.propedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.suberic.util.gui.propedit;
002:
003:        import java.io.*;
004:        import javax.swing.*;
005:        import java.awt.event.ActionEvent;
006:
007:        /**
008:         * This displays the currently selected file (if any), along with a 
009:         * button which will bring up a JFileChooser to choose any other file(s).
010:         */
011:
012:        public class FileSelectorPane extends SwingPropertyEditor {
013:
014:            JLabel label;
015:            JTextField valueDisplay;
016:            JButton inputButton;
017:
018:            int fileSelection;
019:
020:            /**
021:             * @param propertyName The property to be edited.  
022:             * @param template The property that will define the layout of the 
023:             *                 editor.
024:             * @param manager The PropertyEditorManager that will manage the
025:             *                   changes.
026:             * @param isEnabled Whether or not this editor is enabled by default. 
027:             */
028:            public void configureEditor(String propertyName, String template,
029:                    PropertyEditorManager newManager, boolean isEnabled) {
030:                property = propertyName;
031:                manager = newManager;
032:                editorTemplate = template;
033:                originalValue = manager.getProperty(property, "");
034:                String currentValue = parseValue(manager.getProperty(property,
035:                        ""));
036:
037:                if (debug) {
038:                    System.out.println("property is " + property
039:                            + "; editorTemplate is " + editorTemplate);
040:                }
041:
042:                label = createLabel();
043:
044:                valueDisplay = new JTextField(currentValue);
045:
046:                inputButton = createInputButton();
047:
048:                valueDisplay.setPreferredSize(new java.awt.Dimension(
049:                        150 - inputButton.getPreferredSize().width,
050:                        valueDisplay.getMinimumSize().height));
051:
052:                String selectionType = manager.getProperty(editorTemplate
053:                        + ".propertyType", "File");
054:                if (selectionType.equalsIgnoreCase("Directory")) {
055:                    fileSelection = JFileChooser.DIRECTORIES_ONLY;
056:                } else {
057:                    fileSelection = JFileChooser.FILES_ONLY;
058:                }
059:
060:                this .add(label);
061:                labelComponent = label;
062:                JPanel tmpPanel = new JPanel(new java.awt.FlowLayout(
063:                        java.awt.FlowLayout.LEFT, 0, 0));
064:                tmpPanel.add(valueDisplay);
065:                tmpPanel.add(inputButton);
066:                tmpPanel.setPreferredSize(new java.awt.Dimension(150,
067:                        valueDisplay.getMinimumSize().height));
068:                valueComponent = tmpPanel;
069:
070:                this .add(tmpPanel);
071:
072:                this .setEnabled(isEnabled);
073:
074:                manager.registerPropertyEditor(property, this );
075:            }
076:
077:            /**
078:             * Creates a button that will bring up a way to select a new File.
079:             */
080:            public JButton createInputButton() {
081:                try {
082:                    java.net.URL url = this .getClass().getResource(
083:                            manager.getProperty(
084:                                    "FileSelectorPane.inputButton.image",
085:                                    "/net/suberic/util/gui/images/More.gif"));
086:                    if (url != null) {
087:                        ImageIcon icon = new ImageIcon(url);
088:
089:                        JButton newButton = new JButton(icon);
090:
091:                        newButton.setPreferredSize(new java.awt.Dimension(icon
092:                                .getIconHeight(), icon.getIconWidth()));
093:                        newButton.addActionListener(new AbstractAction() {
094:                            public void actionPerformed(ActionEvent e) {
095:                                selectNewFolder();
096:                            }
097:                        });
098:
099:                        return newButton;
100:                    }
101:                } catch (java.util.MissingResourceException mre) {
102:                }
103:
104:                JButton newButton = new JButton();
105:                newButton.addActionListener(new AbstractAction() {
106:                    public void actionPerformed(ActionEvent e) {
107:                        selectNewFolder();
108:                    }
109:                });
110:
111:                return newButton;
112:            }
113:
114:            /**
115:             * This actually brings up a JFileChooser to select a new File for 
116:             * the value of the property.
117:             */
118:            public void selectNewFolder() {
119:                JFileChooser jfc = new JFileChooser((String) valueDisplay
120:                        .getText());
121:                jfc.setMultiSelectionEnabled(false);
122:                jfc.setFileSelectionMode(fileSelection);
123:                jfc.setFileHidingEnabled(false);
124:
125:                int returnValue = jfc.showDialog(this , manager.getProperty(
126:                        "FolderEditorPane.Select", "Select"));
127:
128:                if (returnValue == JFileChooser.APPROVE_OPTION) {
129:                    File returnFile = jfc.getSelectedFile();
130:                    String newValue = returnFile.getAbsolutePath();
131:
132:                    try {
133:                        firePropertyChangingEvent(newValue);
134:                        firePropertyChangedEvent(newValue);
135:
136:                        valueDisplay.setText(newValue);
137:
138:                    } catch (PropertyValueVetoException pvve) {
139:                        manager.getFactory().showError(
140:                                valueDisplay,
141:                                "Error changing value " + label.getText()
142:                                        + " to " + newValue + ":  "
143:                                        + pvve.getReason());
144:                    }
145:                }
146:
147:            }
148:
149:            //  as defined in net.suberic.util.gui.PropertyEditorUI
150:
151:            /**
152:             * This writes the currently configured value in the PropertyEditorUI
153:             * to the source PropertyEditorManager.
154:             */
155:            public void setValue() {
156:                if (isEnabled() && isChanged())
157:                    manager.setProperty(property, (String) valueDisplay
158:                            .getText());
159:            }
160:
161:            /**
162:             * Returns the current values of the edited properties as a 
163:             * java.util.Properties object.
164:             */
165:            public java.util.Properties getValue() {
166:                java.util.Properties retProps = new java.util.Properties();
167:
168:                retProps.setProperty(property, (String) valueDisplay.getText());
169:
170:                return retProps;
171:            }
172:
173:            /**
174:             * This resets the editor to the original (or latest set, if setValue() 
175:             * has been called) value of the edited property.
176:             */
177:            public void resetDefaultValue() {
178:                valueDisplay.setText(originalValue);
179:            }
180:
181:            /**
182:             * Returns whether or not this editor has its original value.
183:             */
184:            public boolean isChanged() {
185:                return (!(originalValue.equals(valueDisplay.getText())));
186:            }
187:
188:            /**
189:             * Sets the enabled property of the PropertyEditorUI.  Disabled 
190:             * editors should not be able to do setValue() calls.
191:             */
192:            public void setEnabled(boolean newValue) {
193:                if (inputButton != null) {
194:                    inputButton.setEnabled(newValue);
195:                    enabled = newValue;
196:                }
197:            }
198:
199:            /**
200:             * Parses any ${} special values out of the string.
201:             */
202:            public String parseValue(String origString) {
203:                StringBuffer newValue = new StringBuffer(origString);
204:                int nextVar = origString.indexOf("${");
205:                int offset = 0;
206:                while (nextVar >= 0) {
207:                    int end = origString.indexOf("}", nextVar);
208:                    if (end >= nextVar) {
209:                        String variable = origString
210:                                .substring(nextVar + 2, end);
211:
212:                        String replaceValue = System.getProperty(variable);
213:                        if (replaceValue == null)
214:                            replaceValue = "";
215:                        newValue.replace(nextVar + offset, end + 1 + offset,
216:                                replaceValue);
217:
218:                        offset = offset - end + nextVar + replaceValue.length()
219:                                - 1;
220:
221:                        nextVar = origString.indexOf("${", end);
222:                    } else {
223:                        nextVar = -1;
224:                    }
225:                }
226:                return newValue.toString();
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.