01: package de.java2html.demo;
02:
03: import java.awt.BorderLayout;
04: import java.awt.event.ActionEvent;
05: import java.awt.event.ActionListener;
06: import java.io.File;
07: import java.io.FileWriter;
08: import java.io.IOException;
09:
10: import javax.swing.JButton;
11: import javax.swing.JPanel;
12: import javax.swing.JScrollPane;
13: import javax.swing.JTextArea;
14:
15: import de.java2html.Java2Html;
16: import de.java2html.JavaSourceConversionSettings;
17: import de.java2html.gui.Java2HtmlOptionsPanel;
18: import de.jdemo.extensions.SwingDemoCase;
19: import de.jdemo.util.FileLauncher;
20:
21: /**
22: * @author Markus Gebhard
23: */
24: public class ConvertToHtmlDemo extends SwingDemoCase {
25:
26: public void demo() {
27: final Java2HtmlOptionsPanel optionsPanel = new Java2HtmlOptionsPanel();
28: final JTextArea textArea = new JTextArea(10, 80);
29: JButton button = new JButton("Convert to Html"); //$NON-NLS-1$
30: button.addActionListener(new ActionListener() {
31: public void actionPerformed(ActionEvent event) {
32: JavaSourceConversionSettings conversionOptions = optionsPanel
33: .getConversionSettings();
34: String htmlText = Java2Html.convertToHtmlPage(textArea
35: .getText(), conversionOptions);
36: File file = null;
37: FileWriter writer = null;
38: try {
39: file = File.createTempFile("demo", "." //$NON-NLS-1$ //$NON-NLS-2$
40: + conversionOptions.createConverter()
41: .getMetaData()
42: .getDefaultFileExtension());
43: writer = new FileWriter(file);
44: writer.write(htmlText);
45: } catch (IOException exception) {
46: // TODO Auto-generated catch block
47: exception.printStackTrace();
48: } finally {
49: if (writer != null) {
50: try {
51: writer.close();
52: } catch (IOException exception) {
53: //nothing to do
54: }
55: }
56: }
57: try {
58: new FileLauncher().launch(file);
59: } catch (Exception e) {
60: // TODO Auto-generated catch block
61: e.printStackTrace();
62: }
63: }
64: });
65:
66: JPanel panel = new JPanel(new BorderLayout());
67: panel.add(optionsPanel.getContent(), BorderLayout.NORTH);
68: panel.add(new JScrollPane(textArea), BorderLayout.CENTER);
69: panel.add(button, BorderLayout.SOUTH);
70:
71: show(panel);
72: }
73: }
|