protected void installKeyboardActions() { InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); if (inputMap != null) { SwingUtilities.replaceUIInputMap(desktop, JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap); } inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); if (inputMap != null) { SwingUtilities.replaceUIInputMap( desktop, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); } LazyActionMap.installLazyActionMap(desktop, BasicDesktopPaneUI.class, "DesktopPane.actionMap"); registerKeyboardActions(); }
protected void installKeyboardActions() { InputMap km = getMyInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km); km = getMyInputMap(JComponent.WHEN_FOCUSED); SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, km); ActionMap am = createMyActionMap(); SwingUtilities.replaceUIActionMap(tabPane, am); tabScroller.scrollForwardButton.setAction(am.get("scrollTabsForwardAction")); tabScroller.scrollBackwardButton.setAction(am.get("scrollTabsBackwardAction")); }
/** * A helper for creating and updating key bindings for components with mnemonics. The {@code * pressed} action will be invoked when the mnemonic is activated and the {@code released} action * will be invoked when the mnemonic is deactivated. * * <p>TODO establish an interface for the mnemonic properties, such as {@code MnemonicEnabled} and * change signature to {@code public static <T extends JComponent & MnemonicEnabled> void * updateMnemonicBinding(T c, String pressed, String released)} * * @param c the component bindings to update * @param pressed the name of the action in the action map to invoke when the mnemonic is pressed * @param released the name of the action in the action map to invoke when the mnemonic is * released (if the action is a toggle style, then this parameter should be {@code null}) * @throws NullPointerException if the component is {@code null} */ public static void updateMnemonicBinding(JComponent c, String pressed, String released) { Class<?> clazz = c.getClass(); int m = -1; try { Method mtd = clazz.getMethod("getMnemonic"); m = (Integer) mtd.invoke(c); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("unable to access mnemonic", e); } InputMap map = SwingUtilities.getUIInputMap(c, JComponent.WHEN_IN_FOCUSED_WINDOW); if (m != 0) { if (map == null) { map = new ComponentInputMapUIResource(c); SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_IN_FOCUSED_WINDOW, map); } map.clear(); // TODO is ALT_MASK right for all platforms? map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, false), pressed); map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, true), released); map.put(KeyStroke.getKeyStroke(m, 0, true), released); } else { if (map != null) { map.clear(); } } }
protected void installKeyboardActions() { InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); SwingUtilities.replaceUIInputMap(optionPane, JComponent.WHEN_IN_FOCUSED_WINDOW, map); LazyActionMap.installLazyActionMap(optionPane, BasicOptionPaneUI.class, "OptionPane.actionMap"); }
protected void uninstallListeners(JFileChooser fc) { if (propertyChangeListener != null) { fc.removePropertyChangeListener(propertyChangeListener); } fc.removePropertyChangeListener(getModel()); SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); SwingUtilities.replaceUIActionMap(fc, null); }
/** Installs the state needed for mnemonics. */ private void initMnemonics() { mnemonicToIndexMap = new Hashtable(); mnemonicInputMap = new InputMapUIResource(); mnemonicInputMap.setParent( SwingUtilities.getUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)); SwingUtilities.replaceUIInputMap( tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, mnemonicInputMap); }
/** * This method installs the keyboard actions for the JToolBar as specified by the look and feel. */ protected void installKeyboardActions() { // Install the input map. InputMap inputMap = (InputMap) SharedUIDefaults.get("ToolBar.ancestorInputMap"); SwingUtilities.replaceUIInputMap( toolBar, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); // FIXME: The JDK uses a LazyActionMap for parentActionMap SwingUtilities.replaceUIActionMap(toolBar, getActionMap()); }
protected void installListeners(JFileChooser fc) { propertyChangeListener = createPropertyChangeListener(fc); if (propertyChangeListener != null) { fc.addPropertyChangeListener(propertyChangeListener); } fc.addPropertyChangeListener(getModel()); InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); ActionMap actionMap = getActionMap(); SwingUtilities.replaceUIActionMap(fc, actionMap); }
// TODO accelerators for buttons private static void installAccelerator(Action action, final JButton button) { if (action.getValue(Action.ACCELERATOR_KEY) instanceof KeyStroke) { KeyStroke keyStroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); InputMap windowInputMap = SwingUtilities.getUIInputMap(button, JComponent.WHEN_IN_FOCUSED_WINDOW); if (windowInputMap == null) { windowInputMap = new ComponentInputMapUIResource(button); SwingUtilities.replaceUIInputMap(button, JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap); } windowInputMap.put(keyStroke, keyStroke.toString()); button.getActionMap().put(keyStroke.toString(), action); } }
@Override protected void installKeyboardActions() { super.installKeyboardActions(); JTextComponent comp = getComponent(); UIDefaults uidefaults = XToolkit.getUIDefaults(); String prefix = getPropertyPrefix(); InputMap map = (InputMap) uidefaults.get(prefix + ".focusInputMap"); if (map != null) { SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED, map); } }
private void uninstallTracking() { InputMap currMap = SwingUtilities.getUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED); if (currMap != null) { InputMap newMap = new InputMap(); KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i]; Object val = currMap.get(stroke); if (stroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)) && "flipTextSelection".equals(val)) { continue; } newMap.put(stroke, val); } SwingUtilities.replaceUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED, newMap); } this.jcomp.getActionMap().remove("flipTextSelection"); }
private void updateMnemonic(int lastMnemonic, int mnemonic) { if (mnemonic == lastMnemonic) { return; } InputMap windowInputMap = SwingUtilities.getUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW); int mask = SystemInfo.isMac ? InputEvent.ALT_MASK | InputEvent.CTRL_MASK : InputEvent.ALT_MASK; if (lastMnemonic != 0 && windowInputMap != null) { windowInputMap.remove(KeyStroke.getKeyStroke(lastMnemonic, mask, false)); } if (mnemonic != 0) { if (windowInputMap == null) { windowInputMap = new ComponentInputMapUIResource(this); SwingUtilities.replaceUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap); } windowInputMap.put(KeyStroke.getKeyStroke(mnemonic, mask, false), "doClick"); } }
private void installTracking() { InputMap currMap = SwingUtilities.getUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED); InputMap newMap = new InputMap(); if (currMap != null) { KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i]; Object val = currMap.get(stroke); newMap.put(stroke, val); } } newMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "flipTextSelection"); this.jcomp .getActionMap() .put( "flipTextSelection", new AbstractAction() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater( new Runnable() { public void run() { int selectionLength = jcomp.getSelectionEnd() - jcomp.getSelectionStart(); if (selectionLength == 0) { jcomp.selectAll(); } else { int lastPos = jcomp.getSelectionEnd(); jcomp.setSelectionStart(0); jcomp.setSelectionEnd(0); jcomp.setCaretPosition(lastPos); } } }); } }); SwingUtilities.replaceUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED, newMap); }
protected void uninstallKeyboardActions() { SwingUtilities.replaceUIInputMap(optionPane, JComponent.WHEN_IN_FOCUSED_WINDOW, null); SwingUtilities.replaceUIActionMap(optionPane, null); }
public DrawingPanel(UI ui_) { setBorder(BorderFactory.createTitledBorder("Network topology")); addComponentListener(this); this.drawingPanel = this; this.ui = ui_; colorMap = null; listOfNodes = new ArrayList<Node>(); listOfFlows = new ArrayList<Flow>(); sourceNodes = new ArrayList<Node>(); destNodes = new ArrayList<Node>(); currFlowID = 1; // Node node1 = new Machine("1", 200, 200); // Node node2 = new Machine("2", 300, 300); // Node node3 = new Primary("3", 400, 400); // node1.isSource = true; // node2.isDestination = true; // // node1.WLS_HW.add("08:11:96:8B:84:F4"); // node1.WLS_Name.add("wlan0"); // node1.ETH_IP = "00:11:22:33:44:55"; // node1.ETH_HW = "08:11:22:33:44:55"; // // node2.WLS_HW.add("08:11:96:8B:84:F3"); // node2.WLS_Name.add("wlan1"); // node2.ETH_IP = "00:11:22:33:44:56"; // node2.ETH_HW = "08:11:22:33:44:56"; // // node3.WLS_HW.add("08:11:96:8B:84:F2"); // node3.WLS_Name.add("wlan1"); // node3.ETH_IP = "00:11:22:33:44:57"; // node3.ETH_HW = "08:11:22:33:44:57"; // // source = node1; // destination = node2; // // listOfNodes.add(node1); // listOfNodes.add(node2); // listOfNodes.add(node3); addMouseListener(this); addMouseMotionListener(this); // Editing Modes. JPanel editingModes = new JPanel(); editingModes.setBorder(BorderFactory.createTitledBorder("")); selectionMode = new JToggleButton("Select"); primaryMode = new JToggleButton("Primary"); machineMode = new JToggleButton("Machine"); edgeMode = new JToggleButton("Edge"); InputMap keyMap = new ComponentInputMap(selectionMode); keyMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "selectionAction"); ActionMap actionMap = new ActionMapUIResource(); actionMap.put("selectionAction", new SelectionAction()); SwingUtilities.replaceUIActionMap(selectionMode, actionMap); SwingUtilities.replaceUIInputMap(selectionMode, JComponent.WHEN_IN_FOCUSED_WINDOW, keyMap); selectionMode.setToolTipText("Normal mode"); selectionMode.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { repaint(); } }); machineMode.setToolTipText("Add a machine node"); machineMode.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { repaint(); } }); primaryMode.setToolTipText("Add a primary user node"); primaryMode.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { repaint(); } }); edgeMode.setToolTipText("To add edge between 2 nodes, drag from a node to the other one"); edgeMode.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { repaint(); } }); modes = new ButtonGroup(); modes.add(selectionMode); modes.add(machineMode); modes.add(primaryMode); modes.add(edgeMode); selectionMode.setSelected(true); editingModes.add(selectionMode); editingModes.add(machineMode); editingModes.add(primaryMode); editingModes.add(edgeMode); add(editingModes); JPanel experimentTools = new JPanel(); experimentTools.setBorder(BorderFactory.createTitledBorder("")); setSourceButton = new JButton("Set Source"); setSourceButton.setToolTipText("Set the selected node as a source node"); setDestinationButton = new JButton("Set Destination"); setDestinationButton.setToolTipText("Set the selected node as a destination node"); setSourceButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (selectedNode != null && selectedNode instanceof Machine) { sourceNodes.add(selectedNode); lastSelectedSourceNode = selectedNode; selectedNode.setSource(true); repaint(); } } }); experimentTools.add(setSourceButton); setDestinationButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (selectedNode != null && selectedNode instanceof Machine) { destNodes.add(selectedNode); selectedNode.setDestination(true); lastSelectedSourceNode.destination = selectedNode; listOfFlows.add(new Flow(currFlowID, lastSelectedSourceNode, selectedNode)); lastSelectedSourceNode.setFlowID(currFlowID); selectedNode.setFlowID(currFlowID); ++currFlowID; repaint(); } } }); experimentTools.add(setDestinationButton); generate = new JButton("Generate"); generate.setToolTipText("Generate Configuration & module files for all nodes"); generate.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (sourceNodes.isEmpty()) { JOptionPane.showMessageDialog(drawingPanel, "Missing source node(s)."); return; } if (destNodes.isEmpty()) { JOptionPane.showMessageDialog(drawingPanel, "Missing destination node(s)."); return; } final JFileChooser fc = new JFileChooser(); int ret = fc.showDialog(drawingPanel, "Choose the source template"); if (ret != JFileChooser.APPROVE_OPTION) { JOptionPane.showMessageDialog(drawingPanel, "Missing source template."); return; } String sourceTemplate = fc.getSelectedFile().getAbsolutePath(); ret = fc.showDialog(drawingPanel, "Choose the hop template"); if (ret != JFileChooser.APPROVE_OPTION) { JOptionPane.showMessageDialog(drawingPanel, "Missing hop template."); return; } String hopTemplate = fc.getSelectedFile().getAbsolutePath(); ret = fc.showDialog(drawingPanel, "Choose the destination template"); if (ret != JFileChooser.APPROVE_OPTION) { JOptionPane.showMessageDialog(drawingPanel, "Missing destination template."); return; } String destinationTemplate = fc.getSelectedFile().getAbsolutePath(); ret = fc.showDialog(drawingPanel, "Choose the primary template"); if (ret != JFileChooser.APPROVE_OPTION) { JOptionPane.showMessageDialog(drawingPanel, "Missing primary template."); return; } String primaryTemplate = fc.getSelectedFile().getAbsolutePath(); NodeMaker nodeMaker = new NodeMaker(); PrimaryMaker primaryMaker = new PrimaryMaker(); ModuleMaker moduleMaker = new ModuleMaker(); // Generate the files from templates. try { // Generate the files for all the nodes. for (Node node : listOfNodes) { // Generate the configuration files for this node. if (node instanceof Primary) { primaryMaker.parseTemplateFile(primaryTemplate, (Primary) node); } else { Node[] adjacentNodes = new Node[node.adjacent.size()]; for (int i = 0; i < node.adjacent.size(); i++) adjacentNodes[i] = node.adjacent.get(i).to; // if(node == source){//Special treatment for the source node. if (node.isSource) { // Special treatment for the source node. // nodeMaker.parseTemplateFile(ui, sourceTemplate, source, destination, // node, adjacentNodes); // #SRC is not needed any more // #DEST is only in source template, and is for the destination corresponding to // this source nodeMaker.parseTemplateFile( ui, sourceTemplate, node.destination, node, adjacentNodes); // }else if(node == destination){//Special treatment for the destination // node. } else if (node.isDestination) { // Special treatment for the destination node. // nodeMaker.parseTemplateFile(ui, destinationTemplate, destination, // node, adjacentNodes); // nodeMaker.parseTemplateFile(ui, destinationTemplate, null, node, // adjacentNodes); nodeMaker.parseTemplateFile(ui, destinationTemplate, node, node, adjacentNodes); } else { // Rest of the nodes treated as hops. // nodeMaker.parseTemplateFile(ui, hopTemplate, null, node, // adjacentNodes); nodeMaker.parseTemplateFile(ui, hopTemplate, node, node, adjacentNodes); } } // Generate moduleMaker.generateModuleFile(node, listOfNodes, ui); } } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(drawingPanel, "Error generating nodes files."); return; } } }); experimentTools.add(generate); visualizeButton = new JToggleButton("Visualize"); visualizeButton.setToolTipText( "Visualize experiment and show statistics - Requires getting statistics first"); visualizeButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (!visualizeButton.isSelected()) { ui.attributesPanel.informationPanelCardLayout.show( ui.attributesPanel.informationPanel, Constants.nullAPCode); ui.attributesPanel.deactiveVisualization(); return; } ui.attributesPanel.informationPanelCardLayout.show( ui.attributesPanel.informationPanel, Constants.visualizeAPCode); ui.attributesPanel.activeVisualization(); sc = new StatisticsCollector(listOfNodes); for (Node node : listOfNodes) { // JFileChooser fc = new JFileChooser(); // int ret = fc.showDialog(drawingPanel, String.format("Choose Node:(%s) // statistics file.", node.name)); // if(ret != JFileChooser.APPROVE_OPTION){ // JOptionPane.showMessageDialog(drawingPanel, "Missing statistics file."); // visualizeButton.setSelected(false); // return; // } // Clear old stats node.totalSwitches = 0; // node.maxTotalSwitches = 0; node.averageNodalDelay = 0; node.averageSwitchingTime = 0; // node.maxAverageNodalDelay = 0; ui.attributesPanel.visualizationPanel.packetsColorModel.current.clear(); ui.attributesPanel.visualizationPanel.packetsColorTable.repaint(); // String statisticsFile = fc.getSelectedFile().getAbsolutePath(); String statisticsFile = "Statistics_" + node.name + ".txt"; if (node instanceof Machine) { sc.parseMachine(statisticsFile); } else if (node instanceof Primary) if (!((Primary) (node)).isVirtual) sc.parsePrimary(statisticsFile); } sc.calculate(); fillColorMap(); maxRange = (int) (sc.maxTimestamp - sc.minTimestamp); ui.attributesPanel.visualizationPanel.ticker.setMaximum(maxRange); ui.attributesPanel.visualizationPanel.ticker.setValue(0); ui.attributesPanel.visualizationPanel.ticker.setMajorTickSpacing(maxRange / 5); ui.attributesPanel.visualizationPanel.ticker.setMinorTickSpacing(maxRange / 50); ui.attributesPanel.visualizationPanel.ticker.setPaintTicks(true); ui.attributesPanel.visualizationPanel.ticker.setPaintLabels(true); } }); experimentTools.add(visualizeButton); add(experimentTools); }
protected void installKeyboardActions() { ActionMap map = getActionMap(); SwingUtilities.replaceUIActionMap(grid, map); InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); SwingUtilities.replaceUIInputMap(grid, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); }
protected void uninstallKeyboardActions() { unregisterKeyboardActions(); SwingUtilities.replaceUIInputMap(desktop, JComponent.WHEN_IN_FOCUSED_WINDOW, null); SwingUtilities.replaceUIInputMap(desktop, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); SwingUtilities.replaceUIActionMap(desktop, null); }
protected void uninstallKeyboardActions() { SwingUtilities.replaceUIActionMap(tabPane, null); SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, null); }