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 CreateServerDialog extends JDialog { 29 private static CreateServerDialog dialog; 30 private static JLabel nameLabel; 31 private static JLabel hostNameLabel; 32 private static JLabel serverIdLabel; 33 private static JLabel portLabel; 34 35 private Frame parent = null; 36 private String name = ""; 37 private String hostName = ""; 38 private short serverId; 39 private int port; 40 41 private JTextField nameField; 42 private JTextField hostNameField; 43 private JTextField serverIdField; 44 private JTextField portField; 45 private JButton submitButton; 46 private boolean actionCancelled = false; 47 48 53 public static CreateServerDialog initialize(Frame parent) { 54 nameLabel = new JLabel("Server name: "); 56 hostNameLabel = new JLabel("Host name (address): "); 57 serverIdLabel = new JLabel("Server id: "); 58 portLabel = new JLabel("Port: "); 59 60 dialog = new CreateServerDialog(parent); 61 62 return dialog; 63 } 64 65 71 public static CreateServerDialog showDialog() { 72 dialog.nameField.setText(""); 73 dialog.hostNameField.setText(""); 74 75 dialog.setTitle("Create server"); 76 dialog.submitButton.setText("Apply"); 77 78 dialog.setActionCancelled(false); 79 dialog.setLocationRelativeTo(dialog.parent); 80 dialog.setVisible(true); 81 82 return dialog; 83 } 84 85 86 private CreateServerDialog(Frame frame) 87 { 88 super(frame, true); 89 90 parent = frame; 91 92 submitButton = new JButton("Create"); 94 JButton cancelButton = new JButton("Cancel"); 95 cancelButton.addActionListener(new ActionListener() { 96 public void actionPerformed(ActionEvent e) { 97 CreateServerDialog.dialog.setVisible(false); 98 CreateServerDialog.dialog.setActionCancelled(true); 99 } 100 }); 101 102 submitButton.addActionListener(new ActionListener() { 103 public void actionPerformed(ActionEvent e) { 104 CreateServerDialog.dialog.setVisible(false); 105 name = nameField.getText(); 106 serverId = Short.parseShort( 107 serverIdField.getText()); 108 hostName = hostNameField.getText(); 109 port = Integer.parseInt( 110 portField.getText()); 111 } 112 }); 113 getRootPane().setDefaultButton(submitButton); 114 115 nameField = new JTextField(name, 20); 117 hostNameField = new JTextField(hostName, 20); 118 serverIdField = new JTextField("" + serverId, 20); 119 portField = new JTextField("" + port, 20); 120 JLabel[] labels = {nameLabel, 121 hostNameLabel, 122 serverIdLabel, 123 portLabel}; 124 JTextField[] textFields = {nameField, 125 hostNameField, 126 serverIdField, 127 portField}; 128 JPanel form = new InputFormPanel(labels, textFields); 129 form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 130 131 JPanel buttonPane = new JPanel(); 133 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); 134 buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 135 buttonPane.add(Box.createHorizontalGlue()); 136 buttonPane.add(submitButton); 137 buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); 138 buttonPane.add(cancelButton); 139 140 Container contentPane = getContentPane(); 142 contentPane.add(form, BorderLayout.CENTER); 143 contentPane.add(buttonPane, BorderLayout.SOUTH); 144 145 pack(); 146 } 147 148 public boolean getActionCancelled() { return actionCancelled; } 149 150 public void setActionCancelled(boolean cancelled) 151 { 152 actionCancelled = cancelled; 153 } 154 155 public String getName() { return name; } 156 157 public void setName(String name) 158 { 159 this.name = name; 160 } 161 162 public String getHostName() { return hostName; } 163 164 public void setHostName(String hostName) 165 { 166 this.hostName = hostName; 167 } 168 169 public short getServerId() { return serverId; } 170 171 public void setServerId(short serverId) 172 { 173 this.serverId = serverId; 174 } 175 176 public int getPort() { return port; } 177 178 public void setPort(int port) 179 { 180 this.port = port; 181 } 182 } 183 | Popular Tags |