1 48 49 package org.exolab.jms.tools.admin; 50 51 import java.awt.BorderLayout ; 52 import java.awt.FlowLayout ; 53 import java.awt.event.ActionEvent ; 54 import java.awt.event.ActionListener ; 55 import java.awt.event.KeyEvent ; 56 import java.awt.event.WindowAdapter ; 57 import java.awt.event.WindowEvent ; 58 59 import javax.swing.BorderFactory ; 60 import javax.swing.JButton ; 61 import javax.swing.JDialog ; 62 import javax.swing.JFrame ; 63 import javax.swing.JLabel ; 64 import javax.swing.JOptionPane ; 65 import javax.swing.JPanel ; 66 import javax.swing.JSeparator ; 67 import javax.swing.JTextField ; 68 import javax.swing.KeyStroke ; 69 import javax.swing.SwingConstants ; 70 import javax.swing.SwingUtilities ; 71 import javax.swing.border.Border ; 72 import javax.swing.text.Keymap ; 73 74 75 82 public class CreateConsumerDialog extends JDialog { 83 84 protected String consumerName_; 86 protected String topicSubscription_; 87 88 protected JTextField displayText; 90 91 final static public int CANCELED = 1; 93 final static public int CONFIRMED = 2; 94 95 protected int status_; 97 98 private JPanel jPanel1; 100 private JButton okButton; 101 private JButton cancelButton; 102 private JPanel jPanel2; 103 private JPanel jPanel3; 104 private JPanel jPanel4; 105 private JSeparator jSeparator2; 106 private JLabel jLabel1; 107 private JTextField jTextField1; 108 private JLabel jLabel2; 109 private JTextField jTextField2; 110 111 static private CreateConsumerDialog instance_; 113 114 119 public CreateConsumerDialog(JFrame parent) { 120 super(parent, true); 121 initComponents(); 122 pack(); 123 } 124 125 130 protected void initComponents() { 131 jPanel1 = new JPanel (); 132 okButton = new JButton (); 133 cancelButton = new JButton (); 134 jPanel2 = new JPanel (); 135 jPanel3 = new JPanel (); 136 jPanel4 = new JPanel (); 137 jLabel1 = new JLabel (); 138 jLabel1.setText("Enter the consumer name"); 139 jLabel2 = new JLabel (); 140 jLabel2.setText("Enter the topic"); 141 jTextField1 = new JTextField (); 142 jTextField2 = new JTextField (); 143 jSeparator2 = new JSeparator (); 144 setTitle("Create Durable Consumer"); 145 setModal(true); 146 setResizable(true); 147 addWindowListener(new WindowAdapter () { 148 149 public void windowClosing(WindowEvent evt) { 150 closeDialog(evt); 151 } 152 } 153 ); 154 155 jPanel1.setLayout(new FlowLayout (1, 50, 10)); 156 okButton.setToolTipText("Press to confirm Action"); 157 okButton.setText("OK"); 158 getRootPane().setDefaultButton(okButton); 159 jPanel1.add(okButton); 160 cancelButton.setToolTipText("Press to abort Action"); 161 cancelButton.setText("Cancel"); 162 jPanel1.add(cancelButton); 163 getContentPane().add(jPanel1, BorderLayout.SOUTH); 164 jPanel2.setLayout(new BorderLayout (0, 15)); 165 jPanel3.setLayout(new BorderLayout (0, 15)); 166 jPanel4.setLayout(new BorderLayout (0, 15)); 167 jTextField1.setToolTipText 168 ("Enter the unique consumer name"); 169 jTextField2.setToolTipText 170 ("Enter the topic or wildcard subscription"); 171 172 Border loweredbevel = BorderFactory.createLoweredBevelBorder(); 173 174 jTextField1.setBorder(loweredbevel); 175 jTextField1.setEditable(true); 176 jTextField1.setText(""); 177 jTextField1.setHorizontalAlignment(SwingConstants.LEFT); 178 179 jTextField2.setBorder(loweredbevel); 180 jTextField2.setEditable(true); 181 jTextField2.setText(""); 182 jTextField2.setHorizontalAlignment(SwingConstants.LEFT); 183 184 jPanel2.add(jLabel1, BorderLayout.NORTH); 185 jPanel2.add(jTextField1, BorderLayout.CENTER); 186 jPanel2.add(jSeparator2, BorderLayout.SOUTH); 187 188 jPanel3.add(jLabel2, BorderLayout.NORTH); 189 jPanel3.add(jTextField2, BorderLayout.CENTER); 190 jPanel3.add(jSeparator2, BorderLayout.SOUTH); 191 192 jPanel4.add(jPanel2, BorderLayout.NORTH); 193 jPanel4.add(jPanel2, BorderLayout.CENTER); 194 jPanel4.add(jSeparator2, BorderLayout.SOUTH); 195 196 getContentPane().add(jPanel4, BorderLayout.CENTER); 197 198 okButton.addActionListener(new ActionListener () { 199 200 public void actionPerformed(ActionEvent evt) { 201 confirm(); 202 } 203 } 204 ); 205 206 cancelButton.addActionListener(new ActionListener () { 207 208 public void actionPerformed(ActionEvent evt) { 209 cancel(); 210 } 211 } 212 ); 213 214 KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); 217 Keymap km = displayText.getKeymap(); 218 km.removeKeyStrokeBinding(enter); 219 } 220 221 224 public void displayCreateConsumer() { 225 jTextField1.setText(""); 226 jTextField2.setText(""); 227 setLocationRelativeTo(getParent()); 228 status_ = CANCELED; 229 setVisible(true); 230 231 SwingUtilities.invokeLater(new Runnable () { 232 233 public void run() { 234 cancelButton.requestFocus(); 235 } 236 } 237 ); 238 } 239 240 245 public String getConsumerName() { 246 return consumerName_; 247 } 248 249 254 public String getTopicSubscription() { 255 return topicSubscription_; 256 } 257 258 264 protected void closeDialog(WindowEvent evt) { 265 setVisible(false); 266 dispose(); 267 } 268 269 275 public boolean isConfirmed() { 276 return status_ == CONFIRMED; 277 } 278 279 284 protected void cancel() { 285 status_ = CANCELED; 286 setVisible(false); 287 dispose(); 288 } 289 290 297 protected void confirm() { 298 consumerName_ = jTextField1.getText(); 299 topicSubscription_ = jTextField2.getText(); 300 301 if ((consumerName_ == null) || 302 (consumerName_.length() == 0) || 303 (topicSubscription_ == null) || 304 (topicSubscription_.length() == 0)) { 305 JOptionPane.showMessageDialog 306 (this, "A consumer name and topic subscription must be suplied", 307 "Create Error", JOptionPane.ERROR_MESSAGE); 308 } else { 309 status_ = CONFIRMED; 310 setVisible(false); 311 dispose(); 312 } 313 } 314 315 322 public static CreateConsumerDialog instance() { 323 return instance_; 324 } 325 326 333 public static CreateConsumerDialog create(JFrame parent) { 334 if (instance_ == null) { 335 instance_ = new CreateConsumerDialog(parent); 336 } 337 return instance_; 338 } 339 340 343 public void display() { 344 JOptionPane.showInputDialog 345 (getParent(), "Enter a unique consumer name", 346 "Create Durable Consumer", JOptionPane.PLAIN_MESSAGE); 347 } 348 } 349 | Popular Tags |