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

📄 propertieskeyshortcuts.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * PropertiesKeyShortcuts.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * 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.executequery.gui.prefs;import java.awt.Container;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.Collections;import java.util.Comparator;import java.util.Iterator;import java.util.Map;import java.util.Properties;import java.util.Set;import java.util.Vector;import javax.swing.Action;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.KeyStroke;import javax.swing.table.AbstractTableModel;import org.executequery.Constants;import org.executequery.GUIUtilities;import org.underworldlabs.swing.actions.BaseActionCommand;import org.underworldlabs.swing.actions.ActionBuilder;import org.executequery.util.SystemResources;import org.underworldlabs.util.MiscUtils;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the  *           release of version 3.0.0beta1 has meant a  *           resetting of CVS revision numbers. * ---------------------------------------------------------- *//** <p>Query Editor syntax highlighting preferences panel. * *  @author   Takis Diakoumis * @version  $Revision: 1.4 $ * @date     $Date: 2006/05/14 06:56:52 $ */public class PropertiesKeyShortcuts extends PropertiesBase                                    implements Constants {        private JTable table;    private Properties userDefinedShortcuts;    private ShortcutsTableModel tableModel;        private static String NONE = "<none>";    private static String delimiter = "+";        /** <p>Constructs a new instance. */    public PropertiesKeyShortcuts() {        try  {            jbInit();        }        catch (Exception e) {            e.printStackTrace();        }    }        /**     * Initializes the state of this instance.     */    private void jbInit() throws Exception {        Vector shortcuts = formatValues(ActionBuilder.getActions());        tableModel = new ShortcutsTableModel(shortcuts);        table = new JTable(tableModel);        table.setFont(PropertiesBase.panelFont);        table.addMouseListener(new MouseHandler());                table.setRowHeight(20);        table.setCellSelectionEnabled(true);        table.setColumnSelectionAllowed(false);        table.setRowSelectionAllowed(false);        table.getTableHeader().setResizingAllowed(false);        table.getTableHeader().setReorderingAllowed(false);                JPanel panel = new JPanel(new GridBagLayout());        GridBagConstraints gbc = new GridBagConstraints();        gbc.insets.left = 5;        gbc.anchor = GridBagConstraints.NORTHWEST;        panel.add(new JLabel("Keyboard Shortcuts:"), gbc);        gbc.fill = GridBagConstraints.BOTH;        gbc.insets.top = 10;        gbc.gridy = 1;        gbc.weighty = 1.0;        gbc.weightx = 1.0;        panel.add(new JScrollPane(table), gbc);                addContent(panel);                userDefinedShortcuts = SystemResources.getUserActionShortcuts();        if (userDefinedShortcuts != null) {            tableModel.loadUserDefined();        }    }            private Vector formatValues(Map actionMap) {        Set set = actionMap.keySet();        BaseActionCommand command = null;        Vector shortcuts = new Vector(actionMap.size());        for (Iterator i = set.iterator(); i.hasNext();) {            command = (BaseActionCommand)actionMap.get(i.next());                        if (command.isAcceleratorEditable()) {                shortcuts.add(                        new ShortcutKey(                                command.getActionId(),                                 (String)command.getValue(Action.NAME),                                (KeyStroke)command.getValue(Action.ACCELERATOR_KEY)));            }        }        Collections.sort(shortcuts, new ShortcutKeyComparator());        return shortcuts;    }        public void restoreDefaults() {        Vector shortcuts = formatValues(                ActionBuilder.reloadActions(Constants.ACTION_CONF_PATH));        tableModel.setShortcuts(shortcuts);    }         public void save() {                if (userDefinedShortcuts == null) {            userDefinedShortcuts = new Properties();        }        Vector shortcuts = tableModel.getShortcuts();        for (int i = 0, k = shortcuts.size(); i < k; i++) {            ShortcutKey shortcut = (ShortcutKey)shortcuts.elementAt(i);                        if (!MiscUtils.isNull(shortcut.keyStrokeText)) {                userDefinedShortcuts.setProperty(                        shortcut.key, shortcut.keyStrokeText);            }        }        SystemResources.setUserActionShortcuts(userDefinedShortcuts);    }            class ShortcutsTableModel extends AbstractTableModel {        private Vector shortcuts;        private String[] columnHeaders = {"Command", "Shortcut"};                ShortcutsTableModel(Vector shortcuts) {            this.shortcuts = shortcuts;        }                public void loadUserDefined() {            if (userDefinedShortcuts == null) {                 return;            }                        KeyStroke keyStroke = null;            for (int i = 0, k = shortcuts.size(); i < k; i++) {                ShortcutKey shortcut = (ShortcutKey)shortcuts.elementAt(i);                                if (userDefinedShortcuts.containsKey(shortcut.key)) {                    keyStroke = KeyStroke.getKeyStroke(                                    userDefinedShortcuts.getProperty(shortcut.key));                    shortcut.value = MiscUtils.keyStrokeToString(keyStroke);                }                            }        }                public void setShortcuts(Vector shortcuts) {            this.shortcuts = shortcuts;            fireTableDataChanged();        }                public int getColumnCount() {            return 2;        }                public int getRowCount() {            return shortcuts.size();        }                public Object getValueAt(int row, int col) {            ShortcutKey shortcut = (ShortcutKey)shortcuts.elementAt(row);                        switch(col) {                case 0:                    return shortcut.label;                case 1:                    return shortcut.value;                default:                    return null;            }        }                public ShortcutKey getShortcut(int index) {            return (ShortcutKey)shortcuts.elementAt(index);        }                public void updateShortcut(ShortcutKey shortcut, int row) {            shortcuts.set(row, shortcut);            fireTableRowsUpdated(row, row);        }                public void setValueAt(Object value, int row, int col) {            ShortcutKey shortcut = (ShortcutKey)shortcuts.elementAt(row);                        switch(col) {                case 0:                    shortcut.label = (String)value;                    break;                case 1:                    shortcut.value = (String)value;                    break;            }            fireTableRowsUpdated(row, row);        }                public boolean isCellEditable(int nRow, int nCol) {            return false;        }                public String getColumnName(int col) {            return columnHeaders[col];        }                public Vector getShortcuts() {            return shortcuts;        }            } // ShortcutsTableModel        class ShortcutDialog extends JDialog                          implements ActionListener {        private int row;        private ShortcutInputField shortcutField;        private ShortcutKey shortcutKey;                public ShortcutDialog(int row) {            super(GUIUtilities.getParentFrame(), "Select Shortcut", true);            this.row = row;            shortcutKey = (ShortcutKey)tableModel.getShortcut(row);            JButton okButton = new JButton("OK");            JButton clearButton = new JButton("Clear");            JButton cancelButton = new JButton("Cancel");                        okButton.addActionListener(this);            clearButton.addActionListener(this);            cancelButton.addActionListener(this);            shortcutField = new ShortcutInputField();            shortcutField.setPreferredSize(new Dimension(300, 20));            Container c = this.getContentPane();            c.setLayout(new GridBagLayout());            GridBagConstraints gbc = new GridBagConstraints();            gbc.gridy++;            gbc.insets = new Insets(10,10,5,10);            gbc.anchor = GridBagConstraints.NORTHWEST;            gbc.fill = GridBagConstraints.HORIZONTAL;            gbc.weightx = 1.0;            c.add(new JLabel("Enter a new shortcut for \"" +                     shortcutKey.label + "\":"), gbc);            gbc.gridy++;            gbc.insets.top = 0;            c.add(shortcutField, gbc);            gbc.gridy++;            c.add(new JLabel("Current assignment: " +                     (MiscUtils.isNull(shortcutKey.value) ? NONE :                         shortcutKey.value)), gbc);            gbc.gridy++;                        JPanel buttonPanel = new JPanel();            buttonPanel.add(okButton);            buttonPanel.add(clearButton);            buttonPanel.add(cancelButton);            gbc.weighty = 1.0;            gbc.insets.bottom = 10;            gbc.fill = GridBagConstraints.BOTH;

⌨️ 快捷键说明

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