⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractfindreplacedialog.java

📁 具有不同语法高亮的编辑器实例
💻 JAVA
字号:
/*
 * 04/08/2004
 *
 * AbstractFindReplaceSearchDialog.java - Base class for FindDialog and
 *                                        ReplaceDialog.
 * Copyright (C) 2004 Robert Futrell
 * email@address.com
 * www.website.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.fife.ui.search;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import org.fife.RUtilities;


/**
 * This is the base class for {@link org.fife.ui.search.FindDialog} and
 * {@link org.fife.ui.search.ReplaceDialog}. It is basically all of the features
 * common to the two dialogs that weren't taken care of in
 * {@link org.fife.ui.search.AbstractSearchDialog}.
 *
 * @author Robert Futrell
 * @version 0.1
 */
public abstract class AbstractFindReplaceDialog extends AbstractSearchDialog
										implements ActionListener {

	public static final String MARK_ALL_PROPERTY			= "SearchDialog.MarkAll";
	public static final String SEARCH_DOWNWARD_PROPERTY	= "SearchDialog.SearchDownward";

	// The radio buttons for changing the search direction.
	protected JRadioButton upButton;
	protected JRadioButton downButton;
	protected JPanel dirPanel;
	private String dirPanelTitle;

	/**
	 * The "mark all" check box.
	 */
	protected JCheckBox markAllCheckBox;


/*****************************************************************************/


	/**
	 * Constructor.  Does initializing for parts common to
	 * <code>FindDialog</code> and <code>ReplaceDialog</code> that isn't
	 * taken care of in <code>AbstractSearchDialog</code>'s constructor.
	 *
	 * @param owner The window that owns this search dialog.
	 * @param resources The resource bundle to use for labels, etc.
	 * @param useRButtons If <code>true</code>, then
	 *                    <code>org.fife.ui.RButton</code>s will be used for
	 *                    all buttons defined here (currently just the Cancel
	 *                    button).  Otherwise, regular <code>JButton</code>s
	 *                    are used.
	 */
	public AbstractFindReplaceDialog(Frame owner, ResourceBundle resources,
								boolean useRButtons) {

		super(owner, resources, useRButtons);

		// Make a panel containing the "search up/down" radio buttons.
		dirPanel = new JPanel();
		dirPanel.setLayout(new BoxLayout(dirPanel, BoxLayout.X_AXIS));
		setSearchButtonsBorderText(resources.getString("Direction"));
		ButtonGroup bg = new ButtonGroup();
		upButton = new JRadioButton(resources.getString("Up"), false);
		upButton.setMnemonic((int)resources.getString("UpMnemonic").charAt(0));
		downButton = new JRadioButton(resources.getString("Down"), true);
		downButton.setMnemonic((int)resources.getString("DownMnemonic").charAt(0));
		upButton.setActionCommand("UpRadioButtonClicked");
		upButton.addActionListener(this);
		downButton.setActionCommand("DownRadioButtonClicked");
		downButton.addActionListener(this);
		bg.add(upButton);
		bg.add(downButton);
		dirPanel.add(upButton);
		dirPanel.add(downButton);

		// Initilialize the "mark all" button.
		markAllCheckBox = RUtilities.createCheckBox(resources, "MarkAll", "MarkAllMnemonic");
		markAllCheckBox.setActionCommand("MarkAll");
		markAllCheckBox.addActionListener(this);

		// Rearrange the search conditions panel.
		searchConditionsPanel.removeAll();
		searchConditionsPanel.setLayout(new BorderLayout());
		JPanel temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.Y_AXIS));
		temp.add(caseCheckBox);
		temp.add(wholeWordCheckBox);
		searchConditionsPanel.add(temp, BorderLayout.WEST);
		temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.Y_AXIS));
		temp.add(regExpCheckBox);
		temp.add(markAllCheckBox);
		searchConditionsPanel.add(temp, BorderLayout.EAST);

	}


/*****************************************************************************/


	/**
	 * Listens for action events in this dialog.
	 *
	 * @param e The event that occured.
	 */
	public void actionPerformed(ActionEvent e) {

		String actionCommand = e.getActionCommand();

		if (actionCommand.equals("UpRadioButtonClicked")) {
			firePropertyChange(SEARCH_DOWNWARD_PROPERTY, true, false);
		}

		else if (actionCommand.equals("DownRadioButtonClicked")) {
			firePropertyChange(SEARCH_DOWNWARD_PROPERTY, false, true);
		}

		else if (actionCommand.equals("MarkAll")) {
			boolean checked = markAllCheckBox.isSelected();
			firePropertyChange(MARK_ALL_PROPERTY, !checked, checked);
		}

		else
			super.actionPerformed(e);

	}


/*****************************************************************************/


	/**
	 * Adds an <code>ActionListener</code> to this dialog.  This method should
	 * be overridden so that search actions are sent to listeners.  For
	 * example, for a Replace dialog, all listeners should receive notification
	 * when the user clicks "Find", "Replace", or "Replace All".
	 *
	 * @param l The listener to add.
	 * @see #removeActionListener
	 */
	public abstract void addActionListener(ActionListener l);


