List of usage examples for javax.swing JMenuItem putClientProperty
public final void putClientProperty(Object key, Object value)
From source file:processing.app.Base.java
public void rebuildImportMenu(JMenu importMenu) { if (importMenu == null) return;//from w w w .j a va2 s. c o m importMenu.removeAll(); JMenuItem menu = new JMenuItem(tr("Manage Libraries...")); // Ctrl+Shift+I on Windows and Linux, Command+Shift+I on macOS menu.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | ActionEvent.SHIFT_MASK)); menu.addActionListener(e -> openLibraryManager("", "")); importMenu.add(menu); importMenu.addSeparator(); JMenuItem addLibraryMenuItem = new JMenuItem(tr("Add .ZIP Library...")); addLibraryMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Base.this.handleAddLibrary(); BaseNoGui.librariesIndexer.rescanLibraries(); Base.this.onBoardOrPortChange(); Base.this.rebuildImportMenu(Editor.importMenu); Base.this.rebuildExamplesMenu(Editor.examplesMenu); } }); importMenu.add(addLibraryMenuItem); importMenu.addSeparator(); // Split between user supplied libraries and IDE libraries TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); if (targetPlatform != null) { LibraryList libs = getSortedLibraries(); String lastLibType = null; for (UserLibrary lib : libs) { String libType = lib.getTypes().get(0); if (!libType.equals(lastLibType)) { if (lastLibType != null) { importMenu.addSeparator(); } lastLibType = libType; JMenuItem platformItem = new JMenuItem(I18n.format(tr("{0} libraries"), tr(lastLibType))); platformItem.setEnabled(false); importMenu.add(platformItem); } AbstractAction action = new AbstractAction(lib.getName()) { public void actionPerformed(ActionEvent event) { UserLibrary l = (UserLibrary) getValue("library"); try { activeEditor.getSketchController().importLibrary(l); } catch (IOException e) { showWarning(tr("Error"), I18n.format("Unable to list header files in {0}", l.getSrcFolder()), e); } } }; action.putValue("library", lib); // Add new element at the bottom JMenuItem item = new JMenuItem(action); item.putClientProperty("library", lib); importMenu.add(item); } } }
From source file:processing.app.Base.java
protected void addLibraries(JMenu menu, LibraryList libs) throws IOException { LibraryList list = new LibraryList(libs); list.sort();/*from w w w . j a v a 2 s .c o m*/ for (UserLibrary lib : list) { @SuppressWarnings("serial") AbstractAction action = new AbstractAction(lib.getName()) { public void actionPerformed(ActionEvent event) { UserLibrary l = (UserLibrary) getValue("library"); try { activeEditor.getSketchController().importLibrary(l); } catch (IOException e) { showWarning(tr("Error"), I18n.format("Unable to list header files in {0}", l.getSrcFolder()), e); } } }; action.putValue("library", lib); // Add new element at the bottom JMenuItem item = new JMenuItem(action); item.putClientProperty("library", lib); menu.add(item); // XXX: DAM: should recurse here so that library folders can be nested } }