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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
package NET.worlds.console;
import NET.worlds.scape.FrameEvent;
import NET.worlds.scape.Pilot;
import NET.worlds.scape.TeleportAction;
import NET.worlds.scape.TeleportStatus;
import java.awt.Container;
import java.awt.Event;
import java.awt.Label;
import java.awt.Menu;
import java.awt.TextField;
import java.util.Vector;
public class URLLine extends TextField implements FramePart, TeleportStatus, DialogDisabled {
private static final long serialVersionUID = -4154943921462354673L;
protected static String nonloadSign = "URL: ";
public Label label = new Label(nonloadSign);
public Menu historyMenu;
public boolean beingEdited = false;
public String lastTextSet = "";
private String currentText = "";
private boolean okToCallGetText;
private boolean isDialogDisabled;
protected boolean teleporting;
protected int lastURLUpdate;
public static Vector<String> historyItems = new Vector<String>();
@Override
public synchronized String getText() {
return this.okToCallGetText ? super.getText() : this.currentText;
}
private synchronized void syncCurrentText() {
this.okToCallGetText = true;
this.currentText = this.getText();
this.okToCallGetText = false;
}
@Override
public synchronized void setText(String s) {
if (!this.beingEdited) {
if (!this.currentText.equals(this.lastTextSet)) {
this.beingEdited = true;
} else {
this.lastTextSet = s;
if (!this.currentText.equals(s)) {
int p = this.getSelectionStart();
super.setText(this.currentText = s);
this.select(p, p);
}
}
}
}
public void cancelEdit() {
this.beingEdited = false;
this.lastTextSet = this.getText();
this.select(1000, 1000);
this.lastURLUpdate = 0;
}
@Override
public boolean keyDown(Event event, int key) {
if (key != 27) {
return super.keyDown(event, key);
} else {
this.cancelEdit();
return true;
}
}
@Override
public void activate(Console c, Container f, Console prev) {
this.historyMenu = new Menu("History");
this.copyBackupToHistoryMenu();
Console.getMenuBar().add(this.historyMenu);
}
@Override
public void deactivate() {
}
@Override
public void dialogDisable(boolean disable) {
this.isDialogDisabled = disable;
}
@Override
public boolean handleEvent(Event event) {
if (this.isDialogDisabled) {
return false;
} else {
boolean ret = super.handleEvent(event);
if (event.target == this) {
this.syncCurrentText();
}
return ret;
}
}
@Override
public boolean action(Event event, Object what) {
if (event.target == this) {
what = this.getText();
if (((String)what).length() != 0) {
TeleportAction.teleport((String)what, null);
this.cancelEdit();
}
return true;
} else {
return true;
}
}
@Override
public void teleportStatus(String err, String url) {
this.teleporting = err != null && err.length() == 0;
if (err == null) {
this.addHistoryItem(getCurrentPositionURL());
this.setText(url);
}
}
@Override
public boolean handle(FrameEvent f) {
if (f.time < this.lastURLUpdate + 500) {
return true;
} else {
this.lastURLUpdate = f.time;
this.setText(getCurrentPositionURL());
if (this.teleporting) {
if (this.label.getText().equals("LOAD ")) {
this.label.setText("_____ ");
} else {
this.label.setText("LOAD ");
}
} else if (!this.label.getText().equals(nonloadSign)) {
this.label.setText(nonloadSign);
}
return true;
}
}
public static String getCurrentPositionURL() {
Pilot pilot = Pilot.getActive();
if (pilot == null) {
return "";
} else {
String newURL = pilot.getURL();
return newURL == null ? "" : newURL;
}
}
private void addHistoryItem(String url) {
if (url.length() != 0) {
historyItems.insertElementAt(url, 0);
int cnt = historyItems.size();
while (cnt > 10) {
historyItems.removeElementAt(--cnt);
}
this.copyBackupToHistoryMenu();
}
}
private void copyBackupToHistoryMenu() {
while (this.historyMenu.getItemCount() > 0) {
this.historyMenu.remove(0);
}
int cnt = historyItems.size();
if (cnt == 0) {
this.historyMenu.add("");
}
for (int i = 0; i < cnt; i++) {
this.historyMenu.add(historyItems.elementAt(i));
}
}
}
|