public final Object getValue(String key) { return action.getValue(key); }
protected JDialog createDialog(Component parent) { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); JDialog dialog = new JDialog(frame, ("Select Font"), true); Action okAction = new DialogOKAction(dialog); Action cancelAction = new DialogCancelAction(dialog); JButton okButton = new JButton(okAction); okButton.setFont(DEFAULT_FONT); JButton cancelButton = new JButton(cancelAction); cancelButton.setFont(DEFAULT_FONT); JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(2, 1)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10)); ActionMap actionMap = buttonsPanel.getActionMap(); actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction); actionMap.put(okAction.getValue(Action.DEFAULT), okAction); InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT)); inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT)); JPanel dialogEastPanel = new JPanel(); dialogEastPanel.setLayout(new BorderLayout()); dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST); dialog.pack(); dialog.setLocationRelativeTo(frame); return dialog; }
copy = new JMenuItem("Copy"); copy.setActionCommand((String)TransferHandler.getCopyAction(). getValue(Action.NAME)); copy.addActionListener(new TransferActionListener()); edit.add(copy);
.getValue(Action.NAME)); copy.addActionListener(new TregexGUI.TransferActionListener()); int mask = TregexGUI.isMacOSX() ? InputEvent.META_MASK : InputEvent.CTRL_MASK; InputMap imap = treeJP.getInputMap(); imap.put(KeyStroke.getKeyStroke("ctrl C"), TransferHandler.getCopyAction().getValue(Action.NAME)); ActionMap map = treeJP.getActionMap(); map.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction()); return treeJP;
public final Object getValue(String key) { return action.getValue(key); }
/** Updates value of the key * @param item item to update * @param action the action to update */ static void updateKey(JMenuItem item, Action action) { if (!(item instanceof JMenu)) { item.setAccelerator((KeyStroke) action.getValue(Action.ACCELERATOR_KEY)); } }
/** */ public ExTextField() { Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); setFont(font); // Do not override getActions() method, because it is has side effect: propogates these actions to defaults. final Action[] actions = ExEditorKit.getInstance().getActions(); final ActionMap actionMap = getActionMap(); for (Action a : actions) { actionMap.put(a.getValue(Action.NAME), a); //System.out.println(" " + a.getValue(Action.NAME)); } setInputMap(WHEN_FOCUSED, new InputMap()); Keymap map = addKeymap("ex", getKeymap()); loadKeymap(map, ExKeyBindings.getBindings(), actions); map.setDefaultAction(new ExEditorKit.DefaultExKeyHandler()); setKeymap(map); addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { setCaretPosition(getText().length()); } @Override public void focusLost(FocusEvent e) { } }); //origCaret = getCaret(); //blockCaret = new BlockCaret(); }
@Override public Object getValue(String name) { if (delegate instanceof Action) { Object ret = ((Action)delegate).getValue(name); if (ret != null) { return ret; } if ( "iconBase".equals(name) && // NOI18N ((Action)delegate).getValue(Action.SMALL_ICON) != null ) { return null; } } Object o = extractCommonAttribute(map, name); // cf. #137709 JG18: return o != null ? o : super.getValue(name); }
public Object getValue(String key) { if (attrs != null && attrs.containsKey(key)) { return attrs.get(key); } Object ret = GeneralAction.extractCommonAttribute(map, this, key); if (ret != null) { return ret; } Action a = findAction(); return a == null ? null : a.getValue(key); }
public void actionPerformed(ActionEvent ev) { LogRecord rec = new LogRecord(Level.FINER, "UI_ACTION_BUTTON_PRESS"); // NOI18N rec.setParameters(new Object[] { button, button.getClass().getName(), action, action.getClass().getName(), action.getValue(Action.NAME) }); rec.setResourceBundle(NbBundle.getBundle(Actions.class)); rec.setResourceBundleName(Actions.class.getPackage().getName() + ".Bundle"); // NOI18N rec.setLoggerName(UILOG.getName()); UILOG.log(rec); }
private void syncActionDelegateProperty(String propertyName, Action actionDelegate) { Object value = extractCommonAttribute(map, propertyName); Object delegateValue = actionDelegate.getValue(propertyName); if (value != null) { if (delegateValue == null) { actionDelegate.putValue(propertyName, value); } else { if (!delegateValue.equals(value)) { // Values differ LOG.log(Level.FINE, "Value of property \"{0}\" of AlwaysEnabledAction " + "is \"{1}\" but delegate {2} has \"{3}\"", new Object[] {propertyName, value, delegate, delegateValue}); } } } // else either both values are null or // this has null and delegate has non-null which is probably fine (declarer does not care) }
/** Constructor. */ public SubMenuBridge(JMenuItem one, JMenu more, Action action, SubMenuModel model, boolean popup) { super(one, action, popup); single = one; multi = more; setMenuText(multi, (String)action.getValue(Action.NAME), popup); prepareMargins(one, action); prepareMargins(more, action); currentOnes = new ArrayList<JMenuItem>(); this.model = model; }
/** @param changedProperty the name of property that has changed * or null if it is not known */ @Override public void updateState(String changedProperty) { super.updateState(changedProperty); if ((changedProperty == null) || !changedProperty.equals(Action.ACCELERATOR_KEY)) { updateKey((JMenuItem) comp, action); } if ((changedProperty == null) || changedProperty.equals(Action.NAME)) { Object s = action.getValue(Action.NAME); if (s instanceof String) { setMenuText(((JMenuItem) comp), (String) s, true); } } }
private void setupActions() { // Mac weirdness... VK_MINUS/VK_PLUS seems to map to english key map always... bindAction(new ZoomAction("Zoom in", 2), ZOOM_IN, KeyStroke.getKeyStroke('+'), KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0)); bindAction(new ZoomAction("Zoom out", .5), ZOOM_OUT, KeyStroke.getKeyStroke('-'), KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0)); bindAction(new ZoomAction("Zoom actual"), ZOOM_ACTUAL, KeyStroke.getKeyStroke('0'), KeyStroke.getKeyStroke(KeyEvent.VK_0, 0)); bindAction(TransferHandler.getCopyAction(), (String) TransferHandler.getCopyAction().getValue(Action.NAME), KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); bindAction(TransferHandler.getPasteAction(), (String) TransferHandler.getPasteAction().getValue(Action.NAME), KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); }
// create an Action doing what you want Action action = new AbstractAction("doSomething") { @Override public void actionPerformed(ActionEvent e) { System.out.println("triggered the action"); } }; // configure the Action with the accelerator (aka: short cut) action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control S")); // create a button, configured with the Action JButton toolBarButton = new JButton(action); // manually register the accelerator in the button's component input map toolBarButton.getActionMap().put("myAction", action); toolBarButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( (KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "myAction");
(changedProperty.equals(Action.NAME) && (action.getValue(Action.SHORT_DESCRIPTION) == null)) || changedProperty.equals(Action.SHORT_DESCRIPTION) ) { String tip = findKey(action); String toolTip = (String) action.getValue(Action.SHORT_DESCRIPTION); toolTip = (String) action.getValue(Action.NAME); toolTip = (toolTip == null) ? "" : cutAmpersand(toolTip); ((changedProperty == null) || changedProperty.equals(Action.NAME)) ) { button.getAccessibleContext().setAccessibleName((String) action.getValue(Action.NAME));
for (int i = 0; i < n; i++) { Action a = actions[i]; map.put(a.getValue(Action.NAME), a); map.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction()); map.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction()); map.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
/** Same method as above, but works just with plain actions. */ private static String findKey(Action action) { if (action == null) { return null; } KeyStroke accelerator = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); if (accelerator == null) { return null; } int modifiers = accelerator.getModifiers(); String acceleratorText = ""; // NOI18N if (modifiers > 0) { acceleratorText = KeyEvent.getKeyModifiersText(modifiers); acceleratorText += "+"; // NOI18N } else if (accelerator.getKeyCode() == KeyEvent.VK_UNDEFINED) { return ""; // NOI18N } acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode()); return acceleratorText; }
((Actions.MenuItem)item).setBridge(b); item.putClientProperty(DynamicMenuContent.HIDE_WHEN_DISABLED, action.getValue(DynamicMenuContent.HIDE_WHEN_DISABLED));