List of usage examples for javax.swing Action actionPerformed
public void actionPerformed(ActionEvent e);
From source file:Main.java
public static boolean invoke(Action action, Object source) { if (action == null || !action.isEnabled()) { return false; }//from w w w . j a va 2 s.co m ActionEvent evt = new ActionEvent(source, ActionEvent.ACTION_PERFORMED, (String) action.getValue(Action.ACTION_COMMAND_KEY), 0); action.actionPerformed(evt); return true; }
From source file:Main.java
public Main() { editorPane.setDocument(doc);//from w ww .j a v a 2 s . c o m editorPane.setEditorKit(styledEditorKit); JScrollPane scrollpane = new JScrollPane(editorPane); scrollpane.setPreferredSize(new Dimension(500, 400)); JPanel comboPanel = new JPanel(); comboPanel.add(fontBox); setLayout(new BorderLayout()); add(scrollpane, BorderLayout.CENTER); add(comboPanel, BorderLayout.SOUTH); Document doc = editorPane.getDocument(); for (int i = 0; i < 20; i++) { int offset = doc.getLength(); String str = "This is line number: " + i + "\n"; try { doc.insertString(offset, str, null); } catch (BadLocationException e) { e.printStackTrace(); } } fontBox.addActionListener(e -> { int size = (Integer) fontBox.getSelectedItem(); Action fontAction = new StyledEditorKit.FontSizeAction(String.valueOf(size), size); fontAction.actionPerformed(e); }); }
From source file:edu.clemson.lph.civet.addons.VspsCviFile.java
public void importVspsFile(Window parent) { String sVspsDir = CivetConfig.getVspsDirPath(); File fDir = new File(sVspsDir); JFileChooser open = new JFileChooser(fDir); Action details = open.getActionMap().get("viewTypeDetails"); details.actionPerformed(null); open.setDialogTitle("Civet: Open PDF File"); open.setFileSelectionMode(JFileChooser.FILES_ONLY); open.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); open.setMultiSelectionEnabled(false); int resultOfFileSelect = open.showOpenDialog(parent); if (resultOfFileSelect == JFileChooser.APPROVE_OPTION) { File fIn = open.getSelectedFile(); saveme(parent, fIn);/*from www. jav a 2s . c o m*/ // vsps.printme(); } }
From source file:com.junichi11.netbeans.modules.backlog.issue.ui.AttachmentPanel.java
private void openLinkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openLinkButtonActionPerformed if (backlogAttachment != null) { Action openAction = backlogAttachment.getOpenAction(); openAction.actionPerformed(evt); }/*from w ww . j a v a 2 s. c o m*/ }
From source file:com.junichi11.netbeans.modules.backlog.issue.ui.AttachmentPanel.java
private void downloadLinkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadLinkButtonActionPerformed if (backlogAttachment != null) { Action saveAction = backlogAttachment.getSaveAction(); saveAction.actionPerformed(evt); }/* w w w . j av a 2s. co m*/ }
From source file:org.pgptool.gui.ui.keyslist.KeysTableView.java
private void safePerformAction(Action action, ActionEvent event) { if (action != null && action.isEnabled()) { action.actionPerformed(event); }//from w w w. j a v a 2 s . com }
From source file:DragPictureDemo2.java
public void actionPerformed(ActionEvent e) { if (focusOwner == null) return;//from w w w . j a v a 2 s . co m String action = (String) e.getActionCommand(); Action a = focusOwner.getActionMap().get(action); if (a != null) { a.actionPerformed(new ActionEvent(focusOwner, ActionEvent.ACTION_PERFORMED, null)); } }
From source file:org.nekorp.workflow.desktop.view.AppMainWindow.java
/** * call this somewhere in your GUI construction *///from w ww .j a va2 s.c om private void setupKeyShortcut() { KeyStroke key1 = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK); actionMap.put(key1, new AbstractAction("guardar") { @Override public void actionPerformed(ActionEvent e) { if (editorMonitor.hasChange()) { try { aplication.guardaServicio(); } catch (IllegalArgumentException ex) { //no lo guardo. } } } }); // key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK); // actionMap.put(key1, new AbstractAction("deshacer") { // @Override // public void actionPerformed(ActionEvent e) { // if (editorMonitor.hasChange()) { // editorMonitor.undo(); // } // } // }); // key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK); // actionMap.put(key1, new AbstractAction("rehacer") { // @Override // public void actionPerformed(ActionEvent e) { // editorMonitor.redo(); // } // }); // add more actions.. KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e); if (actionMap.containsKey(keyStroke)) { final Action a = actionMap.get(keyStroke); final ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), null); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { a.actionPerformed(ae); } }); return true; } return false; } }); }
From source file:au.org.ala.delta.editor.ui.CharacterTree.java
public CharacterTree() { setToggleClickCount(0);//from www. j ava 2 s.c o m _characterListBehaviour = new CharacterListBehaviour(); _stateListBehaviour = new StateListBehaviour(); ToolTipManager.sharedInstance().registerComponent(this); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (_doubleProcessingMouseEvent) { return; } if (!isEditing()) { int selectedRow = getClosestRowForLocation(e.getX(), e.getY()); if ((selectedRow >= 0) && (e.getClickCount() == 2) && SwingUtilities.isLeftMouseButton(e)) { Action action = getActionMap().get(SELECTION_ACTION_KEY); if (action != null) { action.actionPerformed(new ActionEvent(this, -1, "")); } } } } }); addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath selection = e.getNewLeadSelectionPath(); if (selection != null) { Object lastComponent = selection.getLastPathComponent(); if (lastComponent instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent; if (node.isLeaf()) { CharacterTree.super.setTransferHandler(_stateTransferHandler); } else { CharacterTree.super.setTransferHandler(_characterTransferHandler); } } } } }); ActionMap actionMap = Application.getInstance().getContext().getActionMap(this); javax.swing.Action find = actionMap.get("find"); if (find != null) { getActionMap().put("find", find); } javax.swing.Action findNext = actionMap.get("findNext"); if (findNext != null) { getActionMap().put("findNext", findNext); } getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), SELECTION_ACTION_KEY); }
From source file:fll.subjective.SubjectiveFrame.java
/** * Set the tab and return behavior for a table. *///from w w w . j a v a 2 s . c o m private void setupTabReturnBehavior(final JTable table) { final InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); // Have the enter key work the same as the tab key final KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); final KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); im.put(enter, im.get(tab)); // Override the default tab behavior // Tab to the next editable cell. When no editable cells goto next cell. final Action oldTabAction = table.getActionMap().get(im.get(tab)); final Action tabAction = new AbstractAction() { public void actionPerformed(final ActionEvent e) { if (null != oldTabAction) { oldTabAction.actionPerformed(e); } final JTable table = (JTable) e.getSource(); final int rowCount = table.getRowCount(); final int columnCount = table.getColumnCount(); int row = table.getSelectedRow(); int column = table.getSelectedColumn(); // skip the no show when tabbing while (!table.isCellEditable(row, column) || table.getColumnClass(column) == Boolean.class) { column += 1; if (column == columnCount) { column = 0; row += 1; } if (row == rowCount) { row = 0; } // Back to where we started, get out. if (row == table.getSelectedRow() && column == table.getSelectedColumn()) { break; } } table.changeSelection(row, column, false, false); } }; table.getActionMap().put(im.get(tab), tabAction); }