Source code: openfuture/editxml/applet/EditXmlApplet.java
1 package openfuture.editxml.applet;
2
3 /*
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.<p>
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.<p>
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
17 * http://www.gnu.org/copyleft/lesser.html
18 */
19
20 /**
21 * Configuration Management Information:
22 * -------------------------------------
23 * $Id: EditXmlApplet.java,v 1.2 2001/07/22 09:21:56 wreissen Exp $
24 *
25 * Version History:
26 * ----------------
27 * $Log: EditXmlApplet.java,v $
28 * Revision 1.2 2001/07/22 09:21:56 wreissen
29 * - image directory URL added
30 * - locale handling added
31 *
32 * Revision 1.1.1.1 2001/07/08 18:29:29 wreissen
33 * initial version registered ad SourceForge
34 *
35 *
36 */
37
38 import java.applet.AppletContext;
39 import java.awt.BorderLayout;
40 import java.awt.Color;
41 import java.awt.event.WindowAdapter;
42 import java.awt.event.WindowEvent;
43 import java.awt.event.WindowListener;
44 import javax.swing.JApplet;
45 import javax.swing.JFrame;
46 import javax.swing.JLabel;
47 import javax.swing.JPanel;
48 import openfuture.editxml.servlet.EditorServletProxy;
49 import java.util.Locale;
50
51 /**
52 * Applet for editing XML files. <p />
53 *
54 *
55 * Created: Tue Jun 26 06:32:10 2001
56 *
57 * @author <a href="mailto: wolfgang@openfuture.de">Wolfgang Reissenberger</a>
58 * @version $Revision: 1.2 $
59 */
60
61 public class EditXmlApplet extends JApplet{
62
63 private static String servletURL;
64 private static String imagedirURL;
65 private static String localeName;
66
67 /**
68 * Initialize the applet.
69 *
70 */
71 public void init() {
72 try {
73 servletURL = getParameter("servletURL");
74 imagedirURL = getParameter("imagedirURL");
75 localeName = getParameter("locale");
76 } catch (NullPointerException e) {
77 // seems to be started as application
78 }
79 try {
80
81 getContentPane().setBackground(Color.white);
82
83 EditorServletProxy servletProxy =
84 new EditorServletProxy(servletURL);
85
86 RootPanel rootPanel = new RootPanel(servletProxy, imagedirURL,
87 createLocale(localeName));
88
89 getContentPane().setLayout(new BorderLayout());
90 getContentPane().add(rootPanel, BorderLayout.CENTER);
91
92 AppletContext context;
93 try {
94 context = getAppletContext();
95 } catch (NullPointerException e) {
96 // seems to be started as application
97 context = null;
98 }
99 } catch (Exception e) {
100 e.printStackTrace();
101 JPanel mainPanel = new JPanel();
102 mainPanel.add(new JLabel("Initialization failed. Can't contact servlet: " + servletURL));
103 mainPanel.add(new JLabel("Reason: " + e));
104 getContentPane().setLayout(new BorderLayout());
105 getContentPane().add(mainPanel, BorderLayout.CENTER);
106 }
107 }
108
109 /**
110 * Start the applet.
111 *
112 */
113 public void start() {
114 // nothing special
115 }
116
117
118 /**
119 * The applet may be invoked as Java application. Please give the
120 * desired servlet URL as parameter.
121 *
122 * @param args parameter array
123 */
124 public static void main(String[] args) {
125 /*
126 * Create a window. Use JFrame since this window will include
127 * lightweight components.
128 */
129 if (args.length > 1) {
130 servletURL = args[0];
131 imagedirURL = args[1];
132 } else {
133 System.out.println("Usage: java openfuture.editxml.applet.EditXmlApplet <servlet URL> <image directory URL> [<locale>]");
134 return;
135 }
136 if (args.length > 2) {
137 localeName = args[2];
138 } else {
139 localeName = null;
140 }
141
142 JFrame frame = new JFrame("Edit XML");
143
144 WindowListener l = new WindowAdapter() {
145 public void windowClosing(WindowEvent e) {System.exit(0);}
146 };
147 frame.addWindowListener(l);
148
149 EditXmlApplet applet = new EditXmlApplet();
150 applet.init();
151
152 frame.getContentPane().add("Center", applet);
153 frame.setSize(700, 600);
154 frame.setVisible(true);
155 }
156
157 /**
158 * Creates a locale for the given locale name.
159 *
160 * @param name locale name of the form <code>de</code> or
161 * <code>en_GB</code>
162 * @return the corresponding locale
163 */
164 protected Locale createLocale(String name) {
165 if (name != null) {
166 String language;
167 String country;
168 if (name.indexOf("_") > 0) {
169 language = name.substring(0, name.indexOf("_")).toLowerCase();
170 country = name.substring(name.indexOf("_")+1).toUpperCase();
171 } else {
172 language = name.toLowerCase();
173 country = name.toUpperCase();
174 }
175 return(new Locale(language, country));
176
177 } else {
178 return Locale.getDefault();
179 }
180
181 }
182 }// EditXmlApplet