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 ConnectJndiDialog extends JDialog { 31 private static ConnectJndiDialog dialog; 32 private static JLabel hostLabel; 33 private static JLabel portLabel; 34 private static JLabel ctxLabel; 35 36 private Frame parent = null; 37 private String jndiHost; 38 private int jndiPort; 39 private String namedCtx = ""; 40 private JTextField hostField = null; 41 private JFormattedTextField portField = null; 42 private JTextField ctxField = null; 43 private boolean actionCancelled = false; 44 45 50 public static ConnectJndiDialog initialize(Frame parent) { 51 hostLabel = new JLabel("Host: "); 53 portLabel = new JLabel("Port: "); 54 ctxLabel = new JLabel("Context: "); 55 56 dialog = new ConnectJndiDialog(parent); 57 58 return dialog; 59 } 60 61 67 public static ConnectJndiDialog showDialog() throws Exception { 68 if (dialog != null) { 69 dialog.setActionCancelled(false); 70 dialog.setLocationRelativeTo(dialog.parent); 71 dialog.setVisible(true); 72 } 73 else { 74 throw new Exception ("ConnectDialog not initialized"); 75 } 76 77 return dialog; 78 } 79 80 81 private ConnectJndiDialog(Frame frame) 82 { 83 super(frame, "Connect to JNDI directory", true); 84 85 parent = frame; 86 87 jndiHost = System.getProperty(AdminController.PROP_JNDI_HOST) != null ? System.getProperty(AdminController.PROP_JNDI_HOST) : AdminController.DEFAULT_JNDI_HOST; 88 String portStr = System.getProperty(AdminController.PROP_JNDI_PORT) != null ? System.getProperty(AdminController.PROP_JNDI_PORT) : AdminController.DEFAULT_JNDI_PORT; 89 jndiPort = Integer.parseInt(portStr); 90 91 JButton cancelButton = new JButton("Cancel"); 93 final JButton connectButton = new JButton("Connect"); 94 cancelButton.addActionListener(new ActionListener() { 95 public void actionPerformed(ActionEvent e) { 96 ConnectJndiDialog.dialog.setVisible(false); 97 ConnectJndiDialog.dialog.setActionCancelled(true); 98 } 99 }); 100 connectButton.addActionListener(new ActionListener() { 101 public void actionPerformed(ActionEvent e) { 102 ConnectJndiDialog.dialog.setVisible(false); 103 jndiHost = hostField.getText(); 104 jndiPort = Integer.parseInt(portField.getText()); 105 namedCtx = ctxField.getText(); 106 } 107 }); 108 getRootPane().setDefaultButton(connectButton); 109 110 hostField = new JTextField(jndiHost, 30); 112 NumberFormat portFormat = new DecimalFormat("####0"); 113 portFormat.setMaximumIntegerDigits(5); 114 portField = new JFormattedTextField(portFormat); 115 portField.setValue(new Integer (jndiPort)); 116 ctxField = new JTextField(namedCtx, 30); 117 JLabel[] labels = {hostLabel, portLabel, ctxLabel}; 118 JTextField[] textFields = {hostField, portField, ctxField}; 119 JPanel form = new InputFormPanel(labels, textFields); 120 form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 121 122 JPanel buttonPane = new JPanel(); 124 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); 125 buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 126 buttonPane.add(Box.createHorizontalGlue()); 127 buttonPane.add(connectButton); 128 buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); 129 buttonPane.add(cancelButton); 130 131 Container contentPane = getContentPane(); 133 contentPane.add(form, BorderLayout.CENTER); 134 contentPane.add(buttonPane, BorderLayout.SOUTH); 135 136 pack(); 137 } 138 139 public boolean getActionCancelled() { return actionCancelled; } 140 141 public void setActionCancelled(boolean cancelled) 142 { 143 actionCancelled = cancelled; 144 } 145 146 public String getJndiHost() { return jndiHost; } 147 148 public void setJndiHost(String host) 149 { 150 jndiHost = host; 151 } 152 153 public int getJndiPort() { return jndiPort; } 154 155 public void setJndiPort(int port) 156 { 157 jndiPort = port; 158 } 159 160 public String getNamedContext() { return namedCtx; } 161 162 public void setNamedContext(String ctx) 163 { 164 namedCtx = ctx; 165 } 166 } 167 | Popular Tags |