1 22 package org.objectweb.joram.client.tools.admin; 23 24 import javax.swing.*; 25 import java.awt.*; 26 import java.awt.event.*; 27 import java.text.*; 28 29 30 public class ConnectAdminDialog extends JDialog { 31 private static ConnectAdminDialog dialog; 32 private static JLabel hostLabel; 33 private static JLabel portLabel; 34 private static JLabel userLabel; 35 private static JLabel passwdLabel; 36 37 private Frame parent = null; 38 private String adminHost; 39 private int adminPort; 40 private String adminUser; 41 private String adminPasswd; 42 43 private JTextField hostField = null; 44 private JFormattedTextField portField = null; 45 private JTextField userField = null; 46 private JPasswordField passwdField = null; 47 private boolean actionCancelled = false; 48 49 54 public static ConnectAdminDialog initialize(Frame parent) { 55 hostLabel = new JLabel("Host: "); 57 portLabel = new JLabel("Port: "); 58 userLabel = new JLabel("User: "); 59 passwdLabel = new JLabel("Password: "); 60 61 dialog = new ConnectAdminDialog(parent); 62 63 return dialog; 64 } 65 66 72 public static ConnectAdminDialog showDialog() throws Exception { 73 if (dialog != null) { 74 dialog.setActionCancelled(false); 75 dialog.setLocationRelativeTo(dialog.parent); 76 dialog.setVisible(true); 77 } 78 else { 79 throw new Exception ("ConnectDialog not initialized"); 80 } 81 82 return dialog; 83 } 84 85 86 private ConnectAdminDialog(Frame frame) 87 { 88 super(frame, "Connect to Admin server", true); 89 90 parent = frame; 91 92 adminHost = AdminController.DEFAULT_ADMIN_HOST; 93 String portStr = AdminController.DEFAULT_ADMIN_PORT; 94 adminPort = Integer.parseInt(portStr); 95 96 JButton cancelButton = new JButton("Cancel"); 98 final JButton connectButton = new JButton("Connect"); 99 cancelButton.addActionListener(new ActionListener() { 100 public void actionPerformed(ActionEvent e) { 101 ConnectAdminDialog.dialog.setVisible(false); 102 ConnectAdminDialog.dialog.setActionCancelled(true); 103 } 104 }); 105 connectButton.addActionListener(new ActionListener() { 106 public void actionPerformed(ActionEvent e) { 107 ConnectAdminDialog.dialog.setVisible(false); 108 adminHost = hostField.getText(); 109 adminPort = Integer.parseInt(portField.getText()); 110 adminUser = userField.getText(); 111 adminPasswd = new String (passwdField.getPassword()); 112 } 113 }); 114 getRootPane().setDefaultButton(connectButton); 115 116 hostField = new JTextField(adminHost, 30); 118 NumberFormat portFormat = new DecimalFormat("####0"); 119 portFormat.setMaximumIntegerDigits(5); 120 portField = new JFormattedTextField(portFormat); 121 portField.setValue(new Integer (adminPort)); 122 userField = new JTextField(adminUser, 30); 123 passwdField = new JPasswordField(adminPasswd, 30); 124 JLabel[] labels = {hostLabel, portLabel, userLabel, passwdLabel}; 125 JTextField[] textFields = {hostField, portField, userField, passwdField}; 126 JPanel form = new InputFormPanel(labels, textFields); 127 form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 128 129 JPanel buttonPane = new JPanel(); 131 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); 132 buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 133 buttonPane.add(Box.createHorizontalGlue()); 134 buttonPane.add(connectButton); 135 buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); 136 buttonPane.add(cancelButton); 137 138 Container contentPane = getContentPane(); 140 contentPane.add(form, BorderLayout.CENTER); 141 contentPane.add(buttonPane, BorderLayout.SOUTH); 142 143 pack(); 144 } 145 146 public boolean getActionCancelled() { return actionCancelled; } 147 148 public void setActionCancelled(boolean cancelled) 149 { 150 actionCancelled = cancelled; 151 } 152 153 public String getAdminHost() { return adminHost; } 154 155 public void setAdminHost(String host) 156 { 157 adminHost = host; 158 } 159 160 public int getAdminPort() { return adminPort; } 161 162 public void setAdminPort(int port) 163 { 164 adminPort = port; 165 } 166 167 public String getAdminUser() { return adminUser; } 168 169 public void setAdminUser(String user) 170 { 171 adminUser = user; 172 } 173 174 public String getAdminPassword() { return adminPasswd; } 175 176 public void setAdminPassword(String passwd) 177 { 178 adminPasswd = passwd; 179 } 180 } 181 | Popular Tags |