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: import org.quickserver.util.TextFile;
024: import org.quickserver.swing.JFrameUtilities;
025:
026: /**
027: * Main CommandPanel fro
028: * QuickServer Admin GUI - QSAdminGUI
029: * @author Akshathkumar Shetty
030: */
031: public class MainCommandPanel extends JPanel {
032: private QSAdminMain qsadminMain;
033: private JPanel targetPanel;
034: private JPanel commandPanel;
035:
036: private JLabel targetLabel;
037: private JRadioButton serverButton, selfButton;
038:
039: //---
040: private String target = "server";
041: private SimpleCommandSet sms;
042:
043: private GridBagConstraints gbc;
044:
045: public MainCommandPanel(final QSAdminMain qsadminMain) {
046: Container cp = this ;
047: this .qsadminMain = qsadminMain;
048: //target panel
049: targetPanel = new JPanel();
050: targetLabel = new JLabel("<html><font "
051: + "style=\"font-size:10pt;color:#535353\">"
052: + " <b>Target : </b></font>", JLabel.LEFT);
053: serverButton = new JRadioButton("Server");
054: serverButton.setMnemonic(KeyEvent.VK_S);
055: serverButton.setActionCommand("server");
056: serverButton.setSelected(true);
057:
058: selfButton = new JRadioButton("Admin Server");
059: selfButton.setMnemonic(KeyEvent.VK_A);
060: selfButton.setActionCommand("self");
061:
062: ButtonGroup group = new ButtonGroup();
063: group.add(serverButton);
064: group.add(selfButton);
065: class RadioListener implements ActionListener {
066: public void actionPerformed(ActionEvent e) {
067: setTarget(e.getActionCommand());
068: }
069: }
070:
071: RadioListener rListener = new RadioListener();
072: serverButton.addActionListener(rListener);
073: selfButton.addActionListener(rListener);
074:
075: targetPanel.add(targetLabel);
076: targetPanel.add(serverButton);
077: targetPanel.add(selfButton);
078:
079: sms = SimpleCommandSet.getSimpleCommands();
080: java.util.List list = sms.getList();
081: //Map map = sms.getMap();
082: commandPanel = new JPanel();
083: commandPanel.setLayout(new GridLayout((int) list.size(), 1, 2,
084: 2));
085: Iterator cmdIt = list.iterator();
086: SimpleCommand sm = null;
087: JButton cmdButton = null;
088: while (cmdIt.hasNext()) {
089: sm = (SimpleCommand) cmdIt.next();
090: StringBuffer sf = new StringBuffer(sm.getName());
091: if (sf.length() < 15) {
092: sf.append(' ');
093: sf.insert(0, ' ');
094: }
095: cmdButton = new JButton(
096: "<html><font style=\"font-size:10pt;color:#008080\"><b>"
097: + sf.toString() + "</b></font>");
098: cmdButton.setToolTipText(sm.getDesc());
099: cmdButton.addActionListener(getSimpleAction(sm));
100: commandPanel.add(cmdButton);
101: } //end of while
102:
103: //--- layout main panel
104: cp.setLayout(new BorderLayout(0, 10));
105: cp.add(targetPanel, BorderLayout.NORTH);
106: JScrollPane commandScrollPane = new JScrollPane(commandPanel);
107: cp.add(commandScrollPane, BorderLayout.CENTER);
108:
109: /*setBorder(new CompoundBorder(
110: BorderFactory.createEmptyBorder(1,1,1,1),
111: BorderFactory.createTitledBorder("Simple Commands")
112: ));
113: */
114: //setPreferredSize(new java.awt.Dimension(100,200));
115: }
116:
117: public String getTarget() {
118: return target;
119: }
120:
121: private void setTarget(String target) {
122: this .target = target;
123: }
124:
125: private ActionListener getSimpleAction(SimpleCommand cm) {
126: return new SimpleActionListener(qsadminMain, cm,
127: MainCommandPanel.this );
128: }
129:
130: public void updateConnectionStatus(boolean connected) {
131: serverButton.setEnabled(connected);
132: selfButton.setEnabled(connected);
133: commandPanel.setEnabled(connected);
134: }
135: }
|