public PrintfEditor(Frame frame, String title) { super(frame, title, false); originalTemplate = new PrintfTemplate(); editableTemplate = new PrintfTemplate(); try { jbInit(); pack(); initMatches(); } catch (Exception exc) { String logMessage = "Could not set up the printf editor"; logger.critical(logMessage, exc); JOptionPane.showMessageDialog(frame, logMessage, "Printf Editor", JOptionPane.ERROR_MESSAGE); } }
public class PrintfEditor extends JDialog implements EDPEditor, ConfigParamListener { protected PrintfTemplate originalTemplate; protected PrintfTemplate editableTemplate; private EDPCellData m_data; private HashMap paramKeys; private HashMap matchesKeys = new HashMap(); static char[] RESERVED_CHARS = {'[', '\\', '^', '$', '.', '|', '?', '*', '+', '(', ')'}; static String RESERVED_STRING = new String(RESERVED_CHARS); static SimpleAttributeSet PLAIN_ATTR = new SimpleAttributeSet(); static { StyleConstants.setForeground(PLAIN_ATTR, Color.black); StyleConstants.setBold(PLAIN_ATTR, false); StyleConstants.setFontFamily(PLAIN_ATTR, "Helvetica"); StyleConstants.setFontSize(PLAIN_ATTR, 14); } int numParameters = 0; JPanel printfPanel = new JPanel(); ButtonGroup buttonGroup = new ButtonGroup(); JPanel buttonPanel = new JPanel(); JButton cancelButton = new JButton(); JButton saveButton = new JButton(); JLabel formatLabel = new JLabel(); FlowLayout flowLayout1 = new FlowLayout(); JTextArea formatTextArea = new JTextArea(); JPanel parameterPanel = new JPanel(); JLabel parameterLabel = new JLabel(); JTextArea parameterTextArea = new JTextArea(); JButton insertButton = new JButton(); JComboBox paramComboBox = new JComboBox(); GridBagLayout gridBagLayout1 = new GridBagLayout(); ButtonGroup buttonGroup1 = new ButtonGroup(); TitledBorder titledBorder2; JComboBox matchComboBox = new JComboBox(); JButton insertMatchButton = new JButton(); JPanel matchPanel = new JPanel(); JPanel InsertPanel = new JPanel(); GridLayout gridLayout1 = new GridLayout(); GridBagLayout gridBagLayout2 = new GridBagLayout(); GridBagLayout gridBagLayout3 = new GridBagLayout(); JTabbedPane printfTabPane = new JTabbedPane(); JTextPane editorPane = new JTextPane(); JScrollPane editorPanel = new JScrollPane(); int selectedPane = 0; private boolean m_isCrawlRuleEditor = false; private static final String STRING_LITERAL = "String Literal"; protected static Logger logger = Logger.getLogger("PrintfEditor"); public PrintfEditor(Frame frame, String title) { super(frame, title, false); originalTemplate = new PrintfTemplate(); editableTemplate = new PrintfTemplate(); try { jbInit(); pack(); initMatches(); } catch (Exception exc) { String logMessage = "Could not set up the printf editor"; logger.critical(logMessage, exc); JOptionPane.showMessageDialog(frame, logMessage, "Printf Editor", JOptionPane.ERROR_MESSAGE); } } private void initMatches() { matchesKeys.put(STRING_LITERAL, ""); matchesKeys.put("Any number", "[0-9]+"); matchesKeys.put("Anything", ".*"); matchesKeys.put("Start", "^"); matchesKeys.put("End", "$"); matchesKeys.put("Single path component", "[^/]+"); for (Iterator it = matchesKeys.keySet().iterator(); it.hasNext(); ) { matchComboBox.addItem(it.next()); } } private void jbInit() throws Exception { saveButton.setText("Save"); saveButton.addActionListener(new PrintfTemplateEditor_saveButton_actionAdapter(this)); cancelButton.setText("Cancel"); cancelButton.addActionListener(new PrintfTemplateEditor_cancelButton_actionAdapter(this)); this.setTitle(this.getTitle() + " Template Editor"); printfPanel.setLayout(gridBagLayout1); formatLabel.setFont(new java.awt.Font("DialogInput", 0, 12)); formatLabel.setText("Format String:"); buttonPanel.setLayout(flowLayout1); printfPanel.setBorder(BorderFactory.createEtchedBorder()); printfPanel.setMinimumSize(new Dimension(100, 160)); printfPanel.setPreferredSize(new Dimension(380, 160)); parameterPanel.setLayout(gridBagLayout2); parameterLabel.setText("Parameters:"); parameterLabel.setFont(new java.awt.Font("DialogInput", 0, 12)); parameterTextArea.setMinimumSize(new Dimension(100, 25)); parameterTextArea.setPreferredSize(new Dimension(200, 25)); parameterTextArea.setEditable(true); parameterTextArea.setText(""); insertButton.setMaximumSize(new Dimension(136, 20)); insertButton.setMinimumSize(new Dimension(136, 20)); insertButton.setPreferredSize(new Dimension(136, 20)); insertButton.setToolTipText( "insert the format in the format string and add parameter to list."); insertButton.setText("Insert Parameter"); insertButton.addActionListener(new PrintfTemplateEditor_insertButton_actionAdapter(this)); formatTextArea.setMinimumSize(new Dimension(100, 25)); formatTextArea.setPreferredSize(new Dimension(200, 15)); formatTextArea.setText(""); parameterPanel.setBorder(null); parameterPanel.setMinimumSize(new Dimension(60, 40)); parameterPanel.setPreferredSize(new Dimension(300, 40)); insertMatchButton.addActionListener( new PrintfTemplateEditor_insertMatchButton_actionAdapter(this)); insertMatchButton.setText("Insert Match"); insertMatchButton.setToolTipText( "insert the match in the format string and add parameter to list."); insertMatchButton.setPreferredSize(new Dimension(136, 20)); insertMatchButton.setMinimumSize(new Dimension(136, 20)); insertMatchButton.setMaximumSize(new Dimension(136, 20)); matchPanel.setPreferredSize(new Dimension(300, 40)); matchPanel.setBorder(null); matchPanel.setMinimumSize(new Dimension(60, 60)); matchPanel.setLayout(gridBagLayout3); InsertPanel.setLayout(gridLayout1); gridLayout1.setColumns(1); gridLayout1.setRows(2); gridLayout1.setVgap(0); InsertPanel.setBorder(BorderFactory.createEtchedBorder()); InsertPanel.setMinimumSize(new Dimension(100, 100)); InsertPanel.setPreferredSize(new Dimension(380, 120)); editorPane.setText(""); editorPane.addKeyListener(new PrintfEditor_editorPane_keyAdapter(this)); printfTabPane.addChangeListener(new PrintfEditor_printfTabPane_changeAdapter(this)); parameterPanel.add( insertButton, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 6, 13, 8), 0, 10)); parameterPanel.add( paramComboBox, new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(8, 8, 13, 0), 258, 11)); paramComboBox.setRenderer(new MyCellRenderer()); InsertPanel.add(matchPanel, null); InsertPanel.add(parameterPanel, null); buttonPanel.add(cancelButton, null); buttonPanel.add(saveButton, null); this.getContentPane().add(printfTabPane, BorderLayout.NORTH); this.getContentPane().add(InsertPanel, BorderLayout.CENTER); matchPanel.add( insertMatchButton, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 6, 13, 8), 0, 10)); matchPanel.add( matchComboBox, new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(8, 8, 13, 0), 258, 11)); printfPanel.add( parameterLabel, new GridBagConstraints( 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 309, 0)); printfPanel.add( formatLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 5, 0, 5), 288, 0)); printfPanel.add( formatTextArea, new GridBagConstraints( 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 5, 0, 5), 300, 34)); printfPanel.add( parameterTextArea, new GridBagConstraints( 0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 5, 6, 5), 300, 34)); printfTabPane.addTab("Editor View", null, editorPanel, "View in Editor"); printfTabPane.addTab("Printf View", null, printfPanel, "Vies as Printf"); editorPane.setCharacterAttributes(PLAIN_ATTR, true); editorPane.addStyle("PLAIN", editorPane.getLogicalStyle()); editorPanel.getViewport().add(editorPane, null); this.getContentPane().add(buttonPanel, BorderLayout.SOUTH); buttonGroup.add(cancelButton); } /** notifiyParamsChanged */ public void notifiyParamsChanged() { updateParams(m_data); } /** * setEDPData * * @param data EDPCellData */ public void setCellData(EDPCellData data) { m_data = data; paramKeys = data.getPlugin().getPrintfDescrs(!m_isCrawlRuleEditor); data.getPlugin().addParamListener(this); setTemplate((PrintfTemplate) data.getData()); m_isCrawlRuleEditor = data.getKey().equals(DefinableArchivalUnit.KEY_AU_CRAWL_RULES); // initialize the combobox updateParams(data); if (m_isCrawlRuleEditor) { matchPanel.setVisible(true); } else { matchPanel.setVisible(false); } } void saveButton_actionPerformed(ActionEvent e) { updateEditableTemplate(selectedPane); originalTemplate.setFormat(editableTemplate.m_format); originalTemplate.setTokens(editableTemplate.m_tokens); m_data.updateTemplateData(originalTemplate); setVisible(false); } void cancelButton_actionPerformed(ActionEvent e) { setVisible(false); } void printfTabPane_stateChanged(ChangeEvent e) { updateEditableTemplate(selectedPane); selectedPane = printfTabPane.getSelectedIndex(); updatePane(selectedPane); } void updateEditableTemplate(int pane) { switch (pane) { case 0: // use the editor to update the template updateTemplateFromEditor(editableTemplate); break; case 1: // use the printf text areas to update the template. updateTemplateFromPrintf(); break; } } void insertButton_actionPerformed(ActionEvent e) { Object selected = paramComboBox.getSelectedItem(); ConfigParamDescr descr; String key; int type = 0; String format = ""; if (selected instanceof ConfigParamDescr) { descr = (ConfigParamDescr) selected; key = descr.getKey(); type = descr.getType(); switch (type) { case ConfigParamDescr.TYPE_STRING: case ConfigParamDescr.TYPE_URL: case ConfigParamDescr.TYPE_BOOLEAN: format = "%s"; break; case ConfigParamDescr.TYPE_INT: case ConfigParamDescr.TYPE_LONG: case ConfigParamDescr.TYPE_POS_INT: NumericPaddingDialog dialog = new NumericPaddingDialog(); Point pos = this.getLocationOnScreen(); dialog.setLocation(pos.x, pos.y); dialog.pack(); dialog.setVisible(true); StringBuilder fbuf = new StringBuilder("%"); int width = dialog.getPaddingSize(); boolean is_zero = dialog.useZero(); if (width > 0) { fbuf.append("."); if (is_zero) { fbuf.append(0); } fbuf.append(width); } if (type == ConfigParamDescr.TYPE_LONG) { fbuf.append("ld"); } else { fbuf.append("d"); } format = fbuf.toString(); break; case ConfigParamDescr.TYPE_YEAR: if (key.startsWith(DefinableArchivalUnit.PREFIX_AU_SHORT_YEAR)) { format = "%02d"; } else { format = "%d"; } break; case ConfigParamDescr.TYPE_RANGE: case ConfigParamDescr.TYPE_NUM_RANGE: case ConfigParamDescr.TYPE_SET: format = "%s"; break; } if (selectedPane == 0) { insertParameter(descr, format, editorPane.getSelectionStart()); } else if (selectedPane == 1) { // add the combobox data value to the edit box int pos = formatTextArea.getCaretPosition(); formatTextArea.insert(format, pos); pos = parameterTextArea.getCaretPosition(); parameterTextArea.insert(", " + key, pos); } } else { key = selected.toString(); format = escapePrintfChars( (String) JOptionPane.showInputDialog( this, "Enter the string you wish to input", "String Literal Input", JOptionPane.OK_CANCEL_OPTION)); if (StringUtil.isNullString(format)) { return; } if (selectedPane == 0) { insertText(format, PLAIN_ATTR, editorPane.getSelectionStart()); } else if (selectedPane == 1) { // add the combobox data value to the edit box formatTextArea.insert(format, formatTextArea.getCaretPosition()); } } } void insertMatchButton_actionPerformed(ActionEvent e) { String key = (String) matchComboBox.getSelectedItem(); String format = (String) matchesKeys.get(key); if (key.equals(STRING_LITERAL)) { format = escapeReservedChars( (String) JOptionPane.showInputDialog( this, "Enter the string you wish to match", "String Literal Input", JOptionPane.OK_CANCEL_OPTION)); if (StringUtil.isNullString(format)) { return; } } if (selectedPane == 0) { insertText(format, PLAIN_ATTR, editorPane.getSelectionStart()); } else { // add the combobox data value to the edit box int pos = formatTextArea.getCaretPosition(); formatTextArea.insert(format, pos); } } void editorPane_keyPressed(KeyEvent e) { StyledDocument doc = editorPane.getStyledDocument(); int pos = editorPane.getCaretPosition(); int code = e.getKeyCode(); Element el; switch (code) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: if (pos == 0) return; // we want to get the element to the left of position. el = doc.getCharacterElement(pos - 1); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: // we want to get the element to the right of position. el = doc.getCharacterElement(pos + 1); break; default: return; // bail we don't handle it. } AttributeSet attr = el.getAttributes(); String el_name = (String) attr.getAttribute(StyleConstants.NameAttribute); int el_range = el.getEndOffset() - el.getStartOffset() - 1; if (el_name.startsWith("Parameter") && StyleConstants.getComponent(attr) != null) { try { switch (code) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: doc.remove(el.getStartOffset(), el_range); break; case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: editorPane.setCaretPosition(pos - el_range); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: editorPane.setCaretPosition(pos + (el_range)); break; } } catch (BadLocationException ex) { } } } private void insertParameter(ConfigParamDescr descr, String format, int pos) { try { StyledDocument doc = (StyledDocument) editorPane.getDocument(); // The component must first be wrapped in a style Style style = doc.addStyle("Parameter-" + numParameters, null); JLabel label = new JLabel(descr.getDisplayName()); label.setAlignmentY(0.8f); // make sure we line up label.setFont(new Font("Helvetica", Font.PLAIN, 14)); label.setForeground(Color.BLUE); label.setName(descr.getKey()); label.setToolTipText("key: " + descr.getKey() + " format: " + format); StyleConstants.setComponent(style, label); doc.insertString(pos, format, style); numParameters++; } catch (BadLocationException e) { } } private void insertText(String text, AttributeSet set, int pos) { try { editorPane.getDocument().insertString(pos, text, set); } catch (BadLocationException ex) { } } private void appendText(String text, AttributeSet set) { insertText(text, set, editorPane.getDocument().getLength()); } private void updateTemplateFromPrintf() { String format = formatTextArea.getText(); String parameters = parameterTextArea.getText(); editableTemplate.setFormat(format); editableTemplate.setParameters(parameters); } private void updateTemplateFromEditor(PrintfTemplate template) { ArrayList params = new ArrayList(); String format = null; int text_length = editorPane.getDocument().getLength(); try { format = editorPane.getDocument().getText(0, text_length); } catch (BadLocationException ex1) { } Element section_el = editorPane.getDocument().getDefaultRootElement(); // Get number of paragraphs. int num_para = section_el.getElementCount(); for (int p_count = 0; p_count < num_para; p_count++) { Element para_el = section_el.getElement(p_count); // Enumerate the content elements int num_cont = para_el.getElementCount(); for (int c_count = 0; c_count < num_cont; c_count++) { Element content_el = para_el.getElement(c_count); AttributeSet attr = content_el.getAttributes(); // Get the name of the style applied to this content element; may be null String sn = (String) attr.getAttribute(StyleConstants.NameAttribute); // Check if style name match if (sn != null && sn.startsWith("Parameter")) { // we extract the label. JLabel l = (JLabel) StyleConstants.getComponent(attr); if (l != null) { params.add(l.getName()); } } } } template.setFormat(format); template.setTokens(params); } protected void setTemplate(PrintfTemplate template) { originalTemplate = template; editableTemplate.setFormat(template.m_format); editableTemplate.setTokens(template.m_tokens); updatePane(selectedPane); } private void updateParams(EDPCellData data) { paramComboBox.removeAllItems(); paramKeys = data.getPlugin().getPrintfDescrs(!m_isCrawlRuleEditor); if (!m_isCrawlRuleEditor) { paramComboBox.addItem(STRING_LITERAL); } for (Iterator it = paramKeys.values().iterator(); it.hasNext(); ) { ConfigParamDescr descr = (ConfigParamDescr) it.next(); int type = descr.getType(); if (!m_isCrawlRuleEditor && (type == ConfigParamDescr.TYPE_SET || type == ConfigParamDescr.TYPE_RANGE)) continue; paramComboBox.addItem(descr); } paramComboBox.setEnabled(true); paramComboBox.setSelectedIndex(0); paramComboBox.setToolTipText("Select a parameter to insert into the format string"); insertButton.setEnabled(true); } /** * updatePane * * @param sel int */ private void updatePane(int sel) { switch (sel) { case 0: // editor view updateEditorView(); break; case 1: // printf view updatePrintfView(); break; } } private void updatePrintfView() { formatTextArea.setText(editableTemplate.m_format); parameterTextArea.setText(editableTemplate.getTokenString()); } private void updateEditorView() { editorPane.setText(""); numParameters = 0; try { java.util.List elements = editableTemplate.getPrintfElements(); for (Iterator it = elements.iterator(); it.hasNext(); ) { PrintfUtil.PrintfElement el = (PrintfUtil.PrintfElement) it.next(); if (el.getFormat().equals(PrintfUtil.PrintfElement.FORMAT_NONE)) { appendText(el.getElement(), PLAIN_ATTR); } else { insertParameter( (ConfigParamDescr) paramKeys.get(el.getElement()), el.getFormat(), editorPane.getDocument().getLength()); } } } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Invalid Format: " + ex.getMessage(), "Invalid Printf Format", JOptionPane.ERROR_MESSAGE); selectedPane = 1; printfTabPane.setSelectedIndex(selectedPane); updatePane(selectedPane); } } /** * Return a copy of the string with all reserved regexp chars escaped by backslash. * * @param str the string to add escapes to * @return String return a string with escapes or "" if str is null */ private String escapeReservedChars(String str) { if (str == null) return ""; StringBuilder sb = new StringBuilder(); for (int ci = 0; ci < str.length(); ci++) { char ch = str.charAt(ci); if (RESERVED_STRING.indexOf(ch) >= 0) { sb.append('\\'); } sb.append(ch); } return escapePrintfChars(sb.toString()); } private String escapePrintfChars(String str) { if (str == null) return ""; StringBuilder sb = new StringBuilder(); for (int ci = 0; ci < str.length(); ci++) { char ch = str.charAt(ci); if (ch == '%') { sb.append('%'); } sb.append(ch); } return sb.toString(); } }
/** * QSAdminGUI - Control Panel for QuickServer Admin GUI - QSAdminGUI * * @author Akshathkumar Shetty * @since 1.3 */ public class QSAdminGUI extends JPanel /*JFrame*/ { private static Logger logger = Logger.getLogger(QSAdminGUI.class.getName()); private static QSAdminMain qsadminMain = null; private static String pluginDir = "./../plugin"; private ClassLoader classLoader = getClass().getClassLoader(); public ImageIcon logo = new ImageIcon(classLoader.getResource("icons/logo.gif")); public ImageIcon logoAbout = new ImageIcon(classLoader.getResource("icons/logo.png")); public ImageIcon ball = new ImageIcon(classLoader.getResource("icons/ball.gif")); private HeaderPanel headerPanel; private MainCommandPanel mainCommandPanel; private CmdConsole cmdConsole; private PropertiePanel propertiePanel; // private StatsPanel statsPanel; private JTabbedPane tabbedPane; private JFrame parentFrame; final HashMap pluginPanelMap = new HashMap(); // --v1.3.2 private ArrayList plugins = new ArrayList(); private JMenu mainMenu, helpMenu; private JMenuBar jMenuBar; private JMenuItem loginMenuItem, exitMenuItem, aboutMenuItem; /** Logs the interaction, Type can be S - Server Sent C - Client Sent */ public void logComand(String command, char type) { logger.info("For[" + type + "] " + command); } /** Displays the QSAdminGUi with in a JFrame. */ public static void showGUI(String args[], final SplashScreen splash) { java.awt.EventQueue.invokeLater( new Runnable() { public void run() { try { UIManager.setLookAndFeel("net.sourceforge.mlf.metouia.MetouiaLookAndFeel"); } catch (Exception e) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ee) { } } qsadminMain = new QSAdminMain(); JFrame frame = new JFrame("QSAdmin GUI"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); QSAdminGUI qsAdminGUI = new QSAdminGUI(qsadminMain, frame); qsAdminGUI.updateConnectionStatus(false); frame.getContentPane().add(qsAdminGUI); frame.pack(); frame.setSize(700, 450); frame.setIconImage(qsAdminGUI.logo.getImage()); JFrameUtilities.centerWindow(frame); frame.setVisible(true); if (splash != null) splash.kill(); } }); } public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) { this.parentFrame = parentFrame; Container cp = this; qsadminMain.setGUI(this); cp.setLayout(new BorderLayout(5, 5)); headerPanel = new HeaderPanel(qsadminMain, parentFrame); mainCommandPanel = new MainCommandPanel(qsadminMain); cmdConsole = new CmdConsole(qsadminMain); propertiePanel = new PropertiePanel(qsadminMain); if (headerPanel == null || mainCommandPanel == null || cmdConsole == null || propertiePanel == null) { throw new RuntimeException("Loading of one of gui component failed."); } headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); cp.add(headerPanel, BorderLayout.NORTH); JScrollPane propertieScrollPane = new JScrollPane(propertiePanel); // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole); splitPane.setOneTouchExpandable(false); splitPane.setDividerLocation(250); // splitPane.setDividerLocation(0.70); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.addTab("Main", ball, splitPane, "Main Commands"); tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel"); QSAdminPluginConfig qsAdminPluginConfig = null; PluginPanel pluginPanel = null; // -- start of loadPlugins try { File xmlFile = null; ClassLoader classLoader = null; Class mainClass = null; File file = new File(pluginDir); File dirs[] = null; if (file.canRead()) dirs = file.listFiles(new DirFileList()); for (int i = 0; dirs != null && i < dirs.length; i++) { xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml"); if (xmlFile.canRead()) { qsAdminPluginConfig = PluginConfigReader.read(xmlFile); if (qsAdminPluginConfig.getActive().equals("yes") && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) { classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath()); mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass()); logger.fine("Got PluginMainClass " + mainClass); pluginPanel = (PluginPanel) mainClass.newInstance(); if (JPanel.class.isInstance(pluginPanel) == true) { logger.info("Loading plugin : " + qsAdminPluginConfig.getName()); pluginPanelMap.put("" + (2 + i), pluginPanel); plugins.add(pluginPanel); tabbedPane.addTab( qsAdminPluginConfig.getName(), ball, (JPanel) pluginPanel, qsAdminPluginConfig.getDesc()); pluginPanel.setQSAdminMain(qsadminMain); pluginPanel.init(); } } else { logger.info( "Plugin " + dirs[i] + " is disabled so skipping " + qsAdminPluginConfig.getActive() + ":" + qsAdminPluginConfig.getType()); } } else { logger.info("No plugin configuration found in " + xmlFile + " so skipping"); } } } catch (Exception e) { logger.warning("Error loading plugin : " + e); logger.fine("StackTrace:\n" + MyString.getStackTrace(e)); } // -- end of loadPlugins tabbedPane.addChangeListener( new ChangeListener() { int selected = -1; int oldSelected = -1; public void stateChanged(ChangeEvent e) { // if plugin selected = tabbedPane.getSelectedIndex(); if (selected >= 2) { ((PluginPanel) pluginPanelMap.get("" + selected)).activated(); } if (oldSelected >= 2) { ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated(); } oldSelected = selected; } }); // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5)); cp.add(tabbedPane, BorderLayout.CENTER); buildMenu(); } public void setStatus(String msg) { headerPanel.setStatus(msg); } public void setResponse(String res) { int msgType = JOptionPane.PLAIN_MESSAGE; if (res.startsWith("+OK")) msgType = JOptionPane.INFORMATION_MESSAGE; if (res.startsWith("-ERR")) msgType = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog( QSAdminGUI.this, res.substring(res.indexOf(" ") + 1), "Response", msgType); } public void appendToConsole(String msg) { cmdConsole.append(msg); } public void setConsoleSend(boolean flag) { cmdConsole.setSendEdit(flag); } public void updateConnectionStatus(boolean connected) { if (connected == true) { headerPanel.setLogoutText(); loginMenuItem.setText("Logout"); } else { headerPanel.setLoginText(); loginMenuItem.setText("Login..."); } mainCommandPanel.updateConnectionStatus(connected); propertiePanel.updateConnectionStatus(connected); cmdConsole.updateConnectionStatus(connected); Iterator iterator = plugins.iterator(); PluginPanel updatePluginPanel = null; while (iterator.hasNext()) { updatePluginPanel = (PluginPanel) iterator.next(); updatePluginPanel.updateConnectionStatus(connected); } if (connected == true) { int selected = tabbedPane.getSelectedIndex(); if (selected >= 2) { ((PluginPanel) pluginPanelMap.get("" + selected)).activated(); } } } // --v1.3.2 public static void setPluginDir(String dir) { pluginDir = dir; } public static String getPluginDir() { return pluginDir; } private void buildMenu() { jMenuBar = new javax.swing.JMenuBar(); mainMenu = new javax.swing.JMenu(); mainMenu.setText("Main"); loginMenuItem = new JMenuItem("Login..."); loginMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { headerPanel.handleLoginLogout(); } }); mainMenu.add(loginMenuItem); exitMenuItem = new JMenuItem("Exit"); exitMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { if (qsadminMain.isConnected() == true) { headerPanel.handleLoginLogout(); } System.exit(0); } }); mainMenu.add(exitMenuItem); helpMenu = new javax.swing.JMenu(); helpMenu.setText("Help"); aboutMenuItem = new JMenuItem("About..."); aboutMenuItem.setEnabled(true); aboutMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { about(); } }); helpMenu.add(aboutMenuItem); jMenuBar.add(mainMenu); jMenuBar.add(helpMenu); parentFrame.setJMenuBar(jMenuBar); } private void about() { JOptionPane.showMessageDialog( this, "QSAdminGUI\n\n" + "GUI Client for QSAdminServer of QuickServer.\n" + "This is compliant with QuickServer v" + QSAdminMain.VERSION_OF_SERVER + " release.\n\n" + "Copyright (C) QuickServer.org\n" + "http://www.quickserver.org", "About QSAdminGUI", JOptionPane.INFORMATION_MESSAGE, logoAbout); } }
/** Logs the interaction, Type can be S - Server Sent C - Client Sent */ public void logComand(String command, char type) { logger.info("For[" + type + "] " + command); }
public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) { this.parentFrame = parentFrame; Container cp = this; qsadminMain.setGUI(this); cp.setLayout(new BorderLayout(5, 5)); headerPanel = new HeaderPanel(qsadminMain, parentFrame); mainCommandPanel = new MainCommandPanel(qsadminMain); cmdConsole = new CmdConsole(qsadminMain); propertiePanel = new PropertiePanel(qsadminMain); if (headerPanel == null || mainCommandPanel == null || cmdConsole == null || propertiePanel == null) { throw new RuntimeException("Loading of one of gui component failed."); } headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); cp.add(headerPanel, BorderLayout.NORTH); JScrollPane propertieScrollPane = new JScrollPane(propertiePanel); // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole); splitPane.setOneTouchExpandable(false); splitPane.setDividerLocation(250); // splitPane.setDividerLocation(0.70); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.addTab("Main", ball, splitPane, "Main Commands"); tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel"); QSAdminPluginConfig qsAdminPluginConfig = null; PluginPanel pluginPanel = null; // -- start of loadPlugins try { File xmlFile = null; ClassLoader classLoader = null; Class mainClass = null; File file = new File(pluginDir); File dirs[] = null; if (file.canRead()) dirs = file.listFiles(new DirFileList()); for (int i = 0; dirs != null && i < dirs.length; i++) { xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml"); if (xmlFile.canRead()) { qsAdminPluginConfig = PluginConfigReader.read(xmlFile); if (qsAdminPluginConfig.getActive().equals("yes") && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) { classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath()); mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass()); logger.fine("Got PluginMainClass " + mainClass); pluginPanel = (PluginPanel) mainClass.newInstance(); if (JPanel.class.isInstance(pluginPanel) == true) { logger.info("Loading plugin : " + qsAdminPluginConfig.getName()); pluginPanelMap.put("" + (2 + i), pluginPanel); plugins.add(pluginPanel); tabbedPane.addTab( qsAdminPluginConfig.getName(), ball, (JPanel) pluginPanel, qsAdminPluginConfig.getDesc()); pluginPanel.setQSAdminMain(qsadminMain); pluginPanel.init(); } } else { logger.info( "Plugin " + dirs[i] + " is disabled so skipping " + qsAdminPluginConfig.getActive() + ":" + qsAdminPluginConfig.getType()); } } else { logger.info("No plugin configuration found in " + xmlFile + " so skipping"); } } } catch (Exception e) { logger.warning("Error loading plugin : " + e); logger.fine("StackTrace:\n" + MyString.getStackTrace(e)); } // -- end of loadPlugins tabbedPane.addChangeListener( new ChangeListener() { int selected = -1; int oldSelected = -1; public void stateChanged(ChangeEvent e) { // if plugin selected = tabbedPane.getSelectedIndex(); if (selected >= 2) { ((PluginPanel) pluginPanelMap.get("" + selected)).activated(); } if (oldSelected >= 2) { ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated(); } oldSelected = selected; } }); // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5)); cp.add(tabbedPane, BorderLayout.CENTER); buildMenu(); }