/*****************************************************************************/


	/**
	 * Changes the action listener from one component to another.
	 *
	 * @param fromPanel The old <code>ActionListener</code> to remove.
	 * @param toPanel The new <code>ActionListener</code> to add as an action
	 *                listener.
	 */
	public void changeActionListener(ActionListener fromPanel,
								ActionListener toPanel) {
		this.removeActionListener(fromPanel);
		this.addActionListener(toPanel);
	}


/*****************************************************************************/


	/**
	 * Returns the text for the "Down" radio button.
	 *
	 * @return The text for the "Down" radio button.
	 * @see #setDownRadioButtonText
	 */
	public final String getDownRadioButtonText() {
		return downButton.getText();
	}


/*****************************************************************************/


	/**
	 * Returns the text for the search direction's radio buttons' border.
	 *
	 * @return The text for the search radio buttons' border.
	 * @see #setSearchButtonsBorderText
	 */
	public final String getSearchButtonsBorderText() {
		return dirPanelTitle;
	}


/*****************************************************************************/


	/**
	 * Returns the text for the "Up" radio button.
	 *
	 * @return The text for the "Up" radio button.
	 * @see #setUpRadioButtonText
	 */
	public final String getUpRadioButtonText() {
		return upButton.getText();
	}


/*****************************************************************************/


	/**
	 * Removes an <code>ActionListener</code> from this dialog.
	 *
	 * @param l The listener to remove
	 * @see #addActionListener
	 */
	public abstract void removeActionListener(ActionListener l);


/*****************************************************************************/


	/**
	 * Sets the text label for the "Down" radio button.
	 *
	 * @param text The new text label for the "Down" radio button.
	 * @see #getDownRadioButtonText
	 */
	public void setDownRadioButtonText(String text) {
		downButton.setText(text);
	}


/*****************************************************************************/


	/**
	 * Sets the text for the search direction's radio buttons' border.
	 *
	 * @param text The text for the search radio buttons' border.
	 * @see #getSearchButtonsBorderText
	 */
	public final void setSearchButtonsBorderText(String text) {
		dirPanelTitle = text;
		dirPanel.setBorder(createTitledBorder(dirPanelTitle));
	}


/*****************************************************************************/


	/**
	 * This function should be called to update match case, whole word, etc.
	 *
	 * @param searchString The string to be at the top of the combo box of
	 *                     stringsto search for.
	 * @param matchCase Whether or not to match case in the search.
	 * @param wholeWord Whether or not to look for <code>searchString</code>
	 *                  as a separate word when searching.
	 * @param regExp Whether or not to treat <code>searchString</code> as a
	 *               regular expression when searching.
	 * @param searchUp Whether to search up or down.
	 * @param markAll Whether to mark all occurences.
	 */
	public void setSearchParameters(String searchString, boolean matchCase,
									boolean wholeWord,
									boolean regExp, boolean searchUp,
									boolean markAll) {
		setSearchString(searchString);
		caseCheckBox.setSelected(matchCase);
		wholeWordCheckBox.setSelected(wholeWord);
		regExpCheckBox.setSelected(regExp);
		upButton.setSelected(searchUp);
		downButton.setSelected(!searchUp);
		markAllCheckBox.setSelected(markAll);
	}


/*****************************************************************************/


	/**
	 * This function should be called to update match case, whole word, etc.
	 *
	 * @param findComboBoxStrings The strings that the "Find" combo box
	 *                            should contain.
	 * @param matchCase Whether or not to match case in the search.
	 * @param wholeWord Whether or not to look for <code>searchString</code>
	 *                  as a separate word when searching.
	 * @param regExp Whether or not to treat <code>searchString</code> as a
	 *               regular expression when searching.
	 * @param searchUp Whether to search up or down.
	 * @param markAll Whether to mark all occurences.
	 */
	public void setSearchParameters(Vector findComboBoxStrings,
							boolean matchCase, boolean wholeWord,
							boolean regExp, boolean searchUp,
							boolean markAll) {
		findTextComboBox.removeAllItems();
		int size = findComboBoxStrings.size();
		for (int i=size-1; i>=0; i--) {
			findTextComboBox.addItem(findComboBoxStrings.get(i));
		}
		if (size>0)
			findTextComboBox.setSelectedIndex(0);
		caseCheckBox.setSelected(matchCase);
		wholeWordCheckBox.setSelected(wholeWord);
		regExpCheckBox.setSelected(regExp);
		upButton.setSelected(searchUp);
		downButton.setSelected(!searchUp);
		markAllCheckBox.setSelected(markAll);
	}


/*****************************************************************************/


	/**
	 * Sets the text label for the "Up" radio button.
	 *
	 * @param text The new text label for the "Up" radio button.
	 * @see #getUpRadioButtonText
	 */
	public void setUpRadioButtonText(String text) {
		upButton.setText(text);
	}


/*****************************************************************************/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -