Java Code Examples for javax.swing.JMenuItem#putClientProperty()

The following examples show how to use javax.swing.JMenuItem#putClientProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecentFileAction.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and configures an item of the submenu according to the given
 * {@code HistoryItem}.
 *
 * @param hItem the {@code HistoryItem}.
 * @return the munu item.
 */
private JMenuItem newSubMenuItem(final FileObject fo)
        throws DataObjectNotFoundException {
    // Try and find the icon for the history item. If this can't be done
    // eg. because the file no longer exists, then a DataObjectNotFoundException
    // is thrown. The caller should catch this exception and skip the history item
    // it was trying to create a menu item for.
    Icon icon = getIcon(fo);
    final String path = fo.getPath();
    final JMenuItem jmi = new JMenuItem(fo.getName()) {
        public @Override
        void menuSelectionChanged(final boolean isIncluded) {
            super.menuSelectionChanged(isIncluded);
            if (isIncluded) {
                StatusDisplayer.getDefault().setStatusText(path);
            }
        }
    };
    jmi.putClientProperty(PATH_PROP, path);
    jmi.addActionListener(this);
    jmi.setIcon(icon);
    return jmi;
}
 
Example 2
Source File: AbstractContextMenuFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
//        System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
        item.setName(action);
        item.putClientProperty(KEY_ACTION, action);
        item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
        item.putClientProperty(KEY_CREATOR, this);
        item.setText(
            provider.getDisplayName(action, containerCtx));
        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, context);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0; 
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
        //Intentionally use enabled property
        item.setVisible(enabled);
        item.setMnemonic(provider.getMnemonic(action, containerCtx));
        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
Example 3
Source File: AbstractMenuFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
//        System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
        item.setName(action);
        item.putClientProperty(KEY_ACTION, action);
        item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
        item.putClientProperty(KEY_CREATOR, this);
        item.setText(
            provider.getDisplayName(action, containerCtx));
//        System.err.println("  item text is " + item.getText());
        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, context);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0; 
//        System.err.println("action " + action + (enabled ? " enabled" : " disabled"));
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
//        System.err.println("action " + action + (visible ? " visible" : " invisible"));
        item.setVisible(visible);
        item.setMnemonic(provider.getMnemonic(action, containerCtx));
        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
Example 4
Source File: CloseOnMouseClickPropertyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void setProperties(JMenuItem menuItem) {
    switch (type) {
        case CHECK_BOX_MENU_ITEM:
            menuItem.putClientProperty(CHECK_BOX_PROP, compDoNotCloseOnMouseClick);
            UIManager.put(CHECK_BOX_PROP, lafDoNotCloseOnMouseClick);
            break;
        case RADIO_BUTTON_MENU_ITEM:
            menuItem.putClientProperty(RADIO_BUTTON_PROP, compDoNotCloseOnMouseClick);
            UIManager.put(RADIO_BUTTON_PROP, lafDoNotCloseOnMouseClick);
            break;
        default:
            menuItem.putClientProperty(CHECK_BOX_PROP, compDoNotCloseOnMouseClick);
            menuItem.putClientProperty(RADIO_BUTTON_PROP, compDoNotCloseOnMouseClick);
            UIManager.put(CHECK_BOX_PROP, lafDoNotCloseOnMouseClick);
            UIManager.put(RADIO_BUTTON_PROP, lafDoNotCloseOnMouseClick);
    }
}
 
Example 5
Source File: AbstractContextMenuFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JMenuItem getOrCreateMenuItem(int type) {
    JMenuItem result = type == ActionProvider.ACTION_TYPE_ITEM ? new JMenuItem() :
        type == ActionProvider.ACTION_TYPE_SUBCONTEXT ? new JMenu() : null;
    if (type == ActionProvider.ACTION_TYPE_ITEM) {
        result.addActionListener (getItemListener());
    } else if (type == ActionProvider.ACTION_TYPE_SUBCONTEXT){
        //attachToMenu ((JMenu) result);
    }
    result.putClientProperty (KEY_CREATOR, this);
    return result;
}
 
Example 6
Source File: AbstractMenuFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JMenuItem getOrCreateMenuItem(int type) {
    JMenuItem result = type == ActionProvider.ACTION_TYPE_ITEM ? new JMenuItem() :
        type == ActionProvider.ACTION_TYPE_SUBCONTEXT ? new JMenu() : null;
    if (type == ActionProvider.ACTION_TYPE_ITEM) {
        result.addActionListener (getItemListener());
    } else if (type == ActionProvider.ACTION_TYPE_SUBCONTEXT){
        attachToMenu ((JMenu) result);
    }
    result.putClientProperty (KEY_CREATOR, this);
    return result;
}
 
Example 7
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Constructor.
* @param popup pop-up menu
*/
public MenuBridge(JMenuItem item, Action action, boolean popup) {
    super(item, action);
    this.popup = popup;
    
    if (popup) {
        prepareMargins(item, action);
    } else {
        // #40824 hack
        item.putClientProperty("menubridgeresizehack", this);

        // #40824 hack end.
    }
}
 
Example 8
Source File: FilterActions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JMenuItem[] createMenuItems () {
    FiltersDescription filtersDesc = filters.getDescription();
    ArrayList menuItems = new ArrayList();
    for (int i = 0; i < filtersDesc.getFilterCount(); i++) {
        String filterName = filtersDesc.getName(i);
        JMenuItem menuItem = new JCheckBoxMenuItem(
                filtersDesc.getDisplayName(i), filters.isSelected(filterName)); 
        menuItem.addActionListener(this);
        menuItem.putClientProperty(PROP_FILTER_NAME, filterName);
        menuItems.add(menuItem);
    }
    return (JMenuItem[])menuItems.toArray(new JMenuItem[]{});
}
 
