List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java
public static void show() throws JSONException { final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true); dialog.setSize(400, 250);/*from w w w .j ava 2 s. co m*/ dialog.setLocationRelativeTo(Server.currentServer.frame); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel cp = new JPanel(new SpringLayout()); cp.add(new JLabel("Zielverzeichnis:")); JPanel panel = new JPanel(); final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path") ? Server.currentServer.settings.getString("backup.path") : ""), 10); panel.add(path); panel.add(new JButton(new AbstractAction("Whlen...") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText()) : new File(System.getProperty("user.home")))); jfc.setFileHidingEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Backup-Zielverzeichnis whlen"); if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) path.setText(jfc.getSelectedFile().getPath().replace("\\", "/")); } })); cp.add(panel); cp.add(new JLabel("")); cp.add(new JLabel("")); cp.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); cp.add(new JButton(new AbstractAction("Speichern") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { if (path.getText().length() > 0) Server.currentServer.settings.put("backup.path", path.getText()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } })); SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6); dialog.setContentPane(cp); dialog.pack(); dialog.setVisible(true); }
From source file:org.jcurl.core.gui.DtoDialogDemo.java
public DtoDialogDemo() { final Container con = getContentPane(); final JFrame fr = this; con.add(new JButton(new AbstractAction("Edit") { private static final long serialVersionUID = -508686443887297017L; public void actionPerformed(final ActionEvent evt) { if (dialog == null) dialog = new DtoDialog(data, fr); dialog.setVisible(true);// ww w . j a v a 2s . co m } }), "Center"); }
From source file:cool.pandora.modeller.ui.BagInfoInputPane.java
/** * BagInfoInputPane.// w ww. j av a 2 s .c o m * * @param bagView BagView */ public BagInfoInputPane(final BagView bagView) { this.bagView = bagView; this.defaultBag = bagView.getBag(); populateForms(defaultBag); final InputMap im = this.getInputMap(); im.put(KeyStroke.getKeyStroke("F2"), "tabNext"); final ActionMap am = this.getActionMap(); am.put("tabNext", new AbstractAction("tabNext") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(final ActionEvent evt) { final int selected = getSelectedIndex(); final int count = getComponentCount(); if (selected >= 0 && selected < count - 1) { setSelectedIndex(selected + 1); } else { setSelectedIndex(0); } invalidate(); repaint(); } }); this.setActionMap(am); }
From source file:org.openconcerto.erp.core.finance.accounting.ui.AjouterComptePCGtoPCEFrame.java
public AjouterComptePCGtoPCEFrame() { super("Ajouter un compte du plan comptable gnral"); Container f = this.getContentPane(); // instanciation du panel et du menu click droit associ Vector<AbstractAction> actionClickDroitTable = new Vector<AbstractAction>(); actionClickDroitTable.add(new AbstractAction("Ajouter au PCE") { public void actionPerformed(ActionEvent e) { ajoutCompteSelected();/*from w ww. j a v a 2 s .c om*/ } }); this.planPanel = new PlanComptableGPanel(actionClickDroitTable); this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(12, 2, 12, 2); c.gridx = 0; c.gridy = 0; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTHWEST; c.gridwidth = 2; c.gridheight = 1; JLabel label = new JLabel("Choississez le ou les comptes ajouter au Plan Comptable Entreprise"); label.setHorizontalAlignment(SwingConstants.CENTER); f.add(label, c); /******************************************************************************************* * * Affichage du plan comptable entreprise ******************************************************************************************/ c.insets = new Insets(0, 0, 0, 0); c.gridwidth = 2; c.gridheight = 1; c.weightx = 1; c.weighty = 1; c.gridy++; f.add(this.planPanel, c); /******************************************************************************************* * * Bouton ajout / fermer ******************************************************************************************/ c.insets = new Insets(2, 2, 1, 2); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; c.gridy++; c.gridx = 0; c.anchor = GridBagConstraints.SOUTHEAST; f.add(this.boutonAjout, c); this.boutonAjout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ajoutCompteSelected(); } }); c.gridx++; f.add(this.boutonClose, c); this.boutonClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AjouterComptePCGtoPCEFrame.this.setVisible(false); AjouterComptePCGtoPCEFrame.this.dispose(); } }); /* * this.pack(); this.setVisible(true); */ }
From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java
public static void show(ClientFrame frame, final JSONArray data) { final JDialog dialog = new JDialog(frame, "Katalog whlen", true); dialog.setSize(400, 300);/*from ww w .ja v a2 s. c o m*/ dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Client.currentClient.disconnect(); System.exit(0); } }); JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); dialog.setContentPane(contentPane); DefaultListModel dlm = new DefaultListModel(); for (int i = 0; i < data.length(); i++) { try { dlm.addElement(data.getJSONObject(i).getString("name")); } catch (JSONException e) { e.printStackTrace(); } } final JList catalogs = new JList(dlm); catalogs.setDragEnabled(false); catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); jsp.setPreferredSize(new Dimension(396, 200)); contentPane.add(jsp); JPanel mods = new JPanel(new GridLayout(1, 2)); mods.setPreferredSize(new Dimension(50, 22)); mods.add(new JButton(new AbstractAction("+") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(dialog, "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen", JOptionPane.PLAIN_MESSAGE); if (name != null && name.length() > 0) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); for (int i = 0; i < dlm.getSize(); i++) { if (dlm.get(i).toString().equals(name)) { JOptionPane.showMessageDialog(dialog, "Es existert bereits ein Katalog mit diesem Namen!", "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE); actionPerformed(e); return; } } try { dlm.addElement(name); JSONObject o = new JSONObject(); o.put("name", name); o.put("sources", new JSONArray()); o.put("tags", new JSONArray()); data.put(o); Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (Exception e1) { e1.printStackTrace(); } } } })); mods.add(new JButton(new AbstractAction("-") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { if (JOptionPane.showConfirmDialog(dialog, "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?", "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); data.remove(catalogs.getSelectedIndex()); dlm.remove(catalogs.getSelectedIndex()); try { Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (IOException e1) { e1.printStackTrace(); } } } } })); contentPane.add(mods); JLabel l = new JLabel(""); l.setPreferredSize(new Dimension(396, 14)); contentPane.add(l); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); sep.setPreferredSize(new Dimension(396, 10)); contentPane.add(sep); JPanel buttons = new JPanel(new GridLayout(1, 2)); buttons.setPreferredSize(new Dimension(396, 22)); buttons.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Client.currentClient.disconnect(); System.exit(0); } })); buttons.add(new JButton(new AbstractAction("Katalog whlen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { try { Client.currentClient .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex()))); Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } } })); dialog.add(buttons); dialog.setLocationRelativeTo(frame); dialog.setResizable(false); dialog.setVisible(true); }
From source file:com.planetmayo.debrief.satc.util.StraightLineCullingTestForm.java
private void createMenu() { JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Load") { private static final long serialVersionUID = 1L; @Override/*from w w w . j av a 2 s. co m*/ public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(StraightLineCullingTestForm.this) == JFileChooser.APPROVE_OPTION) { try { loadFile(fc.getSelectedFile()); } catch (IOException ex) { } } } }); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:MenuTest.java
public MenuFrame() { setTitle("MenuTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); fileMenu.add(new TestAction("New")); // demonstrate accelerators JMenuItem openItem = fileMenu.add(new TestAction("Open")); openItem.setAccelerator(KeyStroke.getKeyStroke("ctrl O")); fileMenu.addSeparator();/*w ww. j ava2s . com*/ saveAction = new TestAction("Save"); JMenuItem saveItem = fileMenu.add(saveAction); saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S")); saveAsAction = new TestAction("Save As"); fileMenu.add(saveAsAction); fileMenu.addSeparator(); fileMenu.add(new AbstractAction("Exit") { public void actionPerformed(ActionEvent event) { System.exit(0); } }); // demonstrate check box and radio button menus readonlyItem = new JCheckBoxMenuItem("Read-only"); readonlyItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { boolean saveOk = !readonlyItem.isSelected(); saveAction.setEnabled(saveOk); saveAsAction.setEnabled(saveOk); } }); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert"); insertItem.setSelected(true); JRadioButtonMenuItem overtypeItem = new JRadioButtonMenuItem("Overtype"); group.add(insertItem); group.add(overtypeItem); // demonstrate icons Action cutAction = new TestAction("Cut"); cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif")); Action copyAction = new TestAction("Copy"); copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif")); Action pasteAction = new TestAction("Paste"); pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif")); JMenu editMenu = new JMenu("Edit"); editMenu.add(cutAction); editMenu.add(copyAction); editMenu.add(pasteAction); // demonstrate nested menus JMenu optionMenu = new JMenu("Options"); optionMenu.add(readonlyItem); optionMenu.addSeparator(); optionMenu.add(insertItem); optionMenu.add(overtypeItem); editMenu.addSeparator(); editMenu.add(optionMenu); // demonstrate mnemonics JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('H'); JMenuItem indexItem = new JMenuItem("Index"); indexItem.setMnemonic('I'); helpMenu.add(indexItem); // you can also add the mnemonic key to an action Action aboutAction = new TestAction("About"); aboutAction.putValue(Action.MNEMONIC_KEY, new Integer('A')); helpMenu.add(aboutAction); // add all top-level menus to menu bar JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); // demonstrate pop-ups popup = new JPopupMenu(); popup.add(cutAction); popup.add(copyAction); popup.add(pasteAction); JPanel panel = new JPanel(); panel.setComponentPopupMenu(popup); add(panel); // the following line is a workaround for bug 4966109 panel.addMouseListener(new MouseAdapter() { }); }
From source file:maltcms.ui.fileHandles.serialized.JFCPanel.java
/** * *///from w ww. j av a 2s. c o m public JFCPanel() { this.chartPanel = new ChartPanel(new JFreeChart(new XYPlot())); initComponents(); jToggleButton1ActionPerformed(new ActionEvent(this, 0, "")); toggleYAxisFix = new JToggleButton(new AbstractAction("Fix y") { @Override public void actionPerformed(ActionEvent ae) { chartPanel.getChart().getXYPlot().getRangeAxis() .setAutoRange(!chartPanel.getChart().getXYPlot().getRangeAxis().isAutoRange()); } }); this.jToolBar2.add(toggleYAxisFix); toggleXAxisFix = new JToggleButton(new AbstractAction("Fix x") { @Override public void actionPerformed(ActionEvent ae) { chartPanel.getChart().getXYPlot().getDomainAxis() .setAutoRange(!chartPanel.getChart().getXYPlot().getDomainAxis().isAutoRange()); } }); this.jToolBar2.add(toggleXAxisFix); toggleAnnotations = new JToggleButton(new AbstractAction("Annotations") { @Override public void actionPerformed(ActionEvent ae) { if (chartPanel.getChart().getXYPlot().getAnnotations().isEmpty()) { Logger.getLogger(getClass().getName()).info("Adding annotations"); for (XYAnnotation xya : annotations) { chartPanel.getChart().getXYPlot().addAnnotation(xya); } chartPanel.getChart().fireChartChanged(); toggleAnnotations.setSelected(true); } else { Logger.getLogger(getClass().getName()).info("Removing annotations"); List<?> l = chartPanel.getChart().getXYPlot().getAnnotations(); if (!l.isEmpty()) { annotations.clear(); for (Object o : l) { annotations.add((XYAnnotation) o); } } chartPanel.getChart().getXYPlot().clearAnnotations(); } } }); this.jToolBar2.add(toggleAnnotations); toggleAnnotations.setSelected(true); }
From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { JPanel ret = new JPanel(); ret.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = c.HORIZONTAL;//w w w. j a v a 2s . co m c.weightx = 1; c.weighty = 0; c.gridy = 0; final Set<String> avail = graph.getAvailableEdgeLabels(); for (final String str : avail) { final JCheckBox box = new JCheckBox(); box.setSelected(enabledLabels.contains(str)); box.setAction(new AbstractAction(str) { public void actionPerformed(ActionEvent arg0) { if (box.isSelected() != enabledLabels.contains(str)) { if (box.isSelected()) enabledLabels.add(str); else enabledLabels.remove(str); v.settingsChanged(false); } } }); ret.add(box, c); c.gridy++; } return ret; }
From source file:net.sf.jabref.gui.fieldeditors.JTextAreaWithHighlighting.java
private void setupUndoRedo() { undo = new UndoManager(); Document doc = getDocument(); // Listen for undo and redo events doc.addUndoableEditListener(evt -> undo.addEdit(evt.getEdit())); // Create an undo action and add it to the text component getActionMap().put("Undo", new AbstractAction("Undo") { @Override// www . j av a 2 s . com public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException ignored) { // Ignored } } }); // Bind the undo action to ctl-Z getInputMap().put(Globals.getKeyPrefs().getKey(net.sf.jabref.gui.keyboard.KeyBinding.UNDO), "Undo"); // Create a redo action and add it to the text component getActionMap().put("Redo", new AbstractAction(Actions.REDO) { @Override public void actionPerformed(ActionEvent evt) { try { if (undo.canRedo()) { undo.redo(); } } catch (CannotRedoException ignored) { // Ignored } } }); // Bind the redo action to ctrl-Y boolean bind = true; KeyStroke redoKey = Globals.getKeyPrefs().getKey(net.sf.jabref.gui.keyboard.KeyBinding.REDO); if (Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS)) { // If emacs is enabled, check if we have a conflict at keys // If yes, do not bind // Typically, we have: CTRL+y is "yank" in emacs and REDO in 'normal' settings // The Emacs key bindings are stored in the keymap, not in the input map. Keymap keymap = getKeymap(); KeyStroke[] keys = keymap.getBoundKeyStrokes(); int i = 0; while ((i < keys.length) && !keys[i].equals(redoKey)) { i++; } if (i < keys.length) { // conflict found -> do not bind bind = false; } } if (bind) { getInputMap().put(redoKey, "Redo"); } }