KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > net > qsadmin > gui > PropertiePanel


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.net.qsadmin.gui;
16
17 import java.awt.*;
18 import java.awt.event.*;
19 import javax.swing.*;
20 import javax.swing.event.*;
21 import javax.swing.border.*;
22 import java.util.*;
23
24 import org.quickserver.util.TextFile;
25 import org.quickserver.swing.JFrameUtilities;
26
27 /**
28  * PropertiePanel for
29  * QuickServer Admin GUI - QSAdminGUI
30  * @author Akshathkumar Shetty
31  */

32 public class PropertiePanel extends JPanel {
33     private QSAdminMain qsadminMain;
34     private JPanel targetPanel;
35     private JPanel commandPanel;
36
37     private JLabel targetLabel;
38     private JRadioButton serverButton, selfButton;
39     private JButton reloadButton;
40     private ButtonGroup group;
41
42     private PropertieSet propertieSet;
43
44     //---
45
private String JavaDoc target = "server";
46
47     private GridBagConstraints gbc;
48
49     public PropertiePanel(final QSAdminMain qsadminMain) {
50         Container cp = this;
51         this.qsadminMain = qsadminMain;
52         //target panel
53
targetPanel = new JPanel();
54         targetLabel = new JLabel("<html><font "+
55             "style=\"font-size:10pt;color:#535353\">"+
56             " <b>Target : </b></font>",JLabel.LEFT);
57         serverButton = new JRadioButton("Server");
58         serverButton.setMnemonic(KeyEvent.VK_S);
59         serverButton.setActionCommand("server");
60         serverButton.setSelected(true);
61
62         selfButton = new JRadioButton("Admin Server");
63         selfButton.setMnemonic(KeyEvent.VK_A);
64         selfButton.setActionCommand("self");
65         
66         group = new ButtonGroup();
67         group.add(serverButton);
68         group.add(selfButton);
69         class RadioListener implements ActionListener{
70             public void actionPerformed(ActionEvent e) {
71                 setTarget(e.getActionCommand());
72             }
73         }
74
75         RadioListener rListener = new RadioListener();
76         serverButton.addActionListener(rListener);
77         selfButton.addActionListener(rListener);
78
79         propertieSet = PropertieSet.getPropertieSet();
80         final java.util.List JavaDoc list = propertieSet.getList();
81         //Map map = sms.getMap();
82

83         reloadButton = new JButton("Reload Properties For the Target");
84         class ReloadListener implements ActionListener{
85             public void actionPerformed(ActionEvent e) {
86                 Thread JavaDoc performer = new Thread JavaDoc(new Runnable JavaDoc() {
87                     public void run() {
88                         Iterator cmdIt = list.iterator();
89                         Propertie propertie = null;
90                         while(cmdIt.hasNext()) {
91                             propertie = (Propertie)cmdIt.next();
92                             propertie.load(PropertiePanel.this, qsadminMain);
93                         } //end of while
94
updateConnectionStatus(true);
95                     }
96                 }, "QsAdminGUI-ReloadThread");
97                 performer.start();
98             }
99         }
100         ReloadListener reloadListener = new ReloadListener();
101         reloadButton.addActionListener(reloadListener);
102
103         targetPanel.add(targetLabel);
104         targetPanel.add(serverButton);
105         targetPanel.add(selfButton);
106         targetPanel.add(reloadButton);
107         
108         
109         commandPanel = new JPanel();
110         GridBagConstraints gbc = new GridBagConstraints();
111         commandPanel.setLayout(new GridBagLayout());
112         gbc.insets = new Insets( 0, 0, 0, 0 );
113         Iterator cmdIt = list.iterator();
114         Propertie propertie = null;
115         while(cmdIt.hasNext()) {
116             propertie = (Propertie)cmdIt.next();
117             propertie.addToPanel(commandPanel, gbc, this, qsadminMain);
118         } //end of while
119

120
121         //--- layout main panel
122
cp.setLayout(new BorderLayout(0,10));
123         cp.add(targetPanel,BorderLayout.NORTH);
124         cp.add(commandPanel,BorderLayout.CENTER);
125
126     }
127
128     public String JavaDoc getTarget() {
129         return target;
130     }
131     private void setTarget(String JavaDoc target) {
132         this.target = target;
133     }
134
135     public void updateConnectionStatus(boolean connected) {
136         java.util.List JavaDoc list = propertieSet.getList();
137         Iterator cmdIt = list.iterator();
138         Propertie propertie = null;
139         while(cmdIt.hasNext()) {
140             propertie = (Propertie)cmdIt.next();
141             /*
142             if(qsadminMain.isConnected()==false) {
143                 //remove all values
144                 if(propertie.getType().equals("edit")) {
145                     propertie.getEditField().setText("");
146                     propertie.getEditField().setEnabled(false);
147                 } else if(propertie.getType().equals("edit")) {
148                     propertie.getComboBox().setSelectedItem("");
149                     propertie.getComboBox().setEnabled(false);
150                 }
151             }
152             */

153             if(propertie.getSaveButton()!=null)
154                 propertie.getSaveButton().setEnabled(false);
155         }//end of while
156

157         reloadButton.setEnabled(connected);
158         serverButton.setEnabled(connected);
159         selfButton.setEnabled(connected);
160     }
161 }
162
163
Popular Tags