List of usage examples for javax.swing Action NAME
String NAME
To view the source code for javax.swing Action NAME.
Click Source Link
String
name for the action, used for a menu or button. From source file:de.ailis.xadrian.utils.SwingUtils.java
/** * Adds a component action.//ww w.jav a 2 s . co m * * @param component * The compoenet to add the action to * @param action * The action to add */ public static void addComponentAction(final JComponent component, final Action action) { final InputMap imap = component .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap amap = component.getActionMap(); final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); imap.put(ks, action.getValue(Action.NAME)); amap.put(action.getValue(Action.NAME), action); }
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 w w.j av a 2s .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:com.diversityarrays.kdxplore.vistool.AskForTraitInstances.java
AskForTraitInstances(Window owner, String title, boolean xAndYaxes, String okLabel, TraitNameStyle tns, Map<TraitInstance, SimpleStatistics<?>> map, int[] minMax, Closure<List<TraitInstance>> onInstancesChosen) { super(owner, title, ModalityType.MODELESS); this.traitNameStyle = tns; this.minInstances = minMax[0]; this.maxInstances = minMax[1]; this.onInstancesChosen = onInstancesChosen; if (xAndYaxes) { tableModel = new TraitInstanceAxisChoiceTableModel(); } else {/* w ww .j av a2 s . c o m*/ tableModel = new TraitInstanceChoiceTableModel(); } table = new JTable(tableModel); okAction.putValue(Action.NAME, okLabel); traitInstances = new ArrayList<TraitInstance>(map.keySet()); Collections.sort(traitInstances, TraitHelper.COMPARATOR); table.setAutoCreateRowSorter(true); Box box = Box.createHorizontalBox(); box.add(message); box.add(Box.createHorizontalGlue()); box.add(new JButton(okAction)); box.add(new JButton(cancelAction)); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); getContentPane().add(box, BorderLayout.SOUTH); pack(); tableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateOkButton(); } }); updateOkButton(); }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java
/** * Initializes this window. This method is invoked in the constructor, and * should not be invoked again./*w w w .j a v a 2s .c om*/ */ protected void initialize() { //initialize the NFE slider int minimumNFE = Integer.MAX_VALUE; int maximumNFE = Integer.MIN_VALUE; for (Accumulator accumulator : accumulators) { minimumNFE = Math.min(minimumNFE, (Integer) accumulator.get("NFE", 0)); maximumNFE = Math.max(maximumNFE, (Integer) accumulator.get("NFE", accumulator.size("NFE") - 1)); } slider = new JSlider(minimumNFE, maximumNFE, minimumNFE); slider.setPaintTicks(true); slider.setMinorTickSpacing(100); slider.setMajorTickSpacing(1000); slider.addChangeListener(this); //initializes the options available for axis plotting Solution solution = (Solution) ((List<?>) accumulators.get(0).get("Approximation Set", 0)).get(0); Vector<String> objectives = new Vector<String>(); for (int i = 0; i < solution.getNumberOfObjectives(); i++) { objectives.add(localization.getString("text.objective", i + 1)); } for (int i = 0; i < solution.getNumberOfConstraints(); i++) { objectives.add(localization.getString("text.constraint", i + 1)); } for (int i = 0; i < solution.getNumberOfVariables(); i++) { objectives.add(localization.getString("text.variable", i + 1)); } xAxisSelection = new JComboBox(objectives); yAxisSelection = new JComboBox(objectives); xAxisSelection.setSelectedIndex(0); yAxisSelection.setSelectedIndex(1); xAxisSelection.addActionListener(this); yAxisSelection.addActionListener(this); //initialize the reference set bounds initializeReferenceSetBounds(); //initialize plotting controls useInitialBounds = new JRadioButton(localization.getString("action.useInitialBounds.name")); useReferenceSetBounds = new JRadioButton(localization.getString("action.useReferenceSetBounds.name")); useDynamicBounds = new JRadioButton(localization.getString("action.useDynamicBounds.name")); useZoomBounds = new JRadioButton(localization.getString("action.useZoom.name")); useInitialBounds.setToolTipText(localization.getString("action.useInitialBounds.description")); useReferenceSetBounds.setToolTipText(localization.getString("action.useReferenceSetBounds.description")); useDynamicBounds.setToolTipText(localization.getString("action.useDynamicBounds.description")); useZoomBounds.setToolTipText(localization.getString("action.useZoom.description")); ButtonGroup rangeButtonGroup = new ButtonGroup(); rangeButtonGroup.add(useInitialBounds); rangeButtonGroup.add(useReferenceSetBounds); rangeButtonGroup.add(useDynamicBounds); rangeButtonGroup.add(useZoomBounds); if (referenceSet == null) { useReferenceSetBounds.setEnabled(false); } useInitialBounds.setSelected(true); useInitialBounds.addActionListener(this); useReferenceSetBounds.addActionListener(this); useDynamicBounds.addActionListener(this); useZoomBounds.addActionListener(this); //initialize the seed list String[] seeds = new String[accumulators.size()]; for (int i = 0; i < accumulators.size(); i++) { seeds[i] = localization.getString("text.seed", i + 1); } seedList = new JList(seeds); seedList.addListSelectionListener(this); selectAll = new JButton(new AbstractAction() { private static final long serialVersionUID = -3709557130361259485L; { putValue(Action.NAME, localization.getString("action.selectAll.name")); } @Override public void actionPerformed(ActionEvent e) { seedList.getSelectionModel().setSelectionInterval(0, seedList.getModel().getSize() - 1); } }); //initialize miscellaneous components paintHelper = new PaintHelper(); paintHelper.set(localization.getString("text.referenceSet"), Color.BLACK); chartContainer = new JPanel(new BorderLayout()); }
From source file:com.diversityarrays.update.UpdateDialog.java
private void setResultMessage(String msg) { messageLabel.setText(msg); cardLayout.show(cardPanel, CARD_MESSAGE); closeAction.putValue(Action.NAME, Msg.ACTION_CLOSE()); pack(); }
From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferHandler.java
public static void registerWith(SpreadSheet spreadSheet) { NodeListTransferHandler handler = new NodeListTransferHandler(spreadSheet); // if (c instanceof SpreadSheet){ // SpreadSheet spreadSheet=(SpreadSheet)c; // handler.setSpreadSheet(spreadSheet); // } spreadSheet.setTransferHandler(handler); InputMap imap = spreadSheet.getInputMap(); imap.put(KeyStroke.getKeyStroke("ctrl X"), NodeListTransferHandler.getCutAction().getValue(Action.NAME)); imap.put(KeyStroke.getKeyStroke("ctrl C"), NodeListTransferHandler.getCopyAction().getValue(Action.NAME)); imap.put(KeyStroke.getKeyStroke("ctrl V"), NodeListTransferHandler.getPasteAction().getValue(Action.NAME)); //c.setInputMap(JComponent.WHEN_FOCUSED,imap); ActionMap amap = spreadSheet.getActionMap(); amap.put(NodeListTransferHandler.getCutAction().getValue(Action.NAME), NodeListTransferHandler.getCutAction()); amap.put(NodeListTransferHandler.getCopyAction().getValue(Action.NAME), NodeListTransferHandler.getCopyAction()); amap.put(NodeListTransferHandler.getPasteAction().getValue(Action.NAME), NodeListTransferHandler.getPasteAction()); }
From source file:idontwant2see.IDontWant2See.java
public ActionMenu getContextMenuActions(final Program p) { if (p == null) { return null; }//from www . j a va 2 s .co m // check if this program is already hidden final int index = getSearchTextIndexForProgram(p); // return menu to hide the program if (index == -1 || p.equals(getPluginManager().getExampleProgram())) { AbstractAction actionDontWant = getActionDontWantToSee(p); if (mSettings.isSimpleMenu() && !mCtrlPressed) { final Matcher matcher = PATTERN_TITLE_PART.matcher(p.getTitle()); if (matcher.matches()) { actionDontWant = getActionInputTitle(p, matcher.group(2)); } actionDontWant.putValue(Action.NAME, mLocalizer.msg("name", "I don't want to see!")); actionDontWant.putValue(Action.SMALL_ICON, createImageIcon("apps", "idontwant2see", 16)); return new ActionMenu(actionDontWant); } else { final AbstractAction actionInput = getActionInputTitle(p, null); final ContextMenuAction baseAction = new ContextMenuAction( mLocalizer.msg("name", "I don't want to see!"), createImageIcon("apps", "idontwant2see", 16)); return new ActionMenu(baseAction, new Action[] { actionDontWant, actionInput }); } } // return menu to show the program return new ActionMenu(getActionShowAgain(p)); }
From source file:com.diversityarrays.update.UpdateDialog.java
/** * Return true to display the dialog//from www. j a va 2 s .c o m * * @return */ private boolean processReadUrlResult(String updateUrl) { if (kdxploreUpdate == null) { if (RunMode.getRunMode().isDeveloper()) { setResultMessage("<html>Unable to read update information:<br>" + updateUrl); //$NON-NLS-1$ } else { setResultMessage(Msg.ERRMSG_UNABLE_TO_READ_UPDATE_INFO()); } return updateCheckRequest.userCheck; } if (kdxploreUpdate.isError()) { if (!updateCheckRequest.userCheck && kdxploreUpdate.unknownHost) { return false; } setResultMessage(kdxploreUpdate.errorMessage); return true; } // User is checking or we have an update. if (!updateCheckRequest.userCheck) { // Auto check ... if (kdxploreUpdate.versionCode <= updateCheckRequest.versionCode) { // We have the latest setResultMessage(Msg.YOUR_VERSION_IS_THE_LATEST()); return false; } } installUpdateAction.setEnabled(kdxploreUpdate.versionCode > updateCheckRequest.versionCode); closeAction.putValue(Action.NAME, Msg.ACTION_CLOSE()); UpdatePanel updatePanel = new UpdatePanel(updateCheckRequest, kdxploreUpdate, daysToGo); Container cp = getContentPane(); cp.remove(cardPanel); cp.add(updatePanel, BorderLayout.CENTER); pack(); return true; }
From source file:net.sf.jhylafax.JHylaFAX.java
private void initializeSystemTray() { tray = new FaxTray(); if (tray.isSupported()) { tray.getPopupMenu().add(new MenuItem((String) exitAction.getValue(Action.NAME))); }//from ww w . j a v a2s . com }
From source file:TextComponentDemo.java
private void createActionTable(JTextComponent textComponent) { actions = new HashMap<Object, Action>(); Action[] actionsArray = textComponent.getActions(); for (int i = 0; i < actionsArray.length; i++) { Action a = actionsArray[i]; actions.put(a.getValue(Action.NAME), a); }//from w w w . j a v a 2 s . co m }