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

📄 jxfinddialog.java

📁 java实现浏览器等本地桌面的功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: JXFindDialog.java,v 1.9 2005/10/10 18:01:57 rbair Exp $ * * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, * Santa Clara, California 95054, U.S.A. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library 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 * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */package org.jdesktop.swingx;import java.awt.Component;import java.awt.ComponentOrientation;import java.awt.Dimension;import java.awt.Frame;import java.awt.GraphicsConfiguration;import java.awt.GraphicsEnvironment;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.regex.Pattern;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.BorderFactory;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.InputMap;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.KeyStroke;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import javax.swing.plaf.basic.BasicOptionPaneUI;import org.jdesktop.swingx.action.AbstractActionExt;import org.jdesktop.swingx.action.ActionContainerFactory;import org.jdesktop.swingx.action.BoundAction;import org.jdesktop.swingx.plaf.LookAndFeelAddons;/** * Simple FindDialog. *  *  * PENDING: need to extract a common dialog. * PENDING: the base search widget need not be a dialog! *  * @deprecated use SearchFactory.getInstance().showFindDialog() instead * @author ?? * @author Jeanette Winzenburg */public class JXFindDialog extends JDialog {    static {        // Hack to enforce loading of SwingX framework ResourceBundle        LookAndFeelAddons.getAddon();    }        public static final String MATCH_WRAP_ACTION_COMMAND = "wrapSearch";    public static final String MATCH_BACKWARDS_ACTION_COMMAND = "backwardsSearch";    public static final String EXECUTE_FIND_ACTION_COMMAND = "executeSearch";    public static final String EXECUTE_ACTION_COMMAND = "execute";    public static final String CLOSE_ACTION_COMMAND = "close";    private static final String SEARCH_FIELD_LABEL = "searchFieldLabel";    private static final String SEARCH_FIELD_MNEMONIC = SEARCH_FIELD_LABEL + ".mnemonic";//    private static final Object ENTER_ACTION_COMMAND = null;//    private static final Object CANCEL_ACTION_COMMAND = null;        private Searchable searchable;    private JTextField searchField;    private JCheckBox matchCheck;    private JCheckBox wrapCheck;    private JCheckBox backCheck;    private PatternModel patternModel;    public JXFindDialog() {        this(null, null);    }        public JXFindDialog(Searchable searchable) {        this(searchable,             (searchable instanceof Component) ? (Component) searchable : null);     }    public JXFindDialog(Searchable searchable, Component component) {        super(component != null ?               (Frame)SwingUtilities.getWindowAncestor(component) : JOptionPane.getRootFrame(),              "Find in this component");        setSearchable(searchable);        locate();        init();        pack();    }        /**     * Sets the Searchable targeted with this dialog.     *      * @param searchable      */    public void setSearchable(Searchable searchable) {        if ((this.searchable != null) && this.searchable.equals(searchable)) return;        Object old = this.searchable;        this.searchable = searchable;        setLastIndex(-1);        firePropertyChange("searchable", old, this.searchable);    }        /**     *      */    private void locate() {        GraphicsConfiguration gc =            GraphicsEnvironment.getLocalGraphicsEnvironment().            getDefaultScreenDevice().getDefaultConfiguration();        Rectangle bounds = gc.getBounds();        int x = bounds.x+bounds.width/3;        int y = bounds.y+bounds.height/3;        setLocation(x, y);    }    private void init() {        initActions();        initComponents();        build();        bind();    }    //------------------ support synch the model <--> components        /**     *      */    private PatternModel getPatternModel() {        if (patternModel == null) {            patternModel = new PatternModel();            patternModel.addPropertyChangeListener(getPatternModelListener());        }        return patternModel;    }    /**     * creates and returns a PropertyChangeListener to the PatternModel.     *      * NOTE: the patternModel is totally under control of this class - currently     * there's no need to keep a reference to the listener.     *      * @return     */    private PropertyChangeListener getPatternModelListener() {        PropertyChangeListener l = new PropertyChangeListener() {            public void propertyChange(PropertyChangeEvent evt) {                if ("pattern".equals(evt.getPropertyName())) {                    refreshPatternMatchersFromModel();                }            }        };        return l;    }    /**     * callback method from listening to PatternModel.     *     */    protected void refreshPatternMatchersFromModel() {    }    private DocumentListener getSearchFieldListener() {        DocumentListener l = new DocumentListener() {            public void changedUpdate(DocumentEvent ev) {                // JW - really?? we've a PlainDoc without Attributes                refreshModelFromDocument();            }            public void insertUpdate(DocumentEvent ev) {                refreshModelFromDocument();            }            public void removeUpdate(DocumentEvent ev) {                refreshModelFromDocument();            }        };        return l;    }    /**     * callback method from listening to searchField.     *     */    protected void refreshModelFromDocument() {        getPatternModel().setRawText(searchField.getText());    }    private void bind() {        searchField.getDocument().addDocumentListener(getSearchFieldListener());        ActionContainerFactory factory = new ActionContainerFactory(null);        factory.configureButton(matchCheck,                 (AbstractActionExt) getAction(PatternModel.MATCH_CASE_ACTION_COMMAND),                null);        factory.configureButton(wrapCheck,                 (AbstractActionExt) getAction(MATCH_WRAP_ACTION_COMMAND),                null);        factory.configureButton(backCheck,                 (AbstractActionExt) getAction(MATCH_BACKWARDS_ACTION_COMMAND),                null);    }//--------------------- action callbacks    /**     * Action callback for Find action.     */    public void doFind() {        doFind(getPatternModel().isBackwards());    }    public void doFind(boolean backwards) {        if (searchable == null) return;        setLastIndex(searchable.search(getPattern(), getLastIndex(), backwards));        if (getLastIndex() == -1) {            boolean notFound = true;            if (isWrapping()) {                setLastIndex(searchable.search(getPattern(), -1, backwards));                notFound = getLastIndex() == -1;            }             if (notFound) {                JOptionPane.showMessageDialog(this, "Value not found");            }        }    }    private boolean isWrapping() {        return getPatternModel().isWrapping();    }    /**     * Action callback for Close action.

⌨️ 快捷键说明

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