List of usage examples for javax.swing Action setEnabled
public void setEnabled(boolean b);
From source file:org.nuclos.client.common.NuclosCollectController.java
protected void setupSearchToolBar() { final Action actSaveFilter = new CommonAbstractAction( getSpringLocaleDelegate().getMessage("NuclosCollectController.9", "Filter speichern"), Icons.getInstance().getIconSave16(), getSpringLocaleDelegate().getMessage( "NuclosCollectController.5", "Eingestelltes Suchkriterium als Filter speichern")) { @Override/*from ww w . ja va2 s. co m*/ public void actionPerformed(ActionEvent ev) { cmdSaveFilter(); } }; final Action actRemoveFilter = new CommonAbstractAction( getSpringLocaleDelegate().getMessage("NuclosCollectController.8", "Filter l\u00f6schen"), Icons.getInstance().getIconDelete16(), getSpringLocaleDelegate() .getMessage("NuclosCollectController.2", "Ausgew\u00e4hlten Filter l\u00f6schen")) { @Override public void actionPerformed(ActionEvent ev) { cmdRemoveFilter(); } }; //result.add(Box.createHorizontalStrut(5)); CenteringPanel cpSearchFilter = new CenteringPanel(getSearchPanel().cmbbxSearchFilter) { @Override public Dimension getMinimumSize() { return this.getCenteredComponent().getMinimumSize(); } @Override public Dimension getMaximumSize() { return this.getCenteredComponent().getPreferredSize(); } }; cpSearchFilter.setOpaque(false); ColoredLabel bl = new ColoredLabel(cpSearchFilter, getSpringLocaleDelegate().getMessage("CollectController.Search.Filter", "Filter")); bl.setName("blChooseFilter"); this.getSearchPanel().addToolBarComponent(bl); //result.add(cpSearchFilter); //result.add(Box.createHorizontalStrut(2)); this.getSearchPanel().addPopupExtraSeparator(); JMenuItem btnSaveFilter = this.getSearchPanel().addPopupExtraMenuItem(new JMenuItem(actSaveFilter)); JMenuItem btnRemoveFilter = this.getSearchPanel().addPopupExtraMenuItem(new JMenuItem(actRemoveFilter)); //final JButton btnSaveFilter = result.add(actSaveFilter); //final JButton btnRemoveFilter = result.add(actRemoveFilter); // disable the remove filter action initially: actRemoveFilter.setEnabled(false); btnSaveFilter.setName("btnSaveFilter"); btnRemoveFilter.setName("btnRemoveFilter"); getSearchPanel().cmbbxSearchFilter.setName("cmbbxSearchFilter"); getSearchPanel().cmbbxSearchFilter.setToolTipText(getSpringLocaleDelegate() .getMessage("NuclosCollectController.15", "W\u00e4hlen Sie hier einen Suchfilter aus")); getSearchPanel().cmbbxSearchFilter.addActionListener(this.alSearchFilter); // set tool tips dynamically: getSearchPanel().cmbbxSearchFilter.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList lst, Object oValue, int index, boolean bSelected, boolean bCellHasFocus) { final JComponent result = (JComponent) super.getListCellRendererComponent(lst, oValue, index, bSelected, bCellHasFocus); String sToolTip = null; if (oValue != null) { final SearchFilter filter = (SearchFilter) oValue; if (result instanceof JLabel && !StringUtils.isNullOrEmpty(filter.getLabelResourceId())) { ((JLabel) result).setText(getSpringLocaleDelegate() .getTextFallback(filter.getLabelResourceId(), filter.getName())); } if (!StringUtils.isNullOrEmpty(filter.getDescriptionResourceId())) { sToolTip = getSpringLocaleDelegate().getTextFallback(filter.getDescriptionResourceId(), filter.getDescriptionResourceId()); } else { sToolTip = filter.getDescription(); } if (filter.getOwner() != null && !(filter.getOwner().equals(Main.getInstance().getMainController().getUserName()))) { sToolTip = sToolTip + " (" + filter.getOwner() + ")"; } result.setToolTipText(sToolTip); } return result; } }); // set the tool tip for the combobox also, as the tool tip for the renderer seems to be // taken in dropped down items only: getSearchPanel().cmbbxSearchFilter.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent ev) { final boolean bSelected = (ev.getStateChange() == ItemEvent.SELECTED); boolean bRegularFilterSelected = bSelected; String sToolTip = null; if (bSelected) { final SearchFilter filter = (SearchFilter) ev.getItem(); assert filter != null; sToolTip = filter.getDescription(); LOG.debug("Filter selected: " + filter.getName()); bRegularFilterSelected = !filter.isDefaultFilter(); } getSearchPanel().cmbbxSearchFilter.setToolTipText(sToolTip); // enable/disable remove filter action - the empty filter cannot be removed: actRemoveFilter.setEnabled(bRegularFilterSelected); } }); //return result; }
From source file:org.nuclos.client.main.MainController.java
private Action createEntityAction(EntityMetaDataVO entitymetavo, String label, final boolean isNew, final Long processId, final String customUsage) { String entity = entitymetavo.getEntity(); if (!getSecurityCache().isReadAllowedForEntity(entity)) { return null; }//from ww w . j a va 2 s.co m if (isNew && entitymetavo.isStateModel() && !getSecurityCache().isNewAllowedForModuleAndProcess(IdUtils.unsafeToId(entitymetavo.getId()), IdUtils.unsafeToId(processId))) { return null; } Action action = new AbstractAction() { @Override public void actionPerformed(ActionEvent evt) { cmdCollectMasterData(evt, isNew, processId, customUsage); } }; Pair<String, Character> nameAndMnemonic = MenuGenerator.getMnemonic(label); action.putValue(Action.NAME, customUsage == null ? nameAndMnemonic.x : String.format("%s (%s)", nameAndMnemonic.x, customUsage)); if (nameAndMnemonic.y != null) { action.putValue(Action.MNEMONIC_KEY, (int) nameAndMnemonic.y.charValue()); } action.setEnabled(true); action.putValue(Action.SMALL_ICON, MainFrame.resizeAndCacheTabIcon(Main.getInstance().getMainFrame().getEntityIcon(entity))); action.putValue(Action.ACTION_COMMAND_KEY, entity); if (!isNew && processId == null) { if (!StringUtils.isNullOrEmpty(entitymetavo.getAccelerator()) && entitymetavo.getAcceleratorModifier() != null) { int keycode = entitymetavo.getAccelerator().charAt(0); if (keycode > 90) keycode -= 32; action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(keycode, entitymetavo.getAcceleratorModifier().intValue())); } else if (!StringUtils.isNullOrEmpty(entitymetavo.getAccelerator())) { action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(entitymetavo.getAccelerator().charAt(0))); } } return action; }
From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java
/** * Replaces the component in the display either icon or busy label * depending on the passed parameter./*from ww w . j av a2s . com*/ * * @param b Pass <code>true</code> to indicate the creation, * <code>false</code> to indicate that the creation is done. */ void setMeasurementLaunchingStatus(boolean b) { Action a = controller.getAction(ImViewerControl.MEASUREMENT_TOOL); a.setEnabled(!b); toolBar.setMeasurementLaunchingStatus(b); }