summaryrefslogtreecommitdiff
path: root/NET/worlds/console/BookmarkEditDialog.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/console/BookmarkEditDialog.java')
-rw-r--r--NET/worlds/console/BookmarkEditDialog.java146
1 files changed, 146 insertions, 0 deletions
diff --git a/NET/worlds/console/BookmarkEditDialog.java b/NET/worlds/console/BookmarkEditDialog.java
new file mode 100644
index 0000000..7d42600
--- /dev/null
+++ b/NET/worlds/console/BookmarkEditDialog.java
@@ -0,0 +1,146 @@
+package NET.worlds.console;
+
+import java.awt.Button;
+import java.awt.Event;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Label;
+import java.awt.Panel;
+import java.awt.TextField;
+
+class BookmarkEditDialog extends PolledDialog {
+ private static final long serialVersionUID = 3386024535827699136L;
+ private TextField nameField;
+ private TextField URLField;
+ private Button okButton;
+ private Button cancelButton;
+ private String newName;
+ private String newTarget;
+ private int index;
+ private static Font font = new Font(Console.message("MenuFont"), 0, 12);
+ private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);
+
+ BookmarkEditDialog(java.awt.Window parent, DialogReceiver receiver, String title, String name, String url) {
+ this(parent, receiver, title, name, Console.message("OK"), Console.message("Cancel"), url, -1);
+ }
+
+ BookmarkEditDialog(java.awt.Window parent, DialogReceiver receiver, String title, String name, String ok, String cancel, String url) {
+ this(parent, receiver, title, name, ok, cancel, url, -1);
+ }
+
+ BookmarkEditDialog(java.awt.Window parent, DialogReceiver receiver, String name, String url, int index) {
+ this(parent, receiver, Console.message("Edit-WorldsMark"), name, Console.message("OK"), Console.message("Cancel"), url, index);
+ }
+
+ private BookmarkEditDialog(java.awt.Window parent, DialogReceiver receiver, String title, String name, String ok, String cancel, String url, int index) {
+ super(parent, receiver, title, true);
+ this.index = index;
+ this.nameField = new TextField(name, 40);
+ this.URLField = new TextField(url, 40);
+ this.okButton = new Button(ok);
+ this.cancelButton = new Button(cancel);
+ this.ready();
+ }
+
+ @Override
+ protected void build() {
+ GridBagLayout gbag = new GridBagLayout();
+ this.setLayout(gbag);
+ GridBagConstraints c = new GridBagConstraints();
+ c.fill = 0;
+ c.weightx = 1.0;
+ c.weighty = 1.0;
+ c.gridwidth = 2;
+ c.gridheight = 1;
+ Label lName = new Label(Console.message("Name"));
+ this.add(gbag, lName, c);
+ c.gridwidth = 0;
+ c.fill = 2;
+ this.nameField.setFont(font);
+ this.URLField.setFont(font);
+ this.add(gbag, this.nameField, c);
+ c.fill = 0;
+ c.gridwidth = 2;
+ this.add(gbag, new Label("URL:"), c);
+ c.gridwidth = 0;
+ c.fill = 2;
+ this.add(gbag, this.URLField, c);
+ Panel buttons = new Panel();
+ this.okButton.setFont(bfont);
+ this.cancelButton.setFont(bfont);
+ buttons.add(this.okButton);
+ buttons.add(this.cancelButton);
+ c.gridwidth = 0;
+ c.fill = 0;
+ this.add(gbag, buttons, c);
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ Object target = event.target;
+ if (target == this.okButton && this.mayConfirm()) {
+ return this.done(true);
+ } else {
+ return target == this.cancelButton ? this.done(false) : false;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return this.newName;
+ }
+
+ public String getTarget() {
+ return this.newTarget;
+ }
+
+ public int getIndex() {
+ return this.index;
+ }
+
+ private boolean mayConfirm() {
+ this.newName = this.nameField.getText();
+ int i = this.newName.length();
+
+ do {
+ i--;
+ } while (i >= 0 && this.newName.charAt(i) == ' ');
+
+ this.newName = this.newName.substring(0, i + 1);
+ this.newTarget = this.URLField.getText().trim();
+ return this.newName.length() != 0 && this.newTarget.length() != 0;
+ }
+
+ @Override
+ public boolean keyDown(Event event, int key) {
+ if (key == 27) {
+ return this.done(false);
+ } else {
+ if (key == 10) {
+ if (this.mayConfirm()) {
+ return this.done(true);
+ }
+ } else if (key == 9) {
+ if (event.target == this.nameField) {
+ this.URLField.requestFocus();
+ this.URLField.selectAll();
+ } else if (event.target == this.URLField) {
+ this.nameField.requestFocus();
+ this.nameField.selectAll();
+ }
+
+ return true;
+ }
+
+ return super.keyDown(event, key);
+ }
+ }
+
+ @Override
+ public void show() {
+ super.show();
+ this.nameField.requestFocus();
+ this.nameField.selectAll();
+ }
+}