content: /*
   * Copyright (c) 2001 Boulder Real Time Technologies, Inc.
   * All rights reserved
   *
   * This software may be used freely in any way as long as
   * the copyright statement above is not removed.
   *
   * com.brtt.antelope.JFrameOrbStat.java
   *
   * Created on February 23, 2001, 5:33 PM
   */
  
  package com.brtt.antelope;
  
  import java.util.*;
  import javax.swing.*;
  import javax.swing.table.*;
  
  /**
   * This is a main class that will display status information
   * from an Antelope Orb.
   *
   * @author  Danny Harvey, BRTT
   * @version 1.0
   */
  public class JFrameOrbStat extends javax.swing.JFrame {
      private static final int ORB_OPEN = 1;
      private static final int ORB_CLOSE = 2;
      
      protected int orbState = ORB_CLOSE;
      protected int statEvery = 0;
      protected Orb orb = null;
      protected SourcesModel sm = null;
      protected int interval = 5;
      protected RunStat runstat = null;
  
      /** Creates new form JFrameOrbStat */
      public JFrameOrbStat(String orbname) {
  	this.setTitle("JFrameOrbStat");
          initComponents ();
          jTextField1.setText(orbname);
          pack ();
      }
  
      public JFrameOrbStat(String title, String orbname) {
  	this.setTitle(title);
          initComponents ();
          jTextField1.setText(orbname);
          pack ();
      }
      
      private void open() {
        try {
            orb = new Orb (jTextField1.getText(), "r&");
        }
        catch (Throwable exc) {
            jTextArea1.replaceRange("", 0, jTextArea1.getText().length());
            exc.printStackTrace();
            jTextArea1.append(exc.getMessage());
        }
      }
      
      private void stat() {
        try {
            OrbStat stat = orb.stat ();
            jTextArea1.replaceRange(stat.getList(), 0, jTextArea1.getText().length());
            OrbClient clients[] = orb.clients ();
            int n = clients.length;
            jTextArea2.replaceRange("", 0, jTextArea2.getText().length());
            for (int i=0; i<n; i++) {
              jTextArea2.append(clients[i].getList());
            }
            if (sm == null) {
              sm = new SourcesModel(orb, jTable3);
            } else {
              sm.update (orb);
            }
        }
        catch (Throwable exc) {
            jTextArea1.replaceRange("", 0, jTextArea1.getText().length());
            exc.printStackTrace();
            jTextArea1.append(exc.getMessage());
        }
      }
  
  
      /** This method is called from within the constructor to
       * initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is
       * always regenerated by the FormEditor.
       */
      private void initComponents() {//GEN-BEGIN:initComponents
          jPanel1 = new javax.swing.JPanel();
          jTextField1 = new javax.swing.JTextField();
          jButton1 = new javax.swing.JButton();
          jButton2 = new javax.swing.JButton();
          jButton3 = new javax.swing.JButton();
          jButton4 = new javax.swing.JButton();
          jSlider1 = new javax.swing.JSlider();
          jPanel2 = new javax.swing.JPanel();
          jTabbedPane1 = new javax.swing.JTabbedPane();
          jScrollPane1 = new javax.swing.JScrollPane();
          jTextArea1 = new javax.swing.JTextArea();
          jScrollPane2 = new javax.swing.JScrollPane();
          jTextArea2 = new javax.swing.JTextArea();
          jScrollPane3 = new javax.swing.JScrollPane();
          jTable3 = new javax.swing.JTable();
          
          getContentPane().setLayout(new java.awt.GridBagLayout());
          java.awt.GridBagConstraints gridBagConstraints1;
          
          addWindowListener(new java.awt.event.WindowAdapter() {
              public void windowClosing(java.awt.event.WindowEvent evt) {
                  exitForm(evt);
              }
          });
          
          jPanel1.setLayout(new java.awt.GridBagLayout());
          java.awt.GridBagConstraints gridBagConstraints2;
          
          jPanel1.setPreferredSize(new java.awt.Dimension(190, 10));
          jPanel1.setMinimumSize(new java.awt.Dimension(100, 10));
          jTextField1.setText("localhost");
          jTextField1.setPreferredSize(new java.awt.Dimension(100, 20));
          jTextField1.setMinimumSize(new java.awt.Dimension(100, 20));
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints2.ipadx = 10;
          gridBagConstraints2.insets = new java.awt.Insets(0, 1, 0, 1);
          gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH;
          gridBagConstraints2.weightx = 1.0;
          jPanel1.add(jTextField1, gridBagConstraints2);
          
          jButton1.setText("Open");
          jButton1.setBackground(new java.awt.Color(102, 255, 102));
          jButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
          jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseReleased(java.awt.event.MouseEvent evt) {
                  openButton(evt);
              }
          });
          
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH;
          jPanel1.add(jButton1, gridBagConstraints2);
          
          jButton2.setText("Close");
          jButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
          jButton2.setEnabled(false);
          jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseReleased(java.awt.event.MouseEvent evt) {
                  closeButton(evt);
              }
          });
          
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH;
          jPanel1.add(jButton2, gridBagConstraints2);
          
          jButton3.setText("Stat");
          jButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
          jButton3.setEnabled(false);
          jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseReleased(java.awt.event.MouseEvent evt) {
                  statButton(evt);
              }
          });
          
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH;
          jPanel1.add(jButton3, gridBagConstraints2);
          
          jButton4.setText("Stat Every");
          jButton4.setMargin(new java.awt.Insets(0, 0, 0, 0));
          jButton4.setEnabled(false);
          jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseReleased(java.awt.event.MouseEvent evt) {
                  statEveryButton(evt);
              }
          });
          
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH;
          jPanel1.add(jButton4, gridBagConstraints2);
          
          jSlider1.setMinorTickSpacing(1);
          jSlider1.setPaintLabels(true);
          jSlider1.setMinimum(1);
          jSlider1.setMajorTickSpacing(19);
          jSlider1.setMaximum(20);
          jSlider1.setValue(interval);
          jSlider1.setPreferredSize(new java.awt.Dimension(120, 43));
          jSlider1.setMinimumSize(new java.awt.Dimension(120, 43));
          jSlider1.setEnabled(false);
          jSlider1.addInputMethodListener(new java.awt.event.InputMethodListener() {
              public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
              }
              public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                  sliderMoved(evt);
              }
          });
          
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          jPanel1.add(jSlider1, gridBagConstraints2);
          
          gridBagConstraints1 = new java.awt.GridBagConstraints();
          gridBagConstraints1.gridx = 0;
          gridBagConstraints1.gridy = 0;
          gridBagConstraints1.gridwidth = 7;
          gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints1.ipady = 35;
          gridBagConstraints1.insets = new java.awt.Insets(5, 0, 0, 0);
          gridBagConstraints1.weightx = 1.0;
          getContentPane().add(jPanel1, gridBagConstraints1);
          
          jPanel2.setLayout(new java.awt.GridBagLayout());
          java.awt.GridBagConstraints gridBagConstraints3;
          
          jTextArea1.setColumns(60);
          jTextArea1.setRows(22);
          jTextArea1.setFont(new java.awt.Font("Courier New", 0, 11));
          jScrollPane1.setViewportView(jTextArea1);
          
          jTabbedPane1.addTab("OrbStat", jScrollPane1);
          
          jTextArea2.setColumns(60);
          jTextArea2.setRows(22);
          jTextArea2.setFont(new java.awt.Font("Courier New", 0, 11));
          jScrollPane2.setViewportView(jTextArea2);
          
          jTabbedPane1.addTab("OrbClients", jScrollPane2);
          
          jScrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
          jTable3.setFont(new java.awt.Font("Courier New", 0, 11));
          jTable3.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
          jScrollPane3.setViewportView(jTable3);
          
          jTabbedPane1.addTab("OrbSources", jScrollPane3);
          
          gridBagConstraints3 = new java.awt.GridBagConstraints();
          gridBagConstraints3.gridx = 0;
          gridBagConstraints3.gridy = 0;
          gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints3.weightx = 1.0;
          gridBagConstraints3.weighty = 1.0;
          jPanel2.add(jTabbedPane1, gridBagConstraints3);
          
          gridBagConstraints1 = new java.awt.GridBagConstraints();
          gridBagConstraints1.gridx = 0;
          gridBagConstraints1.gridy = 1;
          gridBagConstraints1.gridwidth = 7;
          gridBagConstraints1.gridheight = 6;
          gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints1.anchor = java.awt.GridBagConstraints.SOUTH;
          gridBagConstraints1.weightx = 1.0;
          gridBagConstraints1.weighty = 1.0;
          getContentPane().add(jPanel2, gridBagConstraints1);
          
      }//GEN-END:initComponents
  
    private void sliderMoved(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_sliderMoved
  // Add your handling code here:
    }//GEN-LAST:event_sliderMoved
  
    private void statEveryButton(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_statEveryButton
  // Add your handling code here:
        if (statEvery == 0) {
          statEvery = 1;
          runstat = new RunStat ();
          jButton4.setEnabled (true);
          jButton4.setBackground(new java.awt.Color (255, 153, 153));
          jButton3.setEnabled (false);
          jButton3.setBackground(new java.awt.Color (204, 204, 204));
        } else {
          statEvery = 0;
          runstat.stop();
          jButton4.setEnabled (true);
          jButton4.setBackground(new java.awt.Color (102, 255, 102));
          jButton3.setEnabled (true);
          jButton3.setBackground(new java.awt.Color (153, 153, 255));
        }
    }//GEN-LAST:event_statEveryButton
  
    private void statButton(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_statButton
  // Add your handling code here:
        stat();
    }//GEN-LAST:event_statButton
  
    private void closeButton(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeButton
  // Add your handling code here:
        if (statEvery == 1) {
          statEvery = 0;
          runstat.stop();
        }
        orbState = ORB_CLOSE;
        try { orb.close(); }
        catch (Throwable e) {
            jTextArea1.replaceRange("", 0, jTextArea1.getText().length());
            e.printStackTrace();
            jTextArea1.append(e.getMessage());
        }
        orb = null;
        System.gc();
        jButton1.setEnabled (true);
        jButton1.setBackground(new java.awt.Color (102, 255, 102));
        jTextField1.setEnabled (true);
        jButton2.setEnabled (false);
        jButton2.setBackground(new java.awt.Color (204, 204, 204));
        jButton3.setEnabled (false);
        jButton3.setBackground(new java.awt.Color (204, 204, 204));
        jButton4.setEnabled (false);
        jButton4.setBackground(new java.awt.Color (204, 204, 204));
        jSlider1.setEnabled (false);
    }//GEN-LAST:event_closeButton
  
    private void openButton(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openButton
  // Add your handling code here:
        open();
        stat();
        orbState = ORB_OPEN;
        jButton1.setEnabled (false);
        jButton1.setBackground(new java.awt.Color (204, 204, 204));
        jTextField1.setEnabled (false);
        jButton2.setEnabled (true);
        jButton2.setBackground(new java.awt.Color (255, 153, 153));
        jButton3.setEnabled (true);
        jButton3.setBackground(new java.awt.Color (153, 153, 255));
        jButton4.setEnabled (true);
        jButton4.setBackground(new java.awt.Color (102, 255, 102));
        statEvery = 0;
        jSlider1.setEnabled (true);
    }//GEN-LAST:event_openButton
  
      /** Exit the Application */
      private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
          System.exit (0);
      }//GEN-LAST:event_exitForm
  
      /**
      * @param args the command line arguments
      */
      public static void main (String args[]) {
          String title = "JFrameOrbStat" ;
          String orbname = "localhost" ;
          
          if (args.length > 0) {
  	    title = args[0];
              if (args.length > 1) {
              	orbname = args[1];
  	    }
          }
          new JFrameOrbStat (title, orbname).show ();
      }
  
      private class RunStat extends Object implements Runnable {
          private Thread runner;
          
          public RunStat () {
              runner = new Thread(this);
              runner.start();
          }
          
          public void stop () {
              runner.interrupt();
          }
          
          public void run() {
              while (true) {
                  stat();
                  interval = jSlider1.getValue();
                  try { Thread.sleep(interval * 1000); }
                  catch (InterruptedException e) { return; }
              }
          }
      }
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JPanel jPanel1;
      private javax.swing.JTextField jTextField1;
      private javax.swing.JButton jButton1;
      private javax.swing.JButton jButton2;
      private javax.swing.JButton jButton3;
      private javax.swing.JButton jButton4;
      private javax.swing.JSlider jSlider1;
      private javax.swing.JPanel jPanel2;
      private javax.swing.JTabbedPane jTabbedPane1;
      private javax.swing.JScrollPane jScrollPane1;
      private javax.swing.JTextArea jTextArea1;
      private javax.swing.JScrollPane jScrollPane2;
      private javax.swing.JTextArea jTextArea2;
      private javax.swing.JScrollPane jScrollPane3;
      private javax.swing.JTable jTable3;
      // End of variables declaration//GEN-END:variables
  
  }
  