1 22 package org.objectweb.joram.client.tools.admin; 23 24 import javax.swing.*; 25 import java.awt.*; 26 import java.awt.event.*; 27 28 public class CreateDomainDialog extends JDialog { 29 private static CreateDomainDialog dialog; 30 private static JLabel nameLabel; 31 private static JLabel portLabel; 32 33 private Frame parent = null; 34 private String name = ""; 35 private int port; 36 37 private JTextField nameField; 38 private JTextField portField; 39 private JButton submitButton; 40 private boolean actionCancelled = false; 41 42 47 public static CreateDomainDialog initialize(Frame parent) { 48 nameLabel = new JLabel("Domain name: "); 50 portLabel = new JLabel("Port: "); 51 52 dialog = new CreateDomainDialog(parent); 53 54 return dialog; 55 } 56 57 63 public static CreateDomainDialog showDialog() { 64 dialog.nameField.setText(""); 65 66 dialog.setTitle("Create domain"); 67 dialog.submitButton.setText("Apply"); 68 69 dialog.setActionCancelled(false); 70 dialog.setLocationRelativeTo(dialog.parent); 71 dialog.setVisible(true); 72 73 return dialog; 74 } 75 76 77 private CreateDomainDialog(Frame frame) { 78 super(frame, true); 79 80 parent = frame; 81 82 submitButton = new JButton("Create"); 84 JButton cancelButton = new JButton("Cancel"); 85 cancelButton.addActionListener(new ActionListener() { 86 public void actionPerformed(ActionEvent e) { 87 CreateDomainDialog.dialog.setVisible(false); 88 CreateDomainDialog.dialog.setActionCancelled(true); 89 } 90 }); 91 92 submitButton.addActionListener(new ActionListener() { 93 public void actionPerformed(ActionEvent e) { 94 CreateDomainDialog.dialog.setVisible(false); 95 name = nameField.getText(); 96 port = Integer.parseInt( 97 portField.getText()); 98 } 99 }); 100 getRootPane().setDefaultButton(submitButton); 101 102 nameField = new JTextField(name, 20); 104 portField = new JTextField("" + port, 20); 105 JLabel[] labels = {nameLabel, 106 portLabel}; 107 JTextField[] textFields = {nameField, 108 portField}; 109 JPanel form = new InputFormPanel(labels, textFields); 110 form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 111 112 JPanel buttonPane = new JPanel(); 114 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); 115 buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 116 buttonPane.add(Box.createHorizontalGlue()); 117 buttonPane.add(submitButton); 118 buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); 119 buttonPane.add(cancelButton); 120 121 Container contentPane = getContentPane(); 123 contentPane.add(form, BorderLayout.CENTER); 124 contentPane.add(buttonPane, BorderLayout.SOUTH); 125 126 pack(); 127 } 128 129 public boolean getActionCancelled() { return actionCancelled; } 130 131 public void setActionCancelled(boolean cancelled) 132 { 133 actionCancelled = cancelled; 134 } 135 136 public String getName() { return name; } 137 138 public void setName(String name) 139 { 140 this.name = name; 141 } 142 143 public int getPort() { return port; } 144 145 public void setPort(int port) 146 { 147 this.port = port; 148 } 149 } 150 | Popular Tags |