1 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 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 private String 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 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 list = sms.getList(); 82 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 sf = new StringBuffer (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 } 102 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 113 } 115 116 public String getTarget() { 117 return target; 118 } 119 private void setTarget(String 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 |