home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Sample.bin
/
EditReportDialog.java
< prev
next >
Wrap
Text File
|
1998-11-05
|
23KB
|
639 lines
// Copyright (c) 1997, 1998 Symantec, Inc. All Rights Reserved.
import java.awt.*;
import java.util.Date;
import symantec.itools.awt.ImagePanel;
import symantec.itools.awt.Label3D;
import symantec.itools.awt.Wizard;
import symantec.itools.awt.TabPanel;
/**
* This dialog was added to this project by dragging a Dialog 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) initialize component values from report data
* 2) enable/disable/set the report start and end dates as needed,
* 3) cleanup user-entered URLs,
* 4) validate user-entered data, and
* 5) save the results.
*/
public class EditReportDialog extends Dialog
{
/*
Sets the initial component values from the report data.
*/
void initializeComponentsFromData() {
// Get main program
WebLogAnalyzer wla = (WebLogAnalyzer)getParent();
// Create a new Report record and add it to the program data....
Report report = wla.data.getCurrentReport(); // should always work
// Values specified in the New Report wizard
reportTitleText.setText(report.title);
timeframeChoice.select(report.timeframe); // TIMEFRAME_
if(report.timeframe == Report.TIMEFRAME_SPECIFIC) {
startDateText.setText(WLAUtil.dateTime2String(report.dateStart));
endDateText.setText(WLAUtil.dateTime2String(report.dateEnd));
} else {
startDateText.setText(WLAUtil.timeframeChoice2DateString(report.timeframe, true));
endDateText.setText(WLAUtil.timeframeChoice2DateString(report.timeframe, false));
}
//
userEnteredStartDate = startDateText.getText();
userEnteredEndDate = endDateText.getText();
//
logfileURLText.setText(report.getLogFileURL());
logfileFormatChoice.select(report.getLogFileFormat()); // FORMAT_
homePageFileText.setText(report.homePageFile);
usageChartCheckbox.setState(report.optUsageChart);
generalStatisticsCheckbox.setState(report.optGeneralStatistics);
mostActiveDomainsCheckbox.setState(report.optMostActiveDomains);
}
/*
Validates the user-entered data in this dialog when OK pressed.
*/
boolean validateAllPages() {
if(!validatePage1()) {
try {
tabPanel1.setCurrentPanelNdx(0);
} catch(java.beans.PropertyVetoException x) {
}
return false;
}
if(!validatePage2()) {
try {
tabPanel1.setCurrentPanelNdx(1);
} catch(java.beans.PropertyVetoException x) {
}
return false;
}
return true;
}
// - START of validate code that's identical for new and edit dialogs
/*
This method is the same for both new report and edit report dialogs.
This is because they display/edit the same data, and the field names were
carefully given the same names in both dialogs to simplify coding.
*/
boolean validatePage1() {
// Only validate start/end date if specific user-supplied dates
int timeframe = timeframeChoice.getSelectedIndex(); // TIMEFRAME_
if(timeframe == Report.TIMEFRAME_SPECIFIC) {
if(!WLAUtil.validateDateField(this, startDateText)) {
return false;
}
if(!WLAUtil.validateDateField(this, endDateText)) {
return false;
}
}
return true;
}
/*
This method is the same for both new report and edit report dialogs.
This is because they display/edit the same data, and the field names were
carefully given the same names in both dialogs to simplify coding.
*/
boolean validatePage2() {
// Log file URL must be specified
String logfileURL = logfileURLText.getText();
if(logfileURL.trim().length() == 0) {
logfileURLText.requestFocus();
logfileURLText.selectAll();
// Alert user
new AlertDialog((Frame)getParent(), false, "A log file URL must be supplied.");
return false;
}
return true;
}
// - END of validate code that's identical for new and edit dialogs
// -- AUTOMATICALLY GENERATED/MAINTAINED CODE FRAMEWORK BELOW THIS LINE --
/**
* Constructs this dialog.
* Initializes components the components.
* Registers component listeners.
* All of the code in this routine except the last two lines are
* automatically generated/maintained by Visual Cafe.
*/
public EditReportDialog(Frame parent, boolean modal)
{
super(parent, modal);
// 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(529,407);
setVisible(false);
try {
imagePanel1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-wizardb.jpg"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
imagePanel1.setLayout(null);
add(imagePanel1);
imagePanel1.setBackground(new java.awt.Color(64,128,128));
imagePanel1.setBounds(8,7,506,40);
try {
label3D1.setBevelStyle(symantec.itools.awt.Label3D.BEVEL_LOWERED);
}
catch(java.beans.PropertyVetoException e) { }
try {
label3D1.setText("Edit Report");
}
catch(java.beans.PropertyVetoException e) { }
imagePanel1.add(label3D1);
label3D1.setBackground(java.awt.Color.lightGray);
label3D1.setBounds(11,8,111,24);
try {
{
String[] tempString = new String[3];
tempString[0] = "General";
tempString[1] = "URLs";
tempString[2] = "Report Options";
tabPanel1.setPanelLabels(tempString);
}
}
catch(java.beans.PropertyVetoException e) { }
add(tabPanel1);
tabPanel1.setBounds(1,54,523,312);
panel1.setLayout(null);
tabPanel1.add(panel1);
panel1.setBounds(12,33,499,268);
panel1.setVisible(false);
reportTitleLabel.setText("Report Title, Description");
panel1.add(reportTitleLabel);
reportTitleLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
reportTitleLabel.setBounds(8,8,175,24);
panel1.add(reportTitleText);
reportTitleText.setBounds(5,35,487,22);
timeframeLabel.setText("Select Date Range for Report");
panel1.add(timeframeLabel);
timeframeLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
timeframeLabel.setBounds(7,84,175,24);
timeframeChoice.addItem("All dates in the log");
timeframeChoice.addItem("Today");
timeframeChoice.addItem("Yesterday");
timeframeChoice.addItem("Last two days");
timeframeChoice.addItem("Last seven days");
timeframeChoice.addItem("Last 14 days");
timeframeChoice.addItem("Last 30 days");
timeframeChoice.addItem("Last 60 days");
timeframeChoice.addItem("Last 90 days");
timeframeChoice.addItem("Specific Date Range");
try {
timeframeChoice.select(0);
}
catch (IllegalArgumentException e) { }
panel1.add(timeframeChoice);
timeframeChoice.setBounds(198,84,287,26);
startDateLabel.setText("Start Date");
startDateLabel.setAlignment(java.awt.Label.RIGHT);
startDateLabel.setEnabled(false);
panel1.add(startDateLabel);
startDateLabel.setBounds(199,131,78,20);
endDateLabel.setText("End Date");
endDateLabel.setAlignment(java.awt.Label.RIGHT);
endDateLabel.setEnabled(false);
panel1.add(endDateLabel);
endDateLabel.setBounds(199,156,78,20);
startDateText.setEditable(false);
panel1.add(startDateText);
startDateText.setBounds(293,130,150,21);
endDateText.setEditable(false);
panel1.add(endDateText);
endDateText.setBounds(293,155,150,21);
panel2.setLayout(null);
tabPanel1.add(panel2);
panel2.setBounds(12,33,499,268);
panel2.setVisible(false);
logfileURLLabel.setText("Log File URL");
panel2.add(logfileURLLabel);
logfileURLLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
logfileURLLabel.setBounds(8,8,175,24);
panel2.add(logfileURLText);
logfileURLText.setBounds(8,44,358,24);
logfileURLBrowseButton.setLabel("Browse...");
panel2.add(logfileURLBrowseButton);
logfileURLBrowseButton.setBounds(381,44,62,24);
logfileFormatLabel.setText("Log File Format");
panel2.add(logfileFormatLabel);
logfileFormatLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
logfileFormatLabel.setBounds(8,85,175,24);
logfileFormatChoice.addItem("Detect Log Format Automatically");
logfileFormatChoice.addItem("NCSA - common log format");
logfileFormatChoice.addItem("NCSA - combined/extended log format");
logfileFormatChoice.addItem("MPIS log format");
try {
logfileFormatChoice.select(0);
}
catch (IllegalArgumentException e) { }
logfileFormatChoice.setBackground(java.awt.Color.white);
panel2.add(logfileFormatChoice);
logfileFormatChoice.setBounds(8,111,266,29);
homePageFileLabel.setText("Home Page File");
panel2.add(homePageFileLabel);
homePageFileLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
homePageFileLabel.setBounds(8,155,175,24);
panel2.add(homePageFileText);
homePageFileText.setBounds(8,191,358,24);
homePageFileBrowseButton.setLabel("Browse...");
panel2.add(homePageFileBrowseButton);
homePageFileBrowseButton.setBounds(381,191,62,24);
panel3.setLayout(null);
tabPanel1.add(panel3);
panel3.setBounds(12,33,499,268);
reportOptionsLabel.setText("Report Options");
panel3.add(reportOptionsLabel);
reportOptionsLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
reportOptionsLabel.setBounds(8,8,175,24);
panel4.setLayout(new GridLayout(3,1,0,0));
panel3.add(panel4);
panel4.setBounds(12,40,456,96);
usageChartCheckbox.setLabel("Usage chart");
panel4.add(usageChartCheckbox);
usageChartCheckbox.setBounds(0,0,456,32);
generalStatisticsCheckbox.setLabel("General statistics");
panel4.add(generalStatisticsCheckbox);
generalStatisticsCheckbox.setBounds(0,32,456,32);
mostActiveDomainsCheckbox.setLabel("Most active domains");
panel4.add(mostActiveDomainsCheckbox);
mostActiveDomainsCheckbox.setBounds(0,64,456,32);
try {
tabPanel1.setCurrentPanelNdx(2);
}
catch(java.beans.PropertyVetoException e) { }
panel6.setLayout(new GridLayout(1,1,8,0));
add(panel6);
panel6.setBounds(392,368,121,25);
okButton.setLabel("OK");
panel6.add(okButton);
okButton.setFont(new Font("Dialog", Font.BOLD, 12));
okButton.setBounds(0,0,121,25);
cancelButton.setLabel("Cancel");
panel6.add(cancelButton);
cancelButton.setBounds(64,0,56,25);
setTitle("Edit Report");
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
okButton.addActionListener(lSymAction);
cancelButton.addActionListener(lSymAction);
logfileURLBrowseButton.addActionListener(lSymAction);
homePageFileBrowseButton.addActionListener(lSymAction);
SymItem lSymItem = new SymItem();
timeframeChoice.addItemListener(lSymItem);
SymFocus aSymFocus = new SymFocus();
logfileURLText.addFocusListener(aSymFocus);
//}}
// Initialize the component values
initializeComponentsFromData();
// Simulate an ItemEvent for the timeframeChoice component to
// initialize display
timeframeChoice_ItemStateChanged(null);
// Center this dialog within its parent's bounds
WLAUtil.centerInParent(this);
}
/**
* 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;
/**
* Constructs this Dialog with the given title.
* This routine was automatically generated by Visual Cafe, and is not
* actually used.
*/
public EditReportDialog(Frame parent, String title, boolean modal)
{
this(parent, modal);
setTitle(title);
}
//{{DECLARE_CONTROLS
symantec.itools.awt.ImagePanel imagePanel1 = new symantec.itools.awt.ImagePanel();
symantec.itools.awt.Label3D label3D1 = new symantec.itools.awt.Label3D();
symantec.itools.awt.TabPanel tabPanel1 = new symantec.itools.awt.TabPanel();
java.awt.Panel panel1 = new java.awt.Panel();
java.awt.Label reportTitleLabel = new java.awt.Label();
java.awt.TextField reportTitleText = new java.awt.TextField();
java.awt.Label timeframeLabel = new java.awt.Label();
java.awt.Choice timeframeChoice = new java.awt.Choice();
java.awt.Label startDateLabel = new java.awt.Label();
java.awt.Label endDateLabel = new java.awt.Label();
java.awt.TextField startDateText = new java.awt.TextField();
java.awt.TextField endDateText = new java.awt.TextField();
java.awt.Panel panel2 = new java.awt.Panel();
java.awt.Label logfileURLLabel = new java.awt.Label();
java.awt.TextField logfileURLText = new java.awt.TextField();
java.awt.Button logfileURLBrowseButton = new java.awt.Button();
java.awt.Label logfileFormatLabel = new java.awt.Label();
java.awt.Choice logfileFormatChoice = new java.awt.Choice();
java.awt.Label homePageFileLabel = new java.awt.Label();
java.awt.TextField homePageFileText = new java.awt.TextField();
java.awt.Button homePageFileBrowseButton = new java.awt.Button();
java.awt.Panel panel3 = new java.awt.Panel();
java.awt.Label reportOptionsLabel = new java.awt.Label();
java.awt.Panel panel4 = new java.awt.Panel();
java.awt.Checkbox usageChartCheckbox = new java.awt.Checkbox();
java.awt.Checkbox generalStatisticsCheckbox = new java.awt.Checkbox();
java.awt.Checkbox mostActiveDomainsCheckbox = new java.awt.Checkbox();
java.awt.Panel panel6 = new java.awt.Panel();
java.awt.Button okButton = new java.awt.Button();
java.awt.Button cancelButton = new java.awt.Button();
//}}
/**
* 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 == EditReportDialog.this)
EditReportDialog_WindowClosing(event);
}
}
/**
* Handles the WINDOW_CLOSING WindowEvent.
* This method is automatically added when the Dialog form was added to
* this project.
*/
void EditReportDialog_WindowClosing(java.awt.event.WindowEvent event)
{
dispose();
}
/**
* This is an event listener created by Visual Cafe to handle ActionEvents.
* It was created by the Interaction Wizard.
* The last two "else if"s were simply copied and pasted from the
* NewReportDialog.
*/
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == okButton)
okButton_Action(event);
else if (object == cancelButton)
cancelButton_Action(event);
// Just copied and pasted the next 4 lines
else if (object == logfileURLBrowseButton)
logfileURLBrowseButton_Action(event);
else if (object == homePageFileBrowseButton)
homePageFileBrowseButton_Action(event);
}
}
/**
* This handles the ActionEvents generated by the OK button.
* Created using the Interaction Wizard, then the modified to validate and
* save changes to the report.
*/
void okButton_Action(java.awt.event.ActionEvent event)
{
// to do: code goes here.
// VALIDATE DATA
if(!validateAllPages()) {
return;
}
// SAVE THE EDITS TO THE NEW REPORT
// Get main program
WebLogAnalyzer wla = (WebLogAnalyzer)getParent();
// Access the current report
Report report = wla.data.getCurrentReport(); // should always work
// Values specified in the New Report wizard
report.title = reportTitleText.getText();
report.timeframe = timeframeChoice.getSelectedIndex(); // TIMEFRAME_
try {
report.dateStart = WLAUtil.string2DateTime(startDateText.getText()); // valid if dateRange == TIMEFRAME_SPECIFIC
} catch(java.text.ParseException x) {
// Can't parse the given date (because its "all")
report.dateStart = new Date(0);
}
try {
report.dateEnd = WLAUtil.string2DateTime(endDateText.getText()); // valid if dateRange == TIMEFRAME_SPECIFIC
} catch(java.text.ParseException x) {
// Can't parse the given date (because its "all")
report.dateEnd = new Date(Long.MAX_VALUE);
}
report.setLogFileURL(logfileURLText.getText());
report.setLogFileFormat(logfileFormatChoice.getSelectedIndex()); // FORMAT_
report.homePageFile = homePageFileText.getText();
report.optUsageChart = usageChartCheckbox.getState();
report.optGeneralStatistics = generalStatisticsCheckbox.getState();
report.optMostActiveDomains = mostActiveDomainsCheckbox.getState();
// update the report in the main list of reports
wla.updateCurrentReportInList();
//{{CONNECTION
// Hide the Dialog
setVisible(false);
//}}
}
/**
* This handles the ActionEvents generated by the Cancel button.
* Created using the Interaction Wizard.
*/
void cancelButton_Action(java.awt.event.ActionEvent event)
{
// to do: code goes here.
// Ignore report edits - just close the dialog
//{{CONNECTION
// Hide the Dialog
setVisible(false);
//}}
}
/*
* Simply copied and pasted from the NewReportDialog.
*/
void logfileURLBrowseButton_Action(java.awt.event.ActionEvent event)
{
String urlStr = WLAUtil.browseForURL("*.log");
if(urlStr != null) {
logfileURLText.setText(urlStr);
}
}
/*
* Simply copied and pasted from the NewReportDialog.
*/
void homePageFileBrowseButton_Action(java.awt.event.ActionEvent event)
{
// Get main program
WebLogAnalyzer wla = (WebLogAnalyzer)getParent();
// set the default suffix
wla.openFileURLDialog.setFile("*.html");
// Show the OpenFileDialog
wla.openFileURLDialog.show();
// get the results
String urlStr = wla.openFileURLDialog.getFile();
if(urlStr != null) {
homePageFileText.setText(urlStr);
}
}
/**
* 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 == timeframeChoice)
timeframeChoice_ItemStateChanged(event);
}
}
/*
Created this method by first creating the first interaction it
supports using the Interaction Wizard, then just copied and pasted the
whole method (and fields) from NewReportDialog. Code is identical.
*/
String userEnteredStartDate = WLAUtil.dateTime2String(new Date());
String userEnteredEndDate = WLAUtil.dateTime2String(new Date());
void timeframeChoice_ItemStateChanged(java.awt.event.ItemEvent event)
{
// to do: code goes here.
boolean bSpecificTimeframe = timeframeChoice.getSelectedIndex() == Report.TIMEFRAME_SPECIFIC;
// save/restore user entered start/end date, as needed
if(bSpecificTimeframe) {
// restore, as needed
if(userEnteredStartDate != null) {
startDateText.setText(userEnteredStartDate);
userEnteredStartDate = null;
endDateText.setText(userEnteredEndDate);
userEnteredEndDate = null;
}
} else {
// not bSpecificTime. Save as needed
if(userEnteredStartDate == null) {
userEnteredStartDate = startDateText.getText();
userEnteredEndDate = endDateText.getText();
}
// Now place the chosen timeframe in the text fields
int choice = timeframeChoice.getSelectedIndex();
startDateText.setText(WLAUtil.timeframeChoice2DateString(choice, true));
endDateText.setText(WLAUtil.timeframeChoice2DateString(choice, false));
}
//{{CONNECTION
// Set editablity on condition...
startDateText.setEditable(bSpecificTimeframe);
//}}
//{{CONNECTION
// Enable the TextField on condition...
startDateText.setEnabled(bSpecificTimeframe);
//}}
//{{CONNECTION
// Set editablity on condition...
endDateText.setEditable(bSpecificTimeframe);
//}}
//{{CONNECTION
// Enable the TextField on condition...
endDateText.setEnabled(bSpecificTimeframe);
//}}
//{{CONNECTION
// Enable the Label on condition...
startDateLabel.setEnabled(bSpecificTimeframe);
//}}
//{{CONNECTION
// Enable the Label on condition...
endDateLabel.setEnabled(bSpecificTimeframe);
//}}
}
/*
Just copied and pasted this and all the _LostFocus() methods
from NewReportDialog. Also copied and pasted the 3 lines that
instantiate and use this class in the main class constructor.
*/
class SymFocus extends java.awt.event.FocusAdapter
{
public void focusLost(java.awt.event.FocusEvent event)
{
Object object = event.getSource();
if (object == logfileURLText)
logfileURLText_LostFocus(event);
}
}
/*
Just copied and pasted this method from NewReportDialog.
*/
void logfileURLText_LostFocus(java.awt.event.FocusEvent event)
{
// to do: code goes here.
//{{CONNECTION
// Set the text for TextField...
logfileURLText.setText(WLAUtil.cleanupURLName(logfileURLText.getText()));
//}}
}
}