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 24 import org.quickserver.util.TextFile; 25 import org.quickserver.swing.JFrameUtilities; 26 27 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 private String target = "server"; 46 47 private GridBagConstraints gbc; 48 49 public PropertiePanel(final QSAdminMain qsadminMain) { 50 Container cp = this; 51 this.qsadminMain = qsadminMain; 52 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 list = propertieSet.getList(); 81 83 reloadButton = new JButton("Reload Properties For the Target"); 84 class ReloadListener implements ActionListener{ 85 public void actionPerformed(ActionEvent e) { 86 Thread performer = new Thread (new Runnable () { 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 } 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 } 120 121 cp.setLayout(new BorderLayout(0,10)); 123 cp.add(targetPanel,BorderLayout.NORTH); 124 cp.add(commandPanel,BorderLayout.CENTER); 125 126 } 127 128 public String getTarget() { 129 return target; 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 153 if(propertie.getSaveButton()!=null) 154 propertie.getSaveButton().setEnabled(false); 155 } 157 reloadButton.setEnabled(connected); 158 serverButton.setEnabled(connected); 159 selfButton.setEnabled(connected); 160 } 161 } 162 163 | Popular Tags |