home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-08-31 | 5.6 KB | 188 lines |
- /*
- A basic extension of the java.awt.Dialog class
- */
-
- import java.awt.*;
-
- public class ReplaceDialog extends Dialog {
- Frame theJavaPadFrame;
-
- public ReplaceDialog(Frame parent, boolean modal)
- {
- super(parent, modal);
- theJavaPadFrame = parent;
- // 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 + 278,insets().top + insets().bottom + 107);
- setBackground(new Color(12632256));
- label1 = new java.awt.Label("Find");
- label1.setBounds(insets().left + 7,insets().top + 12,28,24);
- add(label1);
- m_findText = new java.awt.TextField();
- m_findText.setBounds(insets().left + 60,insets().top + 14,124,25);
- add(m_findText);
- m_replaceText = new java.awt.TextField();
- m_replaceText.setBounds(insets().left + 60,insets().top + 46,124,25);
- add(m_replaceText);
- label2 = new java.awt.Label("Replace");
- label2.setBounds(insets().left + 3,insets().top + 47,48,21);
- add(label2);
- m_caseSencb = new java.awt.Checkbox("Case Sensitive");
- m_caseSencb.setBounds(insets().left + 1,insets().top + 77,113,24);
- add(m_caseSencb);
- m_replacebtn = new java.awt.Button();
- m_replacebtn.setActionCommand("button");
- m_replacebtn.setLabel("Replace");
- m_replacebtn.setBounds(insets().left + 196,insets().top + 5,66,21);
- add(m_replacebtn);
- m_repAllbtn = new java.awt.Button();
- m_repAllbtn.setActionCommand("button");
- m_repAllbtn.setLabel("Replace All");
- m_repAllbtn.setBounds(insets().left + 196,insets().top + 42,66,21);
- add(m_repAllbtn);
- m_cancelbtn = new java.awt.Button();
- m_cancelbtn.setActionCommand("button");
- m_cancelbtn.setLabel("Cancel");
- m_cancelbtn.setBounds(insets().left + 196,insets().top + 79,66,21);
- add(m_cancelbtn);
- setTitle("Dialog2");
- //}}
-
- //{{REGISTER_LISTENERS
- SymWindow aSymWindow = new SymWindow();
- addWindowListener(aSymWindow);
- SymAction lSymAction = new SymAction();
- m_replacebtn.addActionListener(lSymAction);
- m_repAllbtn.addActionListener(lSymAction);
- m_cancelbtn.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 ReplaceDialog(Frame parent, String title, boolean modal, FindReplace fr)
- {
- this(parent, modal);
- setTitle(title);
- m_replace = fr;
- m_findText.setText(m_replace.getFind());
- m_replaceText.setText(m_replace.getReplace());
- m_caseSencb.setState(m_replace.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 label1;
- java.awt.TextField m_findText;
- java.awt.TextField m_replaceText;
- java.awt.Label label2;
- java.awt.Checkbox m_caseSencb;
- java.awt.Button m_replacebtn;
- java.awt.Button m_repAllbtn;
- java.awt.Button m_cancelbtn;
- //}}
- FindReplace m_replace;
-
- class SymWindow extends java.awt.event.WindowAdapter
- {
- public void windowClosing(java.awt.event.WindowEvent event)
- {
- Object object = event.getSource();
- if (object == ReplaceDialog.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_replacebtn)
- mReplacebtn_Action(event);
- else if (object == m_repAllbtn)
- mRepAllbtn_Action(event);
- else if (object == m_cancelbtn)
- mCancelbtn_Action(event);
- }
- }
-
- void mReplacebtn_Action(java.awt.event.ActionEvent event)
- {
- m_replace.setReplace(m_replaceText.getText().trim());
- m_replace.setFind(m_findText.getText().trim());
- m_replace.setCase(m_caseSencb.getState());
- m_replace.setReplaceAll(false);
- m_replace.setReplaceIt(false);
- m_replace.setIndex(m_replace.getBody().getSelectionStart());
- hide();
- try{Thread.sleep(250);}catch(InterruptedException ie){}
- (new ReplaceConfirmDialog(theJavaPadFrame, "Replace Confirm", true, m_replace)).show();
-
- }
-
- void mRepAllbtn_Action(java.awt.event.ActionEvent event)
- {
- FindReplaceEngine fre;
- fre = new FindReplaceEngine(m_replace);
- m_replace.setReplace(m_replaceText.getText());
- m_replace.setFind(m_findText.getText());
- m_replace.setReplaceAll(true);
- m_replace.setReplaceIt(true);
- m_replace.setCase(m_caseSencb.getState());
- hide();
- fre.ReplaceAll();
- }
-
- void mCancelbtn_Action(java.awt.event.ActionEvent event)
- {
- hide();
- }
- }
-