home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Sample.bin / ReportViewFrame.java < prev    next >
Text File  |  1998-10-06  |  16KB  |  427 lines

  1. // Copyright (c) 1997, 1998 Symantec, Inc. All Rights Reserved.
  2.  
  3. /*
  4.     A basic extension of the java.awt.Frame class
  5.  */
  6.  
  7. import java.awt.*;
  8. import symantec.itools.awt.ScrollingPanel;
  9. import symantec.itools.multimedia.ImageViewer;
  10. import jclass.chart.JCChartComponent;
  11. import jclass.table.JCTableComponent;
  12. import java.io.BufferedWriter;
  13. import java.io.FileWriter;
  14. import jclass.chart.Chartable;
  15. import java.util.Vector;
  16. import java.util.Date;
  17.  
  18. /**
  19.  * This Frame was added to this project by dragging a Frame form component 
  20.  * into the project.
  21.  * It was then customized with Cafe's visual tools, including the Interaction
  22.  * Wizard.
  23.  * Then it was manually customized to 
  24.  * 1) Use a custom layout manager
  25.  * 2) Initialize the jclass chart and jclass tables, including a class to hand
  26.  *    data to the chart component
  27.  */
  28. public class ReportViewFrame extends Frame
  29. {
  30.     /*
  31.     static final int TIME_INTERVAL_2_JCLASS_TIME_UNITS[] = {
  32.         jclass.chart.JCChartComponent.MINUTES,
  33.         jclass.chart.JCChartComponent.HOURS,
  34.         jclass.chart.JCChartComponent.DAYS,
  35.         jclass.chart.JCChartComponent.WEEKS,
  36.         jclass.chart.JCChartComponent.YEARS
  37.     };
  38.     */
  39.  
  40.     /*
  41.     This method initializes the jclass chart and jclass tables from report data.
  42.     */
  43.     void setupReport() {
  44.         // Setup report from data
  45.         Data data = Data.getDataInstance();
  46.         Report report = data.getCurrentReport();
  47.         StringBuffer buf = new StringBuffer();
  48.  
  49.         // Note report title
  50.         setTitle(report.title);
  51.         setTitleLabel.setText(report.title);
  52.         
  53.         // Setup User Sessions vs Time chart, as needed
  54.         if(!report.optUsageChart) {
  55.             generalUsageChart.setVisible(false);
  56.         } else {
  57.             // chart type needs to be set first...
  58.             generalUsageChart.setDataView1ChartType(jclass.chart.JCChart.BAR);
  59.             // ...then customized
  60.             generalUsageChart.setX1AxisAnnotationMethod(jclass.chart.JCAxis.TIME_LABELS);
  61.              generalUsageChart.setX1AxisTimeUnit(jclass.chart.JCChartComponent.DAYS);
  62.             generalUsageChart.setX1AxisTimeFormatIsDefault(true);
  63.             // set TimeBase
  64.             generalUsageChart.getChartArea().getHorizActionAxis().setTimeBase(new Date(report.startTimestamp));
  65.             generalUsageChart.setY1AxisTitleText("Sessions");
  66.             jclass.chart.ChartDataView cdv = generalUsageChart.getDataView(0);
  67.             if(cdv != null) {
  68.                 cdv.setDataSource(new ChartDataFeeder(report));
  69.             }
  70.         }
  71.         
  72.         // Setup General Statistics table
  73.         if(!report.optGeneralStatistics) {
  74.             generalStatisticsLabel.setVisible(false);
  75.             generalStatisticsTable.setVisible(false);
  76.         } else {
  77.             buf.append("(Report date|");
  78.             buf.append(WLAUtil.dateTime2StringLong(report.analyzedDate));
  79.             buf.append(")(Timespan|");
  80.             buf.append(WLAUtil.millisecondsTime2String(report.startTimestamp));
  81.             buf.append("  -  ");
  82.             buf.append(WLAUtil.millisecondsTime2String(report.endTimestamp));
  83.             buf.append(")(Home page hits|");
  84.             buf.append(report.homePageHits);
  85.             buf.append(")(Total hits|");
  86.             buf.append(report.totalHits);
  87.             buf.append(")(Total user sessions|");
  88.             buf.append(report.totalUserSessionCount);
  89.             buf.append(")(Average hits per day|");
  90.             buf.append(report.avgHitsPerDay);
  91.             buf.append(")(Average sessions per day|");
  92.             buf.append(report.avgUserSessionsPerDay);
  93.             buf.append(")(Average session length <h:m:s>|");
  94.             buf.append(WLAUtil.timeDelta2String(report.avgUserSessionLength));
  95.             // Only include "time interval" stat if not day
  96.             if(report.hitTimeInterval != WLAUtil.MILLISECS_PER_DAY) {
  97.                 String intervalName = WLAUtil.timeInterval2CapPluralString(report.hitTimeInterval);
  98.                 intervalName = WLAUtil.timeInterval2LowerSingularString(report.hitTimeInterval);
  99.                 buf.append(")(Average hits per ");
  100.                 buf.append(intervalName);
  101.                 buf.append("|");
  102.                 buf.append(report.avgHitsPerHitTimeInterval);
  103.                 buf.append(")(Average sessions per ");
  104.                 buf.append(intervalName);
  105.                 buf.append("|");
  106.                 buf.append(report.avgUserSessionsPerHitTimeInterval);
  107.                 // Enlarge to handle extra lines
  108.                 Dimension dim = generalStatisticsTable.getSize();
  109.                 int sizePerLine = 24;
  110.                 int rows = generalStatisticsTable.getNumRows();
  111.                 if(rows != 0) {
  112.                     sizePerLine = 1 + (dim.height / rows);
  113.                 }
  114.                 dim.height += 2 * sizePerLine;
  115.                 generalStatisticsTable.setSize(dim);
  116.                 generalStatisticsTable.setNumRows(rows+2);
  117.             }
  118.             buf.append(")");
  119.             generalStatisticsTable.setCellValues(buf.toString());
  120.         }
  121.         
  122.         // Setup Top Domains table, as needed
  123.         if(!report.optMostActiveDomains) {
  124.             topDomainsLabel.setVisible(false);
  125.             topDomainsTable.setVisible(false);
  126.         } else {
  127.             buf.setLength(0);
  128.             int lim = report.sortedDomains.length > 10 ? 10 : report.sortedDomains.length;
  129.             for(int idx = 0; idx < lim; idx++) {
  130.                 buf.append('(');
  131.                 buf.append(report.sortedDomains[idx].domain);
  132.                 buf.append('|');
  133.                 buf.append(report.sortedDomains[idx].hits);
  134.                 buf.append(')');
  135.             }
  136.             topDomainsTable.setCellValues(buf.toString());
  137.         }
  138.     }
  139.  
  140.     // --  Implement object to hand data to KLGroup's chart
  141.  
  142.     /*
  143.     This class is used to hand data to the jclass chart, eliminating the
  144.     need to write the data to a file for chart use.
  145.     */
  146.     class ChartDataFeeder implements Chartable {
  147.         Report report;
  148.         long timeTillFirstInterval;     // millisecs till first full interval of time being analyzed
  149.         long timeTillFirstDayInterval;  // millisecs till first full day of time being analyzed
  150.  
  151.         /*
  152.         Constructs a ChartDataFeeder for the given report.
  153.         */
  154.         public ChartDataFeeder(Report report) {
  155.             this.report = report;
  156.         }
  157.  
  158.         /*
  159.         Returns a data item for the specified row and column.
  160.         Row 0 specifies the "x-axis" values.
  161.         Rows > 0 specify "y-axis" values.
  162.         */
  163.         public Object getDataItem(int row, int column) {
  164.             if(row == 0) {
  165.                 long millisecs = timeTillFirstInterval + (column * report.hitTimeInterval);
  166.                 return new Double(millisecs/(double)WLAUtil.MILLISECS_PER_DAY);
  167.             }
  168.             return new Double(report.userSessionsVsTimeInterval[column]);
  169.         }
  170.  
  171.         /*
  172.         Returns a vector of row values.
  173.         */
  174.         public Vector getRow(int row) {
  175.             int numCols = report.userSessionsVsTimeInterval.length;
  176.             Vector rv = new Vector(numCols);
  177.             for(int idx = 0; idx < numCols; idx++) {
  178.                 rv.addElement(getDataItem(row, idx));
  179.             }
  180.             return rv;
  181.         }
  182.         /*
  183.         Returns how row/column data is organized.
  184.         */
  185.         public int getDataInterpretation() {
  186.             return ARRAY;
  187.         }
  188.         /*
  189.         Returns the number of rows.
  190.         */
  191.         public int getNumRows() {
  192.             return 2;
  193.         }
  194.         public String[] getPointLabels() {
  195.             return null;
  196.         }
  197.         public String getSeriesName(int row) {
  198.             return null;    //"Series Name";   //null;
  199.         }
  200.         public String getSeriesLabel(int row) {
  201.             return null;    //"Series Label";  //null;
  202.         }
  203.         public String getName() {
  204.             return null;    //"Data Name";
  205.         }
  206.     }
  207.     
  208.  
  209. //  --  AUTOMATICALLY GENERATED/MAINTAINED CODE FRAMEWORK BELOW THIS LINE  --
  210.  
  211.     /*
  212.     Constructs a default ReportViewFrame object
  213.     */
  214.     public ReportViewFrame()
  215.     {
  216.         // This code is automatically generated by Visual Cafe when you add
  217.         // components to the visual environment. It instantiates and initializes
  218.         // the components. To modify the code, only use code syntax that matches
  219.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  220.         // parse your Java file into its visual environment.
  221.         //{{INIT_CONTROLS
  222.         setLayout(new GridLayout(1,1,0,0));
  223.         setVisible(false);
  224.         setSize(664,540);
  225.         setBackground(java.awt.Color.lightGray);
  226.         scrollingPanel1 = new symantec.itools.awt.ScrollingPanel();
  227.         scrollingPanel1.setScrollLineIncrement(10);
  228.         scrollingPanel1.setBounds(0,0,664,540);
  229.         add(scrollingPanel1);
  230.         panel1 = new java.awt.Panel();
  231.         panel1.setLayout(null);
  232.         panel1.setBounds(0,0,644,1120);
  233.         scrollingPanel1.add(panel1);
  234.         panel2 = new java.awt.Panel();
  235.         GridBagLayout gridBagLayout;
  236.         gridBagLayout = new GridBagLayout();
  237.         panel2.setLayout(gridBagLayout);
  238.         panel2.setBounds(0,0,640,220);
  239.         panel1.add(panel2);
  240.         imageViewer1 = new symantec.itools.multimedia.ImageViewer();
  241.         try {
  242.             imageViewer1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-inprogress.gif"));
  243.         }
  244.         catch (java.net.MalformedURLException error) { }
  245.         catch(java.beans.PropertyVetoException e) { }
  246.         imageViewer1.setBounds(362,5,276,198);
  247.         GridBagConstraints gbc;
  248.         gbc = new GridBagConstraints();
  249.         gbc.gridx = 2;
  250.         gbc.gridy = 0;
  251.         gbc.gridheight = 3;
  252.         gbc.weightx = 1.0;
  253.         gbc.weighty = 1.0;
  254.         gbc.fill = GridBagConstraints.BOTH;
  255.         gbc.insets = new Insets(5,48,17,2);
  256.         ((GridBagLayout)panel2.getLayout()).setConstraints(imageViewer1, gbc);
  257.         panel2.add(imageViewer1);
  258.         webLogAnalysisLabel = new java.awt.Label("Web Log Analysis");
  259.         webLogAnalysisLabel.setBounds(15,15,299,50);
  260.         webLogAnalysisLabel.setFont(new Font("SansSerif", Font.PLAIN, 36));
  261.         gbc = new GridBagConstraints();
  262.         gbc.gridx = 0;
  263.         gbc.gridy = 0;
  264.         gbc.fill = GridBagConstraints.NONE;
  265.         gbc.insets = new Insets(15,15,0,0);
  266.         ((GridBagLayout)panel2.getLayout()).setConstraints(webLogAnalysisLabel, gbc);
  267.         panel2.add(webLogAnalysisLabel);
  268.         setTitleLabel = new java.awt.Label("(untitled report)");
  269.         setTitleLabel.setBounds(96,92,136,30);
  270.         setTitleLabel.setFont(new Font("Dialog", Font.PLAIN, 18));
  271.         gbc = new GridBagConstraints();
  272.         gbc.gridx = 0;
  273.         gbc.gridy = 1;
  274.         gbc.gridwidth = 2;
  275.         gbc.fill = GridBagConstraints.NONE;
  276.         gbc.insets = new Insets(27,15,0,0);
  277.         ((GridBagLayout)panel2.getLayout()).setConstraints(setTitleLabel, gbc);
  278.         panel2.add(setTitleLabel);
  279.         generalUsageChart = new jclass.chart.JCChartComponent();
  280.         generalUsageChart.setY1AxisGridIsShowing(true);
  281.         generalUsageChart.setAxisBoundingBox(true);
  282.         generalUsageChart.setBounds(0,235,640,320);
  283.         panel1.add(generalUsageChart);
  284.         generalStatisticsLabel = new java.awt.Label("General Statistics Table");
  285.         generalStatisticsLabel.setBounds(15,578,300,24);
  286.         generalStatisticsLabel.setFont(new Font("Dialog", Font.BOLD, 12));
  287.         panel1.add(generalStatisticsLabel);
  288.         generalStatisticsTable = new jclass.table.JCTableComponent();
  289.         generalStatisticsTable.setAllowCellResize(jclass.table.JCTblEnum.RESIZE_NONE);
  290.         generalStatisticsTable.setColumnLabelsList(jclass.util.JCUtilConverter.toStringList(""));
  291.         generalStatisticsTable.setNumRows(8);
  292.         generalStatisticsTable.setRowLabelsList(jclass.util.JCUtilConverter.toStringList(""));
  293.         generalStatisticsTable.setCharWidthSeries("(all 25)");
  294.         generalStatisticsTable.setColumnLabelOffset(4);
  295.         generalStatisticsTable.setEditableSeries("(all all false)");
  296.         generalStatisticsTable.setSelectedForeground(java.awt.Color.lightGray);
  297.         generalStatisticsTable.setNumColumns(2);
  298.         generalStatisticsTable.setBounds(15,606,625,182);
  299.         generalStatisticsTable.setFont(new Font("Dialog", Font.PLAIN, 12));
  300.         panel1.add(generalStatisticsTable);
  301.         topDomainsLabel = new java.awt.Label("Top Domains Table");
  302.         topDomainsLabel.setBounds(15,845,625,24);
  303.         topDomainsLabel.setFont(new Font("Dialog", Font.BOLD, 12));
  304.         panel1.add(topDomainsLabel);
  305.         topDomainsTable = new jclass.table.JCTableComponent();
  306.         topDomainsTable.setColumnLabelsList(jclass.util.JCUtilConverter.toStringList("Domain,Total Hits"));
  307.         topDomainsTable.setRowLabelsList(jclass.util.JCUtilConverter.toStringList(""));
  308.         topDomainsTable.setCharWidthSeries("(all 25)");
  309.         topDomainsTable.setEditableSeries("(all all false)");
  310.         topDomainsTable.setSelectedForeground(java.awt.Color.lightGray);
  311.         topDomainsTable.setNumColumns(2);
  312.         topDomainsTable.setBounds(15,873,625,240);
  313.         panel1.add(topDomainsTable);
  314.         setTitle("");
  315.         //}}
  316.  
  317.         //{{INIT_MENUS
  318.         //}}
  319.  
  320.         //{{REGISTER_LISTENERS
  321.         SymWindow aSymWindow = new SymWindow();
  322.         this.addWindowListener(aSymWindow);
  323.         //}}
  324.  
  325.         // Use our custom layout manager
  326.         LayoutManager lm = new ReportLayout(panel1, 10, 10);
  327.         panel1.setLayout(lm);
  328.         lm.addLayoutComponent(ReportLayout.PLACE_SAME, panel2);
  329.         lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE, generalUsageChart);
  330.         lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE, generalStatisticsLabel);
  331.         lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE_BREAK, generalStatisticsTable);
  332.         lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE, topDomainsLabel);
  333.         lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE_BREAK, topDomainsTable);
  334.         
  335.         // Setup report
  336.         setupReport();
  337.  
  338.         setLocation(50, 50);
  339.     }
  340.     
  341.     /**
  342.      * Constructs this Dialog with the given title.
  343.      * This routine was automatically generated by Visual Cafe, and is not
  344.      * actually used.
  345.      */
  346.     public ReportViewFrame(String title)
  347.     {
  348.         this();
  349.         setTitle(title);
  350.     }
  351.  
  352.     /**
  353.      * Tells this component that it has been added to a container. 
  354.      * This is a standard Java AWT method which gets called by the AWT when 
  355.      * this component is added to a container. 
  356.      * Typically, it is used to create this component's peer. <br>
  357.      * It has been OVERRIDDEN here to adjust the position of components as needed
  358.      * for the container's insets. <br>
  359.      * This method is automatically generated by Visual Cafe.
  360.      */
  361.     public void addNotify()
  362.     {
  363.         // Record the size of the window prior to calling parents addNotify.
  364.         Dimension d = getSize();
  365.         
  366.         super.addNotify();
  367.  
  368.         if (fComponentsAdjusted)
  369.             return;
  370.  
  371.         // Adjust components according to the insets
  372.         Insets insets = getInsets();
  373.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  374.         Component components[] = getComponents();
  375.         for (int i = 0; i < components.length; i++)
  376.         {
  377.             Point p = components[i].getLocation();
  378.             p.translate(insets.left, insets.top);
  379.             components[i].setLocation(p);
  380.         }
  381.         fComponentsAdjusted = true;
  382.     }
  383.  
  384.     // Used for addNotify check.
  385.     boolean fComponentsAdjusted = false;
  386.  
  387.     //{{DECLARE_CONTROLS
  388.     symantec.itools.awt.ScrollingPanel scrollingPanel1;
  389.     java.awt.Panel panel1;
  390.     java.awt.Panel panel2;
  391.     symantec.itools.multimedia.ImageViewer imageViewer1;
  392.     java.awt.Label webLogAnalysisLabel;
  393.     java.awt.Label setTitleLabel;
  394.     jclass.chart.JCChartComponent generalUsageChart;
  395.     java.awt.Label generalStatisticsLabel;
  396.     jclass.table.JCTableComponent generalStatisticsTable;
  397.     java.awt.Label topDomainsLabel;
  398.     jclass.table.JCTableComponent topDomainsTable;
  399.     //}}
  400.  
  401.     //{{DECLARE_MENUS
  402.     //}}
  403.  
  404.     /** 
  405.      * This is an event listener created by Visual Cafe to handle WindowEvents.
  406.      */
  407.     class SymWindow extends java.awt.event.WindowAdapter
  408.     {
  409.         public void windowClosing(java.awt.event.WindowEvent event)
  410.         {
  411.             Object object = event.getSource();
  412.             if (object == ReportViewFrame.this)
  413.                 ReportViewFrame_WindowClosing(event);
  414.         }
  415.     }
  416.     
  417.     /**
  418.      * Handles the WINDOW_CLOSING WindowEvent.
  419.      * This method is automatically added when the Frame form was added to
  420.      * this project.
  421.      */
  422.     void ReportViewFrame_WindowClosing(java.awt.event.WindowEvent event)
  423.     {
  424.         dispose();         // dispose of the Frame.
  425.     }
  426. }
  427.