1 6 7 package com.quikj.application.web.talk.client; 8 9 import netscape.javascript.*; 10 import java.applet.*; 11 import java.awt.*; 12 import java.util.*; 13 14 18 public class DHTMLSessionScreen implements ChatScreenInterface 19 { 20 21 private JSObject window; 22 23 24 private Applet applet; 25 26 27 private JSObject chat; 28 29 private StringBuffer transcript = new StringBuffer (); 30 31 32 private Locale locale; 33 34 private TalkSession parent; 35 36 37 public DHTMLSessionScreen() 38 { 39 } 40 41 45 public JSObject getWindow() 46 { 47 return this.window; 48 } 49 50 54 public Applet getApplet() 55 { 56 return this.applet; 57 } 58 59 63 public void setApplet(Applet applet) 64 { 65 this.applet = applet; 66 67 window = JSObject.getWindow(applet); 69 chat = (JSObject)window.getMember("chat"); 70 } 71 72 76 public JSObject getChat() 77 { 78 return this.chat; 79 } 80 81 public void initScreen(TalkSession parent, Locale locale, Applet applet) 82 { 83 setLocale(locale); 84 setApplet(applet); 85 setParent(parent); 86 setTitleText(java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.client.language", 87 locale).getString("Talk_Session")); 88 } 89 90 public void setStatusBarText(String text) 91 { 92 chat.call("setStatusBarText", new Object [] 93 {text}); 94 } 95 96 public void alert(String text) 97 { 98 window.call("alert", new Object [] 99 {text}); 100 } 101 102 public void setActionButtonLabel(String label, Color color) 103 { 104 chat.call("setActionButtonLabel", new Object [] 105 {label}); 106 } 107 108 private void addTextSegment(String label, String color, String weight) 109 { 110 chat.call("writeText", new Object [] 111 {label, color, weight}); 112 transcript.append(label); 113 } 114 115 private void endTextSegment() 116 { 117 chat.call("writeHR", null); 118 chat.call("scrollDown", null); 119 transcript.append("\n"); 120 } 121 122 public void mediaFieldsSetEnabled(boolean enabled) 123 { 124 String val = enabled == true ? "false": "true"; 125 126 chat.call("disableActionButton", new Object [] 127 {val}); 128 chat.call("disableSend", new Object [] 129 {val}); 130 131 if (enabled == true) 132 { 133 chat.call("enableMediaBar", new Object [] 134 {"visible"}); 135 } 136 else 137 { 138 chat.call("enableMediaBar", new Object [] 139 {"hidden"}); 140 } 141 } 142 143 public void setTitleText(String title) 144 { 145 chat.call("setTitle", new Object [] 146 {title}); 147 } 148 149 public String getTranscript() 150 { 151 return transcript.toString(); 152 } 153 154 public void focus() 155 { 156 window.call("focus", null); 157 } 158 159 public void showWebPage(String location) 160 { 161 chat.call("openWebPage", new Object [] 162 {location}); 163 } 164 165 public void informationDialog(String title, String text, String button, int timeout) 166 { 167 chat.call("informationDialog", new Object [] 168 {title, text, button, new Integer (timeout)}); 169 } 170 171 public void appendToConversation(String text, java.awt.Color color, int style) 172 { 173 String color_str = ""; 174 if (color != null) 175 { 176 color_str = "RGB(" 177 + color.getRed() 178 + "," + color.getGreen() 179 + "," + color.getBlue() + ")"; 180 } 181 182 String font_str = ""; 183 switch (style) 184 { 185 case Font.BOLD: 186 font_str = "bold"; 187 break; 188 189 case Font.ITALIC: 190 font_str = "italic"; 191 break; 192 } 193 194 195 char[] text_array = text.toCharArray(); 197 char[] new_text_array = new char[text_array.length]; 198 int count = 0; 199 for (int i = 0; i < text_array.length; i++) 200 { 201 if (text_array[i] == '\r') 202 { 203 continue; 204 } 205 206 new_text_array[count++] = text_array[i]; 207 } 208 209 String cr_removed_str = new String (new_text_array, 0, count); 210 StringTokenizer tokens = new StringTokenizer(cr_removed_str, "\n"); 211 int ct = tokens.countTokens(); 212 boolean ends_with_nl = cr_removed_str.endsWith("\n"); 213 214 for (int i = 0; i < ct; i++) 215 { 216 if (i > 0) 217 { 218 endTextSegment(); 219 } 220 221 addTextSegment(tokens.nextToken(), 222 color_str, font_str); 223 224 if (i == ct -1) { 226 if (ends_with_nl == true) 227 { 228 endTextSegment(); 229 } 230 } 231 } 232 } 233 234 235 public void disposeScreen() 236 { 237 mediaFieldsSetEnabled(false); 238 } 239 240 244 public Locale getLocale() 245 { 246 return this.locale; 247 } 248 249 253 public void setLocale(Locale locale) 254 { 255 this.locale = locale; 256 } 257 258 public void setChatText(String text) 259 { 260 } 262 263 public void addMediaMenuItem(String name, String className) 264 { 265 } 267 268 public void menuItemSetEnabled(String name, boolean enabled) 269 { 270 } 272 273 public boolean yesNoDialog(String title, String text, String yes, String no) 274 { 275 return false; 277 } 278 279 public void setParent(TalkSession parent) 280 { 281 this.parent = parent; 282 } 283 284 public Rectangle getBounds() 285 { 286 String bounds_s = (String )chat.call("getBounds", null); 287 StringTokenizer toks = new StringTokenizer(bounds_s, ","); 288 289 try 290 { 291 Rectangle r = new Rectangle(Integer.parseInt(toks.nextToken()), 292 Integer.parseInt(toks.nextToken()), 293 Integer.parseInt(toks.nextToken()), 294 Integer.parseInt(toks.nextToken())); 295 return r; 296 } 297 catch (NumberFormatException ex) 298 { 299 return null; 300 } 301 } 302 303 } 304 | Popular Tags |