List of usage examples for javax.swing InputMap setParent
public void setParent(InputMap map)
From source file:DigitalClock.java
public DigitalClock() { // Set default values for our properties setFormat(DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale())); setUpdateFrequency(1000); // Update once a second // Specify a Swing TransferHandler object to do the dirty work of // copy-and-paste and drag-and-drop for us. This one will transfer // the value of the "time" property. Since this property is read-only // it will allow drags but not drops. setTransferHandler(new TransferHandler("time")); // Since JLabel does not normally support drag-and-drop, we need an // event handler to detect a drag and start the transfer. addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { getTransferHandler().exportAsDrag(DigitalClock.this, e, TransferHandler.COPY); }/* www . j a v a2s .c o m*/ }); // Before we can have a keyboard binding for a Copy command, // the component needs to be able to accept keyboard focus. setFocusable(true); // Request focus when we're clicked on addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { requestFocus(); } }); // Use a LineBorder to indicate when we've got the keyboard focus addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { setBorder(LineBorder.createBlackLineBorder()); } public void focusLost(FocusEvent e) { setBorder(null); } }); // Now bind the Ctrl-C keystroke to a "Copy" command. InputMap im = new InputMap(); im.setParent(getInputMap(WHEN_FOCUSED)); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "Copy"); setInputMap(WHEN_FOCUSED, im); // And bind the "Copy" command to a pre-defined Action that performs // a copy using the TransferHandler we've installed. ActionMap am = new ActionMap(); am.setParent(getActionMap()); am.put("Copy", TransferHandler.getCopyAction()); setActionMap(am); // Create a javax.swing.Timer object that will generate ActionEvents // to tell us when to update the displayed time. Every updateFrequency // milliseconds, this timer will cause the actionPerformed() method // to be invoked. (For non-GUI applications, see java.util.Timer.) timer = new Timer(updateFrequency, new ActionListener() { public void actionPerformed(ActionEvent e) { setText(getTime()); // set label to current time string } }); timer.setInitialDelay(0); // Do the first update immediately timer.start(); // Start timing now! }
From source file:org.docx4all.swing.text.WordMLEditorKit.java
private void initKeyBindings(JEditorPane editor) { ActionMap myActionMap = new ActionMap(); InputMap myInputMap = new InputMap(); KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK); myActionMap.put(insertSoftBreakAction, new InsertSoftBreakAction(insertSoftBreakAction)); myInputMap.put(ks, insertSoftBreakAction); ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); myActionMap.put(enterKeyTypedAction, new EnterKeyTypedAction(enterKeyTypedAction)); myInputMap.put(ks, enterKeyTypedAction); ks = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); myActionMap.put(deleteNextCharAction, new DeleteNextCharAction(deleteNextCharAction)); myInputMap.put(ks, deleteNextCharAction); ks = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0); myActionMap.put(deletePrevCharAction, new DeletePrevCharAction(deletePrevCharAction)); myInputMap.put(ks, deletePrevCharAction); myActionMap.setParent(editor.getActionMap()); myInputMap.setParent(editor.getInputMap()); editor.setActionMap(myActionMap);// ww w . ja v a 2 s . c o m editor.setInputMap(JComponent.WHEN_FOCUSED, myInputMap); }
From source file:org.trianacode.gui.hci.ApplicationFrame.java
/** * Initialises the panels in the main window *///from w ww .j a v a2 s .co m private void initLayout() { GUIEnv.setApplicationFrame(this); ColorManager.setDefaultColorModel(new TrianaColorModel()); ColorManager.registerColorModel(ScriptConstants.SCRIPT_RENDERING_HINT, new ScriptColorModel()); // do this after all other color loading ColorTable.instance().loadUserPrefs(); TaskGraphView defaultview = new TaskGraphView("Default View"); TrianaComponentModel compmodel = new TrianaComponentModel(tools, this, this); defaultview.setDefaultToolModel(compmodel); defaultview.setDefaultOpenGroupModel(compmodel); defaultview.registerToolModel(ScriptConstants.SCRIPT_RENDERING_HINT, new ScriptComponentModel()); defaultview.registerToolModel(TextToolConstants.TEXT_TOOL_RENDERING_HINT, new TextToolComponentModel()); defaultview.registerToolModel(HiddenToolConstants.HIDDEN_RENDERING_HINT, new HiddenComponentModel()); TaskGraphView mapview = new TaskGraphView("Map View", defaultview); mapview.registerOpenGroupModel(MapConstants.MAP_RENDERING_HINT, new MapComponentModel()); mapview.registerToolModel(MapConstants.MAP_LOCATION_RENDERING_HINT, new MapLocationComponentModel()); TaskGraphViewManager.setDefaultTaskGraphView(defaultview); TaskGraphViewManager.registerTaskGraphView(MapConstants.MAP_RENDERING_HINT, mapview); taskGraphFileHandler = new TaskGraphFileHandler(); trianaMenuBar = new TrianaMainMenu(this, tools); this.setJMenuBar(trianaMenuBar); TrianaShutdownHook shutDownHook = new TrianaShutdownHook(); Runtime.getRuntime().addShutdownHook(shutDownHook); getDesktopViewManager().addDesktopViewListener(this); this.workspace.add(getDesktopViewManager().getWorkspace(), BorderLayout.CENTER); ((TrianaMainMenu) trianaMenuBar).addHelp(); ToolTreeModel treemodel = new ToolTreeModel(tools); toolboxTree = new JTree(treemodel); toolboxTree.addFocusListener(this); toolboxTree.setCellRenderer(new TrianaTreeRenderer()); toolmonitor.setTree(toolboxTree); treemodel.addTreeModelListener(this); ToolTipManager.sharedInstance().registerComponent(toolboxTree); ToolTipManager.sharedInstance().setInitialDelay(TOOL_TIP_SHOW_DELAY); ToolTipManager.sharedInstance().setDismissDelay(TOOL_TIP_HIDE_DELAY); //set up key maps MainTrianaKeyMapFactory keymaps = new MainTrianaKeyMapFactory(this, ActionDisplayOptions.DISPLAY_NAME); InputMap inputMap = keymaps.getInputMap(); inputMap.setParent(this.getRootPane().getInputMap()); this.getRootPane().setInputMap(JComponent.WHEN_FOCUSED, inputMap); ActionMap actMap = keymaps.getActionMap(); actMap.setParent(this.getRootPane().getActionMap()); this.getRootPane().setActionMap(actMap); leaflistener = new LeafListener(toolboxTree, this, tools); keymaps = new MainTrianaKeyMapFactory(leaflistener, ActionDisplayOptions.DISPLAY_NAME); inputMap = keymaps.getInputMap(); inputMap.setParent(toolboxTree.getInputMap()); toolboxTree.setInputMap(JComponent.WHEN_FOCUSED, inputMap); actMap = keymaps.getActionMap(); actMap.setParent(toolboxTree.getActionMap()); toolboxTree.setActionMap(actMap); toolboxTree.addMouseListener(leaflistener); toolboxTree.addMouseMotionListener(leaflistener); //toolboxTree.setRootVisible(false); JPanel toolPanel = new JPanel(new BorderLayout()); SearchToolBar searchtoolbar = new SearchToolBar("Search", toolboxTree, treemodel); searchtoolbar.setFloatable(false); toolPanel.add(searchtoolbar, BorderLayout.NORTH); JScrollPane scroll = new JScrollPane(toolboxTree); toolPanel.add(scroll, BorderLayout.CENTER); JSplitPane verticalSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, toolPanel, workspace); TrianaToolBar toolbar = new TrianaToolBar("Main ToolBar", this); TrianaUnitToolBar unitToolbar = new TrianaUnitToolBar("Unit ToolBar"); toolbar.setRollover(true); unitToolbar.setRollover(true); JPanel innerpanel = new JPanel(); innerpanel.setLayout(new BoxLayout(innerpanel, BoxLayout.X_AXIS)); innerpanel.add(toolbar); innerpanel.add(Box.createHorizontalStrut(10)); innerpanel.add(unitToolbar); innerpanel.add(Box.createHorizontalGlue()); JPanel outerpanel = new JPanel(new BorderLayout()); outerpanel.add(innerpanel, BorderLayout.NORTH); outerpanel.add(verticalSplit, BorderLayout.CENTER); getContentPane().add(outerpanel); }