Example usage for javax.swing JTree getInputMap

List of usage examples for javax.swing JTree getInputMap

Introduction

In this page you can find the example usage for javax.swing JTree getInputMap.

Prototype

public final InputMap getInputMap(int condition) 

Source Link

Document

Returns the InputMap that is used during condition.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTree tree = new JTree();
    InputMap inputMap = tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke[] keyStrokes = inputMap.allKeys();
    for (KeyStroke keyStroke : keyStrokes) {
        Object actionCommand = inputMap.get(keyStroke);
        System.out.println("keyStroke = " + keyStroke);
        System.out.println("actionCommand = " + actionCommand);
    }//  www  .j a v a2 s .  co m
}

From source file:org.apache.jmeter.gui.MainFrame.java

private void addQuickComponentHotkeys(JTree treevar) {
    Action quickComponent = new AbstractAction("Quick Component") {
        private static final long serialVersionUID = 1L;

        @Override//from  w  w  w . j a  va  2 s.  co m
        public void actionPerformed(ActionEvent actionEvent) {
            String propname = "gui.quick_" + actionEvent.getActionCommand();
            String comp = JMeterUtils.getProperty(propname);
            log.debug("Event " + propname + ": " + comp);

            if (comp == null) {
                log.warn("No component set through property: " + propname);
                return;
            }

            GuiPackage guiPackage = GuiPackage.getInstance();
            try {
                guiPackage.updateCurrentNode();
                TestElement testElement = guiPackage.createTestElement(SaveService.aliasToClass(comp));
                JMeterTreeNode parentNode = guiPackage.getCurrentNode();
                while (!MenuFactory.canAddTo(parentNode, testElement)) {
                    parentNode = (JMeterTreeNode) parentNode.getParent();
                }
                if (parentNode.getParent() == null) {
                    log.debug("Cannot add element on very top level");
                } else {
                    JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode);
                    guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath()));
                }
            } catch (Exception err) {
                log.warn("Failed to perform quick component add: " + comp, err); // $NON-NLS-1$
            }
        }
    };

    InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2,
            KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7,
            KeyStrokes.CTRL_8, KeyStrokes.CTRL_9, };
    for (int n = 0; n < keyStrokes.length; n++) {
        treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent);
        inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n));
    }
}