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

📄 editkeybindings.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        bindingsJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 1;        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;        gridBagConstraints.weightx = 1.0;        gridBagConstraints.weighty = 1.0;        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);        jPanel4.add(bindingsJList, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 0;        gridBagConstraints.gridheight = 3;        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;        gridBagConstraints.weightx = 1.0;        jPanel2.add(jPanel4, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 1;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.weightx = 1.0;        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);        editKeyBindingsPanel.add(jPanel2, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;        gridBagConstraints.weightx = 1.0;        gridBagConstraints.weighty = 1.0;        getContentPane().add(editKeyBindingsPanel, gridBagConstraints);        pack();    }// </editor-fold>//GEN-END:initComponents    // -------------------------------- Actions ----------------------------------    /**     * Resets a menu item back to its default key bindings     * @param evt the event     */    private void resetitemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetitemActionPerformed        // get currently selected node        EMenuItem item = getSelectedMenuItem();        if (item == null || item == EMenuItem.SEPARATOR || item instanceof EMenu) return;        // reset item to default bindings        menuBar.resetKeyBindings(item);        // update tree view and list box        DefaultTreeModel model = (DefaultTreeModel)commandsTree.getModel();        model.reload(getSelectedTreeNode());        updateListBox(item);    }//GEN-LAST:event_resetitemActionPerformed    /**     * Remove a key binding from the menu item     * @param evt the event     */    private void removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeActionPerformed        // get currently selected node        EMenuItem item = getSelectedMenuItem();        if (item == null || item == EMenuItem.SEPARATOR || item instanceof EMenu) {            JOptionPane.showMessageDialog(this, "Please select a menu item first", "Error", JOptionPane.ERROR_MESSAGE);            return;        }        // get selected key binding        KeyStrokePair pair = getListBoxSelected();        if (pair == null) {            JOptionPane.showMessageDialog(this, "Please select the shortcut from the list to remove", "Error", JOptionPane.ERROR_MESSAGE);            return;        }        // remove it and update view        menuBar.removeKeyBinding(item.getDescription(), pair);        DefaultTreeModel model = (DefaultTreeModel)commandsTree.getModel();        model.reload(getSelectedTreeNode());        updateListBox(item);    }//GEN-LAST:event_removeActionPerformed    /**     * Reset *All* menu items to their default Key Bindings     * @param evt the event     */    /**     * Open dialog to add a key binding to the selected menu item     * @param evt the event     */    private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed        EMenuItem item = getSelectedMenuItem();        if (item == null || item == EMenuItem.SEPARATOR || item instanceof EMenu) return;        EditKeyBinding dialog = new EditKeyBinding(item, menuBar, TopLevel.getCurrentJFrame(), true);		dialog.setVisible(true);        // update tree view        DefaultTreeModel model = (DefaultTreeModel)commandsTree.getModel();        model.reload(getSelectedTreeNode());        updateListBox(item);    }//GEN-LAST:event_addActionPerformed        /** Exit the Application */    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm    }//GEN-LAST:event_exitForm    // -------------------------------- Tree View Population -------------------------------    /** Build tree of menu commands */    private void buildCommandsTree() {        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();        // convert menuBar to tree        for (EMenuItem menu: menuBar.getItems()) {            DefaultMutableTreeNode menuNode = new DefaultMutableTreeNode(new KeyBoundTreeNode(menu));            rootNode.add(menuNode);            addMenu(menuNode, (EMenu)menu);        }        EMenu hiddenMenu = menuBar.getHiddenMenu();        if(hiddenMenu != null) {            DefaultMutableTreeNode menuNode = new DefaultMutableTreeNode(new KeyBoundTreeNode(hiddenMenu));            rootNode.add(menuNode);            addMenu(menuNode, hiddenMenu);        }                commandsTree.setModel(new DefaultTreeModel(rootNode));        // single selection as default		commandsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);		// do not show top-level		commandsTree.setRootVisible(false);		commandsTree.setShowsRootHandles(true);		commandsTree.setToggleClickCount(3);        commandsTree.addTreeSelectionListener(this);    }        /** Adds menu items to parentNode, which represents Menu menu. */    private void addMenu(DefaultMutableTreeNode parentNode, EMenu menu) {        for (EMenuItem menuItem: menu.getItems()) {            DefaultMutableTreeNode menuItemNode = new DefaultMutableTreeNode(new KeyBoundTreeNode(menuItem));            parentNode.add(menuItemNode);            if (menuItem instanceof EMenu)                addMenu(menuItemNode, (EMenu)menuItem);              // recurse        }    }    // ---------------------------- Tree Selection Listener -----------------------    /**     * Called when selection of Node in tree changes.     * It updates the list box to reflect the current tree selection.     */    public void valueChanged(javax.swing.event.TreeSelectionEvent e) {        TreePath path = e.getPath();        if (path == null) return;        Object obj = path.getLastPathComponent();        DefaultMutableTreeNode node = (DefaultMutableTreeNode)obj;        Object n = node.getUserObject();        if (!(n instanceof KeyBoundTreeNode)) return;        KeyBoundTreeNode treeNode = (KeyBoundTreeNode)n;        updateListBox(treeNode.getMenuItem());    }    // ------------------------------- List Box stuff -----------------------------    /**     * Update list box with item's key bindings     * @param item display key bindings for this item     */    private void updateListBox(EMenuItem item) {        if (item == null) {            bindingsJList.setListData(new Object [] {});            return;        }        KeyBindings bindings = menuBar.getKeyBindings(item);        if (bindings == null) {            bindingsJList.setListData(new Object [] {});            return;        }        ArrayList<KeyStrokePair> list = new ArrayList<KeyStrokePair>();        for (Iterator<KeyStrokePair> it = bindings.getKeyStrokePairs(); it.hasNext(); ) {            KeyStrokePair pair = it.next();            list.add(pair);        }        bindingsJList.setListData(list.toArray());    }    private KeyStrokePair getListBoxSelected() {        Object value = bindingsJList.getSelectedValue();        if (value == null) return null;        return (KeyStrokePair)value;    }    //-------------------------- Private Utility Methods ----------------------------    /**     * Get selected menu item in tree view     * @return the selected menu item, or null if none.     */    private EMenuItem getSelectedMenuItem() {        DefaultMutableTreeNode node = getSelectedTreeNode();        if (node == null) return null;        Object obj = node.getUserObject();        if (!(obj instanceof KeyBoundTreeNode)) return null;        KeyBoundTreeNode treeNode = (KeyBoundTreeNode)obj;        EMenuItem item = treeNode.getMenuItem();        return item;    }    /** get selected DefaultMutableTreeNode.     * Returns null if no valid DefaultMutableTree node selected in tree.     */    private DefaultMutableTreeNode getSelectedTreeNode() {        TreePath path = commandsTree.getSelectionPath();        if (path == null) return null;        DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();        return node;    }            // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton add;    private javax.swing.JList bindingsJList;    private javax.swing.JTree commandsTree;    private javax.swing.JPanel editKeyBindingsPanel;    private javax.swing.JLabel jLabel1;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel2;    private javax.swing.JPanel jPanel4;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JButton remove;    private javax.swing.JButton resetitem;    // End of variables declaration//GEN-END:variables    }

⌨️ 快捷键说明

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