PageRenderTime 103ms CodeModel.GetById 25ms app.highlight 62ms RepoModel.GetById 1ms app.codeStats 1ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/search/SearchDialog.java

#
Java | 805 lines | 586 code | 130 blank | 89 comment | 103 complexity | 595aca56e28db0edb1b0454b1e7d8e1f MD5 | raw file
  1/*
  2 * SearchDialog.java - Search and replace dialog
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1998, 1999, 2000, 2001 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package org.gjt.sp.jedit.search;
 24
 25//{{{ Imports
 26import javax.swing.border.*;
 27import javax.swing.event.*;
 28import javax.swing.*;
 29import java.awt.*;
 30import java.awt.event.*;
 31import java.io.File;
 32import org.gjt.sp.jedit.gui.*;
 33import org.gjt.sp.jedit.io.FileVFS;
 34import org.gjt.sp.jedit.msg.SearchSettingsChanged;
 35import org.gjt.sp.jedit.*;
 36import org.gjt.sp.util.Log;
 37//}}}
 38
 39/**
 40 * Search and replace dialog.
 41 * @author Slava Pestov
 42 * @version $Id: SearchDialog.java 3931 2001-12-02 11:40:51Z spestov $
 43 */
 44public class SearchDialog extends EnhancedDialog implements EBComponent
 45{
 46	//{{{ Constants
 47	/**
 48	 * Default file set.
 49	 * @since jEdit 3.2pre2
 50	 */
 51	public static final int CURRENT_BUFFER = 0;
 52	public static final int ALL_BUFFERS = 1;
 53	public static final int DIRECTORY = 2;
 54	//}}}
 55
 56	//{{{ SearchDialog constructor
 57	/**
 58	 * Creates a new search and replace dialog box.
 59	 * @param view The view
 60	 * @param searchString The search string
 61	 */
 62	public SearchDialog(View view, String searchString)
 63	{
 64		this(view,searchString,CURRENT_BUFFER);
 65	} //}}}
 66
 67	//{{{ SearchDialog constructor
 68	/**
 69	 * Creates a new search and replace dialog box.
 70	 * @param view The view
 71	 * @param searchString The search string
 72	 * @param searchIn One of CURRENT_BUFFER, ALL_BUFFERS, or DIRECTORY
 73	 * @since jEdit 3.2pre2
 74	 */
 75	public SearchDialog(View view, String searchString, int searchIn)
 76	{
 77		super(view,jEdit.getProperty("search.title"),false);
 78
 79		this.view = view;
 80
 81		JPanel content = new JPanel(new BorderLayout());
 82		content.setBorder(new EmptyBorder(0,12,12,12));
 83		setContentPane(content);
 84
 85		JPanel centerPanel = new JPanel(new BorderLayout());
 86		centerPanel.add(BorderLayout.NORTH,createFieldPanel());
 87		centerPanel.add(BorderLayout.CENTER,createSearchSettingsPanel());
 88		content.add(BorderLayout.CENTER,centerPanel);
 89		content.add(BorderLayout.SOUTH,createMultiFilePanel());
 90
 91		content.add(BorderLayout.EAST,createButtonsPanel());
 92
 93		if(searchString != null)
 94		{
 95			if(searchString.indexOf('\n') == -1)
 96			{
 97				find.setText(searchString);
 98				find.selectAll();
 99			}
100			else if(searchIn == CURRENT_BUFFER)
101			{
102				searchSelection.setSelected(true);
103				hyperSearch.setSelected(true);
104			}
105		}
106
107		ignoreCase.setSelected(SearchAndReplace.getIgnoreCase());
108		regexp.setSelected(SearchAndReplace.getRegexp());
109		wrap.setSelected(SearchAndReplace.getAutoWrapAround());
110
111		if(SearchAndReplace.getReverseSearch())
112			searchBack.setSelected(true);
113		else
114			searchForward.setSelected(true);
115
116		if(SearchAndReplace.getBeanShellReplace())
117			beanShellReplace.setSelected(true);
118		else
119			stringReplace.setSelected(true);
120
121		if(searchIn == CURRENT_BUFFER)
122		{
123			if(!searchSelection.isSelected())
124			{
125				// might be already selected, see above.
126				searchCurrentBuffer.setSelected(true);
127
128				/* this property is only loaded and saved if
129				 * the 'current buffer' file set is selected.
130				 * otherwise, it defaults to on. */
131				hyperSearch.setSelected(jEdit.getBooleanProperty(
132					"search.hypersearch.toggle"));
133			}
134		}
135		else if(searchIn == ALL_BUFFERS)
136		{
137			searchAllBuffers.setSelected(true);
138			hyperSearch.setSelected(true);
139		}
140		else if(searchIn == DIRECTORY)
141		{
142			hyperSearch.setSelected(true);
143			searchDirectory.setSelected(true);
144		}
145
146		SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
147
148		if(fileset instanceof DirectoryListSet)
149		{
150			filter.setText(((DirectoryListSet)fileset)
151				.getFileFilter());
152			directory.setText(((DirectoryListSet)fileset)
153				.getDirectory());
154			searchSubDirectories.setSelected(((DirectoryListSet)fileset)
155				.isRecursive());
156		}
157		else
158		{
159			String path;
160			if(view.getBuffer().getVFS() instanceof FileVFS)
161			{
162				path = MiscUtilities.getParentOfPath(
163					view.getBuffer().getPath());
164			}
165			else
166				path = System.getProperty("user.dir");
167			directory.setText(path);
168
169			if(fileset instanceof AllBufferSet)
170			{
171				filter.setText(((AllBufferSet)fileset)
172					.getFileFilter());
173			}
174			else
175			{
176				filter.setText("*" + MiscUtilities
177					.getFileExtension(view.getBuffer()
178					.getName()));
179			}
180
181			searchSubDirectories.setSelected(true);
182		}
183
184		keepDialog.setSelected(jEdit.getBooleanProperty(
185			"search.keepDialog.toggle"));
186
187		updateEnabled();
188
189		pack();
190		jEdit.unsetProperty("search.width");
191		jEdit.unsetProperty("search.d-width");
192		jEdit.unsetProperty("search.height");
193		jEdit.unsetProperty("search.d-height");
194		GUIUtilities.loadGeometry(this,"search");
195		show();
196
197		EditBus.addToBus(this);
198
199		GUIUtilities.requestFocus(this,find);
200	} //}}}
201
202	//{{{ ok() method
203	public void ok()
204	{
205		try
206		{
207			setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
208
209			if(!save())
210				return;
211
212			if(hyperSearch.isSelected() || searchSelection.isSelected())
213			{
214				if(SearchAndReplace.hyperSearch(view,
215					searchSelection.isSelected()));
216					closeOrKeepDialog();
217			}
218			else
219			{
220				if(SearchAndReplace.find(view))
221					closeOrKeepDialog();
222			}
223		}
224		finally
225		{
226			setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
227		}
228	} //}}}
229
230	//{{{ cancel() method
231	public void cancel()
232	{
233		save();
234		GUIUtilities.saveGeometry(this,"search");
235		dispose();
236	} //}}}
237
238	//{{{ handleMessage() method
239	public void handleMessage(EBMessage msg)
240	{
241		if(msg instanceof SearchSettingsChanged)
242		{
243			ignoreCase.setSelected(SearchAndReplace.getIgnoreCase());
244			regexp.setSelected(SearchAndReplace.getRegexp());
245		}
246	} //}}}
247
248	//{{{ dispose() method
249	public void dispose()
250	{
251		EditBus.removeFromBus(this);
252		super.dispose();
253	} //}}}
254
255	//{{{ Private members
256
257	//{{{ Instance variables
258	private View view;
259
260	// fields
261	private HistoryTextField find, replace;
262
263	private JRadioButton stringReplace, beanShellReplace;
264
265	// search settings
266	private JCheckBox keepDialog, ignoreCase, regexp, hyperSearch,
267		wrap;
268	private JRadioButton searchBack, searchForward;
269	private JRadioButton searchSelection, searchCurrentBuffer, searchAllBuffers,
270		searchDirectory;
271
272	// multifile settings
273	private HistoryTextField filter, directory;
274	private JCheckBox searchSubDirectories;
275	private JButton choose;
276
277	// buttons
278	private JButton findBtn, replaceBtn, replaceAndFindBtn, replaceAllBtn,
279		closeBtn;
280	//}}}
281
282	//{{{ createFieldPanel() method
283	private JPanel createFieldPanel()
284	{
285		ButtonActionHandler actionHandler = new ButtonActionHandler();
286
287		JPanel fieldPanel = new JPanel(new VariableGridLayout(
288			VariableGridLayout.FIXED_NUM_COLUMNS,1));
289		fieldPanel.setBorder(new EmptyBorder(0,0,12,12));
290
291		JLabel label = new JLabel(jEdit.getProperty("search.find"));
292		label.setDisplayedMnemonic(jEdit.getProperty("search.find.mnemonic")
293			.charAt(0));
294		find = new HistoryTextField("find");
295		find.addActionListener(actionHandler);
296		label.setLabelFor(find);
297		label.setBorder(new EmptyBorder(12,0,2,0));
298		fieldPanel.add(label);
299		fieldPanel.add(find);
300
301		label = new JLabel(jEdit.getProperty("search.replace"));
302		label.setDisplayedMnemonic(jEdit.getProperty("search.replace.mnemonic")
303			.charAt(0));
304		label.setBorder(new EmptyBorder(12,0,0,0));
305		fieldPanel.add(label);
306
307		ButtonGroup grp = new ButtonGroup();
308		ReplaceActionHandler replaceActionHandler = new ReplaceActionHandler();
309
310		// we use a custom JRadioButton subclass that returns
311		// false for isFocusTraversable() so that the user can
312		// tab from the search field to the replace field with
313		// one keystroke
314
315		Box replaceModeBox = new Box(BoxLayout.X_AXIS);
316		stringReplace = new MyJRadioButton(jEdit.getProperty(
317			"search.string-replace-btn"));
318		stringReplace.addActionListener(replaceActionHandler);
319		grp.add(stringReplace);
320		replaceModeBox.add(stringReplace);
321
322		replaceModeBox.add(Box.createHorizontalStrut(12));
323
324		beanShellReplace = new MyJRadioButton(jEdit.getProperty(
325			"search.beanshell-replace-btn"));
326		beanShellReplace.addActionListener(replaceActionHandler);
327		grp.add(beanShellReplace);
328		replaceModeBox.add(beanShellReplace);
329
330		fieldPanel.add(replaceModeBox);
331
332		fieldPanel.add(Box.createVerticalStrut(3));
333
334		replace = new HistoryTextField("replace");
335		replace.addActionListener(actionHandler);
336		label.setLabelFor(replace);
337		fieldPanel.add(replace);
338
339		return fieldPanel;
340	} //}}}
341
342	//{{{ createSearchSettingsPanel() method
343	private JPanel createSearchSettingsPanel()
344	{
345		JPanel searchSettings = new JPanel(new VariableGridLayout(
346			VariableGridLayout.FIXED_NUM_COLUMNS,3));
347		searchSettings.setBorder(new EmptyBorder(0,0,12,12));
348
349		SettingsActionHandler actionHandler = new SettingsActionHandler();
350		ButtonGroup fileset = new ButtonGroup();
351		ButtonGroup direction = new ButtonGroup();
352
353		searchSettings.add(new JLabel(jEdit.getProperty("search.fileset")));
354
355		searchSettings.add(new JLabel(jEdit.getProperty("search.settings")));
356
357		searchSettings.add(new JLabel(jEdit.getProperty("search.direction")));
358
359		searchSelection = new JRadioButton(jEdit.getProperty("search.selection"));
360		searchSelection.setMnemonic(jEdit.getProperty("search.selection.mnemonic")
361			.charAt(0));
362		fileset.add(searchSelection);
363		searchSettings.add(searchSelection);
364		searchSelection.addActionListener(actionHandler);
365
366		keepDialog = new JCheckBox(jEdit.getProperty("search.keep"));
367		keepDialog.setMnemonic(jEdit.getProperty("search.keep.mnemonic")
368			.charAt(0));
369		searchSettings.add(keepDialog);
370
371		searchBack = new JRadioButton(jEdit.getProperty("search.back"));
372		searchBack.setMnemonic(jEdit.getProperty("search.back.mnemonic")
373			.charAt(0));
374		direction.add(searchBack);
375		searchSettings.add(searchBack);
376		searchBack.addActionListener(actionHandler);
377
378		searchCurrentBuffer = new JRadioButton(jEdit.getProperty("search.current"));
379		searchCurrentBuffer.setMnemonic(jEdit.getProperty("search.current.mnemonic")
380			.charAt(0));
381		fileset.add(searchCurrentBuffer);
382		searchSettings.add(searchCurrentBuffer);
383		searchCurrentBuffer.addActionListener(actionHandler);
384
385		ignoreCase = new JCheckBox(jEdit.getProperty("search.case"));
386		ignoreCase.setMnemonic(jEdit.getProperty("search.case.mnemonic")
387			.charAt(0));
388		searchSettings.add(ignoreCase);
389		ignoreCase.addActionListener(actionHandler);
390
391		searchForward = new JRadioButton(jEdit.getProperty("search.forward"));
392		searchForward.setMnemonic(jEdit.getProperty("search.forward.mnemonic")
393			.charAt(0));
394		direction.add(searchForward);
395		searchSettings.add(searchForward);
396		searchForward.addActionListener(actionHandler);
397
398		searchAllBuffers = new JRadioButton(jEdit.getProperty("search.all"));
399		searchAllBuffers.setMnemonic(jEdit.getProperty("search.all.mnemonic")
400			.charAt(0));
401		fileset.add(searchAllBuffers);
402		searchSettings.add(searchAllBuffers);
403		searchAllBuffers.addActionListener(actionHandler);
404
405		regexp = new JCheckBox(jEdit.getProperty("search.regexp"));
406		regexp.setMnemonic(jEdit.getProperty("search.regexp.mnemonic")
407			.charAt(0));
408		searchSettings.add(regexp);
409		regexp.addActionListener(actionHandler);
410
411		wrap = new JCheckBox(jEdit.getProperty("search.wrap"));
412		wrap.setMnemonic(jEdit.getProperty("search.wrap.mnemonic")
413			.charAt(0));
414		searchSettings.add(wrap);
415		wrap.addActionListener(actionHandler);
416
417		searchDirectory = new JRadioButton(jEdit.getProperty("search.directory"));
418		searchDirectory.setMnemonic(jEdit.getProperty("search.directory.mnemonic")
419			.charAt(0));
420		fileset.add(searchDirectory);
421		searchSettings.add(searchDirectory);
422		searchDirectory.addActionListener(actionHandler);
423
424		hyperSearch = new JCheckBox(jEdit.getProperty("search.hypersearch"));
425		hyperSearch.setMnemonic(jEdit.getProperty("search.hypersearch.mnemonic")
426			.charAt(0));
427		searchSettings.add(hyperSearch);
428		hyperSearch.addActionListener(actionHandler);
429
430		return searchSettings;
431	} //}}}
432
433	//{{{ createMultiFilePanel() method
434	private JPanel createMultiFilePanel()
435	{
436		JPanel multifile = new JPanel();
437
438		GridBagLayout layout = new GridBagLayout();
439		multifile.setLayout(layout);
440
441		GridBagConstraints cons = new GridBagConstraints();
442		cons.gridy = cons.gridwidth = cons.gridheight = 1;
443		cons.anchor = GridBagConstraints.WEST;
444		cons.fill = GridBagConstraints.HORIZONTAL;
445
446		MultiFileActionHandler actionListener = new MultiFileActionHandler();
447		filter = new HistoryTextField("search.filter");
448		filter.addActionListener(actionListener);
449
450		cons.insets = new Insets(0,0,3,0);
451
452		JLabel label = new JLabel(jEdit.getProperty("search.filterField"),
453			SwingConstants.RIGHT);
454		label.setBorder(new EmptyBorder(0,0,0,12));
455		label.setDisplayedMnemonic(jEdit.getProperty("search.filterField.mnemonic")
456			.charAt(0));
457		label.setLabelFor(filter);
458		cons.weightx = 0.0f;
459		layout.setConstraints(label,cons);
460		multifile.add(label);
461
462		cons.insets = new Insets(0,0,3,6);
463		cons.weightx = 1.0f;
464		layout.setConstraints(filter,cons);
465		multifile.add(filter);
466
467		cons.gridy++;
468
469		directory = new HistoryTextField("search.directory");
470		directory.addActionListener(actionListener);
471
472		label = new JLabel(jEdit.getProperty("search.directoryField"),
473			SwingConstants.RIGHT);
474		label.setBorder(new EmptyBorder(0,0,0,12));
475
476		label.setDisplayedMnemonic(jEdit.getProperty("search.directoryField.mnemonic")
477			.charAt(0));
478		label.setLabelFor(directory);
479		cons.insets = new Insets(0,0,3,0);
480		cons.weightx = 0.0f;
481		layout.setConstraints(label,cons);
482		multifile.add(label);
483
484		cons.insets = new Insets(0,0,3,6);
485		cons.weightx = 1.0f;
486		cons.gridwidth = 2;
487		layout.setConstraints(directory,cons);
488		multifile.add(directory);
489
490		choose = new JButton(jEdit.getProperty("search.choose"));
491		choose.setMnemonic(jEdit.getProperty("search.choose.mnemonic")
492			.charAt(0));
493		cons.insets = new Insets(0,0,3,0);
494		cons.weightx = 0.0f;
495		cons.gridwidth = 1;
496		layout.setConstraints(choose,cons);
497		multifile.add(choose);
498		choose.addActionListener(actionListener);
499
500		cons.insets = new Insets(0,0,0,0);
501		cons.gridy++;
502		cons.gridwidth = 4;
503
504		searchSubDirectories = new JCheckBox(jEdit.getProperty(
505			"search.subdirs"));
506		searchSubDirectories.setMnemonic(jEdit.getProperty("search.subdirs.mnemonic")
507			.charAt(0));
508		layout.setConstraints(searchSubDirectories,cons);
509		multifile.add(searchSubDirectories);
510
511		return multifile;
512	} //}}}
513
514	//{{{ createButtonsPanel() method
515	private Box createButtonsPanel()
516	{
517		Box box = new Box(BoxLayout.Y_AXIS);
518
519		ButtonActionHandler actionHandler = new ButtonActionHandler();
520
521		box.add(Box.createVerticalStrut(12));
522
523		JPanel grid = new JPanel(new GridLayout(5,1,0,12));
524
525		findBtn = new JButton(jEdit.getProperty("search.findBtn"));
526		getRootPane().setDefaultButton(findBtn);
527		grid.add(findBtn);
528		findBtn.addActionListener(actionHandler);
529
530		replaceBtn = new JButton(jEdit.getProperty("search.replaceBtn"));
531		replaceBtn.setMnemonic(jEdit.getProperty("search.replaceBtn.mnemonic")
532			.charAt(0));
533		grid.add(replaceBtn);
534		replaceBtn.addActionListener(actionHandler);
535
536		replaceAndFindBtn = new JButton(jEdit.getProperty("search.replaceAndFindBtn"));
537		replaceAndFindBtn.setMnemonic(jEdit.getProperty("search.replaceAndFindBtn.mnemonic")
538			.charAt(0));
539		grid.add(replaceAndFindBtn);
540		replaceAndFindBtn.addActionListener(actionHandler);
541
542		replaceAllBtn = new JButton(jEdit.getProperty("search.replaceAllBtn"));
543		replaceAllBtn.setMnemonic(jEdit.getProperty("search.replaceAllBtn.mnemonic")
544			.charAt(0));
545		grid.add(replaceAllBtn);
546		replaceAllBtn.addActionListener(actionHandler);
547
548		closeBtn = new JButton(jEdit.getProperty("common.close"));
549		grid.add(closeBtn);
550		closeBtn.addActionListener(actionHandler);
551
552		grid.setMaximumSize(grid.getPreferredSize());
553
554		box.add(grid);
555		box.add(Box.createGlue());
556
557		return box;
558	} //}}}
559
560	//{{{ updateEnabled() method
561	private void updateEnabled()
562	{
563		wrap.setEnabled(!hyperSearch.isSelected());
564
565		boolean reverseEnabled = !hyperSearch.isSelected()
566			&& searchCurrentBuffer.isSelected();
567		searchBack.setEnabled(reverseEnabled);
568		searchForward.setEnabled(reverseEnabled);
569
570		boolean regexpEnabled = (hyperSearch.isSelected()
571			|| !(searchBack.isEnabled() && searchBack.isSelected()));
572		regexp.setEnabled(regexpEnabled);
573
574		filter.setEnabled(searchAllBuffers.isSelected()
575			|| searchDirectory.isSelected());
576
577		boolean directoryEnabled = searchDirectory.isSelected();
578
579		directory.setEnabled(directoryEnabled);
580		choose.setEnabled(directoryEnabled);
581		searchSubDirectories.setEnabled(directoryEnabled);
582
583		findBtn.setEnabled(!searchSelection.isSelected()
584			|| hyperSearch.isSelected());
585	} //}}}
586
587	//{{{ save() method
588	private boolean save()
589	{
590		String filter = this.filter.getText();
591		this.filter.addCurrentToHistory();
592		if(filter.length() == 0)
593			filter = "*";
594
595		SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
596
597		if(searchSelection.isSelected())
598			fileset = new CurrentBufferSet();
599		else if(searchCurrentBuffer.isSelected())
600		{
601			fileset = new CurrentBufferSet();
602
603			jEdit.setBooleanProperty("search.hypersearch.toggle",
604				hyperSearch.isSelected());
605		}
606		else if(searchAllBuffers.isSelected())
607			fileset = new AllBufferSet(filter);
608		else if(searchDirectory.isSelected())
609		{
610			String directory = this.directory.getText();
611			this.directory.addCurrentToHistory();
612			boolean recurse = searchSubDirectories.isSelected();
613
614			if(fileset instanceof DirectoryListSet)
615			{
616				DirectoryListSet dset = (DirectoryListSet)fileset;
617				if(!dset.getDirectory().equals(directory)
618					|| !dset.getFileFilter().equals(filter)
619					|| !dset.isRecursive() == recurse)
620					fileset = new DirectoryListSet(directory,filter,recurse);
621			}
622			else
623				fileset = new DirectoryListSet(directory,filter,recurse);
624		}
625		else
626		{
627			// can't happen
628			fileset = null;
629		}
630
631		jEdit.setBooleanProperty("search.keepDialog.toggle",
632			keepDialog.isSelected());
633
634		boolean ok = true;
635
636		if(fileset.getFileCount() == 0)
637		{
638			// oops
639			GUIUtilities.error(this,"empty-fileset",null);
640			ok = false;
641		}
642		else
643			SearchAndReplace.setSearchFileSet(fileset);
644
645		if(find.getText().length() != 0)
646		{
647			find.addCurrentToHistory();
648			SearchAndReplace.setSearchString(find.getText());
649			replace.addCurrentToHistory();
650
651			SearchAndReplace.setReplaceString(replace.getText());
652		}
653		else
654			ok = false;
655
656		return ok;
657	} //}}}
658
659	//{{{ closeOrKeepDialog() method
660	private void closeOrKeepDialog()
661	{
662		if(keepDialog.isSelected())
663			return;
664		else
665		{
666			GUIUtilities.saveGeometry(this,"search");
667			dispose();
668		}
669	} //}}}
670
671	//}}}
672
673	//{{{ Inner classes
674
675	//{{{ MyJRadioButton class
676
677	// used for the stringReplace and beanShell replace radio buttons,
678	// so that the user can press tab to go from the find field to the
679	// replace field in one go
680	class MyJRadioButton extends JRadioButton
681	{
682		MyJRadioButton(String label)
683		{
684			super(label);
685		}
686
687		public boolean isFocusTraversable()
688		{
689			return false;
690		}
691	} //}}}
692
693	//{{{ ReplaceActionHandler class
694	class ReplaceActionHandler implements ActionListener
695	{
696		public void actionPerformed(ActionEvent evt)
697		{
698			replace.setModel(beanShellReplace.isSelected()
699				? "replace.script"
700				: "replace");
701			SearchAndReplace.setBeanShellReplace(
702				beanShellReplace.isSelected());
703		}
704	} //}}}
705
706	//{{{ SettingsActionHandler class
707	class SettingsActionHandler implements ActionListener
708	{
709		public void actionPerformed(ActionEvent evt)
710		{
711			Object source = evt.getSource();
712
713			if(source == ignoreCase)
714				SearchAndReplace.setIgnoreCase(ignoreCase.isSelected());
715			else if(source == regexp)
716				SearchAndReplace.setRegexp(regexp.isSelected());
717			else if(source == searchBack || source == searchForward)
718				SearchAndReplace.setReverseSearch(searchBack.isSelected());
719			else if(source == wrap)
720				SearchAndReplace.setAutoWrapAround(wrap.isSelected());
721			else if(source == searchCurrentBuffer)
722				hyperSearch.setSelected(false);
723			else if(source == searchSelection
724				|| source == searchAllBuffers
725				|| source == searchDirectory)
726				hyperSearch.setSelected(true);
727
728			updateEnabled();
729		}
730	} //}}}
731
732	//{{{ MultiFileActionHandler class
733	class MultiFileActionHandler implements ActionListener
734	{
735		public void actionPerformed(ActionEvent evt)
736		{
737			if(evt.getSource() == choose)
738			{
739				File dir = new File(directory.getText());
740				JFileChooser chooser = new JFileChooser(dir.getParent());
741				chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
742				chooser.setSelectedFile(dir);
743
744				if(chooser.showOpenDialog(SearchDialog.this)
745					== JFileChooser.APPROVE_OPTION)
746					directory.setText(chooser.getSelectedFile().getPath());
747			}
748			else // source is directory or filter field
749			{
750				// just as if Enter was pressed in another
751				// text field
752				ok();
753			}
754		}
755	} //}}}
756
757	//{{{ ButtonActionHandler class
758	class ButtonActionHandler implements ActionListener
759	{
760		public void actionPerformed(ActionEvent evt)
761		{
762			Object source = evt.getSource();
763
764			if(source == closeBtn)
765				cancel();
766			else if(source == findBtn || source == find
767				|| source == replace)
768			{
769				ok();
770			}
771			else if(source == replaceBtn
772				|| (source == replaceAllBtn
773				&& searchSelection.isSelected()))
774			{
775				save();
776				if(SearchAndReplace.replace(view))
777					closeOrKeepDialog();
778				else
779					getToolkit().beep();
780			}
781			else if(source == replaceAndFindBtn)
782			{
783				save();
784				if(SearchAndReplace.replace(view))
785					ok();
786				else
787					getToolkit().beep();
788			}
789			else if(source == replaceAllBtn)
790			{
791				setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
792
793				save();
794				if(SearchAndReplace.replaceAll(view))
795					closeOrKeepDialog();
796				else
797					getToolkit().beep();
798
799				setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
800			}
801		}
802	} //}}}
803
804	//}}}
805}