package NET.worlds.console; import NET.worlds.core.IniFile; import NET.worlds.scape.FrameEvent; import java.awt.Color; import java.awt.Container; import java.awt.Event; import java.awt.TextField; import java.util.Observer; import java.util.Vector; public abstract class DuplexPart implements FramePart { private boolean classicTextArea; public TextField line = new FocusPreservingTextField(); public SharedTextArea listen; private Vector talkVec = new Vector(); public DuplexPart() { this(true); } public DuplexPart(boolean isShared) { this(isShared, 3); } public DuplexPart(boolean isShared, int height) { this.classicTextArea = IniFile.gamma().getIniInt("classicChatBox", 1) == 1; if (this.classicTextArea) { this.listen = new ClassicSharedTextArea(height, 30, isShared); this.listen.setBackground(Color.white); } else { this.listen = new NewSharedTextArea(height, 30, isShared); this.listen.setBackground(GammaTextArea.getBackgroundColor()); } this.listen.setForeground(Color.black); } public void forceTakeFocus() { ((FocusPreservingTextField)this.line).takeNextFocus(); } @Override public synchronized void activate(Console c, Container f, Console prev) { if (this instanceof ChatPart) { ((FocusPreservingTextField)this.line).isChatLine(); } if (!this.classicTextArea) { Color bg = GammaTextArea.getBackgroundColor(); this.line.setBackground(bg); this.listen.setBackground(bg); this.line.setForeground(Color.black); this.listen.setForeground(Color.black); this.line.repaint(); this.listen.repaint(); } else { this.listen.setBackground(Color.white); this.listen.setForeground(Color.black); } } @Override public void deactivate() { } public void println(String msg) { this.listen.println(msg); } public synchronized void trigger() { this.talkVec.addElement(this.line.getText()); this.line.setText(""); } public synchronized void say(String s) { this.talkVec.addElement(s); } public void scrollToBottom() { this.listen.scrollToBottom(); } @Override public boolean action(Event event, Object what) { if (event.target == this.line) { this.trigger(); return true; } else { return false; } } public void enableLogging(String fileName, String title, boolean append) { this.listen.enableLogging(fileName, title, append); } public void disableLogging() { this.listen.disableLogging(); } public static void addLogObserver(Observer o) { NewSharedTextArea.addLogObserver(o); ClassicSharedTextArea.addLogObserver(o); } public static void deleteLogObserver(Observer o) { NewSharedTextArea.deleteLogObserver(o); ClassicSharedTextArea.addLogObserver(o); } @Override public synchronized boolean handle(FrameEvent f) { this.listen.poll(); while (this.talkVec.size() > 0) { String text = null; synchronized (this) { text = this.talkVec.firstElement(); this.talkVec.removeElementAt(0); } if (text != null) { this.sendText(text); } } return true; } public static String toHtml(String s) { assert s != null; String h = ""; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch (c) { case '"': h = h + """; break; case '&': h = h + "&"; break; case '<': h = h + "<"; break; case '>': h = h + ">"; break; default: h = h + c; } } return h; } protected abstract void sendText(String var1); }