home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Sample.bin / AnalyzeDialog.java < prev    next >
Text File  |  1998-11-05  |  9KB  |  278 lines

  1. // Copyright (c) 1997, 1998 Symantec, Inc. All Rights Reserved.
  2.  
  3. import java.awt.*;
  4.  
  5. import symantec.itools.multimedia.ImageViewer;
  6. import symantec.itools.awt.WrappingLabel;
  7. import symantec.itools.awt.util.ProgressBar;
  8.  
  9. /**
  10.  * This dialog added to this project by dragging a Dialog form component into the 
  11.  * project.
  12.  * It was then customized with Cafe's visual tools, including the Interaction
  13.  * Wizard.
  14.  * Then it was manually customized a small amount to implement the 
  15.  * TrackProgress interface (that code is at the start of the class), and to
  16.  * start and stop the Analyzer thread.
  17.  * <p>
  18.  * When this dialog opens, it automatically starts the thread that reads and
  19.  * analyzes the appropriate log file. The analyzer thread ends when its done
  20.  * with the log or the user presses Cancel or closes the dialog.
  21.  */
  22. public class AnalyzeDialog extends Dialog implements TrackProgress {
  23.     // Custom fields
  24.     Analyzer analyzer;
  25.  
  26.     // -- INTERFACE IMPLEMENTATION: TrackProgress
  27.  
  28.     /**
  29.     A TrackProgress interface method.
  30.     This method is called to update the message and progressBar that
  31.     keeps the user informed of the thread's progress
  32.     */
  33.     public void step(String stepMsg, int progressPercent) {
  34.         stepText.setText(stepMsg);
  35.         try {
  36.             stepProgressBar.setValue(progressPercent);
  37.         } catch(java.beans.PropertyVetoException x) {
  38.         }
  39.     }
  40.     
  41.     /**
  42.     A TrackProgress interface method.
  43.     This method is called when the thread is done.
  44.     Often the dialog will switch a "Cancel" button to an "OK" button.
  45.     Before calling this method, the thread calls the step method with 
  46.     a "done 100%" status.
  47.     */
  48.     public void done() {
  49.         okCancelButton.setLabel("Done");
  50.     }
  51.  
  52.     /**
  53.     A TrackProgress interface method.
  54.     This method is called to display an "OK or Cancel" alert dialog.
  55.     It returns true if the alert was OK'd.
  56.     */
  57.     public boolean okCancelAlert(String msg) {
  58.         // Show alert
  59.         new AlertDialog((Frame)getParent(), msg);
  60.         // Return true if OKd
  61.         return WebLogAnalyzer.theWLA.alertOKd;
  62.     }
  63.     
  64.     /**
  65.     A TrackProgress interface method.
  66.     This method is called to display an Alert Dialog with only an OK button.
  67.     */
  68.     public void okAlert(String msg) {
  69.         new AlertDialog((Frame)getParent(), false, msg);
  70.     }
  71.  
  72.     // -- Standard dialog code
  73.     
  74.     /**
  75.      * Constructs this dialog.
  76.      * Initializes components the components.
  77.      * Registers component listeners.
  78.      * All of the code in this routine are automatically generated/maintained
  79.      * by Visual Cafe.
  80.      */
  81.     public AnalyzeDialog(Frame parent, boolean modal)
  82.     {
  83.         super(parent, modal);
  84.  
  85.         // This code is automatically generated by Visual Cafe when you add
  86.         // components to the visual environment. It instantiates and initializes
  87.         // the components. To modify the code, only use code syntax that matches
  88.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  89.         // parse your Java file into its visual environment.
  90.  
  91.         //{{INIT_CONTROLS
  92.         setLayout(null);
  93.         setBackground(java.awt.Color.lightGray);
  94.         setSize(434,305);
  95.         setVisible(false);
  96.         okCancelButton.setLabel("Cancel");
  97.         add(okCancelButton);
  98.         okCancelButton.setBounds(355,253,66,27);
  99.         try {
  100.             imageViewer1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-inprogress.gif"));
  101.         }
  102.         catch (java.net.MalformedURLException error) { }
  103.         catch(java.beans.PropertyVetoException e) { }
  104.         try {
  105.             imageViewer1.setStyle(symantec.itools.multimedia.ImageViewer.IMAGE_NORMAL);
  106.         }
  107.         catch(java.beans.PropertyVetoException e) { }
  108.         add(imageViewer1);
  109.         imageViewer1.setBounds(187,2,245,170);
  110.         titleLabel1.setText("Web Log Analysis");
  111.         add(titleLabel1);
  112.         titleLabel1.setFont(new Font("Dialog", Font.PLAIN, 18));
  113.         titleLabel1.setBounds(14,32,157,33);
  114.         titleLabel2.setText("In Progress...");
  115.         add(titleLabel2);
  116.         titleLabel2.setFont(new Font("Dialog", Font.PLAIN, 18));
  117.         titleLabel2.setBounds(14,59,157,33);
  118.         stepText.setText("Initializing");
  119.         add(stepText);
  120.         stepText.setBounds(14,166,162,21);
  121.         try {
  122.             stepProgressBar.setBevelStyle(symantec.itools.awt.util.ProgressBar.BEVEL_RAISED);
  123.         }
  124.         catch(java.beans.PropertyVetoException e) { }
  125.         add(stepProgressBar);
  126.         stepProgressBar.setBounds(14,211,396,28);
  127.         stepLabel.setText("Step:");
  128.         add(stepLabel);
  129.         stepLabel.setFont(new Font("Dialog", Font.BOLD, 12));
  130.         stepLabel.setBounds(14,141,162,21);
  131.         setTitle("Analyze Dialog");
  132.         //}}
  133.  
  134.         //{{REGISTER_LISTENERS
  135.         SymWindow aSymWindow = new SymWindow();
  136.         this.addWindowListener(aSymWindow);
  137.         SymAction lSymAction = new SymAction();
  138.         okCancelButton.addActionListener(lSymAction);
  139.         //}}
  140.         
  141.         // Center this dialog within its parent's bounds
  142.         WLAUtil.centerInParent(this);
  143.     }
  144.  
  145.     /**
  146.      * Constructs this Dialog with the given title.
  147.      * This routine was automatically generated by Visual Cafe, and is not
  148.      * actually used.
  149.      */
  150.     public AnalyzeDialog(Frame parent, String title, boolean modal) 
  151.     {
  152.         this(parent, modal);
  153.         setTitle(title);
  154.     }
  155.  
  156.     /**
  157.      * Tells this component that it has been added to a container. 
  158.      * This is a standard Java AWT method which gets called by the AWT when 
  159.      * this component is added to a container. 
  160.      * Typically, it is used to create this component's peer. <br>
  161.      * It has been OVERRIDDEN here to adjust the position of components as needed
  162.      * for the container's insets. <br>
  163.      * This method is automatically generated by Visual Cafe.
  164.      */
  165.     public void addNotify()
  166.     {
  167.           // Record the size of the window prior to calling parents addNotify.
  168.         Dimension d = getSize();
  169.  
  170.         super.addNotify();
  171.  
  172.         if (fComponentsAdjusted)
  173.             return;
  174.  
  175.         // Adjust components according to the insets
  176.         Insets insets = getInsets();
  177.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  178.         Component components[] = getComponents();
  179.         for (int i = 0; i < components.length; i++)
  180.         {
  181.             Point p = components[i].getLocation();
  182.             p.translate(insets.left, insets.top);
  183.             components[i].setLocation(p);
  184.         }
  185.         fComponentsAdjusted = true;
  186.     }
  187.  
  188.     //{{DECLARE_CONTROLS
  189.     java.awt.Button okCancelButton = new java.awt.Button();
  190.     symantec.itools.multimedia.ImageViewer imageViewer1 = new symantec.itools.multimedia.ImageViewer();
  191.     java.awt.Label titleLabel1 = new java.awt.Label();
  192.     java.awt.Label titleLabel2 = new java.awt.Label();
  193.     java.awt.Label stepText = new java.awt.Label();
  194.     symantec.itools.awt.util.ProgressBar stepProgressBar = new symantec.itools.awt.util.ProgressBar();
  195.     java.awt.Label stepLabel = new java.awt.Label();
  196.     //}}
  197.     
  198.     // Used for addNotify redundency check.
  199.     boolean fComponentsAdjusted = false;
  200.  
  201.     /** 
  202.      * This is an event listener created by Visual Cafe to handle WindowEvents.
  203.      */
  204.     class SymWindow extends java.awt.event.WindowAdapter
  205.     {
  206.         public void windowOpened(java.awt.event.WindowEvent event)
  207.         {
  208.             Object object = event.getSource();
  209.             if (object == AnalyzeDialog.this)
  210.                 AnalyzeDialog_WindowOpen(event);
  211.         }
  212.  
  213.         public void windowClosing(java.awt.event.WindowEvent event)
  214.         {
  215.             Object object = event.getSource();
  216.             if (object == AnalyzeDialog.this)
  217.                 AnalyzeDialog_WindowClosing(event);
  218.         }
  219.     }
  220.  
  221.     /**
  222.      * Handles the WINDOW_OPENING WindowEvent.
  223.      * It was created by the Interaction Wizard.
  224.      * The specified CONNECTION was replaced by code to start the analyzer.
  225.      */
  226.     void AnalyzeDialog_WindowOpen(java.awt.event.WindowEvent event)
  227.     {
  228.         // Create and run the analyzer
  229.         analyzer = new Analyzer(this);
  230.         analyzer.start();
  231.     }
  232.     
  233.     /**
  234.      * Handles the WINDOW_CLOSING WindowEvent.
  235.      * This method is automatically added when the Dialog form was added to
  236.      * this project.
  237.      */
  238.     void AnalyzeDialog_WindowClosing(java.awt.event.WindowEvent event)
  239.     {
  240.         // Stop the analyzer
  241.         Analyzer.cancel(analyzer);
  242.         // get rid of this dialog
  243.         dispose();
  244.     }
  245.     
  246.     /** 
  247.      * This is an event listener created by Visual Cafe to handle ActionEvents.
  248.      * It was created by the Interaction Wizard.
  249.      */
  250.     class SymAction implements java.awt.event.ActionListener
  251.     {
  252.         public void actionPerformed(java.awt.event.ActionEvent event)
  253.         {
  254.             Object object = event.getSource();
  255.             if (object == okCancelButton)
  256.                 okCancelButton_Clicked(event);
  257.         }
  258.     }
  259.  
  260.     /**
  261.      * This handles the ActionEvent generated by the okCancel button.
  262.      * It was created by the Interaction Wizard.
  263.      */
  264.     void okCancelButton_Clicked(java.awt.event.ActionEvent event)
  265.     {
  266.         // Stop the analyzer
  267.         Analyzer.cancel(analyzer);
  268.         // Get main program
  269.         WebLogAnalyzer wla = (WebLogAnalyzer)getParent();
  270.         wla.updateCurrentReportInList();
  271.         
  272.         //{{CONNECTION
  273.         // Clicked from cancelButton Hide the Dialog
  274.         setVisible(false);
  275.         //}}
  276.     }
  277. }
  278.