home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Sample.bin / AlertDialog.java < prev    next >
Text File  |  1998-11-05  |  8KB  |  254 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.  
  8.  
  9. /**
  10.  * This dialog was added to this project by dragging a Dialog form component 
  11.  * into the project.
  12.  * It was then customized with Cafe's visual tools, including the Interaction
  13.  * Wizard.
  14.  * Then it was manually customized to 
  15.  * 1) allow construction with just one (OK) button or two (OK and Cancel)
  16.  * 2) note the results in the main/only WebLogAnalyzer instance
  17.  */
  18. public class AlertDialog extends Dialog {
  19.  
  20.     /*
  21.     This constructor creates and shows the typical OK/Cancel alert dialog 
  22.     with the specified message.
  23.     */
  24.     public AlertDialog(Frame parent, String text) 
  25.     {
  26.         this(parent, true, text);
  27.     }
  28.  
  29.     /*
  30.     This constructor creates and shows an alert with or without a Cancel 
  31.     button.
  32.     */
  33.     public AlertDialog(Frame parent, boolean bCancelButton, String text) 
  34.     {
  35.         this(parent, true);
  36.         try {
  37.             setTextLabel.setText(text);
  38.         }
  39.         catch(java.beans.PropertyVetoException e) { }
  40.         // Hide cancel button, as needed
  41.         if(!bCancelButton) {
  42.             // move the OK button to the lower right where the Cancel button was
  43.             Rectangle r = cancelButton.getBounds();
  44.             cancelButton.setVisible(false);
  45.             panel1.remove(cancelButton);
  46.             Rectangle pr = panel1.getBounds();
  47.             panel1.setBounds(pr.x + r.width, pr.y, pr.width - r.width, pr.height);
  48.         }
  49.         show();
  50.     }
  51.  
  52. //  --  AUTOMATICALLY GENERATED/MAINTAINED CODE FRAMEWORK BELOW THIS LINE  --
  53.  
  54.     /**
  55.      * Constructs this dialog.
  56.      * Initializes components the components.
  57.      * Registers component listeners.
  58.      * All of the code in this routine are automatically generated/maintained
  59.      * by Visual Cafe.
  60.      */
  61.     public AlertDialog(Frame parent, boolean modal)
  62.     {
  63.         super(parent, modal);
  64.  
  65.         // This code is automatically generated by Visual Cafe when you add
  66.         // components to the visual environment. It instantiates and initializes
  67.         // the components. To modify the code, only use code syntax that matches
  68.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  69.         // parse your Java file into its visual environment.
  70.  
  71.         //{{INIT_CONTROLS
  72.         setLayout(null);
  73.         setBackground(java.awt.Color.lightGray);
  74.         setSize(416,114);
  75.         setVisible(false);
  76.         try {
  77.             imageViewer1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/wl-bang.jpg"));
  78.         }
  79.         catch (java.net.MalformedURLException error) { }
  80.         catch(java.beans.PropertyVetoException e) { }
  81.         try {
  82.             imageViewer1.setStyle(symantec.itools.multimedia.ImageViewer.IMAGE_NORMAL);
  83.         }
  84.         catch(java.beans.PropertyVetoException e) { }
  85.         add(imageViewer1);
  86.         imageViewer1.setBounds(7,9,64,94);
  87.         add(setTextLabel);
  88.         setTextLabel.setBounds(86,12,307,63);
  89.         panel1.setLayout(new GridLayout(1,1,8,0));
  90.         add(panel1);
  91.         panel1.setBounds(271,80,121,23);
  92.         okButton.setLabel("OK");
  93.         panel1.add(okButton);
  94.         okButton.setBounds(0,0,56,23);
  95.         cancelButton.setLabel("Cancel");
  96.         panel1.add(cancelButton);
  97.         cancelButton.setBounds(64,0,56,23);
  98.         setTitle("Alert");
  99.         //}}
  100.  
  101.         //{{REGISTER_LISTENERS
  102.         SymWindow aSymWindow = new SymWindow();
  103.         this.addWindowListener(aSymWindow);
  104.         SymAction lSymAction = new SymAction();
  105.         okButton.addActionListener(lSymAction);
  106.         cancelButton.addActionListener(lSymAction);
  107.         //}}
  108.         
  109.         // Center this dialog within its parent's bounds
  110.         WLAUtil.centerInParent(this);
  111.     }
  112.  
  113.     /**
  114.      * Constructs this Dialog with the given title.
  115.      * This routine was automatically generated by Visual Cafe, and is not
  116.      * actually used.
  117.      */
  118.     public AlertDialog(Frame parent, String title, boolean modal) 
  119.     {
  120.         this(parent, modal);
  121.         setTitle(title);
  122.     }
  123.  
  124.     /**
  125.      * Tells this component that it has been added to a container. 
  126.      * This is a standard Java AWT method which gets called by the AWT when 
  127.      * this component is added to a container. 
  128.      * Typically, it is used to create this component's peer. <br>
  129.      * It has been OVERRIDDEN here to adjust the position of components as needed
  130.      * for the container's insets. <br>
  131.      * This method is automatically generated by Visual Cafe.
  132.      */
  133.     public void addNotify()
  134.     {
  135.           // Record the size of the window prior to calling parents addNotify.
  136.         Dimension d = getSize();
  137.  
  138.         super.addNotify();
  139.  
  140.         if (fComponentsAdjusted)
  141.             return;
  142.  
  143.         // Adjust components according to the insets
  144.         Insets insets = getInsets();
  145.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  146.         Component components[] = getComponents();
  147.         for (int i = 0; i < components.length; i++)
  148.         {
  149.             Point p = components[i].getLocation();
  150.             p.translate(insets.left, insets.top);
  151.             components[i].setLocation(p);
  152.         }
  153.         fComponentsAdjusted = true;
  154.     }
  155.  
  156.     // Used for addNotify check.
  157.     boolean fComponentsAdjusted = false;
  158.  
  159.     //{{DECLARE_CONTROLS
  160.     symantec.itools.multimedia.ImageViewer imageViewer1 = new symantec.itools.multimedia.ImageViewer();
  161.     symantec.itools.awt.WrappingLabel setTextLabel = new symantec.itools.awt.WrappingLabel();
  162.     java.awt.Panel panel1 = new java.awt.Panel();
  163.     java.awt.Button okButton = new java.awt.Button();
  164.     java.awt.Button cancelButton = new java.awt.Button();
  165.     //}}
  166.  
  167.     /** 
  168.      * This is an event listener created by Visual Cafe to handle WindowEvents.
  169.      */
  170.     class SymWindow extends java.awt.event.WindowAdapter
  171.     {
  172.         public void windowOpened(java.awt.event.WindowEvent event)
  173.         {
  174.             Object object = event.getSource();
  175.             if (object == AlertDialog.this)
  176.                 AlertDialog_WindowOpen(event);
  177.         }
  178.  
  179.         public void windowClosing(java.awt.event.WindowEvent event)
  180.         {
  181.             Object object = event.getSource();
  182.             if (object == AlertDialog.this)
  183.                 AlertDialog_WindowClosing(event);
  184.         }
  185.     }
  186.  
  187.     /**
  188.      * Handles the WINDOW_CLOSING WindowEvent.
  189.      * This method is automatically added when the Dialog form was added to
  190.      * this project.
  191.      */
  192.     void AlertDialog_WindowClosing(java.awt.event.WindowEvent event)
  193.     {
  194.         dispose();
  195.     }
  196.  
  197.     /** 
  198.      * This is an event listener created by Visual Cafe to handle ActionEvents.
  199.      * It was created by the Interaction Wizard.
  200.      */
  201.     class SymAction implements java.awt.event.ActionListener
  202.     {
  203.         public void actionPerformed(java.awt.event.ActionEvent event)
  204.         {
  205.             Object object = event.getSource();
  206.             if (object == okButton)
  207.                 okButton_Clicked(event);
  208.             else if (object == cancelButton)
  209.                 cancelButton_Action(event);
  210.         }
  211.     }
  212.  
  213.     /**
  214.      * This handles the ActionEvents generated by the OK button.
  215.      * Created using the Interaction Wizard, then the modified to
  216.      * note "OK" in the main/only WebLogAnalyzer instance.
  217.      */
  218.     void okButton_Clicked(java.awt.event.ActionEvent event)
  219.     {
  220.         ((WebLogAnalyzer)getParent()).alertOKd = true;
  221.         //{{CONNECTION
  222.         // Clicked from okButton Hide the Dialog
  223.         dispose();
  224.         //}}
  225.     }
  226.  
  227.     /*
  228.     Created by pulling down the "Events/Methods" choice in the source window
  229.     and selecting WindowOpen. Then modified to
  230.     init "Cancel" in the main/only WebLogAnalyzer instance.
  231.     */
  232.     void AlertDialog_WindowOpen(java.awt.event.WindowEvent event)
  233.     {
  234.         // to do: code goes here.
  235.         
  236.         // Do window-opening init
  237.         ((WebLogAnalyzer)getParent()).alertOKd = false;
  238.     }
  239.  
  240.     /**
  241.      * This handles the ActionEvents generated by the Cancel button.
  242.      * Created using the Interaction Wizard. 
  243.      */
  244.     void cancelButton_Action(java.awt.event.ActionEvent event)
  245.     {
  246.         // to do: code goes here.
  247.              
  248.         //{{CONNECTION
  249.         // Hide the Dialog
  250.         setVisible(false);
  251.         //}}
  252.     }
  253. }
  254.