home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-11-05 | 24.2 KB | 645 lines |
- // Copyright (c) 1997, 1998 Symantec, Inc. All Rights Reserved.
-
- /*
- A basic extension of the java.awt.Dialog class
- */
-
- 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.WizardController;
- import symantec.itools.awt.SimpleWizardController;
- import symantec.itools.awt.WizardInterface;
-
- /**
- * 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) enable/disable/set the report start and end dates as needed,
- * 2) cleanup user-entered URLs,
- * 3) validate user-entered data, and
- * 4) save the results.
- */
- public class NewReportDialog extends Dialog
- {
- /*
- This class extends the SimpleWizardController in order to provide
- validation of user-entered data.
- */
- class MyWizardValidator extends SimpleWizardController {
-
- public MyWizardValidator(WizardInterface wiz) {
- super(wiz);
- }
-
- /*
- Override the SimpleWizardController's validatePage method to
- implement the data validation.
- */
- public boolean validatePage(Component comp,
- Component target,
- int action) {
- // First do std validation and fail if needed
- if(!super.validatePage(comp, target, action)) {
- return false;
- }
-
- // Now do my validation, if not "Next" don't do checks
- if(action != WizardController.NEXT) {
- return true;
- }
-
- // Handle according to page leaving
- if(comp == panel1) {
- if(!validatePage1()) {
- return false;
- }
- } else if(comp == panel2) {
- if(!validatePage2()) {
- return false;
- }
- }
- // Passed validation check OK
- 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 NewReportDialog(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(521,354);
- 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("New Report");
- }
- catch(java.beans.PropertyVetoException e) { }
- imagePanel1.add(label3D1);
- label3D1.setBackground(java.awt.Color.lightGray);
- label3D1.setBounds(11,8,111,24);
- try {
- wizard1.setHelpButtonVisible(false);
- }
- catch(java.beans.PropertyVetoException e) { }
- add(wizard1);
- wizard1.setBounds(8,57,506,284);
- panel1.setLayout(null);
- wizard1.add(panel1);
- panel1.setBounds(0,0,506,241);
- 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);
- wizard1.add(panel2);
- panel2.setBounds(0,0,506,241);
- panel2.setVisible(false);
- panel2.add(logfileURLText);
- logfileURLText.setBounds(8,44,358,24);
- logfileURLLabel.setText("Log File URL");
- panel2.add(logfileURLLabel);
- logfileURLLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
- logfileURLLabel.setBounds(8,8,175,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);
- homePageFileText.setText("index.html");
- panel2.add(homePageFileText);
- homePageFileText.setBounds(8,191,358,24);
- homePageFileBrowseButton.setLabel("Browse...");
- panel2.add(homePageFileBrowseButton);
- homePageFileBrowseButton.setBounds(381,191,62,24);
- panel3.setLayout(null);
- wizard1.add(panel3);
- panel3.setBounds(0,0,506,241);
- 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,99);
- usageChartCheckbox.setState(true);
- usageChartCheckbox.setLabel("Usage chart");
- panel4.add(usageChartCheckbox);
- usageChartCheckbox.setBounds(0,0,456,33);
- generalStatisticsCheckbox.setState(true);
- generalStatisticsCheckbox.setLabel("General statistics");
- panel4.add(generalStatisticsCheckbox);
- generalStatisticsCheckbox.setBounds(0,33,456,33);
- mostActiveDomainsCheckbox.setState(true);
- mostActiveDomainsCheckbox.setLabel("Most active domains");
- panel4.add(mostActiveDomainsCheckbox);
- mostActiveDomainsCheckbox.setBounds(0,66,456,33);
- setTitle("New Report Wizard");
- //}}
-
- //{{REGISTER_LISTENERS
- SymWindow aSymWindow = new SymWindow();
- this.addWindowListener(aSymWindow);
- SymItem lSymItem = new SymItem();
- timeframeChoice.addItemListener(lSymItem);
- SymAction lSymAction = new SymAction();
- wizard1.addActionListener(lSymAction);
- logfileURLBrowseButton.addActionListener(lSymAction);
- homePageFileBrowseButton.addActionListener(lSymAction);
- SymFocus aSymFocus = new SymFocus();
- logfileURLText.addFocusListener(aSymFocus);
- //}}
-
- // Use my WizardController to implement validation
- wizard1.setWizardController(new MyWizardValidator(wizard1));
- // 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 NewReportDialog(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.Wizard wizard1 = new symantec.itools.awt.Wizard();
- 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.TextField logfileURLText = new java.awt.TextField();
- java.awt.Label logfileURLLabel = new java.awt.Label();
- 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();
- //}}
-
- /**
- * 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 == NewReportDialog.this)
- NewReportDialog_WindowClosing(event);
- }
- }
-
- /**
- * Handles the WINDOW_CLOSING WindowEvent.
- * This method is automatically added when the Dialog form was added to
- * this project.
- */
- void NewReportDialog_WindowClosing(java.awt.event.WindowEvent event)
- {
- dispose();
- }
-
- /**
- * 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);
- }
- }
-
- /*
- This method enables/disables/sets the report start and end dates as
- needed. When the timeframeChoice component indicates a specific
- timeframe, the start and end date components need to be initialized
- and enabled. Otherwise, they should be disabled, and show the
- appropriate values for the timeframeChoice selected.
-
- How this method was created:
-
- 1) Use the Interaction Manager to:
- a) Drag connection from timeframeChoice to startDateText. Specify
- interaction for "timeframeChoice" should start with an ItemEvent.
- b) (The item to interact with is already set correctly to
- "startDateText").
- c) Select "Set editability on condition..." for "what to happen".
- d) Press Next.
- e) On the next page, select "A boolean condition or an expression".
- f) Type in "timeframeChoice.getSelectedIndex() ==
- Report.TIMEFRAME_SPECIFIC".
- g) Click "Finish".
-
- 2) Now, because we know we're going to use the expression we entered a lot,
- we decide to save its value in a local var so we don't have to keep
- recalculating it (not to mention re-entering it).
- At the start of the created routine ("timeframeChoice_ItemStateChanged")
- type in "boolean bSpecificTimeframe = " then cut the expression
- out of the "startDateText.setEditable(..." below and append
- it (with an ending semicolon) to the declaration.
- 3) Now enter "bSpecificTimeframe" where you just cutout the expression.
- 4) Using the Interaction Manager, drag a connection from timeframeChoice
- to endDateText and set its editability on condition to be the
- boolean expression "bSpecificTimeframe".
- 5) Do similar things to ENABLE both "startDateLabel" and "endDateLabel".
- 6) Now we would like to fill out the start/endDataText fields with the
- appropriate values when the timeframeChoice changes. Whenever it changes
- to "specific" we should restore and enable the fields with the
- user-entered values.
- a) We need a couple strings to save the user-entered values. Since they
- need to be remembered after this routine is left, we can't make'em
- local. So we place them at class level, even though they are only
- used by this method.
- b) Then we add the code to save/restore start/end date as needed.
- */
- 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);
- //}}
- }
-
- /**
- * 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 == wizard1)
- wizard1_actionPerformed(event);
- else if (object == logfileURLBrowseButton)
- logfileURLBrowseButton_Action(event);
- else if (object == homePageFileBrowseButton)
- homePageFileBrowseButton_Action(event);
- }
- }
-
- /**
- * This handles the ActionEvents generated by the Wizard component.
- * These event occur at key points in the process of using a wizard.
- * Created using Interaction Wizard, then the "Finish" handling code
- * added before the dialog was hidden.
- */
- void wizard1_actionPerformed(java.awt.event.ActionEvent event)
- {
- // to do: code goes here.
- String cmd = event.getActionCommand();
- // If user done with the wizard OK (otherwise cancelled)
- if(cmd.equals("Finish")) {
- // CREATE AND SETUP THE NEW REPORT
- // Get main program
- WebLogAnalyzer wla = (WebLogAnalyzer)getParent();
- // Create a new Report record and add it to the program data....
- Report report = wla.data.newReport();
- // 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();
- // add report to main list of reports
- wla.addReportToList(report, true);
- // done
- }
-
- //{{CONNECTION
- // Hide the Dialog
- setVisible(false);
- //}}
- }
-
- /*
- Routine created with interaction wiz. Any Action on any component.
- Then CONNECTION code gutted (couldn't open dlg in parent frame)
- and good code entered.
- */
- void logfileURLBrowseButton_Action(java.awt.event.ActionEvent event)
- {
- String urlStr = WLAUtil.browseForURL("*.log");
- if(urlStr != null) {
- logfileURLText.setText(urlStr);
- }
- }
-
- /**
- * This handles the ActionEvent generated by the home page browse button.
- * This routine was created using the interaction wizard (any action on
- * any component), then the code was replaced.
- */
- 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 FocusEvents.
- * It was created by the Interaction Wizard.
- */
- 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);
- }
- }
-
- /*
- This handles FOCUS_LOST FocusEvents generated when the logfileURLText
- TextField component loses the keyboard focus.
- Created using Interaction Wizard:
- 1) Select logfileURLText component in project window
- 2) Right-click and select "Add Interaction..." from popup menu
- 3) Start interaction when FocusLost
- 4) Interact with logfileURLText component
- 5) "Set the text for the TextField..."
- 6) Press the Next button
- 7) Select: "A String constant or expression" and clear "add quotes"
- 8) Paste into field: WLAUtil.cleanupURLName(logfileURLText.getText())
- */
- 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()));
- //}}
- }
- }
-
-