home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-08-31 | 4.6 KB | 161 lines |
- /*
- A basic extension of the java.awt.Dialog class
- */
-
- import java.awt.*;
-
- public class FindDialog extends Dialog {
-
- public FindDialog(Frame parent, boolean modal)
- {
- super(parent, modal);
-
- // This code is automatically generated by Visual Cafe when you add
- // components to the visual environment. It instantiates and initializes
- // the components. To modify the code, only use code syntax that matches
- // what Visual Cafe can generate, or Visual Cafe may be unable to back
- // parse your Java file into its visual environment.
- //{{INIT_CONTROLS
- setLayout(null);
- setVisible(false);
- setSize(insets().left + insets().right + 294,insets().top + insets().bottom + 86);
- setBackground(new Color(12632256));
- m_findlabel = new java.awt.Label("Find What");
- m_findlabel.setBounds(insets().left + 5,insets().top + 6,80,16);
- add(m_findlabel);
- m_findText = new java.awt.TextField();
- m_findText.setBounds(insets().left + 5,insets().top + 30,190,20);
- add(m_findText);
- m_findButton = new java.awt.Button();
- m_findButton.setLabel("Find");
- m_findButton.setBounds(insets().left + 209,insets().top + 6,70,20);
- add(m_findButton);
- m_cancelButton = new java.awt.Button();
- m_cancelButton.setLabel("Cancel");
- m_cancelButton.setBounds(insets().left + 209,insets().top + 30,70,20);
- m_cancelButton.setFont(new Font("Dialog", Font.PLAIN, 12));
- add(m_cancelButton);
- m_statuslabel = new java.awt.Label("");
- m_statuslabel.setVisible(false);
- m_statuslabel.setBounds(insets().left + 161,insets().top + 54,120,24);
- add(m_statuslabel);
- m_matchCase = new java.awt.Checkbox("Match case");
- m_matchCase.setBounds(insets().left + 5,insets().top + 54,84,20);
- m_matchCase.setBackground(new Color(12632256));
- add(m_matchCase);
- setTitle("Dialog2");
- //}}
-
- //{{REGISTER_LISTENERS
- SymWindow aSymWindow = new SymWindow();
- addWindowListener(aSymWindow);
- SymAction lSymAction = new SymAction();
- m_findButton.addActionListener(lSymAction);
- m_cancelButton.addActionListener(lSymAction);
- //}}
- }
-
- public void addNotify()
- {
- // Record the size of the window prior to calling parents addNotify.
- Dimension d = getSize();
-
- super.addNotify();
-
- if (fComponentsAdjusted)
- return;
-
- // Adjust components according to the insets
- setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
- Component components[] = getComponents();
- for (int i = 0; i < components.length; i++)
- {
- Point p = components[i].getLocation();
- p.translate(insets().left, insets().top);
- components[i].setLocation(p);
- }
- fComponentsAdjusted = true;
- }
-
- // Used for addNotify check.
- boolean fComponentsAdjusted = false;
-
-
- public FindDialog(Frame parent, String title, boolean modal, FindReplace fr)
- {
- this(parent, modal);
- setTitle(title);
- m_find = fr;
- m_findText.setText(m_find.getFind());
- m_matchCase.setState(m_find.isCase());
- }
-
- public synchronized void show()
- {
- Rectangle bounds = getParent().bounds();
- Rectangle abounds = bounds();
-
- move(bounds.x + (bounds.width - abounds.width)/ 2,
- bounds.y + (bounds.height - abounds.height)/2);
-
- super.show();
- }
-
- //{{DECLARE_CONTROLS
- java.awt.Label m_findlabel;
- java.awt.TextField m_findText;
- java.awt.Button m_findButton;
- java.awt.Button m_cancelButton;
- java.awt.Label m_statuslabel;
- java.awt.Checkbox m_matchCase;
- //}}
- FindReplace m_find;
-
- class SymWindow extends java.awt.event.WindowAdapter
- {
- public void windowClosing(java.awt.event.WindowEvent event)
- {
- Object object = event.getSource();
- if (object == FindDialog.this)
- Dialog1_WindowClosing(event);
- }
- }
-
- void Dialog1_WindowClosing(java.awt.event.WindowEvent event)
- {
- hide();
- }
-
- class SymAction implements java.awt.event.ActionListener
- {
- public void actionPerformed(java.awt.event.ActionEvent event)
- {
- Object object = event.getSource();
- if (object == m_findButton)
- mFindButton_Action(event);
- else if (object == m_cancelButton)
- mCancelButton_Action(event);
- }
- }
-
- void mFindButton_Action(java.awt.event.ActionEvent event)
- {
- FindReplaceEngine fre;
- m_find.setFind(m_findText.getText().trim());
- m_find.setCase(m_matchCase.getState());
- fre = new FindReplaceEngine(m_find);
- fre.FindIt();
- if(m_find.isFoundIt()) m_statuslabel.setText("Found " + m_find.getOccur());
- else {
- m_statuslabel.setText("End of File");
- this.getToolkit().beep();
- }
- m_statuslabel.show();
- }
-
- void mCancelButton_Action(java.awt.event.ActionEvent event)
- {
- hide();
- }
- }
-