001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013: package org.rapla;
014:
015: import java.awt.Color;
016: import java.awt.GridLayout;
017: import java.awt.event.ActionEvent;
018: import java.awt.event.ActionListener;
019: import java.net.URL;
020:
021: import javax.swing.BorderFactory;
022: import javax.swing.JApplet;
023: import javax.swing.JButton;
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026:
027: import org.rapla.framework.StartupEnvironment;
028:
029: /** The applet-encapsulation of the Main.class reads the configuration
030: * from the document-base of the applet and displays
031: * an applet with a start button.
032: * @author Christopher Kohlhaas
033: * @see Main
034: */
035:
036: final public class MainApplet extends JApplet {
037: private static final long serialVersionUID = 1L;
038:
039: JPanel dlg = new JPanel();
040: JButton button;
041: JLabel label;
042:
043: boolean startable = false;
044:
045: public MainApplet() {
046: JPanel panel1 = new JPanel();
047: panel1.setBackground(new Color(255, 255, 204));
048:
049: GridLayout gridLayout1 = new GridLayout();
050: gridLayout1.setColumns(1);
051: gridLayout1.setRows(3);
052: gridLayout1.setHgap(10);
053: gridLayout1.setVgap(10);
054: panel1.setLayout(gridLayout1);
055:
056: label = new JLabel("Rapla-Applet loading");
057: panel1.add(label);
058:
059: button = new JButton("StartRapla");
060: button.addActionListener(new ActionListener() {
061:
062: public void actionPerformed(ActionEvent e) {
063: startThread();
064: }
065:
066: });
067: panel1.add(button);
068:
069: dlg.setBackground(new Color(255, 255, 204));
070: dlg.setBorder(BorderFactory.createMatteBorder(1, 1, 2, 2,
071: Color.black));
072: dlg.add(panel1);
073: }
074:
075: public void start() {
076: getRootPane().putClientProperty("defeatSystemEventQueueCheck",
077: Boolean.TRUE);
078: try {
079: setContentPane(dlg);
080: button.setEnabled(startable);
081: startable = true;
082: button.setEnabled(startable);
083: } catch (Exception ex) {
084: ex.printStackTrace();
085: }
086: }
087:
088: private void updateStartable() {
089: javax.swing.SwingUtilities.invokeLater(new Runnable() {
090: public void run() {
091: button.setEnabled(startable);
092: }
093: });
094: }
095:
096: private void startThread() {
097: (new Thread() {
098: public void run() {
099: try {
100: startable = false;
101: updateStartable();
102: Main main = new Main();
103: URL configURL = new URL(getDocumentBase(),
104: "webclient/"
105: + Main.DEFAULT_CLIENT_CONFIG_NAME);
106: main.init(configURL, StartupEnvironment.APPLET);
107: main.env.setDownloadURL(getDocumentBase());
108: System.out.println("Docbase " + getDocumentBase());
109: main.startRapla();
110: } catch (Exception ex) {
111: ex.printStackTrace();
112: } finally {
113: startable = true;
114: updateStartable();
115: }
116: }
117: }).start();
118: }
119:
120: }
|