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 CreateFactoryDialog extends JDialog { 31 private static CreateFactoryDialog dialog; 32 33 private Frame parent = null; 34 35 private boolean actionCancelled = false; 36 37 private String host; 38 private int port; 39 private String factoryName; 40 private String factoryType; 41 42 private JTextField hostField = null; 43 private JFormattedTextField portField = null; 44 private JTextField factoryNameField = null; 45 private ButtonGroup typeGroup = null; 46 private JRadioButton defaultType = null; 47 48 49 54 public static CreateFactoryDialog initialize(Frame parent) { 55 dialog = new CreateFactoryDialog(parent); 56 57 return dialog; 58 } 59 60 66 public static CreateFactoryDialog showDialog() throws Exception { 67 if (dialog != null) { 68 dialog.setActionCancelled(false); 69 dialog.setLocationRelativeTo(dialog.parent); 70 dialog.hostField.setText(""); 71 dialog.portField.setText(""); 72 dialog.factoryNameField.setText(""); 73 dialog.defaultType.setSelected(true); 74 dialog.setVisible(true); 75 } 76 else { 77 throw new Exception ("CreateFactoryDialog not initialized"); 78 } 79 80 return dialog; 81 } 82 83 84 private CreateFactoryDialog(Frame frame) 85 { 86 super(frame, "Create a connection factory", true); 87 88 parent = frame; 89 90 final JButton createButton = new JButton("Create"); 92 JButton cancelButton = new JButton("Cancel"); 93 cancelButton.addActionListener(new ActionListener() { 94 public void actionPerformed(ActionEvent e) { 95 CreateFactoryDialog.dialog.setVisible(false); 96 CreateFactoryDialog.dialog.setActionCancelled(true); 97 } 98 }); 99 createButton.addActionListener(new ActionListener() { 100 public void actionPerformed(ActionEvent e) { 101 CreateFactoryDialog.dialog.setVisible(false); 102 host = hostField.getText(); 103 port = Integer.parseInt(portField.getText()); 104 factoryName = factoryNameField.getText(); 105 factoryType = typeGroup.getSelection().getActionCommand(); 106 } 107 }); 108 getRootPane().setDefaultButton(createButton); 109 110 hostField = new JTextField(host, 30); 112 NumberFormat portFormat = new DecimalFormat("####0"); 113 portFormat.setMaximumIntegerDigits(5); 114 portField = new JFormattedTextField(portFormat); 115 portField.setValue(new Integer (port)); 116 factoryNameField = new JTextField(factoryName, 30); 117 JLabel[] labels = {new JLabel("Host: "), new JLabel("Port: "), new JLabel("Name: ")}; 118 JTextField[] textFields = {hostField, portField, factoryNameField}; 119 JPanel formPanel = new InputFormPanel(labels, textFields); 120 formPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 121 122 JRadioButton cfButton = new JRadioButton("Connection Factory"); 124 cfButton.setActionCommand("CF"); 125 cfButton.setSelected(true); 126 defaultType = cfButton; 127 128 JRadioButton qcfButton = new JRadioButton("Queue Connection Factory"); 129 qcfButton.setActionCommand("QCF"); 130 JRadioButton tcfButton = new JRadioButton("Topic Connection Factory"); 131 tcfButton.setActionCommand("TCF"); 132 JRadioButton xcfButton = new JRadioButton("XA Connection Factory"); 133 xcfButton.setActionCommand("XCF"); 134 JRadioButton xqcfButton = new JRadioButton("XA Queue Connection Factory"); 135 xqcfButton.setActionCommand("XQCF"); 136 JRadioButton xtcfButton = new JRadioButton("XA Topic Connection Factory"); 137 xtcfButton.setActionCommand("XTCF"); 138 139 typeGroup = new ButtonGroup(); 141 typeGroup.add(cfButton); 142 typeGroup.add(qcfButton); 143 typeGroup.add(tcfButton); 144 typeGroup.add(xcfButton); 145 typeGroup.add(xqcfButton); 146 typeGroup.add(xtcfButton); 147 JPanel typePanel = new JPanel(); 148 typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.Y_AXIS)); 149 typePanel.setBorder(BorderFactory.createCompoundBorder( 150 BorderFactory.createTitledBorder("Factory Type"), 151 BorderFactory.createEmptyBorder(10, 10, 10, 10))); 152 typePanel.add(cfButton); 153 typePanel.add(qcfButton); 154 typePanel.add(tcfButton); 155 typePanel.add(xcfButton); 156 typePanel.add(xqcfButton); 157 typePanel.add(xtcfButton); 158 159 JPanel buttonPanel = new JPanel(); 161 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); 162 buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 163 buttonPanel.add(Box.createHorizontalGlue()); 164 buttonPanel.add(createButton); 165 buttonPanel.add(Box.createRigidArea(new Dimension(10, 0))); 166 buttonPanel.add(cancelButton); 167 168 Container contentPane = getContentPane(); 170 contentPane.add(formPanel, BorderLayout.NORTH); 171 contentPane.add(typePanel, BorderLayout.CENTER); 172 contentPane.add(buttonPanel, BorderLayout.SOUTH); 173 174 pack(); 175 } 176 177 public boolean getActionCancelled() { return actionCancelled; } 178 179 public void setActionCancelled(boolean cancelled) 180 { 181 actionCancelled = cancelled; 182 } 183 184 public String getHost() { return host; } 185 186 public void setHost(String host) 187 { 188 this.host = host; 189 } 190 191 public int getPort() { return port; } 192 193 public void setPort(int port) 194 { 195 this.port = port; 196 } 197 198 public String getFactoryName() { return factoryName; } 199 200 public void setFactoryName(String name) 201 { 202 factoryName = name; 203 } 204 205 public String getFactoryType() { return factoryType; } 206 } 207 | Popular Tags |