@Override public void actionPerformed(ActionEvent e) { if (focusOwner == null) return; String action = e.getActionCommand(); Action a = focusOwner.getActionMap().get(action); if (a != null) { a.actionPerformed(new ActionEvent(focusOwner, ActionEvent.ACTION_PERFORMED, null)); } } }
protected JDialog createDialog(Component parent) { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); JDialog dialog = new JDialog(frame, ("Select Font"), true); Action okAction = new DialogOKAction(dialog); Action cancelAction = new DialogCancelAction(dialog); JButton okButton = new JButton(okAction); okButton.setFont(DEFAULT_FONT); JButton cancelButton = new JButton(cancelAction); cancelButton.setFont(DEFAULT_FONT); JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(2, 1)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10)); ActionMap actionMap = buttonsPanel.getActionMap(); actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction); actionMap.put(okAction.getValue(Action.DEFAULT), okAction); InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT)); inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT)); JPanel dialogEastPanel = new JPanel(); dialogEastPanel.setLayout(new BorderLayout()); dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST); dialog.pack(); dialog.setLocationRelativeTo(frame); return dialog; }
private JComponent createToolBar() { JPanel toolBar = new JPanel(); GroupLayout toolBarLayout = new GroupLayout(toolBar); toolBar.setLayout(toolBarLayout); openAction.setEnabled(true); JButton openButton = new JButton(openAction); saveAction = new SaveAction(); saveAction.setEnabled(false); JButton saveButton = new JButton(saveAction); JButton exportButton; if (solutionBusiness.hasExporter()) { exportAction = new ExportAction(); exportAction.setEnabled(false); exportButton = new JButton(exportAction); } else { JPanel solvePanel = new JPanel(new CardLayout()); solveAction = new SolveAction(); solveAction.setEnabled(false); solveButton = new JButton(solveAction); terminateSolvingEarlyAction = new TerminateSolvingEarlyAction(); terminateSolvingEarlyAction.setEnabled(false); terminateSolvingEarlyButton = new JButton(terminateSolvingEarlyAction); terminateSolvingEarlyButton.setVisible(false);
public void attach(Action action) { Reference<Action> d = delegate; if ((d == null) || (d.get() == action)) { return; } Action prev = d.get(); // reattaches to different action if (prev != null) { prev.removePropertyChangeListener(this); } this.delegate = new WeakReference<Action>(action); action.addPropertyChangeListener(this); }
public boolean isEnabled() { Action a = findAction(); if (a == null) { a = delegate; } // 40915 - hold last action weakly Action last = lastRef == null ? null : lastRef.get(); if (a != last) { if (last != null) { last.removePropertyChangeListener(weakL); } lastRef = new WeakReference<Action>(a); a.addPropertyChangeListener(weakL); } return a.isEnabled(); }
/** Perform the action. Tries the performer and then scans the ActionMap * of selected topcomponent. */ public void actionPerformed(final ActionEvent ev) { // First try global context action. final Action action = GlobalManager.getDefault().findGlobalAction(getActionMapKey(), getSurviveFocusChange()); if (action != null) { if (action.isEnabled()) { action.actionPerformed(ev); } else { Toolkit.getDefaultToolkit().beep(); } return; } final Object ap = getActionPerformer(); if (ap != null) { org.openide.util.actions.ActionInvoker.invokeAction( this, ev, asynchronous(), new Runnable() { public void run() { if (ap == getActionPerformer()) { getActionPerformer().performAction(CallbackSystemAction.this); } } } ); return; } Toolkit.getDefaultToolkit().beep(); }
public ClassListItem(Class<? extends T1> clz) { this.clz = clz; }
searchField.getDocument().addDocumentListener(documentListener); counterLabel = new JLabel(); counterLabel.setVisible(false); JButton nextButton = new JButton(); nextButton.setAction(nextAction); nextButton.setText("Next"); JButton previousButton = new JButton(); crossButton.setAction(closeAction); crossButton.setText("Done"); closeAction.setEnabled(false); panel = new JPanel(); panel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY)); panel.setBackground(new Color(230, 230, 230)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.addComponentListener(compListener); searchField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), closeAction);
searchPersonAction.putValue(Action.NAME, "Search"); JPanel searchInputPanel = new JPanel(); searchInputPanel.setLayout(new BorderLayout()); searchInputPanel.add(searchField, BorderLayout.CENTER); searchField.addActionListener(searchPersonAction); JPanel selectionOptionsPanel = new JPanel(); JButton showPersonDetailsButton = new JButton(personDetailsAction); selectionOptionsPanel.add(showPersonDetailsButton);
/** * Initializes this dialog. */ private void initDialog() { setMinimumSize( new Dimension( 640, 480 ) ); final JComponent settingsPane = createSettingsPane(); final JComponent previewPane = createPreviewPane(); final JPanel contentPane = new JPanel( new GridBagLayout() ); contentPane.add( settingsPane, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets( 2, 0, 2, 0 ), 0, 0 ) ); contentPane.add( previewPane, new GridBagConstraints( 1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets( 2, 0, 2, 0 ), 0, 0 ) ); final JButton runAnalysisButton = ToolUtils.createRunAnalysisButton( this ); this.runAnalysisAction = ( RestorableAction )runAnalysisButton.getAction(); final JButton exportButton = ToolUtils.createExportButton( this ); this.exportAction = exportButton.getAction(); this.exportAction.setEnabled( false ); final JButton closeButton = ToolUtils.createCloseButton(); this.closeAction = closeButton.getAction(); final JComponent buttons = SwingComponentUtils.createButtonPane( runAnalysisButton, exportButton, closeButton ); SwingComponentUtils.setupWindowContentPane( this, contentPane, buttons, runAnalysisButton ); }
if (mouseEvent.isPopupTrigger()) { JList<ItemList> list = (JList<ItemList>) mouseEvent.getSource(); mnSelectAll.setIcon(HelperUi.ICON_EMPTY); mnCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); mnCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); mnPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); mnSelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); Action action = this.dndList.getActionMap().get(TransferHandler.getCopyAction().getValue(Action.NAME)); if (action != null) { action.actionPerformed( new ActionEvent(this.dndList, ActionEvent.ACTION_PERFORMED, null) ); Action action = this.dndList.getActionMap().get(TransferHandler.getCutAction().getValue(Action.NAME)); if (action != null) { action.actionPerformed( new ActionEvent(this.dndList, ActionEvent.ACTION_PERFORMED, null) ); Action action = this.dndList.getActionMap().get(TransferHandler.getPasteAction().getValue(Action.NAME)); if (action != null) { action.actionPerformed( new ActionEvent(this.dndList, ActionEvent.ACTION_PERFORMED, null) );
.getValue(Action.NAME)); copy.addActionListener(new TregexGUI.TransferActionListener()); int mask = TregexGUI.isMacOSX() ? InputEvent.META_MASK : InputEvent.CTRL_MASK; copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, mask)); treePopup.add(copy); treeJP.setTransferHandler(new DisplayTransferHandler()); InputMap imap = treeJP.getInputMap(); imap.put(KeyStroke.getKeyStroke("ctrl C"), TransferHandler.getCopyAction().getValue(Action.NAME)); ActionMap map = treeJP.getActionMap(); map.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction()); return treeJP;
@Override public void mouseClicked(MouseEvent e) { if (e.getModifiers() == InputEvent.BUTTON3_MASK) { if (!(e.getSource() instanceof JTextComponent)) { return; textComponent = (JTextComponent) e.getSource(); textComponent.requestFocus(); undoAction.setEnabled(enabled && editable && (lastActionSelected == Actions.CUT || lastActionSelected == Actions.PASTE)); cutAction.setEnabled(enabled && editable && marked); copyAction.setEnabled(enabled && marked); pasteAction.setEnabled(enabled && editable && pasteAvailable); selectAllAction.setEnabled(enabled && nonempty); int nx = e.getX();
private void addToolbarAction(Action action) { JButton button = new JButton(action); button.setToolTipText((String)action.getValue(Action.NAME)); button.setText(null); button.setBorder(new EmptyBorder(4, 4, 4, 4)); toolbar.add(button); }
private void process(MouseEvent e) { textComponent.requestFocus(); boolean enabled = textComponent.isEnabled(); boolean editable = textComponent.isEditable(); boolean nonempty = !(textComponent.getText() == null || textComponent.getText().equals("")); boolean marked = textComponent.getSelectedText() != null; boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard() .getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor); undoAction.setEnabled(enabled && editable && undoManager.canUndo()); redoAction.setEnabled(enabled && editable && undoManager.canRedo()); cutAction.setEnabled(enabled && editable && marked); copyAction.setEnabled(enabled && marked); pasteAction.setEnabled(enabled && editable && pasteAvailable); deleteAction.setEnabled(enabled && editable && marked); selectAllAction.setEnabled(enabled && nonempty); int nx = e.getX(); if (nx > 500) { nx = nx - popup.getSize().width; } popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height); } }
openAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.open_action")); openAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK)); saveAllAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.save_all")); saveAllAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK)); exportAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.export_gradle")); exportAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK)); prefsAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.preferences")); prefsAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)); syncAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.sync")); syncAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_DOWN_MASK)); textSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.text_search")); textSearchAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)); clsSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.class_search")); clsSearchAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK)); deobfAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("preferences.deobfuscation")); deobfAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)); logAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.log")); logAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_L,
public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1 && choix.getSelectedComponent() != null && action.isEnabled()) { action.actionPerformed(new ActionEvent(choix, ActionEvent.ACTION_PERFORMED, "")); } } }
/** * Selects word based on a mouse event. */ private void selectWord(MouseEvent e) { if (selectedWordEvent != null && selectedWordEvent.getX() == e.getX() && selectedWordEvent.getY() == e.getY()) { // We've already the done selection for this. return; } Action a = null; RTextArea textArea = getTextArea(); ActionMap map = textArea.getActionMap(); if (map != null) { a = map.get(RTextAreaEditorKit.selectWordAction); } if (a == null) { if (selectWord == null) { selectWord = new RTextAreaEditorKit.SelectWordAction(); } a = selectWord; } a.actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, null, e.getWhen(), e.getModifiers())); selectedWordEvent = e; }
@Override public void actionPerformed(ActionEvent ae) { m_BayesNet.centerHorizontal(m_Selection.getSelected()); m_jStatusBar.setText(m_BayesNet.lastActionMsg()); a_undo.setEnabled(true); a_redo.setEnabled(false); repaint(); } } // class ActionCenterHorizontal
public void mouseClicked(MouseEvent e) { if (! e.isConsumed()) { int nclicks = e.getClickCount(); ActionMap map = textArea.getActionMap(); if (map != null) { a = map.get(RTextAreaEditorKit.selectLineAction); a.actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, null, e.getWhen(), e.getModifiers()));