KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > java2html > Java2HtmlApplet


1 package de.java2html;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Container JavaDoc;
5 import java.awt.GridBagConstraints JavaDoc;
6 import java.awt.GridBagLayout JavaDoc;
7 import java.awt.GridLayout JavaDoc;
8
9 import javax.swing.Box JavaDoc;
10 import javax.swing.JApplet JavaDoc;
11 import javax.swing.JFrame JavaDoc;
12 import javax.swing.JLabel JavaDoc;
13 import javax.swing.JPanel JavaDoc;
14
15 import de.java2html.gui.DirectTextConversionPanel;
16 import de.java2html.gui.GuiTools;
17 import de.java2html.gui.IStatisticsView;
18 import de.java2html.gui.Java2HtmlOptionsPanel;
19 import de.java2html.javasource.JavaSourceStatistic;
20
21 /**
22  * Applet for the Java2Html converter.
23  *
24  * For questions, suggestions, bug-reports, enhancement-requests etc. I may be
25  * contacted at: <a HREF="mailto:markus@jave.de">markus@jave.de</a>
26  *
27  * The Java2html home page is located at: <a HREF="http://www.java2html.de">
28  * http://www.java2html.de</a>
29  *
30  * @author <a HREF="mailto:markus@jave.de">Markus Gebhard</a>
31  * @version 2.1, 06/30/02
32  *
33  * Copyright (C) Markus Gebhard 2000-2003
34  *
35  * This program is free software; you can redistribute it and/or modify it
36  * under the terms of the GNU General Public License as published by the Free
37  * Software Foundation; either version 2 of the License, or (at your option)
38  * any later version.
39  *
40  * This program is distributed in the hope that it will be useful, but WITHOUT
41  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
43  * more details.
44  *
45  * You should have received a copy of the GNU General Public License along with
46  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
47  * Place - Suite 330, Boston, MA 02111-1307, USA.
48  */

49 public class Java2HtmlApplet extends JApplet JavaDoc {
50   private static final String JavaDoc EMPTY_STATISTICS_TEXT = "<html>-<br>-<br>-</html>";
51
52   private JLabel JavaDoc lStatistics;
53   private Java2HtmlOptionsPanel optionsPanel;
54
55   /**
56    * Applet info.
57    */

58   public String JavaDoc getAppletInfo() {
59     return Version.getJava2HtmlAppletTitle();
60   }
61
62   public void init() {
63     try {
64       javax.swing.SwingUtilities.invokeAndWait(new Runnable JavaDoc() {
65         public void run() {
66           createGui();
67         }
68       });
69     }
70     catch (Exception JavaDoc e) {
71       System.err.println("createGui didn't successfully complete"); //$NON-NLS-1$
72
}
73   }
74
75   private void createGui() {
76     GuiTools.setNativeLookAndFeel();
77     optionsPanel = new Java2HtmlOptionsPanel();
78     lStatistics = new JLabel JavaDoc(EMPTY_STATISTICS_TEXT);
79
80     final DirectTextConversionPanel directTextConversionPanel = new DirectTextConversionPanel(
81         optionsPanel,
82         new IStatisticsView() {
83           public void setStatistics(JavaSourceStatistic statistic) {
84             lStatistics.setText(statistic == null ? EMPTY_STATISTICS_TEXT : "<html>"
85                 + statistic.getScreenString("<br>")
86                 + "</html>");
87           }
88         });
89
90     JPanel JavaDoc statisticsPanel = GuiTools.createBorderedPanel("Statistics");
91     statisticsPanel.add(lStatistics);
92     JPanel JavaDoc optionsPanelComponent = GuiTools.createBorderedPanel("Options");
93     optionsPanelComponent.add(optionsPanel.getContent());
94
95     JPanel JavaDoc eastPanel = new JPanel JavaDoc(new GridBagLayout JavaDoc());
96     final GridBagConstraints JavaDoc c1 = new GridBagConstraints JavaDoc();
97     c1.fill = GridBagConstraints.HORIZONTAL;
98     c1.gridx = 0;
99     c1.anchor = GridBagConstraints.NORTHWEST;
100     eastPanel.add(optionsPanelComponent, c1);
101     eastPanel.add(statisticsPanel, c1);
102     c1.fill = GridBagConstraints.BOTH;
103     c1.weighty = 1.0;
104     eastPanel.add(Box.createVerticalGlue(), c1);
105
106     Container JavaDoc container = getContentPane();
107     container.setLayout(new BorderLayout JavaDoc(4, 4));
108     container.add(directTextConversionPanel.getContent(), BorderLayout.CENTER);
109     container.add(eastPanel, BorderLayout.EAST);
110     directTextConversionPanel.requestFocus();
111   }
112
113   public void start() {
114     //nothing to do
115
}
116
117   public void stop() {
118     //nothing to do
119
}
120
121   public static void main(String JavaDoc[] args) {
122     //Create frame to run applet in
123
JFrame JavaDoc appletFrame = new JFrame JavaDoc("Applet viewer frame");
124
125     appletFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
126
127     //Setup layout manager
128
appletFrame.setLayout(new GridLayout JavaDoc());
129
130     //Create applet instanse (inset the name of your applet)
131
Java2HtmlApplet myApplet = new Java2HtmlApplet();
132
133     //Add the applet to the frame
134
appletFrame.getContentPane().add(myApplet, BorderLayout.CENTER);
135
136     //Set size of the frame (It can be resized using the mouse)
137
appletFrame.setSize(700, 420);
138
139     //Initialize the applet
140
myApplet.init();
141
142     //Start the applet
143
myApplet.start();
144
145     //Make the frame visible
146
appletFrame.setVisible(true);
147
148     appletFrame.setResizable(false);
149   }
150 }
Popular Tags