/* Chat
* Copyright (C) 1998-2004 Alexis de Bernis <alexis@bernis.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.applet.*;
import org.chateverywhere.*;
public class Chat extends Applet implements ActionListener, FocusListener, ItemListener, KeyListener
{
private static String version = "Swing Applet / 1.0.0";
private TextArea main_text;
private TextField user_text, user_nick;
private Button cleartext, go_login;
private Label error_message, usernum_lbl, user_prompt;
private java.awt.List user_list;
private Socket com_sock;
private InetAddress server;
private String nick;
private Hashtable users;
private ChatComThread com_thread;
private Font fnt, ui_fnt;
private Choice usr_fontsize, usr_fontname;
private Label l_font;
private PopupMenu usr_popup;
private Hashtable pmsg_windows;
private boolean login_completed = false;
private Locale user_locale;
private InputStack input_stack;
private ResourceBundle captions;
private AudioClip bip_sound;
private Button option_menu_trigger;
private PopupMenu option_menu;
private CheckboxMenuItem do_notify_connection, do_auto_scrolling;
private CheckboxMenuItem do_bip_on_new_line, do_bip_as_sound_file;
private boolean tab_pressed = false;
/*****************************************************
* *
* Applet initialisation *
* *
*****************************************************/
public void start()
{
System.out.println("Starting ChatEverywhere, build 200402110945");
// New instanciations
pmsg_windows = new Hashtable();
input_stack = new InputStack();
// Various initialisations
check_locale();
set_applet_main_colors();
set_applet_font();
draw_splash_screen();
initialize_main_components();
draw_login_window();
// Check if the nick has been given as a parameter
if(getParameter("Nick") != null) {
user_nick.setText(getParameter("Nick"));
make_changements(getParameter("Nick"));
}
}
/********************** Locales **********************/
private void check_locale()
{
if(getParameter("Language") != null &&
getParameter("Country") != null)
user_locale = new Locale(getParameter("Language"), getParameter("Country"));
else
user_locale = Locale.getDefault();
// System.out.println("System locale is " + Locale.getDefault());
// System.out.println("User locale is " + user_locale);
captions = ResourceBundle.getBundle("org.chateverywhere.resources.Messages", user_locale);
}
/******* Applet foreground and background color ******/
private void set_applet_main_colors()
{
// Check for a background color
if(getParameter("BgColor") != null) {
Color bg_color = Color.decode(getParameter("BgColor"));
if(bg_color != null)
setBackground(bg_color);
}
// Check for a foreground color
if(getParameter("FgColor") != null) {
Color fg_color = Color.decode(getParameter("FgColor"));
if(fg_color != null)
setForeground(fg_color);
}
}
/******************** Working fonts ******************/
private void set_applet_font()
{
String ui_fnt_name = "Arial";
String fnt_name = "Courier";
if(getParameter("UIFontName") != null)
ui_fnt_name = getParameter("UIFontName");
if(getParameter("TextFontName") != null)
fnt_name = getParameter("TextFontName");
ui_fnt = new Font(ui_fnt_name, Font.PLAIN, 12);
fnt = new Font(fnt_name, Font.PLAIN, 12);
}
/*****************************************************
* *
* User interface *
* *
*****************************************************/
/************** Components initialisation ************/
private void initialize_main_components()
{
int i;
Color a_color;
main_text = new TextArea("",20,60,TextArea.SCROLLBARS_VERTICAL_ONLY);
main_text.setEditable(false);
main_text.setFont(fnt);
main_text.setLocale(user_locale);
user_text = new TextField(80);
user_text.setFont(ui_fnt);
user_text.setLocale(user_locale);
user_text.addKeyListener(this);
user_text.addFocusListener(this);
usernum_lbl = new Label(captions.getString("MSG_USERS")+": ", Label.CENTER);
usernum_lbl.setVisible(false);
user_prompt = new Label(captions.getString("MSG_TYPE_HERE"), Label.LEFT);
cleartext = new Button(captions.getString("MSG_CLEAR"));
cleartext.addActionListener(this);
user_list = new java.awt.List(8);
user_list.setFont(ui_fnt);
user_list.setLocale(user_locale);
user_list.setVisible(false);
user_list.addItemListener(this);
usr_fontsize = new Choice();
for(i = 10; i <= 24; i++) {
usr_fontsize.add(Integer.toString(i));
}
usr_fontsize.setFont(ui_fnt);
usr_fontsize.select("12");
usr_fontsize.addItemListener(this);
usr_fontname = new Choice();
usr_fontname.add("Arial");
usr_fontname.add("Courier");
usr_fontname.setFont(ui_fnt);
usr_fontname.select("Courier");
usr_fontname.addItemListener(this);
l_font = new Label(captions.getString("MSG_FONT")+" : ", Label.RIGHT);
l_font.setFont(ui_fnt);
usr_popup = new PopupMenu(captions.getString("MSG_ACTION"));
usr_popup.setFont(ui_fnt);
usr_popup.add("msg");
usr_popup.add("stats");
usr_popup.add("ignore");
usr_popup.add("unignore");
usr_popup.add("kick");
usr_popup.add("ban");
usr_popup.add("unban");
usr_popup.addActionListener(this);
do_auto_scrolling = new CheckboxMenuItem(
captions.getString("MSG_AUTO_SCROLLING"), true);
do_notify_connection = new CheckboxMenuItem(
captions.getString("MSG_NOTIFY_CONNECT"), false);
do_bip_on_new_line = new CheckboxMenuItem(
captions.getString("MSG_BIP_ON_TEXT"), false);
do_bip_as_sound_file = new CheckboxMenuItem(
captions.getString("MSG_BIP_AS_SOUND_FILE"),false);
option_menu = new PopupMenu();
option_menu.add(do_auto_scrolling);
option_menu.add(do_bip_on_new_line);
option_menu.add(do_bip_as_sound_file);
option_menu.add(do_notify_connection);
option_menu_trigger = new Button( // I don't want to set
captions.getString("MSG_OPTIONS")); // a MenuBar for that
option_menu_trigger.setFont(ui_fnt);
option_menu_trigger.add(option_menu);
option_menu_trigger.addActionListener(this);
// Check for a users zone background color
if(getParameter("UsersBgColor") != null) {
a_color = Color.decode(getParameter("UsersBgColor"));
if(a_color != null)
user_list.setBackground(a_color);
}
// Check for a users zone foreground color
if(getParameter("UsersFgColor") != null) {
a_color = Color.decode(getParameter("UsersFgColor"));
if(a_color != null)
user_list.setForeground(a_color);
}
// Check for a main text zone background color
if(getParameter("TextBgColor") != null) {
a_color = Color.decode(getParameter("TextBgColor"));
if(a_color != null)
main_text.setBackground(a_color);
}
// Check for a main text zone foreground color
if(getParameter("TextFgColor") != null) {
a_color = Color.decode(getParameter("TextFgColor"));
if(a_color != null)