001: /*
002: * Copyright (c) 2000, Jacob Smullyan
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.gui.editor.action;
024:
025: import java.awt.Component;
026: import java.awt.Frame;
027: import java.awt.event.WindowAdapter;
028: import java.awt.event.WindowEvent;
029: import javax.swing.JDialog;
030: import javax.swing.JOptionPane;
031: import javax.swing.WindowConstants;
032: import org.skunk.dav.client.gui.ResourceManager;
033: import org.skunk.dav.client.gui.StateMonitor;
034: import org.skunk.dav.client.gui.View;
035: import org.skunk.dav.client.gui.editor.ISearchPanel;
036: import org.skunk.dav.client.gui.editor.SearchAndReplacePanel;
037: import org.skunk.dav.client.gui.editor.SimpleTextEditor;
038: import org.skunk.trace.Debug;
039:
040: public class SearchAndReplaceAction extends SearchAction {
041: private JDialog dialog;
042: private ISearchPanel panel;
043: private int foundCount = 0;
044: public static final String MATCH_PROPERTY = "search_and_replace_match";
045:
046: protected ISearchPanel createSearchPanel() {
047: ISearchPanel isp = new SearchAndReplacePanel();
048: isp.addActionListener(this );
049: return isp;
050: }
051:
052: protected void showSearchPanel(View currentView, ISearchPanel panel) {
053: this .panel = panel;
054: this .foundCount = 0;
055: Component c = currentView.getComponent();
056: Frame appFrame = (c instanceof Frame) ? (Frame) c : null;
057: dialog = new JDialog(appFrame, ResourceManager
058: .getMessage(ResourceManager.REPLACE_TITLE), true);
059: dialog
060: .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
061: dialog.addWindowListener(new WindowAdapter() {
062: public void windowClosing(WindowEvent woo) {
063: SearchAndReplaceAction.this .panel
064: .fireActionEvent(ISearchPanel.END_SEARCH);
065: Debug.trace(this , Debug.DP3,
066: "have fired end search event");
067: }
068: });
069:
070: dialog.setContentPane(panel.getComponent());
071: dialog.pack();
072: dialog.setLocationRelativeTo(c);
073: dialog.setVisible(true);
074: }
075:
076: protected void hideSearchPanel(View currentView, ISearchPanel panel) {
077: if (dialog != null) {
078: dialog.setVisible(false);
079: dialog.dispose();
080: }
081: }
082:
083: protected void handleMatch(SimpleTextEditor editor, int[] found) {
084: foundCount++;
085: super .handleMatch(editor, found);
086: Debug.trace(this , Debug.DP3,
087: "in handleMatch() -- about to set match property");
088: StateMonitor.setProperty(MATCH_PROPERTY, editor, editor);
089: }
090:
091: protected void handleNoMatch(SimpleTextEditor editor) {
092: if (foundCount == 0)
093: super .handleNoMatch(editor);
094: else {
095: String title = ResourceManager
096: .getMessage(ResourceManager.END_REPLACE_TITLE);
097: Object[] interpolations = new Object[] { new Integer(
098: foundCount) };
099: String message = ResourceManager
100: .getMessage(ResourceManager.END_REPLACE_MESSAGE,
101: interpolations);
102: foundCount = 0;
103: JOptionPane.showMessageDialog(editor.getComponent(),
104: message, title, JOptionPane.INFORMATION_MESSAGE);
105: }
106: StateMonitor.setProperty(MATCH_PROPERTY, null, editor);
107: }
108: }
109: /* $Log: SearchAndReplaceAction.java,v $
110: /* Revision 1.3 2000/12/15 23:22:08 smulloni
111: /* added word wrap to text editor.
112: /*
113: /* Revision 1.2 2000/12/14 23:09:17 smulloni
114: /* fixes to search and replace; partial fix to adding custom properties bug.
115: /*
116: /* Revision 1.1 2000/12/14 06:36:26 smulloni
117: /* changes to search and replace in text editor.
118: /* */
|