/** * <Some description here> * * @param evt * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("enabled")) { Action tmp = this.delegate; if (evt.getNewValue().equals(Boolean.FALSE)) { for (int i = 0; i < this.delegates.length; i++) { if (this.delegates[i].isEnabled()) { this.delegate = this.delegates[i]; break; } } } else { this.delegate = (Action) evt.getSource(); } if (tmp != this.delegate) { this.firePropertyChange(NAME, tmp.getValue(NAME), this.delegate.getValue(NAME)); this.firePropertyChange( SMALL_ICON, tmp.getValue(SMALL_ICON), this.delegate.getValue(SMALL_ICON)); this.firePropertyChange( SHORT_DESCRIPTION, tmp.getValue(SHORT_DESCRIPTION), this.delegate.getValue(SHORT_DESCRIPTION)); } } this.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); }
protected void handleSelection(final KettleQueryEntry value) { final DesignTimeContext designTimeContext = getDesignTimeContext(); final Action editParameterAction = getEditParameterAction(); try { setPanelEnabled(true, datasourcePanel); final KettleEmbeddedQueryEntry selectedQuery = (KettleEmbeddedQueryEntry) value; // This change event gets fired twice, causing the dialog to update twice.. let's stop that. if ((lastSelectedQuery == null) || (selectedQuery != lastSelectedQuery)) { lastSelectedQuery = selectedQuery; updateQueryName(selectedQuery.getName()); selectedQuery.refreshQueryUIComponents( datasourcePanel, designTimeContext, new PreviewChangeListener()); } editParameterAction.setEnabled(true); } catch (Exception e1) { designTimeContext.error(e1); editParameterAction.setEnabled(false); } catch (Throwable t1) { designTimeContext.error(new RuntimeException("Fatal error", t1)); editParameterAction.setEnabled(false); } }
@Override public void valueChanged(@Nullable TreeSelectionEvent e) { Component selectedComponent = myContentPanel.getSelectedComponent(); if (selectedComponent == myColorPickerPanel) { Color color = myColorPicker.getColor(); myNewResourceAction.setEnabled(false); myResultResourceName = ResourceHelper.colorToString(color); updateResourceNameStatus(); } else { boolean isProjectPanel = selectedComponent == myProjectPanel.myComponent; ResourcePanel panel = isProjectPanel ? myProjectPanel : mySystemPanel; ResourceItem element = getSelectedElement(panel.myTreeBuilder, ResourceItem.class); setOKActionEnabled(element != null); myNewResourceAction.setEnabled( isProjectPanel && !panel.myTreeBuilder.getSelectedElements().isEmpty()); if (element == null) { myResultResourceName = null; } else { String prefix = panel == myProjectPanel ? "@" : ANDROID; myResultResourceName = prefix + element.getName(); } panel.showPreview(element); } notifyResourcePickerListeners(myResultResourceName); }
private Action getSystemAction(JTextComponent c) { if (systemAction == null) { Action ea = getEditorAction(c); if (ea != null) { String saClassName = (String) ea.getValue(NbEditorKit.SYSTEM_ACTION_CLASS_NAME_PROPERTY); if (saClassName != null) { Class saClass; try { saClass = Class.forName(saClassName); } catch (Throwable t) { saClass = null; } if (saClass != null) { systemAction = SystemAction.get(saClass); if (systemAction instanceof ContextAwareAction) { Lookup lookup = getContextLookup(c); if (lookup != null) { systemAction = ((ContextAwareAction) systemAction).createContextAwareInstance(lookup); } } } } } } return systemAction; }
private void setPointButtonAction() { JButton button = calculator.getButtonPoint(); Action action = new AbstractAction("colonAction") { @Override public void actionPerformed(ActionEvent e) { appendTextInCalculatorDisplay("."); } }; // Shortcut al punto normal action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, 0)); button.getActionMap().put("colonAction", action); button .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "colonAction"); // Shortcut al punto del numpad action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DECIMAL, 0)); button.getActionMap().put("colonAction", action); button .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "colonAction"); button.addActionListener(action); }
@Override public void actionPerformed(ActionEvent e) { int tamanyo = 14; try { if ((JComboBox) (e.getSource()) == comboTamanyo) { tamanyo = (int) ((JComboBox) e.getSource()).getSelectedItem(); if (tamanyo == 10) jrdm10pt.setSelected(true); else if (tamanyo == 14) jrdm14pt.setSelected(true); else if (tamanyo == 18) jrdm18pt.setSelected(true); else if (tamanyo == 22) jrdm22pt.setSelected(true); } } catch (Exception ex) { } try { if ((JRadioButtonMenuItem) (e.getSource()) == jrdm10pt || (JRadioButtonMenuItem) (e.getSource()) == jrdm14pt || (JRadioButtonMenuItem) (e.getSource()) == jrdm18pt || (JRadioButtonMenuItem) (e.getSource()) == jrdm22pt) { tamanyo = Integer.parseInt(((JRadioButtonMenuItem) e.getSource()).getText()); comboTamanyo.setSelectedItem(tamanyo); } } catch (Exception ex) { } // Establecemos la acción que queremos que haga cuando se cambie Action accion = new StyledEditorKit.FontSizeAction("Tamaño", tamanyo); // Hacemos que la accion ejecute el actionPerformand accion.actionPerformed(e); jtaTexto.requestFocus(); }
private void setMinusButtonAction() { JButton button = calculator.getButtonMinus(); Action action = new AbstractAction("buttonMinusAction") { @Override public void actionPerformed(ActionEvent e) { appendTextInCalculatorDisplay("-"); } }; // Shortcut al menos del numpad action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0)); button.getActionMap().put("buttonMinusAction", action); button .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "buttonMinusAction"); // Shortcut al guion alto action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0)); button.getActionMap().put("buttonMinusAction", action); button .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "buttonMinusAction"); button.addActionListener(action); }
/** * This is the hook through which all menu items are created. It registers the result with the * menuitem hashtable so that it can be fetched with getMenuItem(). * * @see #getMenuItem */ protected JMenuItem createMenuItem(String cmd) { JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix)); URL url = getResource(cmd + imageSuffix); if (url != null) { mi.setHorizontalTextPosition(JButton.RIGHT); mi.setIcon(new ImageIcon(url)); } String astr = getResourceString(cmd + actionSuffix); if (astr == null) { astr = cmd; } mi.setActionCommand(astr); Action myaction = getAction(astr); // if this is a known action if (myaction != null) { mi.addActionListener(myaction); myaction.addPropertyChangeListener(createActionChangeListener(mi)); // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled()); mi.setEnabled(myaction.isEnabled()); } else { System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr); // causes the item to be greyed out mi.setEnabled(false); } menuItems.put(cmd, mi); return mi; }
/** * Add a section to a list of components. * * @param components List of components * @param sectionId The {@link URI} identifying the section * @param menuOptions {@link MenuOptions options} for creating the menu */ private void addSection(List<Component> components, URI sectionId, MenuOptions menuOptions) { List<Component> childComponents = makeComponents(sectionId, menuOptions); MenuComponent sectionDef = uriToMenuElement.get(sectionId); addNullSeparator(components); if (childComponents.isEmpty()) { logger.warn("No sub components found for section " + sectionId); return; } Action sectionAction = sectionDef.getAction(); if (sectionAction != null) { String sectionLabel = (String) sectionAction.getValue(NAME); if (sectionLabel != null) { // No separators before the label stripTrailingNullSeparator(components); Color labelColor = (Color) sectionAction.getValue(SECTION_COLOR); if (labelColor == null) labelColor = GREEN; ShadedLabel label = new ShadedLabel(sectionLabel, labelColor); components.add(label); } } for (Component childComponent : childComponents) if (childComponent == null) { logger.warn("Separator found within section " + sectionId); addNullSeparator(components); } else components.add(childComponent); addNullSeparator(components); }
public Collection<Action> getStatusActions() { if (statusActions == null) { statusActions = new ArrayList<Action>(); Action firstTitle = new ShowStatusAction( translations.getString("COMPONENTSMENU"), createImageIcon("server.png"), true); firstTitle.putValue(Layout.LEAVE_SPACE, false); statusActions.add(firstTitle); statusActions.add( new ShowStatusAction( translations.getString("SCRAPERMENUITEM"), createImageIcon("world.png"))); statusActions.add( new ShowStatusAction( translations.getString("DATABASEMENUITEM"), createImageIcon("database.png"))); statusActions.add( new ShowStatusAction(translations.getString("WEBSERVER"), createImageIcon("server.png"))); statusActions.add( new ShowStatusAction( translations.getString("STATUSMENU"), createImageIcon("server.png"), true)); } return statusActions; }
public Integer getOrder() { getComponent() .getDocument() .getTransactionManager() .readAccess( new Runnable() { public void run() { targetComponent = new WeakReference<DesignComponent>(getTargetComponent()); } }); if (targetComponent == null) throw new IllegalStateException(getComponent() + " has no target component"); // NOI18N Collection<? extends ActionsPresenter> presenters = targetComponent.get().getPresenters(ActionsPresenter.class); for (ActionsPresenter presenter : presenters) { List<Action> pa = presenter.getActions(); for (Action action : pa) { if (action == null) continue; if (actionToInherit == action.getClass()) { return presenter.getOrder(); } } } return null; }
/** @return */ public Action getFindAction() { Action ret = actionMap.get(ACTION_FIND); if (ret == null) { ret = new AbstractAction(ACTION_FIND, getIcon("find.png", IconSize.SMALL)) { private static final long serialVersionUID = 1L; private FindReplaceDialog dialog; @Override public void actionPerformed(ActionEvent event) { try { if (dialog == null) { dialog = new FindReplaceDialog(debuggerFrame, DialogType.SEARCH); } dialog.setVisible(true); } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Find in script."); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('F', menuActionMods)); ret.putValue(Action.MNEMONIC_KEY, new Integer('F')); ret.setEnabled(false); actionMap.put(ACTION_FIND, ret); } return ret; }
private void setButtonAction(JButton button, final String key) { Action action = new AbstractAction("button" + key + "Action") { @Override public void actionPerformed(ActionEvent e) { appendTextInCalculatorDisplay(key.toLowerCase()); } }; // Shortcuts a los numeros comunes action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(key)); button.getActionMap().put("button" + key + "Action", action); button .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "button" + key + "Action"); // Shortcuts a los del numpad if (getNumpadVk(key) != null) { action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(getNumpadVk(key), 0)); button.getActionMap().put("button" + key + "Action", action); button .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "button" + key + "Action"); } button.addActionListener(action); }
/** Perform the callback action */ public void performAction(SystemAction action) { JTextComponent component = getComponent(); Action ea = getEditorAction(); if (component != null && ea != null) { ea.actionPerformed(new ActionEvent(component, 0, "")); // NOI18N } }
/** * Enable/disable an AbstractAction * * @param actionName the key that maps this action in actionTable * @param b true to enable or false to disable the action */ public static synchronized void setActionEnabled(final Integer actionKey, final boolean b) { Action aa = actionTable.get(actionKey); if (aa != null) { aa.setEnabled(b); } }
public void testCreatesTheItemShopMenu() { ItemShop building = new ItemShop(); building.stockItems(Item.BLOCKABALL, Item.HEALVIAL); JMenu menu = _constructor.createBuildingMenu(building, null); Assert.assertNotNull(menu); Assert.assertEquals(building.getName(), menu.getName()); Assert.assertEquals(building.getName(), menu.getText()); Assert.assertEquals(2, menu.getItemCount()); for (int i = 0; i < menu.getItemCount(); i++) { JMenuItem menuItem = menu.getItem(i); Action action = menuItem.getAction(); Assert.assertNotNull(action); Assert.assertEquals(ItemAction.class, action.getClass()); String name = menuItem.getName(); if (name.equals(Item.BLOCKABALL.toString())) { Assert.assertEquals(Item.BLOCKABALL.getWellFormattedString(), menuItem.getText()); } else if (name.equals(Item.HEALVIAL.toString())) { Assert.assertEquals(Item.HEALVIAL.getWellFormattedString(), menuItem.getText()); } else { Assert.fail("Name: " + name + " Text: " + menuItem.getText()); } } }
public void enforce() { logger_.error("xx", new Throwable("looky")); Set transitions = actions_.keySet(); logger_.debug("Machine state = " + machine_.getState()); for (Iterator i = transitions.iterator(); i.hasNext(); ) { ServiceTransition t = (ServiceTransition) i.next(); logger_.debug("Transition = " + t); logger_.debug("Can trans = " + machine_.canTransition(t)); Action action = (Action) actions_.get(t); logger_.debug("Action clas= " + action.getClass().getName()); action.setEnabled(machine_.canTransition(t)); } // for (Iterator i = ServiceTransition.iterator(); i.hasNext(); ) { // ServiceTransition t = (ServiceTransition) i.next(); // Action action = (Action) actions_.get(t); // action.setEnabled(machine_.canTransition(t)); // // // action = startAction // // state = started // // transition = initialize // // } }
private void switchOn() { requestFocusInWindow(); Action action = getAction(); if (action != null) { Object message = action.getValue(Action.LONG_DESCRIPTION); mStatusLabel.setText(message.toString()); } }
public void testInitialTab() throws Exception { Action action = Actions.forID("System", "org.netbeans.modules.autoupdate.ui.actions.PluginManagerAction"); assertNotNull("Action found", action); action.actionPerformed(new ActionEvent(this, 100, "local")); assertEquals("local", PluginManagerAction.getPluginManagerUI().getSelectedTabName()); }
private JToggleButton addToggleButton(Action a) { JToggleButton tb = new JToggleButton((String) a.getValue(Action.NAME), null); tb.setEnabled(a.isEnabled()); tb.setToolTipText((String) a.getValue(Action.SHORT_DESCRIPTION)); tb.setAction(a); add(tb); return tb; }
private void initAccelerator(Class<? extends Action> actionClass, JMenuItem mnuItem) { Action action = _session.getApplication().getActionCollection().get(actionClass); String accel = (String) action.getValue(Resources.ACCELERATOR_STRING); if (null != accel && 0 != accel.trim().length()) { mnuItem.setAccelerator(KeyStroke.getKeyStroke(accel)); } }
boolean insertBreakSpecialHandling(ActionEvent e) { Action a = tokenMaker.getInsertBreakAction(); if (a != null) { a.actionPerformed(e); return true; } return false; }
public String getDisplayTooltip() { if (!name.isEmpty()) return name; Object tt = action.getValue(TaggingPreset.OPTIONAL_TOOLTIP_TEXT); if (tt != null) return (String) tt; return (String) action.getValue(Action.SHORT_DESCRIPTION); }
private JButton addButton(Action a) { JButton button = new JButton((String) a.getValue(Action.NAME), null); button.setEnabled(a.isEnabled()); button.setToolTipText((String) a.getValue(Action.SHORT_DESCRIPTION)); button.setAction(a); add(button); return button; }
public static void renameProject(Project p, Object caller) { if (p == null) { return; } ContextAwareAction action = (ContextAwareAction) CommonProjectActions.renameProjectAction(); Lookup ctx = Lookups.singleton(p); Action ctxAction = action.createContextAwareInstance(ctx); ctxAction.actionPerformed(new ActionEvent(caller, 0, "")); // NOI18N }
public void adjustFeedback() { actionCancel.setEnabled(true); actionChooseNone.setEnabled(true); if (getSwingFocus() == null) { actionChooseSelected.setEnabled(false); } else { actionChooseSelected.setEnabled(true); } }
public ActionMap getActionMap() { ActionMap map = createActionMap(); nextAction = map.get(NEXT); nextAction.putValue(Action.NAME, getString("reservation_wizard.add_appointment")); nextAction.putValue(Action.SMALL_ICON, getIcon("icon.new")); nextAction.setEnabled(false); map.get(FINISH).setEnabled(false); return map; }
private Action getAction(String name) { for (Action action : sourceArea.getActions()) { if (name.equals(action.getValue(Action.NAME).toString())) { return action; } } return null; }
// From GraphSelectionListener Interface public void valueChanged(GraphSelectionEvent e) { super.valueChanged(e); // Group Button only Enabled if a cell is selected boolean enabled = !graph.isSelectionEmpty(); hide.setEnabled(enabled); expand.setEnabled(enabled); expandAll.setEnabled(enabled); collapse.setEnabled(enabled); }
/** * Add icons to an action. This method is used to associate icons with the different states: * unselected, rollover, rollover selected, selected etc. * * @param action The action to which the icons are added. * @param iconRoles A matrix of Strings, where each element consists of two Strings, the absolute * URL of the icon and the key that represents the role of the icon. The keys are usually * static fields from this class, such as {@link #LARGE_ICON}, {@link #ROLLOVER_ICON}, {@link * #ROLLOVER_SELECTED_ICON} or {@link #SELECTED_ICON}. */ public static void addIcons(Action action, String[][] iconRoles) { for (int i = 0; i < iconRoles.length; i++) { URL img = action.getClass().getResource(iconRoles[i][0]); if (img != null) { ImageIcon icon = new ImageIcon(img); action.putValue(iconRoles[i][1], icon); } } }