1 19 22 23 24 import java.awt.*; 25 import java.awt.event.*; 26 import java.util.*; 27 import org.chateverywhere.*; 28 29 public class ChatPrivate extends Frame implements KeyListener, WindowListener 30 { 31 private Chat parent; 32 private String nick, my_nick; 33 private TextField usr_input; 34 private TextArea main_text; 35 private Font txt_fnt; 36 private boolean msg_indicator; 37 private InputStack input_stack; 38 private boolean tab_pressed = false; 39 private ResourceBundle captions; 40 41 42 ChatPrivate(Chat parent, String nick) 43 { 44 super(); 45 46 this.parent = parent; 48 captions = parent.get_translated_messages(); 49 this.setTitle(captions.getString("MSG_CHAT")+" " + nick); 50 this.my_nick = parent.get_my_nick(); 51 this.nick = nick; 52 input_stack = new InputStack(); 53 txt_fnt = parent.get_txt_font(); 54 55 setForeground(parent.getForeground()); 57 setBackground(parent.getBackground()); 58 usr_input = new TextField(30); 59 usr_input.setFont(txt_fnt); 60 usr_input.setForeground(parent.get_fginput_color()); 61 usr_input.setBackground(parent.get_bginput_color()); 62 usr_input.addKeyListener(this); 63 main_text = new TextArea("", 10, 30, TextArea.SCROLLBARS_VERTICAL_ONLY); 64 main_text.setEditable(false); 65 main_text.setFont(txt_fnt); 66 main_text.setForeground(parent.get_fgtext_color()); 67 main_text.setBackground(parent.get_bgtext_color()); 68 69 setLayout(new BorderLayout()); 71 add("Center", main_text); 72 add("South", usr_input); 73 setSize(new Dimension(300, 200)); 74 doLayout(); 75 addWindowListener(this); 76 parent.center_window(this); 77 setVisible(true); 78 } 79 80 public void disp_pmsg(String msg) 81 { 82 display_from(nick, msg); 83 84 if(getFocusOwner() == null) { setTitle("!! "+captions.getString("MSG_CHAT")+" " + nick + " !!"); 86 msg_indicator = true; 87 } 88 } 89 90 public void display_from(String f_nick, String msg) 91 { 92 main_text.append("<" + f_nick + "> " + msg + "\n"); 93 main_text.setCaretPosition(30000); 94 } 95 96 public void change_font(Font new_fnt) { 97 main_text.setFont(new_fnt); 98 } 99 100 101 public void child_terminate() 102 { 103 parent.pchat_closed(nick); 104 dispose(); 105 } 106 107 108 private void send_user_text() 109 { 110 String temp, orig = usr_input.getText(); 111 int nlp; 112 113 temp = orig.trim(); 114 if(temp.length() > 0) { 115 if(temp.startsWith("/")) { 116 parent.proceed_command(temp.substring(1)); 117 input_stack.add(temp); 118 } else { 119 while((nlp = orig.indexOf("\n")) != -1) { 121 String n = orig.substring(0, nlp); 122 parent.send_pmsg(nick, n); 123 display_from(my_nick, n); 124 input_stack.add(n); 125 orig = orig.substring(nlp + 1); 126 } 127 parent.send_pmsg(nick, orig); 128 display_from(my_nick, orig); 129 input_stack.add(orig); 130 } 131 } 132 usr_input.setText(""); 133 } 134 135 136 public void correspondant_has_quit(String byemsg) 137 { 138 main_text.append("**** " + nick + " "+captions.getString("MSG_USER_QUIT")+" (" + byemsg +")\n"); 139 usr_input.setEnabled(false); 140 } 141 142 143 148 149 public void keyPressed(KeyEvent e) { 150 int k_code = e.getKeyCode(); 151 152 if(k_code == KeyEvent.VK_ENTER) { 153 send_user_text(); 154 } else if(k_code == KeyEvent.VK_UP) { 155 String n = input_stack.up(); 156 157 usr_input.setText(n); 158 usr_input.setCaretPosition(n.length() + 1); 159 } else if(k_code == KeyEvent.VK_DOWN) { 160 String n = input_stack.down(); 161 162 if(n != null) { 163 usr_input.setText(n); 164 usr_input.setCaretPosition(n.length() + 1); 165 } 166 } else if(k_code == KeyEvent.VK_ESCAPE) { 167 child_terminate(); 168 } 169 } 170 171 172 173 public void windowClosing(WindowEvent e) 174 { 175 child_terminate(); 176 } 177 178 179 public void windowActivated(WindowEvent e) 180 { 181 if(msg_indicator) { 182 setTitle(captions.getString("MSG_CHAT") + " " + nick); 183 msg_indicator = false; 184 } 185 } 186 187 188 public void keyReleased(KeyEvent e) {} 189 public void keyTyped(KeyEvent e) {} 190 public void windowClosed(WindowEvent e) {} 191 public void windowDeactivated(WindowEvent e) {} 192 public void windowDeiconified(WindowEvent e) {} 193 public void windowIconified(WindowEvent e) {} 194 public void windowOpened(WindowEvent e) {} 195 196 } 197 | Popular Tags |