Example 9
Source File: ShowTabsButton.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
public void click() {
    JPopupMenu    menu = new JPopupMenu();
    List<DockTab> tabs = new ArrayList<>(mHidden);
    Collections.sort(tabs);
    for (DockTab tab : tabs) {
        JMenuItem item = new JMenuItem(tab.getFullTitle(), tab.getIcon());
        item.putClientProperty(this, tab.getDockable());
        item.addActionListener(this);
        menu.add(item);
    }
    menu.show(this, 0, 0);
}
 
Example 10
Source File: Actions.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Attaches menu item to an action.
 * You can supply an alternative implementation
 * for this method by implementing method
 * {@link ButtonActionConnector#connect(JMenuItem, Action, boolean)} and
 * registering an instance of {@link ButtonActionConnector} in the
 * default lookup. 
 * <p>
 * Since version 7.1 the action can also provide properties
 * "menuText" and "popupText" if one wants to use other text on the JMenuItem
 * than the name
 * of the action taken from Action.NAME. The popupText is checked only if the
 * popup parameter is true and takes the biggest precedence. The menuText is
 * tested everytime and takes precedence over standard <code>Action.NAME</code>
 * <p>
 * By default icons are not visible in popup menus. This can be configured
 * via <a href="@[email protected]#branding-USE_MNEMONICS">branding</a>.
 * 
 * @param item menu item
 * @param action action
 * @param popup create popup or menu item
 * @since 3.29
 */
public static void connect(JMenuItem item, Action action, boolean popup) {
    for (ButtonActionConnector bac : buttonActionConnectors()) {
        if (bac.connect(item, action, popup)) {
            return;
        }
    }
    Bridge b;
    if ((item instanceof JCheckBoxMenuItem) && (action.getValue(Actions.ACTION_VALUE_TOGGLE) != null)) {
        b = new CheckMenuBridge((JCheckBoxMenuItem)item, action, popup);
    } else {
        b = new MenuBridge(item, action, popup);
    }
    b.prepare();

    if (item instanceof Actions.MenuItem) {
        ((Actions.MenuItem)item).setBridge(b);
    }
    item.putClientProperty(DynamicMenuContent.HIDE_WHEN_DISABLED, action.getValue(DynamicMenuContent.HIDE_WHEN_DISABLED));
}
 
Example 11
Source File: NbEditorKit.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void addAction(JTextComponent component, JPopupMenu popupMenu, Action action) {
    Lookup contextLookup = getContextLookup(component);
    
    // issue #69688
    EditorKit kit = component.getUI().getEditorKit(component);
    if (contextLookup == null && (kit instanceof NbEditorKit) &&
            ((NbEditorKit)kit).systemAction2editorAction.containsKey(action.getClass().getName())){
        addAction(component, popupMenu, (String) ((NbEditorKit)kit).systemAction2editorAction.get(action.getClass().getName()));
        return;
    }
    
    action = translateContextLookupAction(contextLookup, action);

    if (action != null) {
        JMenuItem item = createLocalizedMenuItem(action);
        if (item instanceof DynamicMenuContent) {
            Component[] cmps = ((DynamicMenuContent)item).getMenuPresenters();
            for (int i = 0; i < cmps.length; i++) {
                if(cmps[i] != null) {
                    popupMenu.add(cmps[i]);
                } else {
                    popupMenu.addSeparator();
                }
            }
        } else {
            if (Boolean.TRUE.equals(action.getValue(DynamicMenuContent.HIDE_WHEN_DISABLED)) && !action.isEnabled()) {
                return;
            }
            if (item == null) {
                LOG.log(Level.WARNING, "Null menu item produced by action {0}.", action);
            } else {
                item.setEnabled(action.isEnabled());
                Object helpID = action.getValue ("helpID"); // NOI18N
                if (helpID != null && (helpID instanceof String)) {
                    item.putClientProperty ("HelpID", helpID); // NOI18N
                }
                assignAccelerator(component.getKeymap(), action, item);
                debugPopupMenuItem(item, action);
                popupMenu.add(item);
            }
        }
    }
}
 
Example 12
Source File: ProjectAntRunJ2SE.java    From tikione-jacocoverage with MIT License 4 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    JMenuItem menuitem = new JMenuItem(this);
    menuitem.putClientProperty(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
    return menuitem;
}
 
Example 13
Source File: ProjectRemoveCoverageData.java    From tikione-jacocoverage with MIT License 4 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    JMenuItem menuitem = new JMenuItem(this);
    menuitem.putClientProperty(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
    return menuitem;
}
 
Example 14
Source File: ProjectAntTestJ2SE.java    From tikione-jacocoverage with MIT License 4 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    JMenuItem menuitem = new JMenuItem(this);
    menuitem.putClientProperty(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
    return menuitem;
}
 
Example 15
Source File: SetMainProject.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Set weakly-referenced project as item's client property.
 *
 * @param menuItem Menu item.
 * @param project The project.
 */
private static void setItemProject(JMenuItem menuItem, Project project) {
    menuItem.putClientProperty(PROJECT_KEY, new WeakReference<Project>(project));
}