diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/DuplexPart.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/DuplexPart.java')
| -rw-r--r-- | NET/worlds/console/DuplexPart.java | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/NET/worlds/console/DuplexPart.java b/NET/worlds/console/DuplexPart.java new file mode 100644 index 0000000..abeb4be --- /dev/null +++ b/NET/worlds/console/DuplexPart.java @@ -0,0 +1,160 @@ +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<String> talkVec = new Vector<String>(); + + 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); +} |