static AlwaysEnabledAction create(Map m) { return (m.containsKey(PREFERENCES_KEY)) ? new CheckBox(m) : new AlwaysEnabledAction(m); }
private synchronized Preferences prefs() { if (preferencesNode == null) { Object prefsNodeOrLookup = getValue(PREFERENCES_NODE); if (prefsNodeOrLookup instanceof String) { String nodeName = (String) prefsNodeOrLookup;
public JMenuItem getPopupPresenter() { if (popupItem == null) { popupItem = new JCheckBoxMenuItem(); popupItem.setSelected(isPreferencesSelected()); Actions.connect(popupItem, this, true); } return popupItem; }
private boolean isPreferencesSelected() { String key = (String) getValue(PREFERENCES_KEY); Preferences prefs = prefs(); boolean value; if (key != null && prefs != null) { Object defaultValue = getValue(PREFERENCES_DEFAULT); value = prefs.getBoolean(key, defaultValue instanceof Boolean ? (Boolean) defaultValue : false); synchronized (this) { if (!prefsListening) { prefsListening = true; prefs.addPreferenceChangeListener(this); } } } else { value = false; } return value; }
public void preferenceChange(PreferenceChangeEvent pce) { updateItemsSelected(); }
@Override public void actionPerformed(ActionEvent e) { // Toggle state in preferences togglePreferencesSelected(); super.actionPerformed(e); }
private void updateItemsSelected() { boolean selected = isPreferencesSelected(); if (menuItem != null) { menuItem.setSelected(selected); } if (popupItem != null) { popupItem.setSelected(selected); } if (toolbarItems != null) { for(AbstractButton b : toolbarItems) { b.setSelected(selected); } } }
@Override public Action createContextAwareInstance(Lookup actionContext) { return new CheckBox(map, this, actionContext, equals); }
private void togglePreferencesSelected() { String key = (String) getValue(PREFERENCES_KEY); Preferences prefs = prefs(); if (key != null && prefs != null) { Object defaultValue = getValue(PREFERENCES_DEFAULT); prefs.putBoolean(key, !prefs.getBoolean(key, defaultValue instanceof Boolean ? (Boolean) defaultValue : false)); } }
public void resultChanged(LookupEvent ev) { preferencesNode = null; preferencesNodeResult = null; updateItemsSelected(); }
public AbstractButton getToolbarPresenter() { if(toolbarItems == null) { toolbarItems = new WeakSet<AbstractButton>(4); } AbstractButton b = new DefaultIconToggleButton(); toolbarItems.add(b); b.setSelected(isPreferencesSelected()); Actions.connect(b, this); return b; }
public JMenuItem getMenuPresenter() { if (menuItem == null) { menuItem = new JCheckBoxMenuItem(); menuItem.setSelected(isPreferencesSelected()); Actions.connect(menuItem, this, false); } return menuItem; }