home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / DefaultSaveChangesDialog.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  3.9 KB  |  153 lines

  1. /*
  2.  * @(#DefaultSaveChangesDialog.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8. package symantec.itools.db.beans.binding;
  9.  
  10. import java.awt.*;
  11.  
  12. public class DefaultSaveChangesDialog extends Dialog implements SaveChangesDialog
  13. {
  14.     private int result = NO;
  15.     
  16.     DefaultSaveChangesDialog()
  17.     {
  18.         super(new Frame(), true);
  19.  
  20.         // This code is automatically generated by Visual Cafe when you add
  21.         // components to the visual environment. It instantiates and initializes
  22.         // the components. To modify the code, only use code syntax that matches
  23.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  24.         // parse your Java file into its visual environment.
  25.         //{{INIT_CONTROLS
  26.         setLayout(null);
  27.         setVisible(false);
  28.         setSize(337,135);
  29.         yesButton = new java.awt.Button();
  30.         yesButton.setLabel(" Yes ");
  31.         yesButton.setBounds(72,80,79,22);
  32.         yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
  33.         add(yesButton);
  34.         noButton = new java.awt.Button();
  35.         noButton.setLabel("  No  ");
  36.         noButton.setBounds(185,80,79,22);
  37.         noButton.setFont(new Font("Dialog", Font.BOLD, 12));
  38.         add(noButton);
  39.         label1 = new java.awt.Label("Save changes?",Label.CENTER);
  40.         label1.setBounds(78,33,180,23);
  41.         add(label1);
  42.         setTitle("DefaultSaveChangesDialog");
  43.         //}}
  44.  
  45.         //{{REGISTER_LISTENERS
  46.         SymWindow aSymWindow = new SymWindow();
  47.         this.addWindowListener(aSymWindow);
  48.         SymAction lSymAction = new SymAction();
  49.         noButton.addActionListener(lSymAction);
  50.         yesButton.addActionListener(lSymAction);
  51.         //}}
  52.     }
  53.  
  54.     public void addNotify()
  55.     {
  56.         // Record the size of the window prior to calling parents addNotify.
  57.         Dimension d = getSize();
  58.         
  59.         super.addNotify();
  60.  
  61.         if (fComponentsAdjusted)
  62.             return;
  63.  
  64.         // Adjust components according to the insets
  65.         setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
  66.         Component components[] = getComponents();
  67.         for (int i = 0; i < components.length; i++)
  68.         {
  69.             Point p = components[i].getLocation();
  70.             p.translate(insets().left, insets().top);
  71.             components[i].setLocation(p);
  72.         }
  73.         fComponentsAdjusted = true;
  74.     }
  75.  
  76.     public DefaultSaveChangesDialog(String title)
  77.     {
  78.         this();
  79.         setTitle(title);
  80.     }
  81.  
  82.     /**
  83.      * Shows or hides the component depending on the boolean flag b.
  84.      * @param b  if true, show the component; otherwise, hide the component.
  85.      * @see java.awt.Component#isVisible
  86.      */
  87.     public void setVisible(boolean b)
  88.     {
  89.         if(b)
  90.         {
  91.             Rectangle bounds = getParent().getBounds();
  92.             Rectangle abounds = getBounds();
  93.     
  94.             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
  95.                  bounds.y + (bounds.height - abounds.height)/2);
  96.         }
  97.         super.setVisible(b);
  98.     }
  99.  
  100.     // Used for addNotify check.
  101.     boolean fComponentsAdjusted = false;
  102.  
  103.     //{{DECLARE_CONTROLS
  104.     java.awt.Button yesButton;
  105.     java.awt.Button noButton;
  106.     java.awt.Label label1;
  107.     //}}
  108.  
  109.     class SymWindow extends java.awt.event.WindowAdapter
  110.     {
  111.         public void windowClosing(java.awt.event.WindowEvent event)
  112.         {
  113.             Object object = event.getSource();
  114.             if (object == DefaultSaveChangesDialog.this)
  115.                 DefaultSaveChangesDialog_WindowClosing(event);
  116.         }
  117.     }
  118.  
  119.     void DefaultSaveChangesDialog_WindowClosing(java.awt.event.WindowEvent event)
  120.     {
  121.            dispose();
  122.     }
  123.  
  124.     class SymAction implements java.awt.event.ActionListener
  125.     {
  126.         public void actionPerformed(java.awt.event.ActionEvent event)
  127.         {
  128.             Object object = event.getSource();
  129.             if (object == noButton)
  130.                 noButton_Clicked(event);
  131.             else if (object == yesButton)
  132.                 yesButton_Clicked(event);
  133.         }
  134.     }
  135.  
  136.     void yesButton_Clicked(java.awt.event.ActionEvent event)
  137.     {
  138.         result = YES;
  139.         hide();
  140.     }
  141.  
  142.     void noButton_Clicked(java.awt.event.ActionEvent event)
  143.     {
  144.         result = NO;
  145.         hide();
  146.     }
  147.  
  148.     public int run()
  149.     {
  150.         show();
  151.         return result;
  152.     }
  153. }