< prev index next >

## src/com/sun/javatest/agent/AgentMonitorTool.java

Print this page

     161
     162             portLabel = uif.createLabel("tool.pool.port", true);
     163             add(portLabel, lc);
     164             portField = uif.createInputField("tool.pool.port", 6);
     165             portField.setText(String.valueOf(activeAgentPool.getPort()));
     166             add(portField, fc);
     167             portLabel.setLabelFor(portField);
     168
     169             timeoutLabel = uif.createLabel("tool.pool.timeout", true);
     170             add(timeoutLabel, lc);
     171             timeoutField = uif.createInputField("tool.pool.timeout", 6);
     172             // agentMgr API is in msec; field is in seconds
     173             int t = activeAgentPool.getTimeout(); // round to nearest second
     174             timeoutField.setText(String.valueOf((t + 500)/1000));
     175             fc.anchor = GridBagConstraints.WEST;
     176             fc.gridwidth = GridBagConstraints.REMAINDER;
     177             fc.weightx = 1;
     178             add(timeoutField, fc);
     179             timeoutLabel.setLabelFor(timeoutField);
     180
     181             listData = new DefaultListModel();
     182             list = uif.createList("tool.pool", listData);
     183             list.setPrototypeCellValue("abcdefghiklmnopqrstuvwxyz");
     184             list.setVisibleRowCount(3);
     185             GridBagConstraints c = new GridBagConstraints();
     186             c.fill = GridBagConstraints.BOTH;
     187             c.gridwidth = GridBagConstraints.REMAINDER;
     188             c.weightx = 1;
     189             c.weighty = 1;
     190             add(uif.createScrollPane(list), c);
     191
     192             // Ensure any existing entries in the pool are displayed
     193             // Note there is a slight synchronization window between the call of
     194             // elements and that of addObserver.
     195             for (Enumeration e = activeAgentPool.elements(); e.hasMoreElements(); ) {
     196                 Connection conn = (Connection)(e.nextElement());
     197                 listData.addElement(conn.getName());
     198             }
     199
     200             activeAgentPool.addObserver(this);
     201             enableFields();
     322             }
     323         }
     324
     325         void setTimeout(int timeout) {
     326             timeoutField.setText(String.valueOf(timeout));
     327         }
     328
     329         private void enableFields() {
     330             boolean enable = !listeningCheck.isSelected();
     331             portLabel.setEnabled(enable);
     332             portField.setEnabled(enable);
     333             timeoutLabel.setEnabled(enable);
     334             timeoutField.setEnabled(enable);
     335         }
     336
     337         private JCheckBox listeningCheck;
     338         private JLabel portLabel;
     339         private JTextField portField;
     340         private JLabel timeoutLabel;
     341         private JTextField timeoutField;
     342         private JList list;
     343         private DefaultListModel listData;
     344     }
     345
     346     private class CurrentAgentsSubpanel extends JPanel
     347         implements ListSelectionListener, AgentManager.Observer
     348     {
     349         CurrentAgentsSubpanel() {
     350             setName("tool.curr");
     351             setBorder(uif.createTitledBorder("tool.curr"));
     352             setLayout(new GridBagLayout());
     353             uif.setToolTip(this, "tool.curr");
     354
     355             listData = new DefaultListModel();
     356             list = uif.createList("tool.list.curr", listData);
     357             list.setVisibleRowCount(5);
     358
     359             list.setCellRenderer(new DefaultListCellRenderer() {
     360                 public Component getListCellRendererComponent(JList list, Object o, int index, boolean isSelected, boolean cellHasFocus) {
     361                     String name = ((Entry)o).toString();
     362                     return super.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
     363                 }
     364             });
     365
     366             list.addListSelectionListener(this);
     367
     368             GridBagConstraints c = new GridBagConstraints();
     369             c.fill = GridBagConstraints.BOTH;
     370             c.gridwidth = GridBagConstraints.REMAINDER;
     371             c.insets.bottom = 5;
     372             c.weightx = 1;
     373             c.weighty = 1;
     374             add(uif.createScrollPane(list), c);
     375
     376             GridBagConstraints lc = new GridBagConstraints();
     377             lc.gridwidth = 1;
     378             lc.weightx = 0;
     379             lc.anchor = GridBagConstraints.EAST;
     380             lc.insets.right = 5;
     381
     404             add(execLabel, lc);
     405             execField = uif.createOutputField("tool.curr.execute", execLabel);
     406             add(execField, fc);
     407
     408             argsLabel = uif.createLabel("tool.curr.args", true);
     409             add(argsLabel, lc);
     410             argsField = uif.createOutputField("tool.curr.args", argsLabel);
     411             add(argsField, fc);
     412
     413             add(uif.createGlue("tool.curr.pad"), lc);
     414             fc.fill = GridBagConstraints.VERTICAL;
     415             fc.weightx = 0;
     416             fc.anchor = GridBagConstraints.WEST;
     417             localizeArgsCheck = uif.createCheckBox("tool.mapArgs", false);
     418             add(localizeArgsCheck, fc);
     419
     420             agentManager.addObserver(this);
     421         }
     422
     423         public synchronized void valueChanged(ListSelectionEvent ev) {
     424             Entry e = (Entry)(list.getSelectedValue());
     425             if (e == null) {
     426                 addressField.setText("");
     427                 tagField.setText("");
     428                 requestField.setText("");
     429                 execField.setText("");
     430                 argsField.setText("");
     431                 localizeArgsCheck.setSelected(false);
     432                 selectedEntry = null;
     433             }
     434             else {
     435                 addressField.setText(e.connection.getName());
     436                 tagField.setText(e.tag);
     437                 requestField.setText(e.request);
     438                 execField.setText(e.executable);
     439                 argsField.setText(StringArray.join(e.args));
     440                 localizeArgsCheck.setSelected(e.localizeArgs);
     441                 selectedEntry = e;
     442             }
     443         }
     444
     453                 };      // end anon. class
     454
     455                 EventQueue.invokeLater(cmd);
     456             }
     457             else
     458                 listData.addElement(new Entry(c, tag, request, executable, args, localizeArgs));
     459         }
     460
     461         public synchronized void finished(final Connection c, final Status status) {
     462             if (!EventQueue.isDispatchThread()) {
     463                 Runnable cmd = new Runnable() {
     464                     public void run() {
     465                         AgentMonitorTool.CurrentAgentsSubpanel.this.finished(c, status);
     466                     }   // run()
     467                 };      // end anon. class
     468
     469                 EventQueue.invokeLater(cmd);
     470             }
     471             else {
     472                 for (int i = 0; i < listData.size(); i++) {
     473                     Entry e = (Entry)(listData.elementAt(i));
     474                     if (e.connection == c) {
     475                         listData.removeElement(e);
     476                         break;
     477                     }
     478                 }   // for
     479             }   // else
     480         }
     481
     482         private class Entry {
     483             Entry(Connection connection,
     484                      String tag, String request, String executable, String[] args,
     485                   boolean localizeArgs) {
     486                 this.connection = connection;
     487                 this.tag = tag;
     488                 this.request = request;
     489                 this.executable = executable;
     490                 this.args = args;
     491                 this.localizeArgs = localizeArgs;
     492             }
     493
     494             public String toString() {
     495                 return uif.getI18NString("tool.entry",
     496                                          new Object[] {connection.getName(), tag});
     497             }
     498
     499             Connection connection;
     500             String tag;
     501             String request;
     502             String executable;
     503             String[] args;
     504             boolean localizeArgs;
     505         }
     506
     507         private JList list;
     508         private DefaultListModel listData;
     509         private Entry selectedEntry;
     510         private JLabel addressLabel;
     511         private JTextField addressField;
     512         private JLabel tagLabel;
     513         private JTextField tagField;
     514         private JLabel requestLabel;
     515         private JTextField requestField;
     516         private JLabel execLabel;
     517         private JTextField execField;
     518         private JLabel argsLabel;
     519         private JTextField argsField;
     520         private JCheckBox localizeArgsCheck;
     521     }
     522 }
     161
     162             portLabel = uif.createLabel("tool.pool.port", true);
     163             add(portLabel, lc);
     164             portField = uif.createInputField("tool.pool.port", 6);
     165             portField.setText(String.valueOf(activeAgentPool.getPort()));
     166             add(portField, fc);
     167             portLabel.setLabelFor(portField);
     168
     169             timeoutLabel = uif.createLabel("tool.pool.timeout", true);
     170             add(timeoutLabel, lc);
     171             timeoutField = uif.createInputField("tool.pool.timeout", 6);
     172             // agentMgr API is in msec; field is in seconds
     173             int t = activeAgentPool.getTimeout(); // round to nearest second
     174             timeoutField.setText(String.valueOf((t + 500)/1000));
     175             fc.anchor = GridBagConstraints.WEST;
     176             fc.gridwidth = GridBagConstraints.REMAINDER;
     177             fc.weightx = 1;
     178             add(timeoutField, fc);
     179             timeoutLabel.setLabelFor(timeoutField);
     180
     181             listData = new DefaultListModel<>();
     182             list = uif.createList("tool.pool", listData);
     183             list.setPrototypeCellValue("abcdefghiklmnopqrstuvwxyz");
     184             list.setVisibleRowCount(3);
     185             GridBagConstraints c = new GridBagConstraints();
     186             c.fill = GridBagConstraints.BOTH;
     187             c.gridwidth = GridBagConstraints.REMAINDER;
     188             c.weightx = 1;
     189             c.weighty = 1;
     190             add(uif.createScrollPane(list), c);
     191
     192             // Ensure any existing entries in the pool are displayed
     193             // Note there is a slight synchronization window between the call of
     194             // elements and that of addObserver.
     195             for (Enumeration e = activeAgentPool.elements(); e.hasMoreElements(); ) {
     196                 Connection conn = (Connection)(e.nextElement());
     197                 listData.addElement(conn.getName());
     198             }
     199
     200             activeAgentPool.addObserver(this);
     201             enableFields();
     322             }
     323         }
     324
     325         void setTimeout(int timeout) {
     326             timeoutField.setText(String.valueOf(timeout));
     327         }
     328
     329         private void enableFields() {
     330             boolean enable = !listeningCheck.isSelected();
     331             portLabel.setEnabled(enable);
     332             portField.setEnabled(enable);
     333             timeoutLabel.setEnabled(enable);
     334             timeoutField.setEnabled(enable);
     335         }
     336
     337         private JCheckBox listeningCheck;
     338         private JLabel portLabel;
     339         private JTextField portField;
     340         private JLabel timeoutLabel;
     341         private JTextField timeoutField;
     342         private JList<String> list;
     343         private DefaultListModel<String> listData;
     344     }
     345
     346     private class CurrentAgentsSubpanel extends JPanel
     347         implements ListSelectionListener, AgentManager.Observer
     348     {
     349         CurrentAgentsSubpanel() {
     350             setName("tool.curr");
     351             setBorder(uif.createTitledBorder("tool.curr"));
     352             setLayout(new GridBagLayout());
     353             uif.setToolTip(this, "tool.curr");
     354
     355             listData = new DefaultListModel<>();
     356             list = uif.createList("tool.list.curr", listData);
     357             list.setVisibleRowCount(5);
     358
     359             list.setCellRenderer(new DefaultListCellRenderer() {
     360                 public Component getListCellRendererComponent(JList list, Object o, int index, boolean isSelected, boolean cellHasFocus) {
     361                     String name = o.toString();
     362                     return super.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
     363                 }
     364             });
     365
     366             list.addListSelectionListener(this);
     367
     368             GridBagConstraints c = new GridBagConstraints();
     369             c.fill = GridBagConstraints.BOTH;
     370             c.gridwidth = GridBagConstraints.REMAINDER;
     371             c.insets.bottom = 5;
     372             c.weightx = 1;
     373             c.weighty = 1;
     374             add(uif.createScrollPane(list), c);
     375
     376             GridBagConstraints lc = new GridBagConstraints();
     377             lc.gridwidth = 1;
     378             lc.weightx = 0;
     379             lc.anchor = GridBagConstraints.EAST;
     380             lc.insets.right = 5;
     381
     404             add(execLabel, lc);
     405             execField = uif.createOutputField("tool.curr.execute", execLabel);
     406             add(execField, fc);
     407
     408             argsLabel = uif.createLabel("tool.curr.args", true);
     409             add(argsLabel, lc);
     410             argsField = uif.createOutputField("tool.curr.args", argsLabel);
     411             add(argsField, fc);
     412
     413             add(uif.createGlue("tool.curr.pad"), lc);
     414             fc.fill = GridBagConstraints.VERTICAL;
     415             fc.weightx = 0;
     416             fc.anchor = GridBagConstraints.WEST;
     417             localizeArgsCheck = uif.createCheckBox("tool.mapArgs", false);
     418             add(localizeArgsCheck, fc);
     419
     420             agentManager.addObserver(this);
     421         }
     422
     423         public synchronized void valueChanged(ListSelectionEvent ev) {
     424             Entry e = list.getSelectedValue();
     425             if (e == null) {
     426                 addressField.setText("");
     427                 tagField.setText("");
     428                 requestField.setText("");
     429                 execField.setText("");
     430                 argsField.setText("");
     431                 localizeArgsCheck.setSelected(false);
     432                 selectedEntry = null;
     433             }
     434             else {
     435                 addressField.setText(e.connection.getName());
     436                 tagField.setText(e.tag);
     437                 requestField.setText(e.request);
     438                 execField.setText(e.executable);
     439                 argsField.setText(StringArray.join(e.args));
     440                 localizeArgsCheck.setSelected(e.localizeArgs);
     441                 selectedEntry = e;
     442             }
     443         }
     444
     453                 };      // end anon. class
     454
     455                 EventQueue.invokeLater(cmd);
     456             }
     457             else
     458                 listData.addElement(new Entry(c, tag, request, executable, args, localizeArgs));
     459         }
     460
     461         public synchronized void finished(final Connection c, final Status status) {
     462             if (!EventQueue.isDispatchThread()) {
     463                 Runnable cmd = new Runnable() {
     464                     public void run() {
     465                         AgentMonitorTool.CurrentAgentsSubpanel.this.finished(c, status);
     466                     }   // run()
     467                 };      // end anon. class
     468
     469                 EventQueue.invokeLater(cmd);
     470             }
     471             else {
     472                 for (int i = 0; i < listData.size(); i++) {
     473                     Entry e = listData.elementAt(i);
     474                     if (e.connection == c) {
     475                         listData.removeElement(e);
     476                         break;
     477                     }
     478                 }   // for
     479             }   // else
     480         }
     481
     482         private class Entry {
     483             Entry(Connection connection,
     484                      String tag, String request, String executable, String[] args,
     485                   boolean localizeArgs) {
     486                 this.connection = connection;
     487                 this.tag = tag;
     488                 this.request = request;
     489                 this.executable = executable;
     490                 this.args = args;
     491                 this.localizeArgs = localizeArgs;
     492             }
     493
     494             public String toString() {
     495                 return uif.getI18NString("tool.entry",
     496                                          new Object[] {connection.getName(), tag});
     497             }
     498
     499             Connection connection;
     500             String tag;
     501             String request;
     502             String executable;
     503             String[] args;
     504             boolean localizeArgs;
     505         }
     506
     507         private JList<Entry> list;
     508         private DefaultListModel<Entry> listData;
     509         private Entry selectedEntry;
     510         private JLabel addressLabel;
     511         private JTextField addressField;
     512         private JLabel tagLabel;
     513         private JTextField tagField;
     514         private JLabel requestLabel;
     515         private JTextField requestField;
     516         private JLabel execLabel;
     517         private JTextField execField;
     518         private JLabel argsLabel;
     519         private JTextField argsField;
     520         private JCheckBox localizeArgsCheck;
     521     }
     522 }

< prev index next >