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

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class ReplaceDialog extends Dialog {
  8.     Frame theJavaPadFrame;
  9.     
  10.     public ReplaceDialog(Frame parent, boolean modal)
  11.     {
  12.         super(parent, modal);
  13.         theJavaPadFrame = parent;
  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 + 278,insets().top + insets().bottom + 107);
  23.         setBackground(new Color(12632256));
  24.         label1 = new java.awt.Label("Find");
  25.         label1.setBounds(insets().left + 7,insets().top + 12,28,24);
  26.         add(label1);
  27.         m_findText = new java.awt.TextField();
  28.         m_findText.setBounds(insets().left + 60,insets().top + 14,124,25);
  29.         add(m_findText);
  30.         m_replaceText = new java.awt.TextField();
  31.         m_replaceText.setBounds(insets().left + 60,insets().top + 46,124,25);
  32.         add(m_replaceText);
  33.         label2 = new java.awt.Label("Replace");
  34.         label2.setBounds(insets().left + 3,insets().top + 47,48,21);
  35.         add(label2);
  36.         m_caseSencb = new java.awt.Checkbox("Case Sensitive");
  37.         m_caseSencb.setBounds(insets().left + 1,insets().top + 77,113,24);
  38.         add(m_caseSencb);
  39.         m_replacebtn = new java.awt.Button();
  40.         m_replacebtn.setActionCommand("button");
  41.         m_replacebtn.setLabel("Replace");
  42.         m_replacebtn.setBounds(insets().left + 196,insets().top + 5,66,21);
  43.         add(m_replacebtn);
  44.         m_repAllbtn = new java.awt.Button();
  45.         m_repAllbtn.setActionCommand("button");
  46.         m_repAllbtn.setLabel("Replace All");
  47.         m_repAllbtn.setBounds(insets().left + 196,insets().top + 42,66,21);
  48.         add(m_repAllbtn);
  49.         m_cancelbtn = new java.awt.Button();
  50.         m_cancelbtn.setActionCommand("button");
  51.         m_cancelbtn.setLabel("Cancel");
  52.         m_cancelbtn.setBounds(insets().left + 196,insets().top + 79,66,21);
  53.         add(m_cancelbtn);
  54.         setTitle("Dialog2");
  55.         //}}
  56.  
  57.         //{{REGISTER_LISTENERS
  58.         SymWindow aSymWindow = new SymWindow();
  59.         addWindowListener(aSymWindow);
  60.         SymAction lSymAction = new SymAction();
  61.         m_replacebtn.addActionListener(lSymAction);
  62.         m_repAllbtn.addActionListener(lSymAction);
  63.         m_cancelbtn.addActionListener(lSymAction);
  64.         //}}
  65.     }
  66.     
  67.     public void addNotify()
  68.     {
  69.           // Record the size of the window prior to calling parents addNotify.
  70.         Dimension d = getSize();
  71.  
  72.         super.addNotify();
  73.  
  74.         if (fComponentsAdjusted)
  75.             return;
  76.  
  77.         // Adjust components according to the insets
  78.         setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
  79.         Component components[] = getComponents();
  80.         for (int i = 0; i < components.length; i++)
  81.         {
  82.             Point p = components[i].getLocation();
  83.             p.translate(insets().left, insets().top);
  84.             components[i].setLocation(p);
  85.         }
  86.         fComponentsAdjusted = true;
  87.     }
  88.  
  89.     // Used for addNotify check.
  90.     boolean fComponentsAdjusted = false;
  91.  
  92.  
  93.     public ReplaceDialog(Frame parent, String title, boolean modal, FindReplace fr)
  94.     {
  95.         this(parent, modal);
  96.         setTitle(title);
  97.         m_replace = fr;
  98.         m_findText.setText(m_replace.getFind());
  99.         m_replaceText.setText(m_replace.getReplace());
  100.         m_caseSencb.setState(m_replace.isCase());
  101.         
  102.     }
  103.  
  104.     public synchronized void show()
  105.     {
  106.         Rectangle bounds = getParent().bounds();
  107.         Rectangle abounds = bounds();
  108.  
  109.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  110.              bounds.y + (bounds.height - abounds.height)/2);
  111.  
  112.         super.show();
  113.     }
  114.  
  115.     //{{DECLARE_CONTROLS
  116.     java.awt.Label label1;
  117.     java.awt.TextField m_findText;
  118.     java.awt.TextField m_replaceText;
  119.     java.awt.Label label2;
  120.     java.awt.Checkbox m_caseSencb;
  121.     java.awt.Button m_replacebtn;
  122.     java.awt.Button m_repAllbtn;
  123.     java.awt.Button m_cancelbtn;
  124.     //}}
  125.     FindReplace m_replace;
  126.  
  127.     class SymWindow extends java.awt.event.WindowAdapter
  128.     {
  129.         public void windowClosing(java.awt.event.WindowEvent event)
  130.         {
  131.             Object object = event.getSource();
  132.             if (object == ReplaceDialog.this)
  133.                 Dialog1_WindowClosing(event);
  134.         }
  135.     }
  136.     
  137.     void Dialog1_WindowClosing(java.awt.event.WindowEvent event)
  138.     {
  139.         hide();
  140.     }
  141.  
  142.     class SymAction implements java.awt.event.ActionListener
  143.     {
  144.         public void actionPerformed(java.awt.event.ActionEvent event)
  145.         {
  146.             Object object = event.getSource();
  147.             if (object == m_replacebtn)
  148.                 mReplacebtn_Action(event);
  149.             else if (object == m_repAllbtn)
  150.                 mRepAllbtn_Action(event);
  151.             else if (object == m_cancelbtn)
  152.                 mCancelbtn_Action(event);
  153.         }
  154.     }
  155.  
  156.     void mReplacebtn_Action(java.awt.event.ActionEvent event)
  157.     {
  158.         m_replace.setReplace(m_replaceText.getText().trim());
  159.         m_replace.setFind(m_findText.getText().trim());
  160.         m_replace.setCase(m_caseSencb.getState());
  161.         m_replace.setReplaceAll(false);
  162.         m_replace.setReplaceIt(false);
  163.         m_replace.setIndex(m_replace.getBody().getSelectionStart());
  164.         hide();
  165.         try{Thread.sleep(250);}catch(InterruptedException ie){}
  166.         (new ReplaceConfirmDialog(theJavaPadFrame, "Replace Confirm", true, m_replace)).show();
  167.         
  168.     }
  169.  
  170.     void mRepAllbtn_Action(java.awt.event.ActionEvent event)
  171.     {
  172.         FindReplaceEngine fre;
  173.         fre = new FindReplaceEngine(m_replace);
  174.         m_replace.setReplace(m_replaceText.getText());
  175.         m_replace.setFind(m_findText.getText());
  176.         m_replace.setReplaceAll(true);
  177.         m_replace.setReplaceIt(true);
  178.         m_replace.setCase(m_caseSencb.getState());
  179.         hide();
  180.         fre.ReplaceAll();
  181.     }
  182.  
  183.     void mCancelbtn_Action(java.awt.event.ActionEvent event)
  184.     {
  185.         hide();
  186.     }
  187. }
  188.