User: juha    
  Date: 01/02/18 12:37:32

  Modified:    src/org/jboss/admin/monitor ApplicationTree.java
                        GraphView.java MonitorFrame.java
                        MonitorFrameMenu.java MonitorResourceConstants.java
                        StatsView.java
  Added:       src/org/jboss/admin/monitor MonitorPane.java StatusBar.java
  Log:
  Mostly GUI prettifying BS.
  
  Revision  Changes    Path
  1.2       +14 -3     admin/src/org/jboss/admin/monitor/ApplicationTree.java
  
  Index: ApplicationTree.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/admin/src/org/jboss/admin/monitor/ApplicationTree.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApplicationTree.java      2000/12/17 20:11:22     1.1
  +++ ApplicationTree.java      2001/02/18 20:37:31     1.2
  @@ -5,8 +5,10 @@
   import javax.swing.tree.TreeSelectionModel;
   
   // non-standard class dependencies
  -import org.jboss.admin.InvocationEntry;
  +import org.jboss.admin.dataholder.InvocationEntry;
  +import org.jboss.admin.dataholder.BeanCacheEntry;
   import org.jboss.admin.monitor.tree.ApplicationTreeModel;
  +import org.jboss.admin.monitor.tree.ApplicationTreeCellRenderer;
   
   
   /**
  @@ -31,6 +33,12 @@
           // Set the selection model for this tree. Our selection model only
           // allows single selection.
           
super.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  +        
  +        // set the angled lines for the tree
  +        putClientProperty("JTree.lineStyle", "Angled");
  +        
  +        // set a custom cell renderer
  +        setCellRenderer(new ApplicationTreeCellRenderer());
       }
       
   /*
  @@ -41,9 +49,12 @@
    *************************************************************************
    */
   
  -    public void addInvocationEntry(InvocationEntry entry) {
  -        ((ApplicationTreeModel)getModel()).addInvocationEntry(entry);
  +    public void addEntry(InvocationEntry entry) {
  +        ((ApplicationTreeModel)getModel()).addEntry(entry);
       }
       
  +    public void addEntry(BeanCacheEntry entry) {
  +        ((ApplicationTreeModel)getModel()).addEntry(entry);
  +    }
       
   }
  
  
  
  1.2       +24 -11    admin/src/org/jboss/admin/monitor/GraphView.java
  
  Index: GraphView.java
  ===================================================================
  RCS file: /products/cvs/ejboss/admin/src/org/jboss/admin/monitor/GraphView.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GraphView.java    2000/12/17 20:11:23     1.1
  +++ GraphView.java    2001/02/18 20:37:31     1.2
  @@ -4,10 +4,9 @@
   import java.awt.BorderLayout;
   import java.awt.Component;
   import java.awt.Dimension;
  -
  +import javax.swing.JComponent;
   import javax.swing.JPanel;
  -import javax.swing.border.EtchedBorder;
  -
  +import javax.swing.border.Border;
   
   // non-standard class dependencies
   import org.jboss.admin.monitor.graph.DefaultGraphModel;
  @@ -26,8 +25,8 @@
   
               // superclass JComponent implements Serializable
               
  -    private GraphRenderer renderer = new DefaultGraphRenderer();
  -    private GraphModel    model    = new DefaultGraphModel();
  +    private GraphRenderer renderer   = new DefaultGraphRenderer();
  +    private GraphModel model         = new DefaultGraphModel();
       
   /*
    *************************************************************************
  @@ -39,8 +38,11 @@
    
       public GraphView() {
           super(new BorderLayout());
  -        
  -        add(renderer.getGraphRendererObject(this), BorderLayout.CENTER);
  +    
  +//        add(renderer.getGraphRendererObject(this), BorderLayout.CENTER);
  +//        add(renderer.getVerticalControlRendererObject(this), BorderLayout.WEST);
  +//        add(renderer.getHorizontalControlRendererObject(this), 
BorderLayout.SOUTH);
  +        setGraphRenderer(renderer);
           model.addGraphModelListener(renderer);
       }
       
  @@ -58,6 +60,14 @@
    *************************************************************************
    */
    
  +    public void setGraphBorder(Border border) {
  +        ((JComponent)renderer).setBorder(border);
  +    }
  +    
  +    public Border getGraphBorder() {
  +        return ((JComponent)renderer).getBorder();
  +    }
  +    
       public void setGraphRenderer(GraphRenderer graphRenderer) {
   
           if (graphRenderer == null)
  @@ -67,7 +77,9 @@
           
           this.renderer = graphRenderer;
           
  -        add(graphRenderer.getGraphRendererObject(this), BorderLayout.CENTER);
  +        add(renderer.getGraphRendererObject(this), BorderLayout.CENTER);
  +        add(renderer.getVerticalControlRendererObject(this), BorderLayout.WEST);
  +        add(renderer.getHorizontalControlRendererObject(this), BorderLayout.SOUTH);
           
           revalidate();
       }
  @@ -82,11 +94,12 @@
               return;
           
           model.removeGraphModelListener(renderer);
  -        remove((Component)renderer);
  -        
  +//        remove((Component)renderer);
  +  
  +        setGraphRenderer(renderer);      
           this.model = graphModel;
   
  -        add(renderer.getGraphRendererObject(this), BorderLayout.CENTER);
  +//        add(renderer.getGraphRendererObject(this), BorderLayout.CENTER);
           model.addGraphModelListener(renderer);
           
           revalidate();
  
  
  
  1.2       +102 -102  admin/src/org/jboss/admin/monitor/MonitorFrame.java
  
  Index: MonitorFrame.java
  ===================================================================
  RCS file: /products/cvs/ejboss/admin/src/org/jboss/admin/monitor/MonitorFrame.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MonitorFrame.java 2000/12/17 20:11:24     1.1
  +++ MonitorFrame.java 2001/02/18 20:37:31     1.2
  @@ -2,7 +2,6 @@
   
   // standard imports
   import java.awt.Container;
  -import java.awt.GridLayout;
   import java.awt.BorderLayout;
   import java.awt.event.WindowAdapter;
   import java.awt.event.WindowEvent;
  @@ -11,7 +10,6 @@
   import javax.swing.ImageIcon;
   import javax.swing.JFrame;
   import javax.swing.JComponent;
  -import javax.swing.JLabel;
   import javax.swing.JPanel;
   import javax.swing.JSplitPane;
   import javax.swing.JScrollPane;
  @@ -19,23 +17,20 @@
   import javax.swing.tree.DefaultMutableTreeNode;
   import javax.swing.event.TreeSelectionListener;
   import javax.swing.event.TreeSelectionEvent;
  -import javax.swing.border.TitledBorder;
  -import javax.swing.border.EmptyBorder;
  -import javax.swing.border.CompoundBorder;
  -import javax.swing.border.EtchedBorder;
  -import javax.swing.border.BevelBorder;
   
   import javax.jms.JMSException;
   import javax.jms.Message;
   import javax.jms.MessageListener;
   import javax.naming.NamingException;
  +import javax.naming.ServiceUnavailableException;
   
   // non-standard class dependencies
  -import org.jboss.admin.InvocationEntry;
  +import org.jboss.admin.dataholder.InvocationEntry;
  +import org.jboss.admin.dataholder.BeanCacheEntry;
   import org.jboss.admin.MetricsConnector;
  -import org.jboss.admin.monitor.graph.GraphModel;
   import org.jboss.admin.monitor.graph.DefaultGraphModel;
   import org.jboss.admin.monitor.tree.MethodTreeNode;
  +import org.jboss.monitor.MetricsConstants;
   
   import org.gjt.lindfors.util.LocalizationSupport;
   
  @@ -44,8 +39,8 @@
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
    */
  -public class MonitorFrame extends JFrame implements MessageListener,
  -                                                    TreeSelectionListener,
  +public class MonitorFrame extends JFrame implements TreeSelectionListener,
  +                                                    MetricsConstants,
                                                       MonitorResourceConstants {
       
               // superclass Frame implements Serializable
  @@ -65,9 +60,9 @@
        * Initialized in the constructor.
        */
       private transient LocalizationSupport lang = null;
  -    
  -
  -    private GraphView graph = null;
  +        
  +    private StatusBar statusBar = new StatusBar();
  +    private MonitorPane monitor = new MonitorPane();
       
   /*
    *************************************************************************
  @@ -81,7 +76,7 @@
        * Constructs a new monitor frame. This constructor creates a frame with
        * a split layout where an application tree is placed on the left and
        * the graph and statistics are on the right. Constructing the frame
  -     * also attempts a connection to the JMS metrics topic ({@link #TOPIC})
  +     * also attempts a connection to the JMS metrics topic (topic/metrics})
        * and registers itself as a subscriber to the topic.
        */
       public MonitorFrame() {
  @@ -95,10 +90,11 @@
           // split pane with a app tree on the left and a graph on the right
           JSplitPane split = new JSplitPane();
           split.setLeftComponent(createApplicationTree());
  -        split.setRightComponent(createMonitorPane());
  +        split.setRightComponent(monitor);
           split.setDividerLocation(200);
           
           c.add(split, BorderLayout.CENTER);
  +        c.add(statusBar, BorderLayout.SOUTH);
           
           // add menu object
           setJMenuBar(new MonitorFrameMenu(this));
  @@ -117,19 +113,6 @@
           setIconImage(icon.getImage());
           
           setTitle(lang.getLabel(MONITOR_FRAME));
  -        
  -        // connect to JMS
  -        try {
  -            MetricsConnector connector = new MetricsConnector(TOPIC);
  -            connector.connect(this);
  -        }
  -        catch (JMSException e) {
  -            System.err.println(e);
  -        }
  -        catch (NamingException e) {
  -            System.err.println(e);
  -        }
  -        
           setSize(700, 450);
       }
   
  @@ -146,39 +129,6 @@
           return lang;
       }
       
  -/*
  - *************************************************************************
  - *
  - *      MESSAGE_LISTENER IMPLEMENTATION
  - *
  - *************************************************************************
  - */
  - 
  -    /**
  -     * Receives the messages from JMS topic and passes them on to the
  -     * application tree for further processing.
  -     */
  -    public void onMessage(final Message msg) {
  -       
  -        // [TODO]  discard all messages that aren't marked as coming from
  -        //         the invocation layer
  -        
  -        SwingUtilities.invokeLater(new Runnable() {
  -            
  -            // adding invocation entries updates GUI, hence not thread safe
  -            
  -            public void run() {
  -                try {    
  -                    InvocationEntry entry = new InvocationEntry(msg);
  -            
  -                    tree.addInvocationEntry(entry);
  -                }
  -                catch (JMSException e) {
  -                    System.err.println(e);
  -                }
  -            }
  -        });       
  -    }
   
   /*
    *************************************************************************
  @@ -204,24 +154,37 @@
            
               // ATM all leaves are methodnode instances
               MethodTreeNode methodNode = (MethodTreeNode)node;
  -            
  -            GraphModel model = methodNode.getGraphModel();
  -            
  -            graph.setModel(model);
  -            graph.repaint();
  +            monitor.setGraphModel(methodNode.getGraphModel());
  +            monitor.repaint();
           }
           
  -        // right now just display empty stats for all branches
  +        // right just display empty stats for all branches
           // will do "summary" displays later
           else {
  -            graph.setModel(new DefaultGraphModel());
  -            graph.repaint();
  +            monitor.setGraphModel(new DefaultGraphModel());
  +            monitor.repaint();
           }
           
       }
  +    
   /*
    *************************************************************************
    *
  + *      METHOD OVERRIDES
  + *
  + *************************************************************************
  + */     
  +
  +    public void setVisible(boolean b) {
  +        super.setVisible(b);
  +        
  +        Thread connectorThread = new Thread(new ConnectorThread());
  +        connectorThread.start();
  +    }
  + 
  +/*
  + *************************************************************************
  + *
    *      PRIVATE INSTANCE METHODS
    *
    *************************************************************************
  @@ -245,40 +208,77 @@
           return pane;
       }
       
  -    /**
  -     * Creates the monitor pane component. The pane consist of graph(s) and
  -     * stat displays.
  -     *
  -     * @return component
  -     */
  -    private JComponent createMonitorPane() {
  -
  -        // Create the initial graph view. This view's model will be changed
  -        // according to to the node selected in the application tree.
  -        graph     = new GraphView();
  -        EtchedBorder graphLines    = new EtchedBorder();
  -        TitledBorder graphTitle    = new TitledBorder(graphLines, "  Graph View  ");
  -        EmptyBorder  graphInsets   = new EmptyBorder(0, 5, 5, 5);
  -        BevelBorder  graphBevel    = new BevelBorder(BevelBorder.LOWERED);
  -        CompoundBorder graphBorder = new CompoundBorder(graphTitle,
  -                                     new CompoundBorder(graphInsets, graphBevel));
  -                                     
  -        StatsView stats = new StatsView();
  -        EtchedBorder statsLines  = new EtchedBorder();
  -        TitledBorder statsBorder = new TitledBorder(statsLines, "  Statistics  ");
  -        
  -        graph.setBorder(graphBorder);
  -        stats.setBorder(statsBorder);
  -        
  -        JPanel pane = new JPanel(new GridLayout(0, 1));
  -        pane.setBorder(new EmptyBorder(10, 10, 10, 10));
  +    
  +/*
  + *************************************************************************
  + *
  + *      INNER CLASSES
  + *
  + *************************************************************************
  + */     
  + 
  +    private class ConnectorThread implements Runnable, MessageListener {
           
  -        pane.add(graph);
  -        pane.add(stats);
  +        final static String TOPIC      = "topic/metrics";
  +        final static String SELECTOR   = 
  +            "JMSType = 'Invocation' OR JMSType = 'BeanCache'";
  +        
  +        public void run() {
  +            // connect to JMS
  +            try {
  +                statusBar.setMessage(lang.getString(CONNECTING_JNDI));
  +                
  +                MetricsConnector connector = new MetricsConnector();
  +                connector.setTopic(TOPIC);
  +                connector.setMessageSelector(SELECTOR);
  +                connector.connect(this);
  +                
  +                statusBar.clear();
  +            }
  +            catch (ServiceUnavailableException e) {
  +                statusBar.setAlert(lang.getString(JNDI_NOT_AVAILABLE));
  +            }
  +            catch (JMSException e) {
  +                System.err.println(e);
  +            }
  +            catch (NamingException e) {
  +                statusBar.setAlert(e.getMessage());
  +            }
  +        }
           
  -        return pane;
  -    }
  +     
  +        /**
  +         * Receives the messages from JMS topic and passes them on to the
  +         * application tree for further processing.
  +         */
  +        public void onMessage(final Message msg) {
       
  -
  +            SwingUtilities.invokeLater(new Runnable() {
  +                
  +                // adding invocation entries updates GUI, hence not thread safe
  +                public void run() {
  +                    try {    
  +                        Object msgType = msg.getJMSType();
  +                        
  +                        if (msgType.equals(INVOCATION_METRICS)) {
  +                            InvocationEntry entry = new InvocationEntry(msg);
  +                            tree.addEntry(entry);
  +                        }
  +                        else if (msgType.equals(BEANCACHE_METRICS)) {
  +                            BeanCacheEntry entry = new BeanCacheEntry(msg);
  +                            tree.addEntry(entry);
  +                        }
  +                        else {
  +                            // noop, we ignore unknown msg types
  +                            // these should get passed by msg selector anyways
  +                        }
  +                    }
  +                    catch (JMSException e) {
  +                        System.err.println(e);
  +                    }
  +                }
  +            });       
  +        }
  +    }
   }
   
  
  
  
  1.2       +11 -0     admin/src/org/jboss/admin/monitor/MonitorFrameMenu.java
  
  Index: MonitorFrameMenu.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/admin/src/org/jboss/admin/monitor/MonitorFrameMenu.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MonitorFrameMenu.java     2000/12/17 20:11:24     1.1
  +++ MonitorFrameMenu.java     2001/02/18 20:37:31     1.2
  @@ -9,6 +9,7 @@
   import javax.swing.JSeparator;
   
   // non-standard class dependencies
  +import org.jboss.admin.monitor.action.AboutAction;
   import org.jboss.admin.monitor.action.SaveAsCSVAction;
   import org.jboss.admin.monitor.action.GraphContinuousAction;
   import org.jboss.admin.monitor.action.GraphPerInvocationAction;
  @@ -60,6 +61,7 @@
           add(createEditMenu());
           add(createViewMenu());
           add(createToolsMenu());
  +        add(createHelpMenu());
       }
   
   
  @@ -112,6 +114,15 @@
           tools.add("Launch EJB Verifier...");
           
           return tools;
  +    }
  +    
  +    private JMenu createHelpMenu() {
  +     
  +        JMenu help = new JMenu(lang.getLabel(HELP_MENU));
  +        
  +        help.add(AboutAction.getInstance(frame.getLocale()));
  +        
  +        return help;
       }
       
   }
  
  
  
  1.2       +40 -8     admin/src/org/jboss/admin/monitor/MonitorResourceConstants.java
  
  Index: MonitorResourceConstants.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/admin/src/org/jboss/admin/monitor/MonitorResourceConstants.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MonitorResourceConstants.java     2000/12/17 20:11:24     1.1
  +++ MonitorResourceConstants.java     2001/02/18 20:37:31     1.2
  @@ -2,23 +2,39 @@
   
   
   public interface MonitorResourceConstants {
  -
  -    /** The topic we're listening on in JMS */
  -    final static String TOPIC      = "topic/metrics";
       
       /** Language bundle path and name */
  -    final static String LANG_PKG   = "resources/lang/MonitorBundle";
  +    final static String LANG_PKG            = "resources/lang/MonitorBundle";
       /** Context help bundle path and name */
  -    final static String HELP_PKG   = "resources/lang/MonitorHelp";
  +    final static String HELP_PKG            = "resources/lang/MonitorHelp";
       
       /** jBoss icon image path */
  -    final static String JBOSS_ICON = "/resources/images/jBossIcon.gif";
  +    final static String JBOSS_ICON          = "/resources/images/JBossIcon.gif";
  +    /** Server 16x16 icon image path */
  +    final static String SERVER_ICON_16      = "/resources/images/Server16.gif";
  +    /** Ejb-jar 16x16 icon image path */
  +    final static String EJB_JAR_ICON_16     = 
"/resources/images/EnterpriseJavaBeanJar16.gif";
       /** Enterprise bean 16x16 icon image path */
  -    final static String BEAN_ICON_16 = "/resources/images/EnterpriseJavaBean16.gif";
  +    final static String EJB_BEAN_ICON_16    = 
"/resources/images/EnterpriseJavaBean16.gif";
  +    /** Jar 16x16 icon image path */
  +    final static String JAR_ICON_16         = "/resources/images/Jar16.gif";
  +    /** Bean 16x16 icon image path */
  +    final static String BEAN_ICON_16        = "/resources/images/Bean16.gif";
  +    /** Bean cache 16x16 icon image path */
  +    final static String CACHE_ICON_16       = "/resources/images/BeanCache16.gif";
  +    /** Method 16x16 icon image path */
  +    final static String METHOD_ICON_16      = "/resources/images/Method16.gif";
  +    /** JBoss logo image path */
  +    final static String JBOSS_LOGO          = "/resources/images/JBossLogo.gif";
  +    
  +    /** Resource bundle key for a close button. */
  +    final static String  CLOSE     = "button.close";
       
       
       /** Resource bundle key for the monitor main window title. */
  -    final static String  MONITOR_FRAME           = "frame";    
  +    final static String  MONITOR_FRAME           = "frame";   
  +    /** Resource bundle key for the about dialog title. */
  +    final static String  ABOUT_DIALOG            = "dialog.about";
       /** Resource bundle key for the File menu. */
       final static String  FILE_MENU               = "menu.file";
       /** Resource bundle key for the Edit menu. */
  @@ -27,6 +43,8 @@
       final static String  VIEW_MENU               = "menu.view";
       /** Resource bundle key for the Tools menu. */
       final static String  TOOLS_MENU              = "menu.tools";
  +    /** Resource bundle key for the Help menu. */
  +    final static String  HELP_MENU               = "menu.help";
       
       /** Resource bundle key for the Save as CSV action. */
       final static String  SAVE_AS_CSV             = "action.saveas.csv";
  @@ -36,9 +54,23 @@
       final static String  GRAPH_CONTINUOUS        = "action.graph.continuous";
       /** Resource bundle key for the Launch JNDI Browser action. */
       final static String  JNDI_BROWSER            = "action.jndiBrowser";
  +    /** Resource bundle key for the About action. */
  +    final static String  ABOUT                   = "action.about";
       
       
  +    /** Resource bundle key for Status message. */
  +    final static String  CONNECTING_JNDI         = "msg.connect.jndi";
  +    /** Resource bundle key for Status message. */
  +    final static String  JNDI_NOT_AVAILABLE      = "msg.not_available.jndi";
  +    
  +    /** Resource bundle key for Stats view entry. */
  +    final static String  AVG_INVOCATION_TIME     = "stats.invocation.avg_time";
  +    /** Resource bundle key for Stats view entry. */
  +    final static String  TOTAL_INVOCATION_COUNT  = "stats.invocation.total";
  +
  +    
       final static String  INVOCATION_GRAPH_BORDER = "border.invocation.graph";
  +    
       
       
   }
  
  
  
  1.2       +114 -1    admin/src/org/jboss/admin/monitor/StatsView.java
  
  Index: StatsView.java
  ===================================================================
  RCS file: /products/cvs/ejboss/admin/src/org/jboss/admin/monitor/StatsView.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatsView.java    2000/12/17 20:11:24     1.1
  +++ StatsView.java    2001/02/18 20:37:31     1.2
  @@ -1,10 +1,123 @@
   package org.jboss.admin.monitor;
   
   // standard imports
  +import java.awt.BorderLayout;
  +import java.awt.Color;
  +import java.awt.FlowLayout;
  +import java.util.Locale;
  +
  +import javax.swing.JComponent;
  +import javax.swing.JLabel;
   import javax.swing.JPanel;
  +import javax.swing.border.EmptyBorder;
  +import javax.swing.border.TitledBorder;
  +
  +// non-standard class dependencies
  +import org.jboss.admin.monitor.event.GraphModelListener;
  +import org.jboss.admin.monitor.event.GraphModelEvent;
  +
  +import org.hs.jfc.FormPanel;
  +import org.gjt.lindfors.util.LocalizationSupport;
  +
  +
  +/**
  + * ...
  + *
  + * @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
  + */
  +public class StatsView extends JPanel implements GraphModelListener,
  +                                                 MonitorResourceConstants {
  +
  +            // superclass implements Serializable
  +            
  +    /**
  +     * Support class for localization. Used for loading language resource bundles
  +     * and retrieving localized info.
  +     *
  +     * Initialized in the constructor.
  +     */
  +    private transient LocalizationSupport lang = null;
  +    
  +    private int totalInvocations    = 0;
  +    private int totalInvocationTime = 0;
  +
  +    private JLabel avgTimePanel;
  +    private JLabel totalInvPanel;
  +    
  +/*
  + *************************************************************************
  + *
  + *      CONSTRUCTORS
  + *
  + *************************************************************************
  + */
  + 
  +    /*
  +     * Default constructor
  +     */
  +    public StatsView() {
  +        super(new FlowLayout(FlowLayout.LEFT));
  +        
  +        //setLocale(getParent().getLocale());
  +        lang = new LocalizationSupport(LANG_PKG, Locale.getDefault());
  +
  +        add(createLayout());        
  +    }
  +    
  +/*
  + *************************************************************************
  + *
  + *      IMPLEMENTS GRAPH_MODEL_LISTENER INTERFACE
  + *
  + *************************************************************************
  + */
  + 
  +    public void valueAppended(GraphModelEvent evt) {
  +    
  +        int value = (int)evt.getValue();
  +        
  +        // Ignore zero additions; there will be lots of these if the
  +        // continuous graph update is being used, no need to count them
  +        if (value <= 0)
  +            return;
  +            
  +        ++totalInvocations;
  +        totalInvocationTime += value;
  +        
  +        avgTimePanel.setText(String.valueOf(totalInvocationTime / 
totalInvocations));
  +        
  +        repaint();
  +    }
   
  -public class StatsView extends JPanel {
  +/*
  + *************************************************************************
  + *
  + *      PRIVATE INSTANCE METHODS
  + *
  + *************************************************************************
  + */
   
  +    private JComponent createLayout() {
   
  +        FormPanel p = new FormPanel();
  +        
  +        JLabel average      = new JLabel(lang.getLabel(AVG_INVOCATION_TIME) + ":");
  +        JLabel averageValue = new JLabel();
  +        JLabel total        = new JLabel(lang.getLabel(TOTAL_INVOCATION_COUNT) + 
":");
  +        JLabel totalValue   = new JLabel("" + totalInvocations);
  +        JLabel millisecs    = new JLabel("ms");
  +        
  +        if (totalInvocations <= 0)
  +            averageValue.setText("0.0");  // [TODO] localize number formatting
  +        else 
  +            averageValue.setText(String.valueOf(totalInvocationTime / 
totalInvocations));
  +        
  +        p.add(average, averageValue, 1, 1);  // row 1, col 1
  +        p.add(millisecs,             1, 2);
  +        p.add(total, totalValue,     2, 1);
  +        
  +        return p;
  +    }
  +        
   }
   
  
  
  
  1.1                  admin/src/org/jboss/admin/monitor/MonitorPane.java
  
  Index: MonitorPane.java
  ===================================================================
  package org.jboss.admin.monitor;
  
  // standard imports
  import java.awt.GridLayout;
  import javax.swing.JPanel;
  import javax.swing.border.BevelBorder;
  import javax.swing.border.EtchedBorder;
  import javax.swing.border.EmptyBorder;
  import javax.swing.border.TitledBorder;
  import javax.swing.border.CompoundBorder;
  
  // non-standard class dependencies
  import org.jboss.admin.monitor.graph.GraphModel;
  
  /**
   * ...
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
   */     
  public class MonitorPane extends JPanel {
  
      private GraphView graph = null;
      private StatsView stats = null;
      
      
  /*
   *************************************************************************
   *
   *      CONSTRUCTORS
   *
   *************************************************************************
   */     
      
      public MonitorPane() {
          super(new GridLayout(0, 1, 0, 10));
          init();
      }
      
  /*
   *************************************************************************
   *
   *      PUBLIC INSTANCE METHODS
   *
   *************************************************************************
   */     
   
      public void setGraphModel(GraphModel model) {
          graph.setModel(model);
      }
      
  /*
   *************************************************************************
   *
   *      PRIVATE INSTANCE METHODS
   *
   *************************************************************************
   */     
  
      private void init() {
  
          // Create the initial graph view. This view's model will be changed
          // according to to the node selected in the application tree.
          graph = new GraphView();
          stats = new StatsView();
          //graph.addModelListener(stats);
          
          EtchedBorder graphLines    = new EtchedBorder();
          TitledBorder graphTitle    = new TitledBorder(graphLines, "  Graph View  ");
          EmptyBorder  graphInsets   = new EmptyBorder(0, 5, 5, 5);
          CompoundBorder graphBorder = new CompoundBorder(graphTitle, graphInsets);
                                               
          EtchedBorder statsLines  = new EtchedBorder();
          TitledBorder statsBorder = new TitledBorder(statsLines, "  Statistics  ");
          
          graph.setBorder(graphBorder);
          stats.setBorder(statsBorder);
          
          setBorder(new EmptyBorder(10, 10, 10, 10));
          add(graph);
          add(stats);
      }    
  
  }
  
  
  
  1.1                  admin/src/org/jboss/admin/monitor/StatusBar.java
  
  Index: StatusBar.java
  ===================================================================
  package org.jboss.admin.monitor;
  
  // standard imports
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.FlowLayout;
  import java.awt.Font;
  import java.awt.GridBagLayout;
  import java.awt.GridBagConstraints;
  
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.SwingUtilities;
  import javax.swing.border.EmptyBorder;
  import javax.swing.border.EtchedBorder;
  import javax.swing.border.BevelBorder;
  import javax.swing.border.CompoundBorder;
  import javax.swing.border.SoftBevelBorder;
  
  /**
   * ...
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
   */     
  public class StatusBar extends JPanel {
    
      private JLabel alert = new JLabel();
      
  /*
   *************************************************************************
   *
   *      CONSTRUCTORS
   *
   *************************************************************************
   */     
   
      public StatusBar() {
          init();
      }
      
  /*
   *************************************************************************
   *
   *      PUBLIC INSTANCE METHODS
   *
   *************************************************************************
   */     
   
      /**
       * <p>
       * This method is thread safe, although most Swing methods
       * are not.
       */
      public void setAlert(final String msg) {
      
          if (SwingUtilities.isEventDispatchThread())
              unsafeSetMessage(msg, Color.red);
          else 
              safe(new Runnable() {
                  public void run() {
                      unsafeSetMessage(msg, Color.red);
                  }
              });
      }
      
      /**
       * <p>
       * This method is thread safe, although most Swing methods
       * are not.
       */
      public void setMessage(final String msg) {
          
          if (SwingUtilities.isEventDispatchThread())
              unsafeSetMessage(msg, Color.black);
          else
              safe(new Runnable() {
                  public void run() {
                      unsafeSetMessage(msg, Color.black);
                  }
              });
      }
      
      /**
       * <p>
       * This method is thread safe, although most Swing methods
       * are not.
       */
      public void clear() {
          
          if (SwingUtilities.isEventDispatchThread())
              unsafeClear();
          else
              safe(new Runnable() {
                  public void run() {
                      unsafeClear();
                  }
              });
      }
  
  /*
   *************************************************************************
   *
   *      PRIVATE INSTANCE METHODS
   *
   *************************************************************************
   */     
  
      private void safe(Runnable runnable) {
          SwingUtilities.invokeLater(runnable);
      }
  
      private void unsafeSetMessage(String msg, Color color) {
  
          if ( (msg == null) || (msg.equals("")) ) {
              unsafeClear();
              return;
          }
      
          alert.setText(msg);
          alert.setForeground(color);
          alert.repaint();
      }
  
  
      private void unsafeClear() {                    
          alert.setText("");
          alert.repaint();
      }
      
      private void init() {
      
          setLayout(new GridBagLayout());
          
          BevelBorder bevel    = new SoftBevelBorder(BevelBorder.LOWERED);
          EmptyBorder insets   = new EmptyBorder(0, 5, 0, 5);
          CompoundBorder combo = new CompoundBorder(bevel, insets);
          
          alert.setBorder(combo);
          alert.setMinimumSize(new Dimension(150, 20));
          alert.setPreferredSize(new Dimension(300, 20));
          alert.setMaximumSize(new Dimension(500, 20));
          alert.setFont(new Font("SansSerif", Font.PLAIN, 12));
          
          // alert layout constraints
          GridBagConstraints constraints = new GridBagConstraints();
          constraints.gridwidth  = 30;
          constraints.weightx    = 300;
          constraints.anchor     = GridBagConstraints.WEST;
          
          add(alert, constraints);
          
          JLabel bar = new JLabel();
          bar.setBorder(bevel);
          bar.setMinimumSize(new Dimension(20, 20));
          bar.setPreferredSize(new Dimension(20, 20));
          bar.setMaximumSize(new Dimension(20, 20));
          
          // constraints
          constraints = new GridBagConstraints();
          constraints.gridwidth   = 3;
          constraints.weightx     = 3;
          constraints.anchor      = GridBagConstraints.EAST;
          constraints.gridx       = GridBagConstraints.RELATIVE;
          constraints.gridy       = 0;
          
          add(bar, constraints);
  
          JLabel foo = new JLabel();
          foo.setBorder(bevel);
          foo.setMinimumSize(new Dimension(20, 20));
          foo.setPreferredSize(new Dimension(20, 20));
          foo.setMaximumSize(new Dimension(20, 20));
          
          // constraints
          constraints = new GridBagConstraints();
          constraints.gridwidth   = 3;
          constraints.weightx     = 3;
          constraints.anchor      = GridBagConstraints.EAST;
          constraints.gridx       = GridBagConstraints.RELATIVE;
          constraints.gridy       = 0;
          
          add(foo, constraints);
      }
  }
  
  
  
  

Reply via email to