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.io.IOException ; 23 24 import org.quickserver.util.*; 25 import java.util.logging.*; 26 import org.quickserver.swing.JFrameUtilities; 27 import java.io.*; 29 import java.util.*; 30 import org.quickserver.util.io.*; 31 import org.quickserver.util.*; 32 import org.quickserver.util.xmlreader.QSAdminPluginConfig; 33 import org.quickserver.util.xmlreader.PluginConfigReader; 34 35 36 42 public class QSAdminGUI extends JPanel { 43 private static Logger logger = Logger.getLogger( 44 QSAdminGUI.class.getName()); 45 46 private static QSAdminMain qsadminMain = null; 47 private static String pluginDir = "./../plugin"; 48 49 private ClassLoader classLoader = getClass().getClassLoader(); 50 public ImageIcon logo = new ImageIcon( 51 classLoader.getResource("icons/logo.gif")); 52 public ImageIcon logoAbout = new ImageIcon( 53 classLoader.getResource("icons/logo.png")); 54 public ImageIcon ball = new ImageIcon( 55 classLoader.getResource("icons/ball.gif")); 56 57 private HeaderPanel headerPanel; 58 private MainCommandPanel mainCommandPanel; 59 private CmdConsole cmdConsole; 60 private PropertiePanel propertiePanel; 61 63 private JTabbedPane tabbedPane; 64 private JFrame parentFrame; 65 66 final HashMap pluginPanelMap = new HashMap(); 67 68 private ArrayList plugins = new ArrayList(); 70 71 private JMenu mainMenu, helpMenu; 72 private JMenuBar jMenuBar; 73 private JMenuItem loginMenuItem, exitMenuItem, aboutMenuItem; 74 75 76 82 public void logComand(String command, char type) { 83 logger.info("For["+type+"] "+command); 84 } 85 86 89 public static void showGUI(String args[], final SplashScreen splash) { 90 java.awt.EventQueue.invokeLater(new Runnable () { 91 public void run() { 92 try { 93 UIManager.setLookAndFeel( 94 "net.sourceforge.mlf.metouia.MetouiaLookAndFeel"); 95 } catch(Exception e) { 96 try { 97 UIManager.setLookAndFeel( 98 UIManager.getSystemLookAndFeelClassName()); 99 } catch(Exception ee) {} 100 } 101 102 qsadminMain = new QSAdminMain(); 103 104 JFrame frame = new JFrame("QSAdmin GUI"); 105 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 106 107 QSAdminGUI qsAdminGUI = new QSAdminGUI(qsadminMain, frame); 108 qsAdminGUI.updateConnectionStatus(false); 109 frame.getContentPane().add(qsAdminGUI); 110 frame.pack(); 111 frame.setSize(700, 450); 112 frame.setIconImage(qsAdminGUI.logo.getImage()); 113 JFrameUtilities.centerWindow(frame); 114 frame.setVisible(true); 115 if(splash!=null) splash.kill(); 116 } 117 }); 118 } 119 120 public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) { 121 this.parentFrame = parentFrame; 122 Container cp = this; 123 qsadminMain.setGUI(this); 124 cp.setLayout(new BorderLayout(5,5)); 125 headerPanel = new HeaderPanel(qsadminMain, parentFrame); 126 mainCommandPanel = new MainCommandPanel(qsadminMain); 127 cmdConsole = new CmdConsole(qsadminMain); 128 propertiePanel = new PropertiePanel(qsadminMain); 129 130 if(headerPanel==null || mainCommandPanel==null || 131 cmdConsole==null || propertiePanel==null) { 132 throw new RuntimeException ("Loading of one of gui component failed."); 133 } 134 135 headerPanel.setBorder(BorderFactory.createEmptyBorder(0,5,0,5)); 136 cp.add(headerPanel, BorderLayout.NORTH); 137 JScrollPane propertieScrollPane = new JScrollPane(propertiePanel); 138 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 140 true, mainCommandPanel, cmdConsole); 141 splitPane.setOneTouchExpandable(false); 142 splitPane.setDividerLocation(250); 143 145 tabbedPane = new JTabbedPane(JTabbedPane.TOP); 146 tabbedPane.addTab("Main", ball, splitPane, "Main Commands"); 147 tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel"); 148 149 QSAdminPluginConfig qsAdminPluginConfig = null; 150 PluginPanel pluginPanel = null; 151 try { 153 File xmlFile = null; 154 ClassLoader classLoader = null; 155 Class mainClass = null; 156 157 File file = new File(pluginDir); 158 File dirs[] = null; 159 160 if(file.canRead()) 161 dirs = file.listFiles(new DirFileList()); 162 163 for(int i=0;dirs!=null && i<dirs.length;i++) { 164 xmlFile = new File(dirs[i].getAbsolutePath()+ 165 File.separator+"plugin.xml"); 166 if(xmlFile.canRead()) { 167 qsAdminPluginConfig = PluginConfigReader.read(xmlFile); 168 if(qsAdminPluginConfig.getActive().equals("yes") && 169 qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) { 170 classLoader = ClassUtil.getClassLoaderFromJars( dirs[i].getAbsolutePath() ); 171 mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass()); 172 logger.fine("Got PluginMainClass "+mainClass); 173 pluginPanel = (PluginPanel) mainClass.newInstance(); 174 if( JPanel.class.isInstance(pluginPanel)==true ) { 175 logger.info("Loading plugin : "+qsAdminPluginConfig.getName()); 176 pluginPanelMap.put(""+(2+i), pluginPanel); 177 plugins.add(pluginPanel); 178 tabbedPane.addTab(qsAdminPluginConfig.getName(), 179 ball, (JPanel)pluginPanel, qsAdminPluginConfig.getDesc()); 180 pluginPanel.setQSAdminMain(qsadminMain); 181 pluginPanel.init(); 182 } 183 } else { 184 logger.info("Plugin "+dirs[i]+" is disabled so skipping"); 185 } 186 } else { 187 logger.info("No plugin configuration found in "+xmlFile+" so skipping"); 188 } 189 } 190 } catch(Exception e) { 191 logger.warning("Error loading plugin : "+e); 192 logger.fine("StackTrace:\n"+MyString.getStackTrace(e)); 193 } 194 196 tabbedPane.addChangeListener(new ChangeListener() { 197 int selected = -1; 198 int oldSelected = -1; 199 public void stateChanged(ChangeEvent e) { 200 selected = tabbedPane.getSelectedIndex(); 202 if(selected>=2) { 203 ( (PluginPanel)pluginPanelMap.get(""+selected) ).activated(); 204 } 205 if(oldSelected>=2) { 206 ( (PluginPanel)pluginPanelMap.get(""+oldSelected) ).deactivated(); 207 } 208 oldSelected = selected; 209 } 210 }); 211 212 cp.add(tabbedPane, BorderLayout.CENTER); 214 215 buildMenu(); 216 } 217 218 public void setStatus(String msg) { 219 headerPanel.setStatus(msg); 220 } 221 222 public void setResponse(String res) { 223 int msgType = JOptionPane.PLAIN_MESSAGE ; 224 if(res.startsWith("+OK")) 225 msgType = JOptionPane.INFORMATION_MESSAGE; 226 if(res.startsWith("-ERR")) 227 msgType = JOptionPane.ERROR_MESSAGE; 228 JOptionPane.showMessageDialog(QSAdminGUI.this, 229 res.substring(res.indexOf(" ")+1), "Response", msgType); 230 } 231 232 public void appendToConsole(String msg) { 233 cmdConsole.append(msg); 234 } 235 236 public void setConsoleSend(boolean flag) { 237 cmdConsole.setSendEdit(flag); 238 } 239 240 public void updateConnectionStatus(boolean connected) { 241 if(connected==true) { 242 headerPanel.setLogoutText(); 243 loginMenuItem.setText("Logout"); 244 } else { 245 headerPanel.setLoginText(); 246 loginMenuItem.setText("Login..."); 247 } 248 mainCommandPanel.updateConnectionStatus(connected); 249 propertiePanel.updateConnectionStatus(connected); 250 cmdConsole.updateConnectionStatus(connected); 251 Iterator iterator = plugins.iterator(); 252 PluginPanel updatePluginPanel = null; 253 while(iterator.hasNext()) { 254 updatePluginPanel = (PluginPanel)iterator.next(); 255 updatePluginPanel.updateConnectionStatus(connected); 256 } 257 258 if(connected==true) { 259 int selected = tabbedPane.getSelectedIndex(); 260 if(selected>=2) { 261 ( (PluginPanel)pluginPanelMap.get(""+selected) ).activated(); 262 } 263 } 264 } 265 266 public static void setPluginDir(String dir) { 268 pluginDir = dir; 269 } 270 public static String getPluginDir() { 271 return pluginDir; 272 } 273 274 private void buildMenu() { 275 jMenuBar = new javax.swing.JMenuBar (); 276 mainMenu = new javax.swing.JMenu (); 277 mainMenu.setText("Main"); 278 279 loginMenuItem = new JMenuItem("Login..."); 280 loginMenuItem.addActionListener(new java.awt.event.ActionListener () { 281 public void actionPerformed(java.awt.event.ActionEvent evt) { 282 headerPanel.handleLoginLogout(); 283 } 284 }); 285 286 mainMenu.add(loginMenuItem); 287 288 exitMenuItem = new JMenuItem("Exit"); 289 exitMenuItem.addActionListener(new java.awt.event.ActionListener () { 290 public void actionPerformed(java.awt.event.ActionEvent evt) { 291 if(qsadminMain.isConnected()==true) { 292 headerPanel.handleLoginLogout(); 293 } 294 System.exit(0); 295 } 296 }); 297 mainMenu.add(exitMenuItem); 298 299 helpMenu = new javax.swing.JMenu (); 300 helpMenu.setText("Help"); 301 302 aboutMenuItem = new JMenuItem("About..."); 303 aboutMenuItem.setEnabled(true); 304 aboutMenuItem.addActionListener(new java.awt.event.ActionListener () { 305 public void actionPerformed(java.awt.event.ActionEvent evt) { 306 about(); 307 } 308 }); 309 helpMenu.add(aboutMenuItem); 310 311 jMenuBar.add(mainMenu); 312 jMenuBar.add(helpMenu); 313 314 parentFrame.setJMenuBar(jMenuBar); 315 } 316 317 private void about() { 318 JOptionPane.showMessageDialog(this, 319 "QSAdminGUI\n\n"+ 320 "GUI Client for QSAdminServer of QuickServer.\n"+ 321 "This is compliant with QuickServer v"+QSAdminMain.VERSION_OF_SERVER+" release.\n\n"+ 322 "Copyright (C) QuickServer.org\n"+ 323 "http://www.quickserver.org", 324 "About QSAdminGUI", 325 JOptionPane.INFORMATION_MESSAGE, 326 logoAbout); 327 } 328 } 329 | Popular Tags |