home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 February / VPR9802A.ISO / APP_DEMO / VC / SAMPLES.BIN / FindDialog.java < prev    next >
Text File  |  1997-10-27  |  5KB  |  161 lines

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