package NET.worlds.console; import java.awt.Button; import java.awt.Color; 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; public class LocationDialog extends PolledDialog { private static final long serialVersionUID = -6550771504344935484L; private Button okButton = new Button(Console.message("OK")); private Button cancelButton = new Button(Console.message("Cancel")); private Label label = new Label(Console.message("New-URL")); private static Font font = new Font(Console.message("ButtonFont"), 0, 12); private static Font gfont = new Font(Console.message("GammaTextFont"), 0, 12); private TextField locationField; public LocationDialog(java.awt.Window parent, DialogReceiver receiver, String title, String location) { super(parent, receiver, title, true); this.locationField = new TextField(location, 40); this.locationField.setFont(gfont); this.ready(); } public String getLocationURL() { return this.locationField.getText(); } @Override protected void build() { this.setBackground(Color.white); GridBagLayout gbag = new GridBagLayout(); this.setLayout(gbag); GridBagConstraints c = new GridBagConstraints(); c.weightx = 0.0; c.weighty = 0.0; c.gridheight = 1; c.fill = 0; c.anchor = 13; c.gridwidth = 1; this.label.setFont(font); this.add(gbag, this.label, c); c.weightx = 1.0; c.weighty = 0.0; c.gridwidth = 0; c.fill = 2; c.anchor = 17; this.locationField.setFont(gfont); this.add(gbag, this.locationField, c); Panel buttons = new Panel(); this.okButton.setFont(font); this.cancelButton.setFont(font); buttons.add(this.okButton); buttons.add(this.cancelButton); c.gridwidth = 0; c.anchor = 10; c.fill = 0; this.add(gbag, buttons, c); } @Override public void show() { super.show(); this.locationField.requestFocus(); } @Override public boolean handleEvent(Event event) { return event.id == 201 ? this.done(false) : super.handleEvent(event); } @Override public boolean action(Event event, Object what) { Object target = event.target; if (target == this.cancelButton) { return this.done(false); } else { return target == this.okButton ? this.done(true) : false; } } @Override public boolean keyDown(Event event, int key) { if (key == 27) { return this.done(false); } else { return key == 10 ? this.done(true) : super.keyDown(event, key); } } }