1 /*****************************************************/
2 /* This java file is a part of the */
4 /* - Plouf's Java IRC Client - */
6 /* Copyright (C) 2002 - 2005 Philippe Detournay */
8 /* All contacts : theplouf@yahoo.com */
10 /* PJIRC is free software; you can redistribute */
11 /* it and/or modify it under the terms of the GNU */
12 /* General Public License as published by the */
13 /* Free Software Foundation; version 2 or later of */
16 /* PJIRC is distributed in the hope that it will */
17 /* be useful, but WITHOUT ANY WARRANTY; without */
18 /* even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
20 /* General Public License for more details. */
22 /* You should have received a copy of the GNU */
23 /* General Public License along with PJIRC; if */
24 /* not, write to the Free Software Foundation, */
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
26 /* MA 02111-1307 USA */
28 /*****************************************************/
30 import irc.AppletFileHandler;
31 import irc.AppletImageLoader;
32 import irc.AppletSoundHandler;
33 import irc.AppletURLHandler;
34 import irc.ConfigurationLoader;
35 import irc.EventDispatcher;
36 import irc.FileHandler;
37 import irc.IRCApplication;
38 import irc.IRCConfiguration;
39 import irc.ParameterMixer;
40 import irc.ParameterProvider;
41 import irc.StartupConfiguration;
42 import irc.StreamParameterProvider;
44 import java.awt.FlowLayout;
45 import java.awt.Label;
48 * Root IRCApplet, what is actually displayed in the browser.
50 public class IRCApplet extends java.applet.Applet implements ParameterProvider {
54 private static final long serialVersionUID = 1L;
55 private IRCApplication _application;
60 EventDispatcher.disableBadThreadWarning();
61 EventDispatcher.dispatchEventSyncEx(this, "startEff", new Object[0]);
62 EventDispatcher.enableBadThreadWarning();
63 } catch (Throwable ex) {
64 throw new RuntimeException(ex.toString());
69 public void destroy() {
71 EventDispatcher.disableBadThreadWarning();
72 EventDispatcher.dispatchEventSyncEx(this, "stopEff", new Object[0]);
73 EventDispatcher.enableBadThreadWarning();
74 } catch (Throwable ex) {
75 throw new RuntimeException(ex.toString());
82 public void startEff() {
84 ParameterProvider provider = this;
86 String useFileParameter = getParameter("fileparameter");
87 if (useFileParameter == null)
88 useFileParameter = "pjirc.cfg";
90 FileHandler file = new AppletFileHandler(this);
91 provider = new ParameterMixer(provider, new StreamParameterProvider(file.getInputStream(useFileParameter)));
93 ConfigurationLoader loader = new ConfigurationLoader(provider, new AppletURLHandler(getAppletContext()),
94 new AppletImageLoader(this), new AppletSoundHandler(this), new AppletFileHandler(this));
95 IRCConfiguration ircConfiguration = loader.loadIRCConfiguration();
96 StartupConfiguration startupConfiguration = loader.loadStartupConfiguration();
98 _application = new IRCApplication(ircConfiguration, startupConfiguration, this);
102 } catch (Throwable e) {
103 setLayout(new FlowLayout(FlowLayout.LEFT));
104 add(new Label("Startup error : " + e));
111 public void stopEff() {
112 if (_application != null)
113 _application.uninit();
118 /** -- javascript support -- **/
121 * Send the given string to the current source interpretor.
124 * string to send to the interpretor.
126 public void sendString(String str) {
127 if (_application != null)
128 EventDispatcher.dispatchEventAsync(_application, "sendString", new Object[] { str });
132 * Send the given command to the given source interpretor.
135 * the source's server name, or an empty string if no server
136 * filtering needs to be done.
142 * the command to send.
144 public void sendString(String serverName, String type, String name, String cmd) {
145 if (_application != null)
146 EventDispatcher.dispatchEventAsync(_application, "sendString", new Object[] { serverName, type, name, cmd });
150 * Set the current textfield text.
153 * new textfield text.
155 public void setFieldText(String txt) {
156 if (_application != null)
157 EventDispatcher.dispatchEventAsync(_application, "setFieldText", new Object[] { txt });
161 * Get the current textfield text.
163 * @return the current textfield text.
165 public String getFieldText() {
166 if (_application != null) {
168 return (String) EventDispatcher.dispatchEventAsyncAndWaitEx(_application, "getFieldText", new Object[0]);
169 } catch (Throwable ex) {
170 throw new RuntimeException(ex.toString());
177 * Validate the current textfield text, as if user pressed return key.
179 public void validateText() {
180 if (_application != null)
181 EventDispatcher.dispatchEventAsync(_application, "validateText", new Object[0]);
185 * Request the active source to gain focus.
187 public void requestSourceFocus() {
188 if (_application != null)
189 EventDispatcher.dispatchEventAsync(_application, "requestSourceFocus", new Object[0]);
193 * Request the given source to gain focus.
196 * the source's server name, or an empty string if no server
197 * filtering needs to be done.
203 public void requestSourceFocus(String serverName, String type, String name) {
204 if (_application != null)
205 EventDispatcher.dispatchEventAsync(_application, "requestSourceFocus", new Object[] { serverName, type, name });
209 * Send the given event value to the given plugin.
214 * the event value to be sent.
216 public void sendPluginEvent(String pluginName, Object event) {
217 if (_application != null)
218 EventDispatcher.dispatchEventAsync(_application, "sendPluginEvent", new Object[] { pluginName, event });
222 * Get the plugin value from the given plugin name.
228 * @return the returned plugin value, or null if the plugin is not found.
230 public Object getPluginValue(String pluginName, Object valueName) {
231 if (_application != null) {
233 return EventDispatcher.dispatchEventAsyncAndWaitEx(_application, "getPluginValue", new Object[] { pluginName,
235 } catch (Throwable ex) {
236 throw new RuntimeException(ex.toString());
243 * Get the IRCApplication instance. For advanced use only.
245 * @return the IRCApplication instance.
247 public IRCApplication getIRCApplication() {