001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.net.qsadmin.gui;
016:
017: import java.awt.*;
018: import java.awt.event.*;
019: import javax.swing.*;
020: import javax.swing.event.*;
021: import javax.swing.border.*;
022: import java.util.*;
023:
024: import org.quickserver.util.TextFile;
025: import org.quickserver.swing.JFrameUtilities;
026:
027: /**
028: * PropertiePanel for
029: * QuickServer Admin GUI - QSAdminGUI
030: * @author Akshathkumar Shetty
031: */
032: public class PropertiePanel extends JPanel {
033: private QSAdminMain qsadminMain;
034: private JPanel targetPanel;
035: private JPanel commandPanel;
036:
037: private JLabel targetLabel;
038: private JRadioButton serverButton, selfButton;
039: private JButton reloadButton;
040: private ButtonGroup group;
041:
042: private PropertieSet propertieSet;
043:
044: //---
045: private String target = "server";
046:
047: private GridBagConstraints gbc;
048:
049: public PropertiePanel(final QSAdminMain qsadminMain) {
050: Container cp = this ;
051: this .qsadminMain = qsadminMain;
052: //target panel
053: targetPanel = new JPanel();
054: targetLabel = new JLabel("<html><font "
055: + "style=\"font-size:10pt;color:#535353\">"
056: + " <b>Target : </b></font>", JLabel.LEFT);
057: serverButton = new JRadioButton("Server");
058: serverButton.setMnemonic(KeyEvent.VK_S);
059: serverButton.setActionCommand("server");
060: serverButton.setSelected(true);
061:
062: selfButton = new JRadioButton("Admin Server");
063: selfButton.setMnemonic(KeyEvent.VK_A);
064: selfButton.setActionCommand("self");
065:
066: group = new ButtonGroup();
067: group.add(serverButton);
068: group.add(selfButton);
069: class RadioListener implements ActionListener {
070: public void actionPerformed(ActionEvent e) {
071: setTarget(e.getActionCommand());
072: }
073: }
074:
075: RadioListener rListener = new RadioListener();
076: serverButton.addActionListener(rListener);
077: selfButton.addActionListener(rListener);
078:
079: propertieSet = PropertieSet.getPropertieSet();
080: final java.util.List list = propertieSet.getList();
081: //Map map = sms.getMap();
082:
083: reloadButton = new JButton("Reload Properties For the Target");
084: class ReloadListener implements ActionListener {
085: public void actionPerformed(ActionEvent e) {
086: Thread performer = new Thread(new Runnable() {
087: public void run() {
088: Iterator cmdIt = list.iterator();
089: Propertie propertie = null;
090: while (cmdIt.hasNext()) {
091: propertie = (Propertie) cmdIt.next();
092: propertie.load(PropertiePanel.this ,
093: qsadminMain);
094: } //end of while
095: updateConnectionStatus(true);
096: }
097: }, "QsAdminGUI-ReloadThread");
098: performer.start();
099: }
100: }
101: ReloadListener reloadListener = new ReloadListener();
102: reloadButton.addActionListener(reloadListener);
103:
104: targetPanel.add(targetLabel);
105: targetPanel.add(serverButton);
106: targetPanel.add(selfButton);
107: targetPanel.add(reloadButton);
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: //--- layout main panel
121: cp.setLayout(new BorderLayout(0, 10));
122: cp.add(targetPanel, BorderLayout.NORTH);
123: cp.add(commandPanel, BorderLayout.CENTER);
124:
125: }
126:
127: public String getTarget() {
128: return target;
129: }
130:
131: private void setTarget(String target) {
132: this .target = target;
133: }
134:
135: public void updateConnectionStatus(boolean connected) {
136: java.util.List 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: }
|