List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction()
From source file:Main.java
private void addKeyBindings(JComponent c) { c.getInputMap(JComboBox.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("ENTER"), "doSomething"); c.getActionMap().put("doSomething", new AbstractAction() { @Override//from w ww . ja v a 2 s . com public void actionPerformed(ActionEvent e) { Object selectedItem = comboBox.getSelectedItem(); if (selectedItem != null) { model.addElement((String) selectedItem); } } }); }
From source file:Main.java
public static void setDontSaveButton(final JRootPane rp, final JButton b) { rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0), "dontSave"); rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_D, rp.getToolkit().getMenuShortcutKeyMask()), "dontSave"); rp.getActionMap().put("dontSave", new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent ev) { b.doClick();//from w w w . j a v a2 s .c o m } }); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopLink.java
public DesktopLink() { impl = new JXHyperlink(); impl.setAction(new AbstractAction() { @Override//from w ww .ja v a2s.co m public void actionPerformed(ActionEvent e) { String targetUrl = DesktopLink.this.url; if (StringUtils.isNotEmpty(targetUrl)) { DesktopWindowManager wm = App.getInstance().getMainFrame().getWindowManager(); wm.showWebPage(targetUrl, Collections.<String, Object>emptyMap()); } } }); }
From source file:maltcms.ui.fileHandles.serialized.JFCView.java
/** * */// www . jav a2 s .c om public JFCView() { this.jfcv = new JFCPanel(); Action doNothing = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { //do nothing } }; this.jfcv.getActionMap().put("doNothing", doNothing); }
From source file:com.github.alexfalappa.nbspringboot.codegen.SpringDependencyDialog.java
/** Creates new form NewOkCancelDialog */ public SpringDependencyDialog(java.awt.Frame parent) { super(parent, true); initComponents();//www . j a v a 2 s. c om // Close the dialog when Esc is pressed String cancelName = "cancel"; InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = rootPane.getActionMap(); actionMap.put(cancelName, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { doClose(RET_CANCEL); } }); }
From source file:com.emr.schemas.SavedProcessesDataMover.java
/** * Constructor/*ww w .j av a 2 s.c om*/ */ public SavedProcessesDataMover() { initComponents(); this.setClosable(true); final Action processDelete = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String foreignKeysTable = (String) tblProcesses.getModel().getValueAt(modelRow, 0); if (foreignKeysTable == null || "".equals(foreignKeysTable)) { JOptionPane.showMessageDialog(null, "Table is Empty", "Empty Table", JOptionPane.ERROR_MESSAGE); } else { } } }; final SQLiteGetProcesses sp = new SQLiteGetProcesses(); sp.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { switch (event.getPropertyName()) { case "progress": System.out.println("Fetching data from db"); break; case "state": switch ((SwingWorker.StateValue) event.getNewValue()) { case DONE: try { model = sp.get(); tblProcesses.setModel(model); tblProcesses.getColumnModel().getColumn(0).setMaxWidth(300); //hide irrelevant columns tblProcesses.getColumnModel().getColumn(2).setMinWidth(0); tblProcesses.getColumnModel().getColumn(2).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(3).setMinWidth(0); tblProcesses.getColumnModel().getColumn(3).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(4).setMinWidth(0); tblProcesses.getColumnModel().getColumn(4).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(5).setMinWidth(0); tblProcesses.getColumnModel().getColumn(5).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(6).setMinWidth(0); tblProcesses.getColumnModel().getColumn(6).setMaxWidth(0); ButtonColumn buttonColumn = new ButtonColumn(tblProcesses, processDelete, 7, "Delete"); } catch (final CancellationException ex) { Logger.getLogger(SavedProcessesDataMover.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(SavedProcessesDataMover.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(SavedProcessesDataMover.class.getName()).log(Level.SEVERE, null, ex); } break; } break; } } }); sp.execute(); tblProcesses.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { JTable target = (JTable) e.getSource(); int rowIndex = target.getSelectedRow(); String selectQry = (String) target.getModel().getValueAt(rowIndex, 2); String destinationTable = (String) target.getModel().getValueAt(rowIndex, 3); String truncateFirst = (String) target.getModel().getValueAt(rowIndex, 4); String destinationColumns = (String) target.getModel().getValueAt(rowIndex, 5); String columnsToBeMapped = (String) target.getModel().getValueAt(rowIndex, 6); lblUpdateText.setText("<html><b color='red'>Moving Data</b></html>"); dbProgressBar.setIndeterminate(true); new DBUpdater(selectQry, destinationTable, truncateFirst, destinationColumns, columnsToBeMapped) .execute(); } } @Override public void mousePressed(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseReleased(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseEntered(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseExited(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); }
From source file:org.openconcerto.erp.core.supplychain.order.element.CommandeSQLElement.java
public CommandeSQLElement() { super("COMMANDE", "une commande fournisseur", "commandes fournisseur"); // Transfert vers facture PredicateRowAction factureAction = new PredicateRowAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { CommandeSQLElement.this.transfertFacture(IListe.get(e).getSelectedRow().getID()); }//ww w .j a v a 2 s . co m }, false, "supplychain.order.create.purchase"); factureAction.setPredicate(IListeEvent.getSingleSelectionPredicate()); getRowActions().add(factureAction); }
From source file:networkmonitor.MainIBMApplicationForm.java
public MainIBMApplicationForm() { setSize(850, 320); //set size setTitle("Network Monitor");//Setting the title setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Setting the action close to the close button //............menu........... /* JMenuBar menuBar = new JMenuBar(); //from w w w . j a v a 2 s . c o m // Add the menubar to the frame setJMenuBar(menuBar); // Define and add two drop down menu to the menubar JMenu about = new JMenu(""); menuBar.add(about); menuBar.add(Box.createHorizontalGlue()); JMenu version = new JMenu(""); menuBar.add(version);*/ //.................. series1 = new XYSeries("b/w usage in KBps"); dataset = createDataset(); chart = createChart(dataset); chartPanel = new ChartPanel(chart); //chartPanel.setPreferredSize(new java.awt.Dimension(850, 320)); // chartPanel.setLayout(); chartPanel.add(current_bandwidth_label); setContentPane(chartPanel); pmt = new PacketMonitoringThread(); pmt.start(); Action updateCursorAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { int current_bandwidth = new Integer((int) TcpPacketCapturer.getPacketSizeTillNowAndResetSize()); qe.add(current_bandwidth); current_bandwidth_label.setText("" + current_bandwidth); if (qe.size() > 20) { System.out.println(qe.poll()); } dataset = createDataset(); chart = createChart(dataset); chartPanel = new ChartPanel(chart); // getContentPane().repaint(); // SwingUtilities.updateComponentTreeUI(chartPanel); } }; // its timer, it works like sleep, and in this apps its give you Internet speed KB/sec. new Timer(1000, updateCursorAction).start(); }
From source file:GUI.MainJF.java
public void LlenarTabla() { String[] columnNames = { "ID", "Nombre", "Email", "Edad", "Tipo", "", "" }; Object[][] data = null;/*from w w w . j a v a 2 s .c o m*/ DefaultTableModel model = new DefaultTableModel(data, columnNames); HttpResponse response; response = JSON.request(Config.URL + "usuarios/listar.json"); JSONObject jObject = JSON.JSON(response); try { JSONArray jsonArr = jObject.getJSONArray("data"); for (int i = 0; i < jsonArr.length(); i++) { JSONObject data_json = jsonArr.getJSONObject(i); model.addRow( new Object[] { data_json.get("idUsuario").toString(), data_json.get("nombre").toString(), data_json.get("email").toString(), data_json.get("edad").toString(), data_json.get("descripcion").toString(), "Editar", "Eliminar" }); } } catch (Exception e) { e.printStackTrace(); } tb_usuarios.setModel(model); Action editar = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0); String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1); String email = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 2); String edad = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 3); String tipo = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 4); FormUsuarios U = new FormUsuarios(); U.setID(id); U.setNombre(nombre); U.setEmail(email); U.setEdad(edad); U.setTipo(tipo); U.setLocationRelativeTo(null); U.setVisible(true); } }; ButtonColumn botonEditar = new ButtonColumn(tb_usuarios, editar, 5); botonEditar.setMnemonic(KeyEvent.VK_D); Action eliminar = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0); String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1); int rs = JOptionPane.showConfirmDialog(null, "Estas seguro que deseas eliminas el usuario: " + nombre + " ?", "Eliminar", JOptionPane.YES_NO_OPTION); if (rs == JOptionPane.YES_OPTION) { List<NameValuePair> parametros = new ArrayList<NameValuePair>(); parametros.add(new BasicNameValuePair("idUsuario", id)); HttpResponse response = JSON.request(Config.URL + "usuarios/eliminar.json", parametros); JSONObject jObject = JSON.JSON(response); int code = Integer.parseInt(jObject.get("code").toString()); /*if(code == 201){ JOptionPane.showMessageDialog(null, "Usuario eliminado"); //((DefaultTableModel)table.getModel()).removeRow(modelRow); }else{ JOptionPane.showMessageDialog(null, "Error eliminar Usuario"); }*/ } } }; ButtonColumn botonEliminar = new ButtonColumn(tb_usuarios, eliminar, 6); botonEliminar.setMnemonic(KeyEvent.VK_D); model.fireTableDataChanged(); }
From source file:FileTree2.java
public FileTree2() { super("Directories Tree [Popup Menus]"); setSize(400, 300);/*from www . j a v a 2s. c o m*/ DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer")); DefaultMutableTreeNode node; File[] roots = File.listRoots(); for (int k = 0; k < roots.length; k++) { node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k]))); top.add(node); node.add(new DefaultMutableTreeNode(new Boolean(true))); } m_model = new DefaultTreeModel(top); m_tree = new JTree(m_model); m_tree.putClientProperty("JTree.lineStyle", "Angled"); TreeCellRenderer renderer = new IconCellRenderer(); m_tree.setCellRenderer(renderer); m_tree.addTreeExpansionListener(new DirExpansionListener()); m_tree.addTreeSelectionListener(new DirSelectionListener()); m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); m_tree.setShowsRootHandles(true); m_tree.setEditable(false); JScrollPane s = new JScrollPane(); s.getViewport().add(m_tree); getContentPane().add(s, BorderLayout.CENTER); m_display = new JTextField(); m_display.setEditable(false); getContentPane().add(m_display, BorderLayout.NORTH); // NEW m_popup = new JPopupMenu(); m_action = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (m_clickedPath == null) return; if (m_tree.isExpanded(m_clickedPath)) m_tree.collapsePath(m_clickedPath); else m_tree.expandPath(m_clickedPath); } }; m_popup.add(m_action); m_popup.addSeparator(); Action a1 = new AbstractAction("Delete") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree2.this, "Delete option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a1); Action a2 = new AbstractAction("Rename") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree2.this, "Rename option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a2); m_tree.add(m_popup); m_tree.addMouseListener(new PopupTrigger()); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }