Java Code Examples for javax.swing.JMenuItem#getClientProperty()
The following examples show how to use
javax.swing.JMenuItem#getClientProperty() .
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 |
/** * Opens recently closed file, using OpenFile support. * * Note that method works as action handler for individual submenu items * created in fillSubMenu, not for whole RecentFileAction. */ @Override public void actionPerformed(final ActionEvent evt) { Object source = evt.getSource(); if (source instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem) source; String path = (String) menuItem.getClientProperty(PATH_PROP); String msg = openFile(path); if (msg != null) { StatusDisplayer.getDefault().setStatusText(msg); Toolkit.getDefaultToolkit().beep(); RecentFiles.pruneHistory(); } } // TODO: processing of pressing of a shortcut key that can be associated // with this action. Note, in this case, any UI component can be passed // as the source. }
Example 2
Source File: AbstractMenuFactory.java From netbeans with Apache License 2.0 | 6 votes |
private void updateMenu (JMenu menu) { ActionProvider provider = getEngine().getActionProvider(); Map context = getEngine().getContextProvider().getContext(); String containerCtx = (String) menu.getClientProperty(KEY_CONTAINERCONTEXT); boolean isDynamic = getEngine().getContainerProvider().isDynamicContext( ContainerProvider.TYPE_MENU, containerCtx); String[] actions = provider.getActionNames(containerCtx); // System.err.println("Updating menu " + containerCtx + "actions: " + Arrays.asList(actions)); int count = menu.getItemCount(); // System.err.println("Item count = " + count); //XXX for dynamic menus, we'll need to compare the contents of the //menu with the list of strings, and add/prune for (int i=0; i < count; i++) { JMenuItem item = menu.getItem(i); if (item != null) { String action = (String) item.getClientProperty (KEY_ACTION); configureMenuItem (item, containerCtx, action, provider, context); } } }
Example 3
Source File: XDMMenuItemUI.java From xdm with GNU General Public License v2.0 | 5 votes |
@Override protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { ButtonModel model = menuItem.getModel(); Color oldColor = g.getColor(); int menuWidth = menuItem.getWidth(); int menuHeight = menuItem.getHeight(); Color bgc = (Color) menuItem.getClientProperty("bgColor"); if (bgc != null) { g.setColor(bgc); } else { g.setColor(colorBg); } g.fillRect(0, 0, menuWidth, menuHeight); if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { paintButtonPressed(g, menuItem); } else { // if (menuItem.getIcon() != null) { // int gap = menuItem.getIcon().getIconWidth() + 2; // g.setColor(this.darkColor); // g.drawLine(gap, 0, gap, menuItem.getHeight()); // g.setColor(this.lightColor); // g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight()); // } } if (menuItem instanceof JCheckBoxMenuItem) { if (((JCheckBoxMenuItem) menuItem).isSelected()) { // chkIcon.paintIcon(menuItem, g, 5, 5); } } g.setColor(oldColor); }
Example 4
Source File: NewFile.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed( ActionEvent e ) { JMenuItem source = (JMenuItem)e.getSource(); Boolean inProject = (Boolean)source.getClientProperty( IN_PROJECT_PROPERTY ); DataObject template = (DataObject)source.getClientProperty( TEMPLATE_PROPERTY ); if ( inProject != null && inProject == Boolean.FALSE ) { doPerform( null, template, false ); } else { doPerform( null, template, true ); } }
Example 5
Source File: SetMainProject.java From netbeans with Apache License 2.0 | 5 votes |
/** * Get project weakly-referenced from an item. * * @param menuItem Menu item. * * @return The project, or null if it is not set or has been * garbage-collected. */ private static Project getItemProject(JMenuItem menuItem) { Reference<Project> p = (Reference<Project>) menuItem.getClientProperty(PROJECT_KEY); if (p == null) { return null; } else { return p.get(); } }
Example 6
Source File: DebugMainProjectAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { JMenuItem item = (JMenuItem)e.getSource(); final BuildExecutionSupport.ActionItem ai = (BuildExecutionSupport.ActionItem) item.getClientProperty(DEBUG_ACTION_ITEM_PROP_NAME); RP.post(new Runnable() { @Override public void run() { ai.repeatExecution(); } }); }
Example 7
Source File: RecentProjects.java From netbeans with Apache License 2.0 | 4 votes |
@Messages({ "# {0} - URL to project directory", "STATUS_loading_recent=Loading project at {0}...", "ERR_InvalidProject=The project is either not valid or deleted" }) @Override public void actionPerformed(ActionEvent e) { if ( e.getSource() instanceof JMenuItem ) { JMenuItem jmi = (JMenuItem)e.getSource(); final URL url = (URL)jmi.getClientProperty( PROJECT_URL_KEY ); StatusDisplayer.getDefault().setStatusText(STATUS_loading_recent(url)); RP.post(new Runnable() { @Override public void run() { Project project = null; FileObject dir = URLMapper.findFileObject( url ); if ( dir != null && dir.isFolder() ) { try { project = ProjectManager.getDefault().findProject( dir ); } catch ( IOException ioEx ) { // Ignore invalid folders } } if ( project != null ) { OpenProjectList.getDefault().open( new Project[] {project}, false, true ); final String name = ProjectUtils.getInformation(project).getName(); EventQueue.invokeLater(new Runnable() { @Override public void run() { ProjectTab ptLogical = ProjectTab.findDefault(ProjectTab.ID_LOGICAL); Node root = ptLogical.getExplorerManager ().getRootContext (); Node projNode = root.getChildren().findChild(name); if (projNode != null) { try { ptLogical.getExplorerManager().setSelectedNodes(new Node[] {projNode}); } catch (PropertyVetoException ignore) { // may ignore it } } else { Logger.getLogger(RecentProjects.class.getName()).log(Level.WARNING, "Could not find {0} among {1}", new Object[] {name, Arrays.asList(root.getChildren().getNodes())}); } ProjectUtilities.makeProjectTabVisible(); } }); } else { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(ERR_InvalidProject())); } } }); } }