summaryrefslogtreecommitdiff
path: root/NET/worlds/console/URLLine.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/URLLine.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/URLLine.java')
-rw-r--r--NET/worlds/console/URLLine.java184
1 files changed, 184 insertions, 0 deletions
diff --git a/NET/worlds/console/URLLine.java b/NET/worlds/console/URLLine.java
new file mode 100644
index 0000000..7f4772f
--- /dev/null
+++ b/NET/worlds/console/URLLine.java
@@ -0,0 +1,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));
+ }
+ }
+}