List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction()
From source file:org.openstreetmap.josm.gui.preferences.imagery.CacheContentsPanel.java
private static JTable getTableForCache(final CacheAccess<String, BufferedImageCacheEntry> cache, final TableModel tableModel) { final JTable ret = new JTable(tableModel); ButtonColumn buttonColumn = new ButtonColumn(new AbstractAction() { @Override/* w w w . j a v a 2 s .co m*/ public void actionPerformed(ActionEvent e) { int row = ret.convertRowIndexToModel(ret.getEditingRow()); tableModel.setValueAt("0", row, 1); cache.remove(ret.getValueAt(row, 0).toString() + ':'); } }); TableColumn tableColumn = ret.getColumnModel().getColumn(2); tableColumn.setCellRenderer(buttonColumn); tableColumn.setCellEditor(buttonColumn); return ret; }
From source file:com.isecpartners.gizmo.ThirdIdea.java
public ThirdIdea(final BlobScroller scroller, final HTTPMessage msg, final boolean request) { try {//from w w w . ja v a 2s . c om this.buffer_file = File.createTempFile("tmp", "end"); } catch (IOException ex) { Logger.getLogger(ThirdIdea.class.getName()).log(Level.SEVERE, null, ex); } initComponents(); init(scroller, msg.contents(), new AbstractAction() { public void actionPerformed(ActionEvent e) { if (request) { scroller.setCommand(jTextPane1.getText(), request, (HttpRequest) msg); } ThirdIdea.this.dispose(); } }); }
From source file:fxts.stations.util.preferences.PreferencesSheetPanel.java
/** * Constructor PreferencesSheetPanel./* w ww .j av a 2s .c o m*/ * * @param aUserName parent dialog included this panel. */ public PreferencesSheetPanel(String aUserName) { mUserName = aUserName; try { mResMan = ResourceManager.getManager("fxts.stations.util.preferences.resources.Resources"); } catch (Exception e) { mLogger.error("The fatal error"); e.printStackTrace(); } mResMan.addLocaleListener(this); //Define table mTableModel = new PrefTableModel(); mTable = new AAJTable(mTableModel); mTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); PreferencesTableCellRenderer renderer = new PreferencesTableCellRenderer(); mTable.setDefaultRenderer(AValueEditorPanel.class, renderer); mEditor = new PreferencesTableCellEditor(); mTable.setDefaultEditor(AValueEditorPanel.class, mEditor); //Do not change columns order mTable.getTableHeader().setReorderingAllowed(false); //Assign exterior a table mTable.setBorder(new EtchedBorder()); //Prepare to used Escape key mDefaultEditingCancelAction = SwingUtilities.getUIActionMap(mTable).get("cancel"); AbstractAction exitAction = new AbstractAction() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent aEvent) { if (mEditor.isEditing()) { mEditor.cancelCellEditing(); if (mDefaultEditingCancelAction != null) { mDefaultEditingCancelAction.actionPerformed(aEvent); } } else { mDefaultExitAction.actionPerformed(aEvent); } } }; KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); mTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke, "ExitAction"); SwingUtilities.getUIActionMap(mTable).put("ExitAction", exitAction); super.setViewportView(mTable); }
From source file:org.cds06.speleograph.graph.SeriesMenu.java
private JPopupMenu createPopupMenuForSeries(final Series series) { if (series == null) return new JPopupMenu(); final JPopupMenu menu = new JPopupMenu(series.getName()); menu.removeAll();/*from w ww .ja v a 2 s . co m*/ menu.add(new AbstractAction() { { putValue(NAME, "Renommer la srie"); } @Override public void actionPerformed(ActionEvent e) { menu.setVisible(false); String newName = ""; while (newName == null || newName.equals("")) { newName = (String) JOptionPane.showInputDialog(application, "Entrez un nouveau nom pour la srie", null, JOptionPane.QUESTION_MESSAGE, null, null, series.getName()); } series.setName(newName); } }); if (series.hasOwnAxis()) { menu.add(new AbstractAction() { { putValue(NAME, "Supprimer l'axe spcifique"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes vous sr de vouloir supprimer cet axe ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { series.setAxis(null); } } }); } else { menu.add(new JMenuItem(new AbstractAction() { { putValue(NAME, "Crer un axe spcifique pour la srie"); } @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(application, "Quel titre pour cet axe ?", series.getAxis().getLabel()); if (name == null || "".equals(name)) return; // User has canceled series.setAxis(new NumberAxis(name)); } })); } menu.add(new SetTypeMenu(series)); if (series.isWater()) { menu.addSeparator(); menu.add(new SumOnPeriodAction(series)); menu.add(new CreateCumulAction(series)); } if (series.isWaterCumul()) { menu.addSeparator(); menu.add(new SamplingAction(series)); } if (series.isPressure()) { menu.addSeparator(); menu.add(new CorrelateAction(series)); menu.add(new WaterHeightAction(series)); } menu.addSeparator(); menu.add(new AbstractAction() { { String name; if (series.canUndo()) name = "Annuler " + series.getItemsName(); else name = series.getLastUndoName(); putValue(NAME, name); if (series.canUndo()) setEnabled(true); else { setEnabled(false); } } @Override public void actionPerformed(ActionEvent e) { series.undo(); } }); menu.add(new AbstractAction() { { String name; if (series.canRedo()) { name = "Refaire " + series.getNextRedoName(); setEnabled(true); } else { name = series.getNextRedoName(); setEnabled(false); } putValue(NAME, name); } @Override public void actionPerformed(ActionEvent e) { series.redo(); } }); menu.add(new AbstractAction() { { putValue(NAME, I18nSupport.translate("menus.serie.resetSerie")); if (series.canUndo()) setEnabled(true); else setEnabled(false); } @Override public void actionPerformed(ActionEvent e) { series.reset(); } }); menu.add(new LimitDateRangeAction(series)); menu.add(new HourSettingAction(series)); menu.addSeparator(); { JMenuItem deleteItem = new JMenuItem("Supprimer la srie"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir supprimer cette srie ?\n" + "Cette action est dfinitive.", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { series.delete(); } } }); menu.add(deleteItem); } menu.addSeparator(); { final JMenuItem up = new JMenuItem("Remonter dans la liste"), down = new JMenuItem("Descendre dans la liste"); ActionListener listener = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(up)) { series.upSeriesInList(); } else { series.downSeriesInList(); } } }; up.addActionListener(listener); down.addActionListener(listener); if (series.isFirst()) { menu.add(down); } else if (series.isLast()) { menu.add(up); } else { menu.add(up); menu.add(down); } } menu.addSeparator(); { menu.add(new SeriesInfoAction(series)); } { JMenuItem colorItem = new JMenuItem("Couleur de la srie"); colorItem.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { series.setColor(JColorChooser.showDialog(application, I18nSupport.translate("actions.selectColorForSeries"), series.getColor())); } }); menu.add(colorItem); } { JMenu plotRenderer = new JMenu("Affichage de la srie"); final ButtonGroup modes = new ButtonGroup(); java.util.List<DrawStyle> availableStyles; if (series.isMinMax()) { availableStyles = DrawStyles.getDrawableStylesForHighLow(); } else { availableStyles = DrawStyles.getDrawableStyles(); } for (final DrawStyle s : availableStyles) { final JRadioButtonMenuItem item = new JRadioButtonMenuItem(DrawStyles.getHumanCheckboxText(s)); item.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (item.isSelected()) series.setStyle(s); } }); modes.add(item); if (s.equals(series.getStyle())) { modes.setSelected(item.getModel(), true); } plotRenderer.add(item); } menu.add(plotRenderer); } menu.addSeparator(); menu.add(new AbstractAction() { { putValue(Action.NAME, "Fermer le fichier"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir fermer toutes les sries du fichier ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { final File f = series.getOrigin(); for (final Series s : Series.getInstances().toArray(new Series[Series.getInstances().size()])) { if (s.getOrigin().equals(f)) s.delete(); } } } }); return menu; }
From source file:org.kepler.gui.WorkflowOutlineTabPane.java
/** Initialize the search panel. */ private void _initializeSearchPanel() { _searchUIJPanel = new SearchUIJPanel(); _searchUIJPanel.setBorderTitle("Search Workflow"); // add action for search button _searchUIJPanel.setSearchAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { _searchUIJPanel.setCancelButtonEnabled(true); String term = _searchUIJPanel.getSearchTerm(); _outlinePanel.search(term.trim()); }/*from ww w .j a v a 2s. c o m*/ }); // add action for cancel button, and on mac when X // is pressed in search field _searchUIJPanel.setCancelAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { _searchUIJPanel.setCancelButtonEnabled(false); _outlinePanel.search(""); } }); _searchUIJPanel.init(); }
From source file:com.isecpartners.gizmo.FourthIdea.java
public FourthIdea(final BlobScroller scroller, String str) { initComponents();// w ww.ja v a2s.c o m init(scroller, str, new AbstractAction() { public void actionPerformed(ActionEvent e) { FourthIdea.this.dispose(); } }); }
From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java
@Override protected JToolBar buildTopToolBar() { JToolBar bar = super.buildTopToolBar(); JButton addCatButton = new JButton(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADD)); addCatButton.setToolTipText("Add category"); addCatButton.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { addCategory();/*from ww w .j ava 2s. c om*/ } }); bar.add(addCatButton); return bar; }
From source file:org.notebook.gui.widget.GuiUtils.java
/** * Adds the close action with escape key. * //from w ww.j av a2 s .c om * @param dialog * the dialog */ public static void addCloseActionWithEscapeKey(final JDialog dialog) { // Handle escape key to close the dialog KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Action escapeAction = new AbstractAction() { private static final long serialVersionUID = 0L; @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }; dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); dialog.getRootPane().getActionMap().put("ESCAPE", escapeAction); }
From source file:com.isecpartners.gizmo.ThirdIdea.java
public ThirdIdea(final BlobScroller scroller, String str) { initComponents();/*from www . j a v a 2 s .com*/ init(scroller, str, new AbstractAction() { public void actionPerformed(ActionEvent e) { ThirdIdea.this.dispose(); } }); }
From source file:org.drugis.addis.gui.WelcomeDialog.java
private void initComps() { final ButtonGroup examples = new ButtonGroup(); examples.add(new JRadioButton(Main.Examples.DEPRESSION.name, true)); examples.add(new JRadioButton(Main.Examples.HYPERTENSION.name)); final AbstractAction exampleAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { d_main.loadExampleDomain(Main.Examples.findFileName(getSelection(examples).getText())); closeWelcome();/*w w w. j a v a 2s . c o m*/ } }; final AbstractAction loadAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { if (d_main.fileLoadActions() == JFileChooser.APPROVE_OPTION) { closeWelcome(); } } }; final AbstractAction newAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { d_main.newFileActions(); closeWelcome(); } }; FormLayout layout = new FormLayout("left:pref, " + SPACING + "px, left:pref", "p, 3dlu, p, " + SPACING + "px, p, " + SPACING + "px, p, 3dlu, p"); PanelBuilder builder = new PanelBuilder(layout); final CellConstraints cc = new CellConstraints(); builder.add(createImageLabel(FileNames.IMAGE_HEADER), cc.xyw(1, 1, 3)); builder.add(createButton("Load example", FileNames.ICON_TIP, exampleAction), cc.xy(1, 3)); final PanelBuilder radios = new PanelBuilder(new FormLayout("p, fill:pref:grow, right:pref", "p, 3dlu, p")); final ArrayList<AbstractButton> buttons = Collections.list(examples.getElements()); forAllDo(buttons, new Closure<AbstractButton>() { public void execute(final AbstractButton exampleOption) { int row = buttons.indexOf(exampleOption) == 0 ? 1 : buttons.indexOf(exampleOption) + 2; exampleOption.setOpaque(false); radios.add(exampleOption, cc.xy(1, row)); radios.add(createHelpButton(exampleOption), cc.xy(3, row)); } private JButton createHelpButton(final AbstractButton exampleOption) { JButton help = GUIFactory.createIconButton(org.drugis.mtc.gui.FileNames.ICON_ABOUT, "Information about this example"); removeBackground(help); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Examples example = Examples.findByName(exampleOption.getText()); String helpText = s_help.getHelpText(example.name().toLowerCase()); showExampleInfo(helpText); } }); return help; } }); JPanel radiosPanel = radios.getPanel(); setBorder(radiosPanel); builder.add(radiosPanel, cc.xy(3, 3)); builder.add(createButton("Open file", FileNames.ICON_OPENFILE, loadAction), cc.xy(1, 5)); JTextPane load = createLabel("Load an existing ADDIS data file stored on your computer."); builder.add(load, cc.xy(3, 5)); builder.add(createButton("New dataset", FileNames.ICON_FILE_NEW, newAction), cc.xy(1, 7)); builder.add(createLabel("Start with an empty file to build up your own data and analyses."), cc.xy(3, 7)); builder.add(createImageLabel(FileNames.IMAGE_FOOTER), cc.xyw(1, 9, 3)); setContentPane(builder.getPanel()); }