1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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);
}
|