home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-10-06 | 15.3 KB | 427 lines |
- // Copyright (c) 1997, 1998 Symantec, Inc. All Rights Reserved.
-
- /*
- A basic extension of the java.awt.Frame class
- */
-
- import java.awt.*;
- import symantec.itools.awt.ScrollingPanel;
- import symantec.itools.multimedia.ImageViewer;
- import jclass.chart.JCChartComponent;
- import jclass.table.JCTableComponent;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import jclass.chart.Chartable;
- import java.util.Vector;
- import java.util.Date;
-
- /**
- * This Frame was added to this project by dragging a Frame form component
- * into the project.
- * It was then customized with Cafe's visual tools, including the Interaction
- * Wizard.
- * Then it was manually customized to
- * 1) Use a custom layout manager
- * 2) Initialize the jclass chart and jclass tables, including a class to hand
- * data to the chart component
- */
- public class ReportViewFrame extends Frame
- {
- /*
- static final int TIME_INTERVAL_2_JCLASS_TIME_UNITS[] = {
- jclass.chart.JCChartComponent.MINUTES,
- jclass.chart.JCChartComponent.HOURS,
- jclass.chart.JCChartComponent.DAYS,
- jclass.chart.JCChartComponent.WEEKS,
- jclass.chart.JCChartComponent.YEARS
- };
- */
-
- /*
- This method initializes the jclass chart and jclass tables from report data.
- */
- void setupReport() {
- // Setup report from data
- Data data = Data.getDataInstance();
- Report report = data.getCurrentReport();
- StringBuffer buf = new StringBuffer();
-
- // Note report title
- setTitle(report.title);
- setTitleLabel.setText(report.title);
-
- // Setup User Sessions vs Time chart, as needed
- if(!report.optUsageChart) {
- generalUsageChart.setVisible(false);
- } else {
- // chart type needs to be set first...
- generalUsageChart.setDataView1ChartType(jclass.chart.JCChart.BAR);
- // ...then customized
- generalUsageChart.setX1AxisAnnotationMethod(jclass.chart.JCAxis.TIME_LABELS);
- generalUsageChart.setX1AxisTimeUnit(jclass.chart.JCChartComponent.DAYS);
- generalUsageChart.setX1AxisTimeFormatIsDefault(true);
- // set TimeBase
- generalUsageChart.getChartArea().getHorizActionAxis().setTimeBase(new Date(report.startTimestamp));
- generalUsageChart.setY1AxisTitleText("Sessions");
- jclass.chart.ChartDataView cdv = generalUsageChart.getDataView(0);
- if(cdv != null) {
- cdv.setDataSource(new ChartDataFeeder(report));
- }
- }
-
- // Setup General Statistics table
- if(!report.optGeneralStatistics) {
- generalStatisticsLabel.setVisible(false);
- generalStatisticsTable.setVisible(false);
- } else {
- buf.append("(Report date|");
- buf.append(WLAUtil.dateTime2StringLong(report.analyzedDate));
- buf.append(")(Timespan|");
- buf.append(WLAUtil.millisecondsTime2String(report.startTimestamp));
- buf.append(" - ");
- buf.append(WLAUtil.millisecondsTime2String(report.endTimestamp));
- buf.append(")(Home page hits|");
- buf.append(report.homePageHits);
- buf.append(")(Total hits|");
- buf.append(report.totalHits);
- buf.append(")(Total user sessions|");
- buf.append(report.totalUserSessionCount);
- buf.append(")(Average hits per day|");
- buf.append(report.avgHitsPerDay);
- buf.append(")(Average sessions per day|");
- buf.append(report.avgUserSessionsPerDay);
- buf.append(")(Average session length <h:m:s>|");
- buf.append(WLAUtil.timeDelta2String(report.avgUserSessionLength));
- // Only include "time interval" stat if not day
- if(report.hitTimeInterval != WLAUtil.MILLISECS_PER_DAY) {
- String intervalName = WLAUtil.timeInterval2CapPluralString(report.hitTimeInterval);
- intervalName = WLAUtil.timeInterval2LowerSingularString(report.hitTimeInterval);
- buf.append(")(Average hits per ");
- buf.append(intervalName);
- buf.append("|");
- buf.append(report.avgHitsPerHitTimeInterval);
- buf.append(")(Average sessions per ");
- buf.append(intervalName);
- buf.append("|");
- buf.append(report.avgUserSessionsPerHitTimeInterval);
- // Enlarge to handle extra lines
- Dimension dim = generalStatisticsTable.getSize();
- int sizePerLine = 24;
- int rows = generalStatisticsTable.getNumRows();
- if(rows != 0) {
- sizePerLine = 1 + (dim.height / rows);
- }
- dim.height += 2 * sizePerLine;
- generalStatisticsTable.setSize(dim);
- generalStatisticsTable.setNumRows(rows+2);
- }
- buf.append(")");
- generalStatisticsTable.setCellValues(buf.toString());
- }
-
- // Setup Top Domains table, as needed
- if(!report.optMostActiveDomains) {
- topDomainsLabel.setVisible(false);
- topDomainsTable.setVisible(false);
- } else {
- buf.setLength(0);
- int lim = report.sortedDomains.length > 10 ? 10 : report.sortedDomains.length;
- for(int idx = 0; idx < lim; idx++) {
- buf.append('(');
- buf.append(report.sortedDomains[idx].domain);
- buf.append('|');
- buf.append(report.sortedDomains[idx].hits);
- buf.append(')');
- }
- topDomainsTable.setCellValues(buf.toString());
- }
- }
-
- // -- Implement object to hand data to KLGroup's chart
-
- /*
- This class is used to hand data to the jclass chart, eliminating the
- need to write the data to a file for chart use.
- */
- class ChartDataFeeder implements Chartable {
- Report report;
- long timeTillFirstInterval; // millisecs till first full interval of time being analyzed
- long timeTillFirstDayInterval; // millisecs till first full day of time being analyzed
-
- /*
- Constructs a ChartDataFeeder for the given report.
- */
- public ChartDataFeeder(Report report) {
- this.report = report;
- }
-
- /*
- Returns a data item for the specified row and column.
- Row 0 specifies the "x-axis" values.
- Rows > 0 specify "y-axis" values.
- */
- public Object getDataItem(int row, int column) {
- if(row == 0) {
- long millisecs = timeTillFirstInterval + (column * report.hitTimeInterval);
- return new Double(millisecs/(double)WLAUtil.MILLISECS_PER_DAY);
- }
- return new Double(report.userSessionsVsTimeInterval[column]);
- }
-
- /*
- Returns a vector of row values.
- */
- public Vector getRow(int row) {
- int numCols = report.userSessionsVsTimeInterval.length;
- Vector rv = new Vector(numCols);
- for(int idx = 0; idx < numCols; idx++) {
- rv.addElement(getDataItem(row, idx));
- }
- return rv;
- }
- /*
- Returns how row/column data is organized.
- */
- public int getDataInterpretation() {
- return ARRAY;
- }
- /*
- Returns the number of rows.
- */
- public int getNumRows() {
- return 2;
- }
- public String[] getPointLabels() {
- return null;
- }
- public String getSeriesName(int row) {
- return null; //"Series Name"; //null;
- }
- public String getSeriesLabel(int row) {
- return null; //"Series Label"; //null;
- }
- public String getName() {
- return null; //"Data Name";
- }
- }
-
-
- // -- AUTOMATICALLY GENERATED/MAINTAINED CODE FRAMEWORK BELOW THIS LINE --
-
- /*
- Constructs a default ReportViewFrame object
- */
- public ReportViewFrame()
- {
- // This code is automatically generated by Visual Cafe when you add
- // components to the visual environment. It instantiates and initializes
- // the components. To modify the code, only use code syntax that matches
- // what Visual Cafe can generate, or Visual Cafe may be unable to back
- // parse your Java file into its visual environment.
- //{{INIT_CONTROLS
- setLayout(new GridLayout(1,1,0,0));
- setVisible(false);
- setSize(664,540);
- setBackground(java.awt.Color.lightGray);
- scrollingPanel1 = new symantec.itools.awt.ScrollingPanel();
- scrollingPanel1.setScrollLineIncrement(10);
- scrollingPanel1.setBounds(0,0,664,540);
- add(scrollingPanel1);
- panel1 = new java.awt.Panel();
- panel1.setLayout(null);
- panel1.setBounds(0,0,644,1120);
- scrollingPanel1.add(panel1);
- panel2 = new java.awt.Panel();
- GridBagLayout gridBagLayout;
- gridBagLayout = new GridBagLayout();
- panel2.setLayout(gridBagLayout);
- panel2.setBounds(0,0,640,220);
- panel1.add(panel2);
- imageViewer1 = new symantec.itools.multimedia.ImageViewer();
- try {
- imageViewer1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-inprogress.gif"));
- }
- catch (java.net.MalformedURLException error) { }
- catch(java.beans.PropertyVetoException e) { }
- imageViewer1.setBounds(362,5,276,198);
- GridBagConstraints gbc;
- gbc = new GridBagConstraints();
- gbc.gridx = 2;
- gbc.gridy = 0;
- gbc.gridheight = 3;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.insets = new Insets(5,48,17,2);
- ((GridBagLayout)panel2.getLayout()).setConstraints(imageViewer1, gbc);
- panel2.add(imageViewer1);
- webLogAnalysisLabel = new java.awt.Label("Web Log Analysis");
- webLogAnalysisLabel.setBounds(15,15,299,50);
- webLogAnalysisLabel.setFont(new Font("SansSerif", Font.PLAIN, 36));
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(15,15,0,0);
- ((GridBagLayout)panel2.getLayout()).setConstraints(webLogAnalysisLabel, gbc);
- panel2.add(webLogAnalysisLabel);
- setTitleLabel = new java.awt.Label("(untitled report)");
- setTitleLabel.setBounds(96,92,136,30);
- setTitleLabel.setFont(new Font("Dialog", Font.PLAIN, 18));
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 1;
- gbc.gridwidth = 2;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(27,15,0,0);
- ((GridBagLayout)panel2.getLayout()).setConstraints(setTitleLabel, gbc);
- panel2.add(setTitleLabel);
- generalUsageChart = new jclass.chart.JCChartComponent();
- generalUsageChart.setY1AxisGridIsShowing(true);
- generalUsageChart.setAxisBoundingBox(true);
- generalUsageChart.setBounds(0,235,640,320);
- panel1.add(generalUsageChart);
- generalStatisticsLabel = new java.awt.Label("General Statistics Table");
- generalStatisticsLabel.setBounds(15,578,300,24);
- generalStatisticsLabel.setFont(new Font("Dialog", Font.BOLD, 12));
- panel1.add(generalStatisticsLabel);
- generalStatisticsTable = new jclass.table.JCTableComponent();
- generalStatisticsTable.setAllowCellResize(jclass.table.JCTblEnum.RESIZE_NONE);
- generalStatisticsTable.setColumnLabelsList(jclass.util.JCUtilConverter.toStringList(""));
- generalStatisticsTable.setNumRows(8);
- generalStatisticsTable.setRowLabelsList(jclass.util.JCUtilConverter.toStringList(""));
- generalStatisticsTable.setCharWidthSeries("(all 25)");
- generalStatisticsTable.setColumnLabelOffset(4);
- generalStatisticsTable.setEditableSeries("(all all false)");
- generalStatisticsTable.setSelectedForeground(java.awt.Color.lightGray);
- generalStatisticsTable.setNumColumns(2);
- generalStatisticsTable.setBounds(15,606,625,182);
- generalStatisticsTable.setFont(new Font("Dialog", Font.PLAIN, 12));
- panel1.add(generalStatisticsTable);
- topDomainsLabel = new java.awt.Label("Top Domains Table");
- topDomainsLabel.setBounds(15,845,625,24);
- topDomainsLabel.setFont(new Font("Dialog", Font.BOLD, 12));
- panel1.add(topDomainsLabel);
- topDomainsTable = new jclass.table.JCTableComponent();
- topDomainsTable.setColumnLabelsList(jclass.util.JCUtilConverter.toStringList("Domain,Total Hits"));
- topDomainsTable.setRowLabelsList(jclass.util.JCUtilConverter.toStringList(""));
- topDomainsTable.setCharWidthSeries("(all 25)");
- topDomainsTable.setEditableSeries("(all all false)");
- topDomainsTable.setSelectedForeground(java.awt.Color.lightGray);
- topDomainsTable.setNumColumns(2);
- topDomainsTable.setBounds(15,873,625,240);
- panel1.add(topDomainsTable);
- setTitle("");
- //}}
-
- //{{INIT_MENUS
- //}}
-
- //{{REGISTER_LISTENERS
- SymWindow aSymWindow = new SymWindow();
- this.addWindowListener(aSymWindow);
- //}}
-
- // Use our custom layout manager
- LayoutManager lm = new ReportLayout(panel1, 10, 10);
- panel1.setLayout(lm);
- lm.addLayoutComponent(ReportLayout.PLACE_SAME, panel2);
- lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE, generalUsageChart);
- lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE, generalStatisticsLabel);
- lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE_BREAK, generalStatisticsTable);
- lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE, topDomainsLabel);
- lm.addLayoutComponent(ReportLayout.PLACE_NEW_LINE_BREAK, topDomainsTable);
-
- // Setup report
- setupReport();
-
- setLocation(50, 50);
- }
-
- /**
- * Constructs this Dialog with the given title.
- * This routine was automatically generated by Visual Cafe, and is not
- * actually used.
- */
- public ReportViewFrame(String title)
- {
- this();
- setTitle(title);
- }
-
- /**
- * Tells this component that it has been added to a container.
- * This is a standard Java AWT method which gets called by the AWT when
- * this component is added to a container.
- * Typically, it is used to create this component's peer. <br>
- * It has been OVERRIDDEN here to adjust the position of components as needed
- * for the container's insets. <br>
- * This method is automatically generated by Visual Cafe.
- */
- public void addNotify()
- {
- // Record the size of the window prior to calling parents addNotify.
- Dimension d = getSize();
-
- super.addNotify();
-
- if (fComponentsAdjusted)
- return;
-
- // Adjust components according to the insets
- Insets insets = getInsets();
- setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
- Component components[] = getComponents();
- for (int i = 0; i < components.length; i++)
- {
- Point p = components[i].getLocation();
- p.translate(insets.left, insets.top);
- components[i].setLocation(p);
- }
- fComponentsAdjusted = true;
- }
-
- // Used for addNotify check.
- boolean fComponentsAdjusted = false;
-
- //{{DECLARE_CONTROLS
- symantec.itools.awt.ScrollingPanel scrollingPanel1;
- java.awt.Panel panel1;
- java.awt.Panel panel2;
- symantec.itools.multimedia.ImageViewer imageViewer1;
- java.awt.Label webLogAnalysisLabel;
- java.awt.Label setTitleLabel;
- jclass.chart.JCChartComponent generalUsageChart;
- java.awt.Label generalStatisticsLabel;
- jclass.table.JCTableComponent generalStatisticsTable;
- java.awt.Label topDomainsLabel;
- jclass.table.JCTableComponent topDomainsTable;
- //}}
-
- //{{DECLARE_MENUS
- //}}
-
- /**
- * This is an event listener created by Visual Cafe to handle WindowEvents.
- */
- class SymWindow extends java.awt.event.WindowAdapter
- {
- public void windowClosing(java.awt.event.WindowEvent event)
- {
- Object object = event.getSource();
- if (object == ReportViewFrame.this)
- ReportViewFrame_WindowClosing(event);
- }
- }
-
- /**
- * Handles the WINDOW_CLOSING WindowEvent.
- * This method is automatically added when the Frame form was added to
- * this project.
- */
- void ReportViewFrame_WindowClosing(java.awt.event.WindowEvent event)
- {
- dispose(); // dispose of the Frame.
- }
- }
-