001 package de.java2html;
002
003 import java.awt.BorderLayout;
004 import java.awt.Container;
005 import java.awt.GridBagConstraints;
006 import java.awt.GridBagLayout;
007 import java.awt.GridLayout;
008
009 import javax.swing.Box;
010 import javax.swing.JApplet;
011 import javax.swing.JFrame;
012 import javax.swing.JLabel;
013 import javax.swing.JPanel;
014
015 import de.java2html.gui.DirectTextConversionPanel;
016 import de.java2html.gui.GuiTools;
017 import de.java2html.gui.IStatisticsView;
018 import de.java2html.gui.Java2HtmlOptionsPanel;
019 import de.java2html.javasource.JavaSourceStatistic;
020
021 /**
022 * Applet for the Java2Html converter.
023 *
024 * For questions, suggestions, bug-reports, enhancement-requests etc. I may be
025 * contacted at: <a href="mailto:markus@jave.de">markus@jave.de</a>
026 *
027 * The Java2html home page is located at: <a href="http://www.java2html.de">
028 * http://www.java2html.de</a>
029 *
030 * @author <a href="mailto:markus@jave.de">Markus Gebhard</a>
031 * @version 2.1, 06/30/02
032 *
033 * Copyright (C) Markus Gebhard 2000-2003
034 *
035 * This program is free software; you can redistribute it and/or modify it
036 * under the terms of the GNU General Public License as published by the Free
037 * Software Foundation; either version 2 of the License, or (at your option)
038 * any later version.
039 *
040 * This program is distributed in the hope that it will be useful, but WITHOUT
041 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
042 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
043 * more details.
044 *
045 * You should have received a copy of the GNU General Public License along with
046 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
047 * Place - Suite 330, Boston, MA 02111-1307, USA.
048 */
049 public class Java2HtmlApplet extends JApplet {
050 private static final String EMPTY_STATISTICS_TEXT = "<html>-<br>-<br>-</html>";
051
052 private JLabel lStatistics;
053 private Java2HtmlOptionsPanel optionsPanel;
054
055 /**
056 * Applet info.
057 */
058 @Override
059 public String getAppletInfo() {
060 return Version.getJava2HtmlAppletTitle();
061 }
062
063 @Override
064 public void init() {
065 try {
066 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
067 public void run() {
068 createGui();
069 }
070 });
071 }
072 catch (final Exception e) {
073 System.err.println("createGui didn't successfully complete"); //$NON-NLS-1$
074 }
075 }
076
077 private void createGui() {
078 GuiTools.setNativeLookAndFeel();
079 optionsPanel = new Java2HtmlOptionsPanel();
080 lStatistics = new JLabel(EMPTY_STATISTICS_TEXT);
081
082 final DirectTextConversionPanel directTextConversionPanel = new DirectTextConversionPanel(
083 optionsPanel,
084 new IStatisticsView() {
085 public void setStatistics(JavaSourceStatistic statistic) {
086 lStatistics.setText(statistic == null ? EMPTY_STATISTICS_TEXT : "<html>"
087 + statistic.getScreenString("<br>")
088 + "</html>");
089 }
090 });
091
092 final JPanel statisticsPanel = GuiTools.createBorderedPanel("Statistics");
093 statisticsPanel.add(lStatistics);
094 final JPanel optionsPanelComponent = GuiTools.createBorderedPanel("Options");
095 optionsPanelComponent.add(optionsPanel.getContent());
096
097 final JPanel eastPanel = new JPanel(new GridBagLayout());
098 final GridBagConstraints c1 = new GridBagConstraints();
099 c1.fill = GridBagConstraints.HORIZONTAL;
100 c1.gridx = 0;
101 c1.anchor = GridBagConstraints.NORTHWEST;
102 eastPanel.add(optionsPanelComponent, c1);
103 eastPanel.add(statisticsPanel, c1);
104 c1.fill = GridBagConstraints.BOTH;
105 c1.weighty = 1.0;
106 eastPanel.add(Box.createVerticalGlue(), c1);
107
108 final Container container = getContentPane();
109 container.setLayout(new BorderLayout(4, 4));
110 container.add(directTextConversionPanel.getContent(), BorderLayout.CENTER);
111 container.add(eastPanel, BorderLayout.EAST);
112 directTextConversionPanel.requestFocus();
113 }
114
115 @Override
116 public void start() {
117 //nothing to do
118 }
119
120 @Override
121 public void stop() {
122 //nothing to do
123 }
124
125 public static void main(String[] args) {
126 //Create frame to run applet in
127 final JFrame appletFrame = new JFrame("Applet viewer frame");
128
129 appletFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
130
131 //Setup layout manager
132 appletFrame.setLayout(new GridLayout());
133
134 //Create applet instanse (inset the name of your applet)
135 final Java2HtmlApplet myApplet = new Java2HtmlApplet();
136
137 //Add the applet to the frame
138 appletFrame.getContentPane().add(myApplet, BorderLayout.CENTER);
139
140 //Set size of the frame (It can be resized using the mouse)
141 appletFrame.setSize(700, 420);
142
143 //Initialize the applet
144 myApplet.init();
145
146 //Start the applet
147 myApplet.start();
148
149 //Make the frame visible
150 appletFrame.setVisible(true);
151
152 appletFrame.setResizable(false);
153 }
154 }
|