1 22 package org.objectweb.joram.client.tools.admin; 23 import javax.swing.*; 24 import java.awt.*; 25 import java.awt.event.*; 26 27 28 public class CreateDestinationDialog extends JDialog { 29 private static CreateDestinationDialog dialog; 30 31 private Frame parent = null; 32 33 private boolean actionCancelled = false; 34 35 private String destName; 36 private String destType; 37 38 private JTextField destNameField = null; 39 private ButtonGroup typeGroup = null; 40 private JRadioButton defaultType = null; 41 42 43 48 public static CreateDestinationDialog initialize(Frame parent) { 49 dialog = new CreateDestinationDialog(parent); 50 51 return dialog; 52 } 53 54 60 public static CreateDestinationDialog showDialog() throws Exception { 61 if (dialog != null) { 62 dialog.setActionCancelled(false); 63 dialog.setLocationRelativeTo(dialog.parent); 64 dialog.destNameField.setText(""); 65 dialog.defaultType.setSelected(true); 66 dialog.setVisible(true); 67 } 68 else { 69 throw new Exception ("CreateDestinationDialog not initialized"); 70 } 71 72 return dialog; 73 } 74 75 76 private CreateDestinationDialog(Frame frame) 77 { 78 super(frame, "Create a destination", true); 79 80 parent = frame; 81 82 final JButton createButton = new JButton("Create"); 84 JButton cancelButton = new JButton("Cancel"); 85 cancelButton.addActionListener(new ActionListener() { 86 public void actionPerformed(ActionEvent e) { 87 CreateDestinationDialog.dialog.setVisible(false); 88 CreateDestinationDialog.dialog.setActionCancelled(true); 89 } 90 }); 91 createButton.addActionListener(new ActionListener() { 92 public void actionPerformed(ActionEvent e) { 93 CreateDestinationDialog.dialog.setVisible(false); 94 destName = destNameField.getText(); 95 destType = typeGroup.getSelection().getActionCommand(); 96 } 97 }); 98 getRootPane().setDefaultButton(createButton); 99 100 JPanel namePanel = new JPanel(); 102 namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.X_AXIS)); 103 namePanel.add(new JLabel("Name: ")); 104 destNameField = new JTextField(destName, 30); 105 namePanel.add(destNameField); 106 107 JRadioButton qButton = new JRadioButton("Queue"); 109 qButton.setActionCommand("Q"); 110 qButton.setSelected(true); 111 defaultType = qButton; 112 113 JRadioButton tButton = new JRadioButton("Topic"); 114 tButton.setActionCommand("T"); 115 JRadioButton dmqButton = new JRadioButton("Dead Message Queue"); 116 dmqButton.setActionCommand("DMQ"); 117 118 typeGroup = new ButtonGroup(); 120 typeGroup.add(qButton); 121 typeGroup.add(tButton); 122 typeGroup.add(dmqButton); 123 JPanel typePanel = new JPanel(); 124 typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.Y_AXIS)); 125 typePanel.setBorder(BorderFactory.createCompoundBorder( 126 BorderFactory.createTitledBorder("Destination Type"), 127 BorderFactory.createEmptyBorder(10, 10, 10, 10))); 128 typePanel.add(qButton); 129 typePanel.add(tButton); 130 typePanel.add(dmqButton); 131 132 JPanel buttonPanel = new JPanel(); 134 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); 135 buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 136 buttonPanel.add(Box.createHorizontalGlue()); 137 buttonPanel.add(createButton); 138 buttonPanel.add(Box.createRigidArea(new Dimension(10, 0))); 139 buttonPanel.add(cancelButton); 140 141 Container contentPane = getContentPane(); 143 contentPane.add(namePanel, BorderLayout.NORTH); 144 contentPane.add(typePanel, BorderLayout.CENTER); 145 contentPane.add(buttonPanel, BorderLayout.SOUTH); 146 147 pack(); 148 } 149 150 public boolean getActionCancelled() { return actionCancelled; } 151 152 public void setActionCancelled(boolean cancelled) 153 { 154 actionCancelled = cancelled; 155 } 156 157 public String getDestinationName() { return destName; } 158 159 public void setDestinationName(String name) 160 { 161 destName = name; 162 } 163 164 public String getDestinationType() { return destType; } 165 } 166 | Popular Tags |