home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Sample.bin
/
WebLogAnalyzer.java
< prev
next >
Wrap
Text File
|
1998-11-05
|
26KB
|
779 lines
// Copyright (c) 1997, 1998 Symantec, Inc. All Rights Reserved.
/*
This simple extension of the java.awt.Frame class
contains all the elements necessary to act as the
main window of an application.
*/
import java.awt.*;
import java.awt.event.*;
import symantec.itools.awt.MultiList;
import symantec.itools.awt.BorderPanel;
import symantec.itools.awt.util.ToolBarPanel;
import symantec.itools.awt.ImageButton;
import symantec.itools.awt.util.ToolBarSpacer;
/**
* The program's main class.
* This class was automatically generated as part of Visual Cafe's
* "Basic Application" project.
* It was then filled out using Cafe's visual tools (form editor, property
* editor, and interaction wizard).
* After that, it was further customized manually.
*/
public class WebLogAnalyzer extends Frame
{
/*
Since Visual Cafe adds source code to the end of a class as needed,
all of the manually generated methods/fields are placed at the front.
This is NOT REQUIRED, but should make it easier to see the code framework
that Visual Cafe generates and maintains versus the manually added code.
*/
// the one-and-only instance of this app
static WebLogAnalyzer theWLA;
// Program "meat" (non-UI) data
Data data = null;
// Return value of AlertDialog
boolean alertOKd = false;
/**
* Displays the splash screen and loads program data while it's displayed.
* The splash screen (with its copyright notice) is guaranteed to be
* displayed for at least 3.5 seconds.
* The program data is loaded using the Java serialization feature.
* A serialized object of class Data gets read in from the ini file.
*/
void splashNLoad() {
// display the splash screen
SplashDialog splash = new SplashDialog(this,false);
splash.show();
// note time that is was displayed
long startMillisecs = System.currentTimeMillis();
// Load data
String msg = Data.loadDataInstance();
// Display msg, as needed
if(msg != null) {
new AlertDialog(this, false, "Error reading program initialization file (" + msg + "). Using defaults.");
}
// Get my data instance
data = Data.getDataInstance();
// Initialize report list component with program data
initializeReportList();
// Enable/disable components as needed
enableComponents();
// be sure splash shows for at least a few seconds
long millisecs = System.currentTimeMillis();
// get length of time to load data
millisecs -= startMillisecs;
// want to splash for about 3.5 secs, total
millisecs = 3500 - millisecs;
if(millisecs > 0) {
try {
Thread.sleep(millisecs);
} catch(java.lang.InterruptedException x) {
}
}
// take down splash screen
splash.setVisible(false);
}
/**
* The program data is saved using the Java serialization feature.
* A serialized object of class Data gets written into the ini file.
*/
void saveProgramData() {
String msg = Data.saveDataInstance();
// Display msg, as needed
if(msg != null) {
new AlertDialog(this, false, "Error writing program initialization file (" + msg + ").");
}
}
/**
* Enable/disable components as needed.
*/
void enableComponents() {
// Enable the delete button and menu, as needed
boolean bEnabled = isReportSelected();
analyzeLogButton.setEnabled(bEnabled);
miAnalyzeLog.setEnabled(bEnabled);
editReportButton.setEnabled(bEnabled);
miEditReport.setEnabled(bEnabled);
deleteReportButton.setEnabled(bEnabled);
miDeleteReport.setEnabled(bEnabled);
// Only allow viewing if the report has been run
bEnabled = bEnabled && data.getCurrentReport().hasBeenRun();
viewReportButton.setEnabled(bEnabled);
miViewReport.setEnabled(bEnabled);
}
// -- REPORT LIST ROUTINES
// Associates an object (Report) with each row in reportList
/**
* Fills the reportList component from the program data.
*/
void initializeReportList() {
int lim = data.reports.size();
for(int idx = 0; idx < lim; idx++) {
updateReportListRow(idx, (Report)data.reports.elementAt(idx));
}
if(data.currentReportIndex != -1) {
reportList.selectRow(data.currentReportIndex);
}
}
/**
* Returns true if a report is currently selected in the reportList.
*/
boolean isReportSelected() {
return data.isReportSelected();
}
/**
* Appends a new report to the reportList, selecting it as specified.
*/
void addReportToList(Report report, boolean selectAddedReport) {
int row = data.reports.size()-1;
updateReportListRow(row, report);
if(selectAddedReport) {
reportList.selectRow(row);
}
}
/**
* Updates the displayed information for the report currently selected
* in the reportList.
*/
void updateCurrentReportInList() {
int row = data.currentReportIndex;
Report report = data.getCurrentReport();
updateReportListRow(row, report);
}
/**
* Displays information on the given report in the specified row of the
* reportList.
*/
void updateReportListRow(int row, Report report) {
// update reportList cells
reportList.addTextCell(row, 0, report.title);
reportList.addTextCell(row, 1, report.getLogFileURL());
String str;
if(report.hasBeenRun()) {
str = WLAUtil.dateTime2String(report.analyzedDate);
} else {
str = "(never run)";
}
reportList.addTextCell(row, 2, str);
}
/**
* Deletes the currently selected row from the reportList, and deletes
* the report itself from the program's data.
*/
void deleteCurrentReport() {
int idx = reportList.getSelectedRow();
reportList.removeRow(idx);
data.disposeReport(idx);
}
/**
* This handles the ActionEvent generated by the "Delete Report" button or menu item.
* This routine was created using the interaction wizard to show the AlertDialog.
* Then it was manually changed to create the alert with the given text message,
* among other things.
* Then, since there is another routine with identical functionality, it
* was made into a method that is shared by both routines.
*/
void handleDeleteReport() {
// to do: code goes here.
if(!isReportSelected()) {
return;
}
//{{CONNECTION
// Create and show as modal
new AlertDialog(this, "Are you sure you want to delete this report?");
//}}
// Delete current row, if OK'd
if(alertOKd) {
// Delete current row
deleteCurrentReport();
}
}
// -- AUTOMATICALLY GENERATED/MAINTAINED CODE FRAMEWORK BELOW THIS LINE --
/**
* Constructs the WebLogAnalyzer object.
* Initializes components in this frame.
* Registers component listeners.
* Centers the window in the screen.
* All of the code in this routine except the first line and the last few
* lines (that center this window) are automatically generated/maintained
* by Visual Cafe.
*/
public WebLogAnalyzer()
{
theWLA = this;
// 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(null);
setBackground(java.awt.Color.lightGray);
setSize(600,400);
setVisible(false);
openFileURLDialog.setMode(FileDialog.LOAD);
openFileURLDialog.setTitle("Open");
//$$ openFileURLDialog.move(0,0);
try {
{
String[] tempString = new String[3];
tempString[0] = "Report Description";
tempString[1] = "URL Path";
tempString[2] = "Last Run";
reportList.setHeadings(tempString);
}
}
catch(java.beans.PropertyVetoException e) { }
add(reportList);
reportList.setBackground(java.awt.Color.white);
reportList.setFont(new Font("SansSerif", Font.PLAIN, 10));
reportList.setBounds(8,101,575,279);
try {
toolBarPanel1.setBevelStyle(symantec.itools.awt.util.ToolBarPanel.BEVEL_NONE);
}
catch(java.beans.PropertyVetoException e) { }
add(toolBarPanel1);
toolBarPanel1.setBounds(9,7,581,84);
try {
analyzeLogButton.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-analyze.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(analyzeLogButton);
analyzeLogButton.setBounds(0,0,70,70);
try {
viewReportButton.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-view.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(viewReportButton);
viewReportButton.setBounds(70,0,69,70);
try {
toolBarSpacer1.setSpace(32);
}
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(toolBarSpacer1);
toolBarSpacer1.setBounds(139,0,32,70);
try {
newReportButton.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-new.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(newReportButton);
newReportButton.setBounds(171,0,70,70);
try {
editReportButton.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-edit.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(editReportButton);
editReportButton.setBounds(241,0,70,70);
try {
deleteReportButton.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-delete.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(deleteReportButton);
deleteReportButton.setBounds(311,0,70,70);
try {
toolBarSpacer2.setSpace(114);
}
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(toolBarSpacer2);
toolBarSpacer2.setBounds(381,0,114,70);
try {
programOptionsButton.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-options.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
toolBarPanel1.add(programOptionsButton);
programOptionsButton.setBounds(495,0,70,70);
setTitle("Web Log Analyzer");
setResizable(false);
//}}
//{{INIT_MENUS
menuFile.setLabel("File");
menuFile.add(miNew);
miNew.setLabel("New Report...");
menuFile.add(miProgramOptions);
miProgramOptions.setLabel("Program Options...");
menuFile.addSeparator();
menuFile.add(miExit);
miExit.setLabel("Exit");
mainMenuBar.add(menuFile);
menuReport.setLabel("Report");
menuReport.add(miAnalyzeLog);
miAnalyzeLog.setLabel("Analyze Log");
menuReport.add(miViewReport);
miViewReport.setLabel("View Report");
menuReport.addSeparator();
menuReport.add(miNewReport);
miNewReport.setLabel("New Report...");
menuReport.add(miEditReport);
miEditReport.setLabel("Edit Report...");
menuReport.addSeparator();
menuReport.add(miDeleteReport);
miDeleteReport.setLabel("Delete Report...");
mainMenuBar.add(menuReport);
menuHelp.setLabel("Help");
menuHelp.add(miAbout);
miAbout.setLabel("About..");
mainMenuBar.add(menuHelp);
mainMenuBar.setHelpMenu(menuHelp);
//$$ mainMenuBar.move(5,374);
setMenuBar(mainMenuBar);
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
miAbout.addActionListener(lSymAction);
miExit.addActionListener(lSymAction);
miNew.addActionListener(lSymAction);
analyzeLogButton.addActionListener(lSymAction);
viewReportButton.addActionListener(lSymAction);
newReportButton.addActionListener(lSymAction);
editReportButton.addActionListener(lSymAction);
programOptionsButton.addActionListener(lSymAction);
miAnalyzeLog.addActionListener(lSymAction);
miViewReport.addActionListener(lSymAction);
miNewReport.addActionListener(lSymAction);
miEditReport.addActionListener(lSymAction);
miProgramOptions.addActionListener(lSymAction);
deleteReportButton.addActionListener(lSymAction);
miDeleteReport.addActionListener(lSymAction);
SymItem lSymItem = new SymItem();
reportList.addItemListener(lSymItem);
reportList.addActionListener(lSymAction);
//}}
/* Move to the center of the screen.
We do this here instead of in setVisible() so we're already in the correct
position when the SplashDialog is shown. That dialog uses the position
of this window to determine its location.
*/
Dimension screen = getToolkit().getScreenSize();
int x = (screen.width /2) - (getSize().width / 2);
int y = (screen.height / 2) - (getSize().height / 2);
setLocation(x,y);
}
/**
* Constructs a WebLogAnalyzer with the given title.
* This routine was automatically generated by Visual Cafe, and is not
* actually used.
*/
public WebLogAnalyzer(String title)
{
this();
setTitle(title);
}
/*
* Note: Removed the auto-generated show() method.
* Its extended functionality was not needed.
*/
/**
* This program's entry point.
* It creates the main WebLogAnalyzer object, shows the splash screen while
* loading program data, and then shows the WebLogAnalyzer.
*/
static public void main(String args[])
{
// create main program object
WebLogAnalyzer webLogAnalyzer = new WebLogAnalyzer();
// display the splash screen and load program data while it's displayed
webLogAnalyzer.splashNLoad();
// show the main window
webLogAnalyzer.show();
}
/**
* 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
java.awt.FileDialog openFileURLDialog = new java.awt.FileDialog(this);
symantec.itools.awt.MultiList reportList = new symantec.itools.awt.MultiList();
symantec.itools.awt.util.ToolBarPanel toolBarPanel1 = new symantec.itools.awt.util.ToolBarPanel();
symantec.itools.awt.ImageButton analyzeLogButton = new symantec.itools.awt.ImageButton();
symantec.itools.awt.ImageButton viewReportButton = new symantec.itools.awt.ImageButton();
symantec.itools.awt.util.ToolBarSpacer toolBarSpacer1 = new symantec.itools.awt.util.ToolBarSpacer();
symantec.itools.awt.ImageButton newReportButton = new symantec.itools.awt.ImageButton();
symantec.itools.awt.ImageButton editReportButton = new symantec.itools.awt.ImageButton();
symantec.itools.awt.ImageButton deleteReportButton = new symantec.itools.awt.ImageButton();
symantec.itools.awt.util.ToolBarSpacer toolBarSpacer2 = new symantec.itools.awt.util.ToolBarSpacer();
symantec.itools.awt.ImageButton programOptionsButton = new symantec.itools.awt.ImageButton();
//}}
//{{DECLARE_MENUS
java.awt.MenuBar mainMenuBar = new java.awt.MenuBar();
java.awt.Menu menuFile = new java.awt.Menu();
java.awt.MenuItem miNew = new java.awt.MenuItem();
java.awt.MenuItem miProgramOptions = new java.awt.MenuItem();
java.awt.MenuItem miExit = new java.awt.MenuItem();
java.awt.Menu menuReport = new java.awt.Menu();
java.awt.MenuItem miAnalyzeLog = new java.awt.MenuItem();
java.awt.MenuItem miViewReport = new java.awt.MenuItem();
java.awt.MenuItem miNewReport = new java.awt.MenuItem();
java.awt.MenuItem miEditReport = new java.awt.MenuItem();
java.awt.MenuItem miDeleteReport = new java.awt.MenuItem();
java.awt.Menu menuHelp = new java.awt.Menu();
java.awt.MenuItem miAbout = new java.awt.MenuItem();
//}}
/**
* 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 == WebLogAnalyzer.this)
WebLogAnalyzer_WindowClosing(event);
}
}
/**
* This handles WINDOW_CLOSING WindowEvents.
*/
void WebLogAnalyzer_WindowClosing(java.awt.event.WindowEvent event)
{
// Save the "ini" file data
saveProgramData();
// Hide the main window
dispose(); // free the system resources
System.exit(0); // close the application
}
/**
* This is an event listener created by Visual Cafe to handle ActionEvents.
* It was created by the Interaction Wizard.
*/
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == miAbout)
miAbout_Action(event);
else if (object == miExit)
miExit_Action(event);
else if (object == miNew)
miNew_Action(event);
else if (object == analyzeLogButton)
analyzeLogButton_actionPerformed(event);
else if (object == viewReportButton)
viewReportButton_actionPerformed(event);
else if (object == newReportButton)
newReportButton_actionPerformed(event);
else if (object == editReportButton)
editReportButton_actionPerformed(event);
else if (object == programOptionsButton)
programOptionsButton_actionPerformed(event);
else if (object == miAnalyzeLog)
miAnalyzeLog_Action(event);
else if (object == miViewReport)
miViewReport_Action(event);
else if (object == miNewReport)
miNewReport_Action(event);
else if (object == miEditReport)
miEditReport_Action(event);
else if (object == miProgramOptions)
miProgramOptions_Action(event);
else if (object == deleteReportButton)
deleteReportButton_actionPerformed(event);
else if (object == miDeleteReport)
miDeleteReport_Action(event);
else if (object == reportList)
reportList_actionPerformed(event);
}
}
/**
* This handles the ActionEvent generated by the "About.." menu item.
*/
void miAbout_Action(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Action from About Create and show as modal
(new AboutDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Exit" menu item.
*/
void miExit_Action(java.awt.event.ActionEvent event)
{
// post a WINDOW_CLOSING event
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((java.awt.Window)this, WindowEvent.WINDOW_CLOSING));
}
/**
* This handles the ActionEvent generated by the "New Report..." menu item.
*/
void miNew_Action(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new NewReportDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Analyze Log" button.
*/
void analyzeLogButton_actionPerformed(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new AnalyzeDialog(this, true)).show();
//}}
// Enable/disable buttons as needed
enableComponents();
}
/**
* This handles the ActionEvent generated by the "View Report" button.
*/
void viewReportButton_actionPerformed(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show the Frame
(new ReportViewFrame()).show();
//}}
}
/**
* This handles the ActionEvent generated by the "New Report" button.
*/
void newReportButton_actionPerformed(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new NewReportDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Edit" button.
*/
void editReportButton_actionPerformed(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new EditReportDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Options" button.
*/
void programOptionsButton_actionPerformed(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new OptionsDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Analyze Log" menu item.
*/
void miAnalyzeLog_Action(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new AnalyzeDialog(this, true)).show();
//}}
// Enable/disable buttons as needed
enableComponents();
}
/**
* This handles the ActionEvent generated by the "View Report" menu item.
*/
void miViewReport_Action(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show the Frame
(new ReportViewFrame()).show();
//}}
}
/**
* This handles the ActionEvent generated by the "New Report" menu item.
*/
void miNewReport_Action(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new NewReportDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Edit Report" menu item.
*/
void miEditReport_Action(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new EditReportDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Program Options" menu item.
*/
void miProgramOptions_Action(java.awt.event.ActionEvent event)
{
//{{CONNECTION
// Create and show as modal
(new OptionsDialog(this, true)).show();
//}}
}
/**
* This handles the ActionEvent generated by the "Delete Report" button.
* This routine was created using the interaction wizard to show the AlertDialog.
* Then it was manually changed to create the alert with the given text message,
* among other things.
* Then, since there is another routine with identical functionality, it
* was made into a method that is shared by both routines.
*/
void deleteReportButton_actionPerformed(java.awt.event.ActionEvent event)
{
handleDeleteReport();
}
/**
* This handles the ActionEvent generated by the "Delete Report" menu item.
* This routine was created using the interaction wizard to show the AlertDialog.
* Then it was manually changed to create the alert with the given text message,
* among other things.
* Then, since there is another routine with identical functionality, it
* was made into a method that is shared by both routines.
*/
void miDeleteReport_Action(java.awt.event.ActionEvent event)
{
handleDeleteReport();
}
/**
* This is an event listener created by Visual Cafe to handle ItemEvents.
*/
class SymItem implements java.awt.event.ItemListener
{
public void itemStateChanged(java.awt.event.ItemEvent event)
{
Object object = event.getSource();
if (object == reportList)
reportList_itemStateChanged(event);
}
}
/**
* Created with interaction wizard.
* The interaction details were unimportant, since the wizard was just used
* to create the method skeleton. The generated method code was removed and
* custom code to track the current report index added.
*/
void reportList_itemStateChanged(java.awt.event.ItemEvent event)
{
// to do: code goes here.
if(data != null) {
data.currentReportIndex = reportList.getSelectedRow();
}
enableComponents();
}
/**
* This handles the ActionEvent generated by the reportList component.
* This event is generated when the user double-clicks on a row.
* If the selected report has been run, shows the results.
*/
void reportList_actionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
// Only allow viewing if the report has been run
if(!data.getCurrentReport().hasBeenRun()) {
return;
}
//{{CONNECTION
// Create and show the Frame
(new ReportViewFrame()).show();
//}}
}
}