List of usage examples for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
To view the source code for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.
Click Source Link
registerKeyboardAction
that means that the command should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component. From source file:org.trzcinka.intellitrac.view.toolwindow.tickets.ticket_editor.NewAttachmentPopup.java
public NewAttachmentPopup(Window parent, Integer id) { super(parent); ticketId = id;//from w w w. j a va 2 s . com setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); buttonCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE contentPane.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); selectFileButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false); int ret = fc.showOpenDialog(contentPane); if (ret == JFileChooser.APPROVE_OPTION) { selectedFile = fc.getSelectedFile(); fileName.setText(selectedFile.getName()); buttonOK.setEnabled(true); pack(); } } }); }
From source file:pcgen.gui2.PCGenFrame.java
private void initComponents() { setLayout(new BorderLayout()); JComponent root = getRootPane(); root.setActionMap(actionMap);/* w ww . jav a 2s.c o m*/ root.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, createInputMap(actionMap)); characterTabs.add(new InfoGuidePane(this, uiContext)); setJMenuBar(new PCGenMenuBar(this, uiContext)); add(new PCGenToolBar(this), BorderLayout.NORTH); add(characterTabs, BorderLayout.CENTER); add(statusBar, BorderLayout.SOUTH); updateTitle(); setIconImage(Icons.PCGenApp.getImageIcon().getImage()); }
From source file:simplealbum.mvc.autocomplete.DController.java
private void configureKeyBoard() { reassignKeyStrokes(jTextPane, JComponent.WHEN_FOCUSED, "pressed ENTER", "shift pressed ENTER"); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed ENTER", new MyAction("pressed ENTER")); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed ESCAPE", new MyAction("DO_ESCAPE")); reassignKeyStrokes(jTextPane, JComponent.WHEN_FOCUSED, "pressed TAB", "shift pressed TAB"); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed TAB", new MyAction("DO_TAB")); reassignKeyStrokes(jTextPane, JComponent.WHEN_FOCUSED, "pressed UP", "alt UP"); reassignKeyStrokes(jScrollPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, "pressed UP", "alt UP"); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed UP", new MyAction("DO_UP")); reassignKeyStrokes(jTextPane, JComponent.WHEN_FOCUSED, "pressed DOWN", "alt DOWN"); reassignKeyStrokes(jScrollPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, "pressed DOWN", "alt DOWN"); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed DOWN", new MyAction("DO_DOWN")); reassignKeyStrokes(jTextPane, JComponent.WHEN_FOCUSED, "pressed PAGE_UP", "alt PAGE_UP"); reassignKeyStrokes(jScrollPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, "pressed PAGE_UP", "alt PAGE_UP"); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed PAGE_UP", new MyAction("DO_PAGE_UP")); reassignKeyStrokes(jTextPane, JComponent.WHEN_FOCUSED, "pressed PAGE_DOWN", "alt PAGE_DOWN"); reassignKeyStrokes(jScrollPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, "pressed PAGE_DOWN", "alt PAGE_DOWN"); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed PAGE_DOWN", new MyAction("DO_PAGE_DOWN")); assignKeyStrokes(view.getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, "pressed F5", new MyAction("pressed F5")); }
From source file:utybo.branchingstorytree.swing.editor.StoryEditor.java
public StoryEditor(BranchingStory baseStory) throws BSTException { setLayout(new MigLayout("hidemode 3", "[grow]", "[][grow]")); JToolBar toolBar = new JToolBar(); toolBar.setBorder(null);//from w w w . j ava2s . com toolBar.setFloatable(false); add(toolBar, "cell 0 0,growx"); JButton btnSaveAs = new JButton(Lang.get("saveas"), new ImageIcon(Icons.getImage("Save As", 16))); btnSaveAs.addActionListener(e -> { saveAs(); }); toolBar.add(btnSaveAs); JButton btnSave = new JButton(Lang.get("save"), new ImageIcon(Icons.getImage("Save", 16))); btnSave.addActionListener(e -> { save(); }); toolBar.add(btnSave); JButton btnPlay = new JButton(Lang.get("play"), new ImageIcon(Icons.getImage("Circled Play", 16))); btnPlay.addActionListener(ev -> { try { String s = exportToString(); File f = Files.createTempDirectory("openbst").toFile(); File bstFile = new File(f, "expoted.bst"); try (FileOutputStream fos = new FileOutputStream(bstFile);) { IOUtils.write(s, fos, StandardCharsets.UTF_8); } OpenBSTGUI.getInstance().openStory(bstFile); } catch (Exception e) { OpenBST.LOG.error("Export failed", e); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.exportfail"), e); } }); toolBar.add(btnPlay); JButton btnFilePreview = new JButton(Lang.get("editor.exportpreview"), new ImageIcon(Icons.getImage("PreviewText", 16))); btnFilePreview.addActionListener(e -> { try { String s = exportToString(); JDialog dialog = new JDialog(OpenBSTGUI.getInstance(), Lang.get("editor.exportpreview")); JTextArea jta = new JTextArea(s); jta.setLineWrap(true); jta.setWrapStyleWord(true); dialog.add(new JScrollPane(jta)); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setSize((int) (Icons.getScale() * 350), (int) (Icons.getScale() * 300)); dialog.setLocationRelativeTo(OpenBSTGUI.getInstance()); dialog.setVisible(true); } catch (Exception x) { OpenBST.LOG.error("Failed to preview", x); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.previewerror"), x); } }); toolBar.add(btnFilePreview); Component horizontalGlue = Box.createHorizontalGlue(); toolBar.add(horizontalGlue); JButton btnClose = new JButton(Lang.get("close"), new ImageIcon(Icons.getImage("Cancel", 16))); btnClose.addActionListener(e -> { askClose(); }); toolBar.add(btnClose); for (final Component component : toolBar.getComponents()) { if (component instanceof JButton) { ((JButton) component).setHideActionText(false); ((JButton) component).setToolTipText(((JButton) component).getText()); ((JButton) component).setText(""); } } JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setTabPlacement(JTabbedPane.LEFT); add(tabbedPane, "cell 0 1,grow"); tabbedPane.addTab("Beta Warning", new StoryEditorWelcomeScreen()); details = new StoryDetailsEditor(this); tabbedPane.addTab(Lang.get("editor.details"), details); nodesEditor = new StoryNodesEditor(); tabbedPane.addTab(Lang.get("editor.nodes"), nodesEditor); this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control S"), "doSave"); this.getActionMap().put("doSave", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { save(); } }); importFrom(baseStory); }