KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.quickserver.util.TextFile;
24 import org.quickserver.swing.JFrameUtilities;
25
26 /**
27  * Main CommandPanel fro
28  * QuickServer Admin GUI - QSAdminGUI
29  * @author Akshathkumar Shetty
30  */

31 public class MainCommandPanel extends JPanel {
32     private QSAdminMain qsadminMain;
33     private JPanel targetPanel;
34     private JPanel commandPanel;
35
36     private JLabel targetLabel;
37     private JRadioButton serverButton, selfButton;
38
39     //---
40
private String JavaDoc target = "server";
41     private SimpleCommandSet sms;
42
43     private GridBagConstraints gbc;
44
45     public MainCommandPanel(final QSAdminMain qsadminMain) {
46         Container cp = this;
47         this.qsadminMain = qsadminMain;
48         //target panel
49
targetPanel = new JPanel();
50         targetLabel = new JLabel("<html><font "+
51             "style=\"font-size:10pt;color:#535353\">"+
52             " <b>Target : </b></font>",JLabel.LEFT);
53         serverButton = new JRadioButton("Server");
54         serverButton.setMnemonic(KeyEvent.VK_S);
55         serverButton.setActionCommand("server");
56         serverButton.setSelected(true);
57
58         selfButton = new JRadioButton("Admin Server");
59         selfButton.setMnemonic(KeyEvent.VK_A);
60         selfButton.setActionCommand("self");
61         
62         ButtonGroup group = new ButtonGroup();
63         group.add(serverButton);
64         group.add(selfButton);
65         class RadioListener implements ActionListener{
66             public void actionPerformed(ActionEvent e) {
67                 setTarget(e.getActionCommand());
68             }
69         }
70
71         RadioListener rListener = new RadioListener();
72         serverButton.addActionListener(rListener);
73         selfButton.addActionListener(rListener);
74
75         targetPanel.add(targetLabel);
76         targetPanel.add(serverButton);
77         targetPanel.add(selfButton);
78         
79
80         sms = SimpleCommandSet.getSimpleCommands();
81         java.util.List JavaDoc list = sms.getList();
82         //Map map = sms.getMap();
83
commandPanel = new JPanel();
84         commandPanel.setLayout(new GridLayout((int)list.size(), 1,2,2));
85         Iterator cmdIt = list.iterator();
86         SimpleCommand sm = null;
87         JButton cmdButton = null;
88         while(cmdIt.hasNext()) {
89             sm = (SimpleCommand)cmdIt.next();
90             StringBuffer JavaDoc sf = new StringBuffer JavaDoc(sm.getName());
91             if(sf.length()<15) {
92                 sf.append(' ');
93                 sf.insert(0, ' ');
94             }
95             cmdButton = new JButton("<html><font style=\"font-size:10pt;color:#008080\"><b>"+
96             sf.toString()+"</b></font>");
97             cmdButton.setToolTipText(sm.getDesc());
98             cmdButton.addActionListener(getSimpleAction(sm));
99             commandPanel.add(cmdButton);
100         } //end of while
101

102         //--- layout main panel
103
cp.setLayout(new BorderLayout(0,10));
104         cp.add(targetPanel,BorderLayout.NORTH);
105         JScrollPane commandScrollPane = new JScrollPane(commandPanel);
106         cp.add(commandScrollPane,BorderLayout.CENTER);
107
108         /*setBorder(new CompoundBorder(
109             BorderFactory.createEmptyBorder(1,1,1,1),
110             BorderFactory.createTitledBorder("Simple Commands")
111             ));
112         */

113         //setPreferredSize(new java.awt.Dimension(100,200));
114
}
115
116     public String JavaDoc getTarget() {
117         return target;
118     }
119     private void setTarget(String JavaDoc target) {
120         this.target = target;
121     }
122
123     private ActionListener getSimpleAction(SimpleCommand cm) {
124         return new SimpleActionListener(qsadminMain, cm,
125             MainCommandPanel.this);
126     }
127
128     public void updateConnectionStatus(boolean connected) {
129         serverButton.setEnabled(connected);
130         selfButton.setEnabled(connected);
131         commandPanel.setEnabled(connected);
132     }
133 }
134
135
Popular Tags