Source Code Cross Referenced for FileConversionPanel.java in  » Code-Analyzer » Java2Html » de » java2html » gui » 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 » Code Analyzer » Java2Html » de.java2html.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.java2html.gui;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.FlowLayout;
005:        import java.awt.GridLayout;
006:        import java.awt.Toolkit;
007:        import java.awt.datatransfer.Clipboard;
008:        import java.awt.datatransfer.StringSelection;
009:        import java.awt.event.ActionEvent;
010:        import java.awt.event.ActionListener;
011:        import java.io.File;
012:        import java.io.IOException;
013:        import java.io.StringWriter;
014:
015:        import javax.swing.DefaultListModel;
016:        import javax.swing.JButton;
017:        import javax.swing.JComponent;
018:        import javax.swing.JFileChooser;
019:        import javax.swing.JLabel;
020:        import javax.swing.JList;
021:        import javax.swing.JOptionPane;
022:        import javax.swing.JPanel;
023:        import javax.swing.JScrollPane;
024:        import javax.swing.border.EmptyBorder;
025:        import javax.swing.event.ListDataEvent;
026:        import javax.swing.event.ListDataListener;
027:        import javax.swing.event.ListSelectionEvent;
028:        import javax.swing.event.ListSelectionListener;
029:        import javax.swing.filechooser.FileFilter;
030:
031:        import de.java2html.JavaSourceConversionSettings;
032:        import de.java2html.converter.IJavaSourceConverter;
033:        import de.java2html.javasource.JavaSource;
034:        import de.java2html.javasource.JavaSourceParser;
035:        import de.java2html.util.Ensure;
036:
037:        public class FileConversionPanel implements  ActionListener {
038:
039:            private final DefaultListModel fileListModel = new DefaultListModel();
040:            private final JList list;
041:            private final JButton bAdd;
042:            private final JButton bRemove;
043:            private final JButton bConvert;
044:            private final JButton bClear;
045:            private File currentDirectory;
046:            private final JComponent content;
047:            private final Java2HtmlOptionsPanel optionsPanel;
048:
049:            public FileConversionPanel(Java2HtmlOptionsPanel optionsPanel) {
050:                Ensure.ensureArgumentNotNull(optionsPanel);
051:                this .optionsPanel = optionsPanel;
052:                list = new JList(fileListModel);
053:
054:                bAdd = new JButton("Add...");
055:                bAdd.addActionListener(this );
056:
057:                bRemove = new JButton("Remove");
058:                bRemove.addActionListener(this );
059:                bRemove.setEnabled(false);
060:
061:                bClear = new JButton("Clear");
062:                bClear.addActionListener(this );
063:                bClear.setEnabled(false);
064:
065:                bConvert = new JButton("Convert");
066:                bConvert.addActionListener(this );
067:                bConvert.setEnabled(false);
068:
069:                final JPanel fileButtonPanel = new JPanel(new GridLayout(0, 1,
070:                        6, 6));
071:                fileButtonPanel.add(bAdd);
072:                fileButtonPanel.add(bRemove);
073:                fileButtonPanel.add(bClear);
074:
075:                final JPanel buttonPanel = new JPanel(new BorderLayout());
076:                buttonPanel.add(fileButtonPanel, BorderLayout.NORTH);
077:
078:                final JPanel filesToConvertPanel = new JPanel(new BorderLayout(
079:                        4, 4));
080:                filesToConvertPanel.add(new JLabel("Files to convert:"),
081:                        BorderLayout.NORTH);
082:                filesToConvertPanel.add(new JScrollPane(list),
083:                        BorderLayout.CENTER);
084:                filesToConvertPanel.add(buttonPanel, BorderLayout.EAST);
085:
086:                final JPanel southPanel = new JPanel(new FlowLayout(
087:                        FlowLayout.LEFT));
088:                southPanel.add(bConvert);
089:
090:                final JPanel panel = new JPanel(new BorderLayout(4, 4));
091:                panel.setBorder(new EmptyBorder(5, 6, 5, 6));
092:                panel.add(filesToConvertPanel, BorderLayout.CENTER);
093:                panel.add(southPanel, BorderLayout.SOUTH);
094:                this .content = panel;
095:
096:                list.addListSelectionListener(new ListSelectionListener() {
097:                    public void valueChanged(ListSelectionEvent e) {
098:                        updateButtonsEnabled();
099:                    }
100:                });
101:                fileListModel.addListDataListener(new ListDataListener() {
102:                    public void contentsChanged(ListDataEvent e) {
103:                        updateButtonsEnabled();
104:                    }
105:
106:                    public void intervalRemoved(ListDataEvent e) {
107:                        updateButtonsEnabled();
108:                    }
109:
110:                    public void intervalAdded(ListDataEvent e) {
111:                        updateButtonsEnabled();
112:                    }
113:                });
114:                updateButtonsEnabled();
115:            }
116:
117:            private void updateButtonsEnabled() {
118:                bRemove.setEnabled(!list.isSelectionEmpty());
119:                bClear.setEnabled(!fileListModel.isEmpty());
120:                bConvert.setEnabled(!fileListModel.isEmpty());
121:            }
122:
123:            private void add() {
124:                JFileChooser chooser = new JFileChooser(currentDirectory);
125:                chooser.setDialogTitle("Open Java Source");
126:                chooser.setFileFilter(new FileFilter() {
127:                    public String getDescription() {
128:                        return "*.java";
129:                    }
130:
131:                    public boolean accept(File f) {
132:                        return f.isDirectory()
133:                                || f.getName().toLowerCase().endsWith(".java");
134:                    }
135:                });
136:                int result = chooser.showOpenDialog(content);
137:                if (result != JFileChooser.APPROVE_OPTION) {
138:                    return;
139:                }
140:                File selectedFile = chooser.getSelectedFile();
141:                currentDirectory = selectedFile.getParentFile();
142:                fileListModel.addElement(selectedFile);
143:            }
144:
145:            private void remove() {
146:                Object[] files = list.getSelectedValues();
147:                for (int i = 0; i < files.length; ++i) {
148:                    fileListModel.removeElement(files[i]);
149:                }
150:            }
151:
152:            private void clear() {
153:                fileListModel.clear();
154:            }
155:
156:            private void convert() {
157:                JavaSourceConversionSettings settings = optionsPanel
158:                        .getConversionSettings();
159:                settings.getConversionOptions().setShowJava2HtmlLink(true);
160:
161:                //Collect statistical information
162:                final StringBuffer report = new StringBuffer();
163:
164:                //Collect conversion-results
165:                StringWriter writer = new StringWriter();
166:
167:                //Create the converter
168:                IJavaSourceConverter converter = settings.createConverter();
169:
170:                Object[] files = fileListModel.toArray();
171:                try {
172:                    converter.writeDocumentHeader(writer, settings
173:                            .getConversionOptions(), "");
174:
175:                    for (int count = 0; count < files.length; ++count) {
176:                        final File file = (File) files[count];
177:                        report.append("<li>File " + (count + 1) + ": "
178:                                + file.getName() + "<blockquote>");
179:
180:                        try {
181:                            if (count > 0) {
182:                                converter.writeBlockSeparator(writer, settings
183:                                        .getConversionOptions());
184:                            }
185:                            JavaSourceParser parser = new JavaSourceParser(
186:                                    settings.getConversionOptions());
187:                            JavaSource source = parser.parse(file);
188:                            converter.convert(source, settings
189:                                    .getConversionOptions(), writer);
190:
191:                            writer.write('\n');
192:
193:                            report.append(source.getStatistic()
194:                                    .getScreenString("<br>")
195:                                    + "</blockquote></li>");
196:                        } catch (IOException e) {
197:                            //TODO Sep 13, 2004 (Markus Gebhard): Error handling!
198:                            System.err.println("Error converting " + file
199:                                    + ": " + e);
200:                        }
201:                    }
202:
203:                    converter.writeDocumentFooter(writer, settings
204:                            .getConversionOptions());
205:                } catch (IOException e) {
206:                    //    TODO Sep 13, 2004 (Markus Gebhard): Error handling!
207:                    System.err.println("Error converting files " + e);
208:                }
209:
210:                //Copy result to system clipboard
211:                StringSelection sel = new StringSelection(writer.getBuffer()
212:                        .toString());
213:                Clipboard clipboard = Toolkit.getDefaultToolkit()
214:                        .getSystemClipboard();
215:                clipboard.setContents(sel, sel);
216:
217:                String plural = "";
218:                if (files.length > 1) {
219:                    plural = "s";
220:                }
221:
222:                //Show success-dialog
223:
224:                final String title = "File" + plural + " converted";
225:                final String text = "<html><b>"
226:                        + files.length
227:                        + " File"
228:                        + plural
229:                        + " successfully converted.</b>"
230:                        + "<ul>"
231:                        + report.toString()
232:                        + "</ul>"
233:                        + "<b>The converted source code has been copied the system clipboard</b>"
234:                        + "</html>";
235:                JOptionPane.showMessageDialog(content, text, title,
236:                        JOptionPane.INFORMATION_MESSAGE);
237:            }
238:
239:            public JComponent getContent() {
240:                return content;
241:            }
242:
243:            public void actionPerformed(ActionEvent evt) {
244:                Object source = evt.getSource();
245:                if (source == bAdd) {
246:                    add();
247:                } else if (source == bRemove) {
248:                    remove();
249:                } else if (source == bClear) {
250:                    clear();
251:                } else {
252:                    convert();
253:                }
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.