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: public String getAppletInfo() {
059: return Version.getJava2HtmlAppletTitle();
060: }
061:
062: public void init() {
063: try {
064: javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
065: public void run() {
066: createGui();
067: }
068: });
069: } catch (Exception e) {
070: System.err
071: .println("createGui didn't successfully complete"); //$NON-NLS-1$
072: }
073: }
074:
075: private void createGui() {
076: GuiTools.setNativeLookAndFeel();
077: optionsPanel = new Java2HtmlOptionsPanel();
078: lStatistics = new JLabel(EMPTY_STATISTICS_TEXT);
079:
080: final DirectTextConversionPanel directTextConversionPanel = new DirectTextConversionPanel(
081: optionsPanel, new IStatisticsView() {
082: public void setStatistics(
083: JavaSourceStatistic statistic) {
084: lStatistics
085: .setText(statistic == null ? EMPTY_STATISTICS_TEXT
086: : "<html>"
087: + statistic
088: .getScreenString("<br>")
089: + "</html>");
090: }
091: });
092:
093: JPanel statisticsPanel = GuiTools
094: .createBorderedPanel("Statistics");
095: statisticsPanel.add(lStatistics);
096: JPanel optionsPanelComponent = GuiTools
097: .createBorderedPanel("Options");
098: optionsPanelComponent.add(optionsPanel.getContent());
099:
100: JPanel eastPanel = new JPanel(new GridBagLayout());
101: final GridBagConstraints c1 = new GridBagConstraints();
102: c1.fill = GridBagConstraints.HORIZONTAL;
103: c1.gridx = 0;
104: c1.anchor = GridBagConstraints.NORTHWEST;
105: eastPanel.add(optionsPanelComponent, c1);
106: eastPanel.add(statisticsPanel, c1);
107: c1.fill = GridBagConstraints.BOTH;
108: c1.weighty = 1.0;
109: eastPanel.add(Box.createVerticalGlue(), c1);
110:
111: Container container = getContentPane();
112: container.setLayout(new BorderLayout(4, 4));
113: container.add(directTextConversionPanel.getContent(),
114: BorderLayout.CENTER);
115: container.add(eastPanel, BorderLayout.EAST);
116: directTextConversionPanel.requestFocus();
117: }
118:
119: public void start() {
120: //nothing to do
121: }
122:
123: public void stop() {
124: //nothing to do
125: }
126:
127: public static void main(String[] args) {
128: //Create frame to run applet in
129: JFrame appletFrame = new JFrame("Applet viewer frame");
130:
131: appletFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
132:
133: //Setup layout manager
134: appletFrame.setLayout(new GridLayout());
135:
136: //Create applet instanse (inset the name of your applet)
137: Java2HtmlApplet myApplet = new Java2HtmlApplet();
138:
139: //Add the applet to the frame
140: appletFrame.getContentPane().add(myApplet, BorderLayout.CENTER);
141:
142: //Set size of the frame (It can be resized using the mouse)
143: appletFrame.setSize(700, 420);
144:
145: //Initialize the applet
146: myApplet.init();
147:
148: //Start the applet
149: myApplet.start();
150:
151: //Make the frame visible
152: appletFrame.setVisible(true);
153:
154: appletFrame.setResizable(false);
155: }
156: }
|