Source Code Cross Referenced for FileChooserExample.java in  » Swing-Library » wings3 » wingset » 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 » wings3 » wingset 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2005 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:        package wingset;
014:
015:        import org.wings.*;
016:        import org.wings.border.SEmptyBorder;
017:        import org.wings.util.SStringBuilder;
018:
019:        import java.awt.*;
020:        import java.awt.event.ActionEvent;
021:        import java.awt.event.ItemEvent;
022:        import java.awt.event.ItemListener;
023:        import java.io.BufferedReader;
024:        import java.io.File;
025:        import java.io.FileReader;
026:        import java.io.IOException;
027:
028:        /**
029:         * @author <a href="mailto:engels@mercatis.de">Holger Engels</a>
030:         */
031:        public class FileChooserExample extends WingSetPane {
032:            static final Color WARN_COLOR = new Color(255, 255, 127);
033:
034:            /**
035:             * the file chooser that gets the files.
036:             */
037:            SFileChooser chooser;
038:
039:            /**
040:             * three cards for different content to be previewd: images, text and
041:             * unknown.
042:             */
043:            SCardLayout contentSwitcher;
044:
045:            /**
046:             * label that shows image content.
047:             */
048:            SLabel iconLabel;
049:
050:            /**
051:             * text area to show text content.
052:             */
053:            STextArea textArea;
054:
055:            /**
056:             * form, that contains the text-area
057:             */
058:            SPanel textForm;
059:
060:            /**
061:             * label for unknown content.
062:             */
063:            SLabel unknownLabel;
064:
065:            /**
066:             * remember the previous file to remove it.
067:             */
068:            File previousFile;
069:            private FileChooserControls controls;
070:
071:            protected SComponent createControls() {
072:                controls = new FileChooserControls();
073:                return controls;
074:            }
075:
076:            public SComponent createExample() {
077:                SPanel panel = new SPanel(new SBorderLayout());
078:                panel.add(createUpload(), SBorderLayout.WEST);
079:                panel.add(createPreview(), SBorderLayout.CENTER);
080:                panel.setVerticalAlignment(SConstants.TOP_ALIGN);
081:
082:                controls.addControllable(chooser);
083:                return panel;
084:            }
085:
086:            protected String getText(File f) {
087:                try {
088:                    SStringBuilder buffer = new SStringBuilder();
089:                    BufferedReader reader = new BufferedReader(
090:                            new FileReader(f));
091:
092:                    String line = reader.readLine();
093:                    while (line != null) {
094:                        buffer.append(line).append("\n");
095:                        line = reader.readLine();
096:                    }
097:
098:                    return buffer.toString();
099:                } catch (Exception ex) {
100:                    return "got exception " + ex.getMessage();
101:                }
102:            }
103:
104:            protected void adaptPreview() {
105:                if (previousFile != null) {
106:                    previousFile.delete();
107:                    previousFile = null;
108:                }
109:                try {
110:                    if (chooser.getFileType().startsWith("text/")) {
111:                        textArea.setText(getText(chooser.getSelectedFile()));
112:                        contentSwitcher.show(textForm);
113:                    } else if (chooser.getFileType().startsWith("image/")) {
114:                        iconLabel
115:                                .setIcon(new SFileIcon(chooser
116:                                        .getSelectedFile(), null, chooser
117:                                        .getFileType()));
118:                        contentSwitcher.show(iconLabel);
119:                    } else {
120:                        contentSwitcher.show(unknownLabel);
121:                    }
122:                    previousFile = chooser.getSelectedFile();
123:                } catch (Exception ex) {
124:                    contentSwitcher.show(unknownLabel);
125:                }
126:            }
127:
128:            protected SComponent createPreview() {
129:                SPanel p = new SPanel(new SFlowDownLayout());
130:                p.setVerticalAlignment(TOP);
131:
132:                contentSwitcher = new SCardLayout();
133:
134:                SPanel contentPane = new SPanel(contentSwitcher);
135:
136:                iconLabel = new SLabel();
137:
138:                textForm = new SPanel();
139:
140:                textArea = new STextArea();
141:                textArea.setColumns(50);
142:                textArea.setRows(20);
143:                textArea.setEditable(false);
144:
145:                unknownLabel = new SLabel("Unknown Content");
146:                unknownLabel.setBackground(WARN_COLOR);
147:
148:                contentPane.add(iconLabel, "ICON");
149:
150:                textForm.add(textArea);
151:                contentPane.add(textForm, "TEXT");
152:
153:                contentPane.add(unknownLabel, "UNKNOWN");
154:
155:                contentSwitcher.show(unknownLabel);
156:
157:                p.setBorder(new SEmptyBorder(20, 80, 0, 0));
158:                p.add(contentPane);
159:
160:                return p;
161:            }
162:
163:            protected SComponent createUpload() {
164:                SPanel form = new SPanel(new SFlowDownLayout());
165:                form.setBorder(new SEmptyBorder(20, 20, 0, 0));
166:
167:                chooser = new SFileChooser();
168:                chooser.setColumns(25);
169:                form.add(chooser);
170:
171:                SButton submit = new SButton("Upload");
172:                submit.setVerticalAlignment(SConstants.RIGHT_ALIGN);
173:                form.add(new SSpacer(0, 10));
174:                form.add(submit);
175:
176:                SPanel p = new SPanel(new SGridLayout(0, 2, 10, 5));
177:                p.add(new SLabel("Message:"));
178:                final SLabel message = new SLabel("");
179:                p.add(message);
180:
181:                p.add(new SLabel("Filename:"));
182:                final SLabel filename = new SLabel("");
183:                p.add(filename);
184:
185:                p.add(new SLabel("Fileid:"));
186:                final SLabel fileid = new SLabel("");
187:                p.add(fileid);
188:
189:                p.add(new SLabel("Filetype:"));
190:                final SLabel filetype = new SLabel("");
191:                p.add(filetype);
192:
193:                p.add(new SLabel("Size:"));
194:                final SLabel size = new SLabel("");
195:                p.add(size);
196:
197:                form.add(new SSpacer(0, 30));
198:                form.add(p);
199:
200:                submit.addActionListener(new java.awt.event.ActionListener() {
201:                    public void actionPerformed(ActionEvent e) {
202:                        try {
203:                            if (chooser.getSelectedFile() != null) {
204:                                message.setText("OK");
205:                                message.setBackground(null);
206:                                filename.setText(chooser.getFileName());
207:                                fileid.setText(chooser.getFileId());
208:                                filetype.setText(chooser.getFileType());
209:                                size.setText(""
210:                                        + chooser.getSelectedFile().length());
211:                                adaptPreview();
212:                            } else {
213:                                message.setText("No file chosen");
214:                                message.setBackground(WARN_COLOR);
215:                            }
216:                        } catch (IOException ex) {
217:                            message.setText(ex.getMessage());
218:                            message.setBackground(WARN_COLOR);
219:                            filename.setText("");
220:                            fileid.setText("");
221:                            filetype.setText("");
222:                            size.setText("");
223:                            contentSwitcher.show(unknownLabel);
224:                        }
225:                        chooser.reset();
226:                    }
227:                });
228:
229:                form.setVerticalAlignment(TOP);
230:
231:                return form;
232:            }
233:
234:            class FileChooserControls extends ComponentControls {
235:                public FileChooserControls() {
236:                    //showAsFormComponentCheckBox.setVisible(false);
237:                    globalControls.setVisible(false);
238:
239:                    Object[] values = { new Integer(1), new Integer(2),
240:                            new Integer(4), new Integer(8), new Integer(16),
241:                            new Integer(32), new Integer(64), new Integer(128),
242:                            new Integer(256) };
243:
244:                    final SComboBox comboBox = new SComboBox(values);
245:                    comboBox.addItemListener(new ItemListener() {
246:                        public void itemStateChanged(ItemEvent e) {
247:                            getSession().setMaxContentLength(
248:                                    ((Integer) comboBox.getSelectedItem())
249:                                            .intValue());
250:                        }
251:                    });
252:                    comboBox.setSelectedItem(new Integer(getSession()
253:                            .getMaxContentLength()));
254:
255:                    addControl(new SLabel(" Maximum Content Length [kB]"));
256:                    addControl(comboBox);
257:                }
258:            }
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.