KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > tools > admin > ServerPanel


1 /*
2  * Created on May 31, 2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 /*
8  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA.
24  *
25  * Initial developer(s): Alexander Fedorowicz
26  * Contributor(s):
27  */

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 /**
39  * @author afedoro
40  *
41  * To change the template for this generated type comment go to
42  * Window>Preferences>Java>Code Generation>Code and Comments
43  */

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 JavaDoc t = thresholdField.getText();
89       if (t != null && t.length() > 0) {
90         try {
91           c.setDefaultThreshold(id, Integer.parseInt(t));
92         }
93         catch (Exception JavaDoc exc) {
94           thresholdField.setText("");
95           JOptionPane.showMessageDialog(null, exc.getMessage());
96         }
97       }
98       else {
99         try {
100           c.unsetDefaultThreshold(id);
101         }
102         catch (Exception JavaDoc 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 JavaDoc exc) {
113           JOptionPane.showMessageDialog(null, exc.getMessage());
114         }
115       }
116       else {
117         try {
118           c.unsetDefaultDMQ(id);
119         }
120         catch (Exception JavaDoc 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 JavaDoc threshold) { thresholdField.setText(threshold); }
133
134   public void setDMQList(java.util.List JavaDoc 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       // TODO: This comparison is not very clean and should be improved
143
if (ddmq != null && ddmq.toString().equals(dmq.toString()))
144         dmqCombo.setSelectedItem(dmq);
145     }
146   }
147 }
148
Popular Tags