home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / VCSAMPL.BIN / ReplaceConfirmDialog.java < prev    next >
Text File  |  1997-08-31  |  5KB  |  167 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class ReplaceConfirmDialog extends Dialog {
  8.     FindReplaceEngine FRE;
  9.     
  10.     public ReplaceConfirmDialog(Frame parent, boolean modal)
  11.     {
  12.         super(parent, modal);
  13.  
  14.         // This code is automatically generated by Visual Cafe when you add
  15.         // components to the visual environment. It instantiates and initializes
  16.         // the components. To modify the code, only use code syntax that matches
  17.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  18.         // parse your Java file into its visual environment.
  19.         //{{INIT_CONTROLS
  20.         setLayout(null);
  21.         setVisible(false);
  22.         setSize(insets().left + insets().right + 261,insets().top + insets().bottom + 71);
  23.         setBackground(new Color(12632256));
  24.         confirmlabel = new java.awt.Label("Replace this occurrence?");
  25.         confirmlabel.setBounds(insets().left + 48,insets().top + 12,166,21);
  26.         add(confirmlabel);
  27.         btn_yes = new java.awt.Button();
  28.         btn_yes.setActionCommand("button");
  29.         btn_yes.setLabel("Yes");
  30.         btn_yes.setBounds(insets().left + 10,insets().top + 39,45,22);
  31.         add(btn_yes);
  32.         btn_no = new java.awt.Button();
  33.         btn_no.setActionCommand("button");
  34.         btn_no.setLabel("No");
  35.         btn_no.setBounds(insets().left + 68,insets().top + 39,45,22);
  36.         add(btn_no);
  37.         btn_cancel = new java.awt.Button();
  38.         btn_cancel.setActionCommand("button");
  39.         btn_cancel.setLabel("Cancel");
  40.         btn_cancel.setBounds(insets().left + 126,insets().top + 39,45,22);
  41.         add(btn_cancel);
  42.         cb_confirm = new java.awt.Checkbox("Confirm");
  43.         cb_confirm.setBounds(insets().left + 184,insets().top + 39,69,18);
  44.         add(cb_confirm);
  45.         setTitle("Dialog2");
  46.         //}}
  47.         
  48.         
  49.         //{{REGISTER_LISTENERS
  50.         SymWindow aSymWindow = new SymWindow();
  51.         addWindowListener(aSymWindow);
  52.         SymAction lSymAction  = new SymAction();
  53.         btn_yes.addActionListener(lSymAction);
  54.         btn_no.addActionListener(lSymAction);
  55.         btn_cancel.addActionListener(lSymAction);
  56.         //}}
  57.  
  58.     }
  59.     
  60.     public void addNotify()
  61.     {
  62.           // Record the size of the window prior to calling parents addNotify.
  63.         Dimension d = getSize();
  64.  
  65.         super.addNotify();
  66.  
  67.         if (fComponentsAdjusted)
  68.             return;
  69.  
  70.         // Adjust components according to the insets
  71.         setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
  72.         Component components[] = getComponents();
  73.         for (int i = 0; i < components.length; i++)
  74.         {
  75.             Point p = components[i].getLocation();
  76.             p.translate(insets().left, insets().top);
  77.             components[i].setLocation(p);
  78.         }
  79.         fComponentsAdjusted = true;
  80.     }
  81.  
  82.     // Used for addNotify check.
  83.     boolean fComponentsAdjusted = false;
  84.  
  85.  
  86.     public ReplaceConfirmDialog(Frame parent, String title, boolean modal, FindReplace replace)
  87.     {
  88.         this(parent, modal);
  89.         setTitle(title);
  90.         m_replace = replace;
  91.         FRE = new FindReplaceEngine(m_replace);
  92.     }
  93.  
  94.     public synchronized void show()
  95.     {
  96.         Rectangle bounds = getParent().bounds();
  97.         Rectangle abounds = bounds();
  98.  
  99.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  100.              bounds.y + (bounds.height - abounds.height)/2);
  101.  
  102.         super.show();
  103.            FRE.FindIt();  //Initiate first find
  104.     }
  105.  
  106.     //{{DECLARE_CONTROLS
  107.     java.awt.Label confirmlabel;
  108.     java.awt.Button btn_yes;
  109.     java.awt.Button btn_no;
  110.     java.awt.Button btn_cancel;
  111.     java.awt.Checkbox cb_confirm;
  112.     //}}
  113.     FindReplace m_replace;
  114.     
  115.     class SymWindow extends java.awt.event.WindowAdapter
  116.     {
  117.         public void windowClosing(java.awt.event.WindowEvent event)
  118.         {
  119.             Object object = event.getSource();
  120.             if (object == ReplaceConfirmDialog.this)
  121.                 Dialog1_WindowClosing(event);
  122.         }
  123.     }
  124.     
  125.     void Dialog1_WindowClosing(java.awt.event.WindowEvent event)
  126.     {
  127.         hide();
  128.     }
  129.  
  130.  
  131.  
  132.     class SymAction implements java.awt.event.ActionListener
  133.     {
  134.         public void actionPerformed(java.awt.event.ActionEvent event)
  135.         {
  136.             Object object = event.getSource();
  137.             if (object == btn_yes)
  138.                 btnYes_Action(event);
  139.             else if (object == btn_no)
  140.                 btnNo_Action(event);
  141.             else if (object == btn_cancel)
  142.                 btnCancel_Action(event);
  143.         }
  144.     }
  145.  
  146.     void btnYes_Action(java.awt.event.ActionEvent event)
  147.     {
  148.         if(m_replace.isFoundIt()) {
  149.             m_replace.setIndex(FRE.ReplaceIt());
  150.             if(cb_confirm.getState()) {
  151.                 FRE.ReplaceAll();
  152.             }
  153.         }    
  154.         FRE.FindIt();
  155.     }
  156.  
  157.     void btnNo_Action(java.awt.event.ActionEvent event)
  158.     {
  159.         FRE.FindIt();
  160.     }
  161.  
  162.     void btnCancel_Action(java.awt.event.ActionEvent event)
  163.     {
  164.         hide();
  165.     }
  166. }
  167.