1 7 28 package org.objectweb.joram.client.tools.admin; 29 30 import java.awt.*; 31 import java.awt.event.*; 32 import javax.swing.*; 33 import java.util.*; 34 35 import org.objectweb.joram.client.jms.admin.DeadMQueue; 36 37 38 44 public class ServerPanel extends JPanel { 45 private final AdminController c; 46 47 private int id = 0; 48 private JLabel idLabel = new JLabel(""); 49 private JTextField thresholdField = new JTextField(10); 50 private JComboBox dmqCombo = new JComboBox(); 51 52 public ServerPanel(AdminController c) { 53 super(new BorderLayout()); 54 this.c = c; 55 56 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 57 58 JLabel title = new JLabel("Server Information"); 59 title.setFont(new Font("Arial", Font.BOLD, 18)); 60 title.setHorizontalAlignment(JLabel.LEFT); 61 add(title, BorderLayout.NORTH); 62 63 Box form = Box.createVerticalBox(); 64 form.add(Box.createVerticalStrut(25)); 65 JPanel idPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 66 idPanel.add(new JLabel("Server Id: ")); 67 idPanel.add(idLabel); 68 form.add(idPanel); 69 JPanel dtPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 70 dtPanel.add(new JLabel("Default Threshold: ")); 71 dtPanel.add(thresholdField); 72 form.add(dtPanel); 73 JPanel dmqPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 74 dmqPanel.add(new JLabel("Default Dead Message Queue: ")); 75 dmqPanel.add(dmqCombo); 76 form.add(dmqPanel); 77 form.add(Box.createVerticalStrut(30)); 78 79 JButton applyButton = new JButton("Apply Changes"); 80 applyButton.addActionListener(new ApplyActionListener()); 81 form.add(applyButton, BorderLayout.SOUTH); 82 form.add(Box.createVerticalStrut(250)); 83 add(form, BorderLayout.CENTER); 84 } 85 86 private class ApplyActionListener implements ActionListener { 87 public void actionPerformed(ActionEvent e) { 88 String t = thresholdField.getText(); 89 if (t != null && t.length() > 0) { 90 try { 91 c.setDefaultThreshold(id, Integer.parseInt(t)); 92 } 93 catch (Exception exc) { 94 thresholdField.setText(""); 95 JOptionPane.showMessageDialog(null, exc.getMessage()); 96 } 97 } 98 else { 99 try { 100 c.unsetDefaultThreshold(id); 101 } 102 catch (Exception exc) { 103 JOptionPane.showMessageDialog(null, exc.getMessage()); 104 } 105 } 106 107 int i = dmqCombo.getSelectedIndex(); 108 if (i > 0) { 109 try { 110 c.setDefaultDMQ(id, (DeadMQueue) dmqCombo.getSelectedItem()); 111 } 112 catch (Exception exc) { 113 JOptionPane.showMessageDialog(null, exc.getMessage()); 114 } 115 } 116 else { 117 try { 118 c.unsetDefaultDMQ(id); 119 } 120 catch (Exception exc) { 121 JOptionPane.showMessageDialog(null, exc.getMessage()); 122 } 123 } 124 } 125 } 126 127 public void setServerId(int id) { 128 this.id = id; 129 idLabel.setText(Integer.toString(id)); 130 } 131 132 public void setDefaultThreshold(String threshold) { thresholdField.setText(threshold); } 133 134 public void setDMQList(java.util.List dmqs, DeadMQueue ddmq) { 135 dmqCombo.removeAllItems(); 136 dmqCombo.addItem("No Default DMQ"); 137 138 for (Iterator i = dmqs.iterator(); i.hasNext();) { 139 DeadMQueue dmq = (DeadMQueue) i.next(); 140 dmqCombo.addItem(dmq); 141 142 if (ddmq != null && ddmq.toString().equals(dmq.toString())) 144 dmqCombo.setSelectedItem(dmq); 145 } 146 } 147 } 148 | Popular Tags |