下面列出了怎么用javax.swing.JPopupMenu的API类实例代码及写法,或者点击链接到github查看源代码。
private void showPopupMenu(final int rowIndex, final MouseEvent event) {
final JPopupMenu popupMenu = new JPopupMenu();
final JFrame owner =
(JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, DataSectionComponent.this);
final TypeInstanceContainer instanceContainer =
module.getContent().getTypeInstanceContainer();
final TypeManager typeManager = module.getTypeManager();
popupMenu.add(
new CreateTypeInstanceAction(owner, instanceContainer, typeManager, currentSection));
if (rowIndex != -1) {
final TypeInstance existingInstance = typeDataModel.getTypeAtRow(rowIndex);
popupMenu.add(
new EditTypeInstanceAction(owner, typeManager, existingInstance, instanceContainer));
popupMenu.add(new DeleteTypeInstanceAction(owner, existingInstance, instanceContainer));
}
popupMenu.show(event.getComponent(), event.getX(), event.getY());
}
private void customizeTemplatesLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customizeTemplatesLabelMouseClicked
String viewTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.VIEW_TEMPLATE);
String editTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.EDIT_TEMPLATE);
String createTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.CREATE_TEMPLATE);
String listTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.LIST_TEMPLATE);
String baseTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.BASE_TEMPLATE);
String controllerTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.CONTROLLER_TEMPLATE);
String paginationTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.PAGINATION_TEMPLATE);
String utilTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.UTIL_TEMPLATE);
String bundleTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.PAGES, getTemplatesStyle(), WizardProperties.BUNDLE_TEMPLATE);
JPopupMenu menu = new JPopupMenu();
List<String> paths = new ArrayList<>();
processValidPath(menu, paths, viewTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.viewTemplate"));
processValidPath(menu, paths, editTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.editTemplate"));
processValidPath(menu, paths, createTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.createTemplate"));
processValidPath(menu, paths, listTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.listTemplate"));
processValidPath(menu, paths, baseTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.baseTemplate"));
processValidPath(menu, paths, controllerTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.controllerTemplate"));
processValidPath(menu, paths, paginationTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.paginationTemplate"));
processValidPath(menu, paths, utilTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.utilTemplate"));
processValidPath(menu, paths, bundleTemplatePath, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.bundleTemplate"));
menu.insert(new OpenTemplateAction(this, NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "PersistenceClientSetupPanelVisual.allTemplates"), paths.toArray(new String[paths.size()])), 0);
menu.show(customizeTemplatesLabel, evt.getX(), evt.getY());
}
public FileSaver(JProgressBar bar, JLabel label) {
this.bar = bar;
this.label = label;
final JPopupMenu menu = new JPopupMenu("Cancel");
final JMenuItem item = new JMenuItem("Cancel");
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
setCancel(true);
}
});
menu.add(item);
this.label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent ev) {
if (SwingUtilities.isRightMouseButton(ev) && isExtracting())
menu.show(ev.getComponent(), ev.getX(), ev.getY());
}
});
}
/**
* Triggered when mouse is pressed.
*
* @param e mouse event
*/
@Override
public void mousePressed (MouseEvent e)
{
if (isContextWanted(e)) {
JPopupMenu popup = new SeparablePopupMenu();
// A title for this menu
JMenuItem head = new JMenuItem("Boards for selection:");
head.setHorizontalAlignment(SwingConstants.CENTER);
head.setEnabled(false);
popup.add(head);
popup.addSeparator();
for (Board board : boards) {
JMenuItem item = new JCheckBoxMenuItem(board.getName(), board.isSelected());
item.addItemListener(this);
item.setToolTipText(
board.isSelected() ? "Deselect this board?" : "Select this board?");
popup.add(item);
}
popup.show(component, e.getX(), e.getY());
}
}
private JPopupMenu getPopupMenu() {
Action copyAction = new AbstractAction(Messages.getString("MissingPlotsListener.2")) { //$NON-NLS-1$
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
disclaimerTextArea.selectAll();
String selection = disclaimerTextArea.getSelectedText();
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
if (selection == null) {
return;
}
StringSelection clipString = new StringSelection(selection);
clipboard.setContents(clipString, clipString);
}
};
JPopupMenu popup = new JPopupMenu();
popup.add(copyAction);
return popup;
}
@Override
public JPopupMenu getPopupMenu(final Set<UserObject> selectedUserObjects) {
JPopupMenu menu = new JPopupMenu();
ResourceBundleUtil labels = ResourceBundleUtil.getBundle(I18nPlantOverview.TREEVIEW_PATH);
JMenuItem item = new JMenuItem(labels.getString("groupsMouseAdapter.popupMenuItem_removeFromGroup.text"));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openTCSView.removeGroupMembers(selectedUserObjects);
}
});
menu.add(item);
return menu;
}
/**
* Show popup maybe.
*
* @param e the e
*/
private void showPopupMaybe(MouseEvent e) {
// Mouse event is pop-up trigger?
if (e.isPopupTrigger()) {
Object o = e.getSource();
// Event was triggered over the tree?
if (o instanceof javax.swing.JTree) {
JTree tree = (JTree) o;
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
// Get the node in the tree model where context click occurred.
Object leafComponent = path.getLastPathComponent();
if (leafComponent instanceof FSNode) {
FSNode node = (FSNode) leafComponent;
// FSNode is a string node and was shortened?
if (node.getNodeClass() == FSNode.STRING_FS && node.isShortenedString()) {
// Show pop-up
JPopupMenu menu = new JPopupMenu();
JMenuItem showStringItem = new JMenuItem("Show full string");
showStringItem.addActionListener(new ShowStringHandler(node.getFullString()));
menu.add(showStringItem);
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
}
}
}
private void jList_DataFilesMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
//JOptionPane.showMessageDialog(null, this.jList_DataFiles.getSelectedValue().toString(), "", JOptionPane.INFORMATION_MESSAGE);
if (evt.getButton() == MouseEvent.BUTTON1) {
if (this.jList_DataFiles.getSelectedIndex() < 0 || this.jList_DataFiles.getSelectedIndex() == _selectedIndex) {
return;
}
_meteoDataInfo = _dataInfoList.get(this.jList_DataFiles.getSelectedIndex());
updateParameters();
_selectedIndex = this.jList_DataFiles.getSelectedIndex();
} else if (evt.getButton() == MouseEvent.BUTTON3) {
JPopupMenu mnuLayer = new JPopupMenu();
JMenuItem removeLayerMI = new JMenuItem("Remove Data File");
removeLayerMI.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onRemoveDataClick(e);
}
});
mnuLayer.add(removeLayerMI);
mnuLayer.show(this.jList_DataFiles, evt.getX(), evt.getY());
}
}
public Component getToolbarPresenter() {
if (toolbarPresenter == null) {
// gets the real action registered in the menu from layer
Action a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachMainProject"); // NOI18N
final Action attachProjectAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();
// gets the real action registered in the menu from layer
a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachAction"); // NOI18N
final Action attachProcessAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();
JPopupMenu dropdownPopup = new JPopupMenu();
dropdownPopup.add(createDropdownItem(defaultAction));
dropdownPopup.add(createDropdownItem(attachProjectAction));
dropdownPopup.addSeparator();
dropdownPopup.add(createDropdownItem(attachProcessAction));
JButton button = DropDownButtonFactory.createDropDownButton(new ImageIcon(
new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), dropdownPopup);
Actions.connect(button, defaultAction);
toolbarPresenter = button;
}
return toolbarPresenter;
}
private void showPopupMenu(int x, int y) {
JPopupMenu menu = new JPopupMenu();
for (ViewLayer next : layers) {
Action action = layerActions.get(next);
JMenu layerMenu = new JMenu(next.getName());
layerMenu.add(new JMenuItem(action));
if (next.isVisible()) {
List<JMenuItem> items = next.getPopupMenuItems();
if (items != null && !items.isEmpty()) {
layerMenu.addSeparator();
for (JMenuItem item : items) {
layerMenu.add(item);
}
}
}
menu.add(layerMenu);
}
menu.show(this, x, y);
}
private void doSelect(JComponent owner) {
invokingComponent = owner;
invokingComponent.addMouseListener(this);
invokingComponent.addMouseMotionListener(this);
pTable.addMouseListener(this);
pTable.addMouseMotionListener(this);
pTable.getSelectionModel().addListSelectionListener( this );
displayer.getModel().addComplexListDataListener( this );
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
popup = new JPopupMenu();
popup.setBorderPainted( false );
popup.setBorder( BorderFactory.createEmptyBorder() );
popup.add( pTable );
popup.pack();
int locationX = x - (int) pTable.getPreferredSize().getWidth();
int locationY = y + 1;
popup.setLocation( locationX, locationY );
popup.setInvoker( invokingComponent );
popup.addPopupMenuListener( this );
popup.setVisible( true );
shown = true;
invocationTime = System.currentTimeMillis();
}
@Override
public void configureMenu(JPopupMenu menu, Project proj) {
this.proj = proj;
this.frame = proj.getFrame();
this.circState = proj.getCircuitState();
Object attrs = instance.getAttributeSet();
if (attrs instanceof RomAttributes) {
((RomAttributes) attrs).setProject(proj);
}
boolean enabled = circState != null;
edit = createItem(enabled, Strings.get("ramEditMenuItem"));
clear = createItem(enabled, Strings.get("ramClearMenuItem"));
load = createItem(enabled, Strings.get("ramLoadMenuItem"));
save = createItem(enabled, Strings.get("ramSaveMenuItem"));
// assembler = createItem(enabled, Strings.get("Assembler"));
menu.addSeparator();
menu.add(edit);
menu.add(clear);
menu.add(load);
menu.add(save);
// menu.add(assembler);
}
protected void showPopup (MouseEvent e) {
int selRow = table.rowAtPoint(e.getPoint());
if (selRow != -1) {
if (! table.getSelectionModel().isSelectedIndex(selRow)) {
table.getSelectionModel().clearSelection();
table.getSelectionModel().setSelectionInterval(selRow, selRow);
}
} else {
table.getSelectionModel().clearSelection();
}
Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TableView.this);
if (isPopupAllowed()) {
JPopupMenu pop = createPopup(p);
TableView.this.showPopup(p.x, p.y, pop);
e.consume();
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
JPopupMenu popMenu = new JPopupMenu();
JMenuItem mtCopy = new JMenuItem(resourceMap.getString("mtCopy.text"));
JMenuItem mtPaste = new JMenuItem(resourceMap.getString("mtPaste.text"));
JMenuItem mtSelAll = new JMenuItem(resourceMap.getString("mtSelAll.text"));
JMenuItem mtClean = new JMenuItem(resourceMap.getString("mtClean.text"));
popMenu.add(mtCopy);
popMenu.add(mtPaste);
popMenu.add(mtSelAll);
popMenu.add(mtClean);
JTextArea ta = getTextArea();
if(ta.getSelectedText() == null || ta.getSelectedText().length()==0){
mtCopy.setEnabled(false);
}
mtCopy.addActionListener(new TextAreaMenuItemActionListener(1));
mtPaste.addActionListener(new TextAreaMenuItemActionListener(2));
mtSelAll.addActionListener(new TextAreaMenuItemActionListener(3));
mtClean.addActionListener(new TextAreaMenuItemActionListener(4));
popMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
@Override
protected javax.swing.JPopupMenu getVertVariablesPopup() {
if(varPopup==null) {
buildVarPopup();
}
isHorzVarPopup = false;
FontSizer.setFonts(varPopup, FontSizer.getLevel());
for(Component c : varPopup.getComponents()) {
JMenuItem item = (JMenuItem) c;
if(yLine.getText().equals(item.getActionCommand())) {
item.setFont(item.getFont().deriveFont(Font.BOLD));
} else {
item.setFont(item.getFont().deriveFont(Font.PLAIN));
}
}
return varPopup;
}
private AbstractButton getExportButton() {
final AbstractButton export = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Export24.gif"),
false);
export.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPopupMenu viewPopup = new JPopupMenu("Export");
viewPopup.add(exportAsCsvAction);
viewPopup.add(putStatisticsIntoVectorDataAction);
final Rectangle buttonBounds = export.getBounds();
viewPopup.show(export, 1, buttonBounds.height + 1);
}
});
export.setEnabled(false);
return export;
}
/**
* Action called when a Variant button is clicked.
*
* @param number Variant number.
*/
public void actionVariant(String number) {
JPopupMenu menu = new JPopupMenu();
int variantNumber = Integer.parseInt(number);
String prefix = language.getCode();
if (script != null) {
prefix += "-" + script.getCode();
}
if (region != null) {
prefix += "-" + region.getCode();
}
for (int i = 0; i < variantNumber; i++) {
if (variant.get(i) != null) {
prefix += "-" + variant.get(i).getCode();
}
}
List<LanguageRegistry.Variant> variants = registry.getVariants(prefix);
for (LanguageRegistry.Variant tmpVariant : variants) {
JMenuItem item = new JMenuItem(tmpVariant.toString());
item.setActionCommand(number + ";" + tmpVariant.getCode());
item.addActionListener(EventHandler.create(
ActionListener.class, this, "selectVariant", "actionCommand"));
menu.add(item);
}
menu.show(buttonVariant.get(variantNumber), 0, buttonVariant.get(variantNumber).getHeight());
}
/**
* Creates a popup menu with entries from the selected nodes
* related to the given component (usually a ETable subclass). The popup
* is created for the table element in given column and row (column
* and row are in the view's coordinates (not the model's)).
*/
public JPopupMenu createPopupMenu(int row, int column, Node[] selectedNodes,
Component component) {
Action[] actions = NodeOp.findActions (selectedNodes);
JPopupMenu res = Utilities.actionsToPopup(actions, component);
if (showQuickFilter) {
if ((component instanceof ETable) && (column >= 0)) {
ETable et = (ETable)component;
if (row >= 0) {
Object val = et.getValueAt(row, column);
val = et.transformValue(val);
String s = NbBundle.getMessage(NodePopupFactory.class, "LBL_QuickFilter");
res.add(et.getQuickFilterPopup(column, val, s));
} else if (et.getQuickFilterColumn() == column) {
addNoFilterItem(et, res);
}
}
}
return res;
}
public static void main(String[] args) {
Robot r = Util.createRobot();
JWindow w = new JWindow();
w.setSize(100, 100);
w.setVisible(true);
Util.waitForIdle(r);
final JPopupMenu menu = new JPopupMenu();
JButton item = new JButton("A button in popup");
menu.add(item);
w.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
menu.show(me.getComponent(), me.getX(), me.getY());
System.out.println("Showing menu at " + menu.getLocationOnScreen() +
" isVisible: " + menu.isVisible() +
" isValid: " + menu.isValid());
}
});
Util.clickOnComp(w, r);
Util.waitForIdle(r);
if (!menu.isVisible()) {
throw new RuntimeException("menu was not shown");
}
menu.hide();
System.out.println("Test passed.");
}
@Override
public Component getToolbarPresenter() {
JPopupMenu menu = new JPopupMenu();
JButton button = DropDownButtonFactory.createDropDownButton(
new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
final JMenuItem item = new JMenuItem(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText")));
item.setEnabled(isEnabled());
addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propName = evt.getPropertyName();
if ("enabled".equals(propName)) {
item.setEnabled((Boolean) evt.getNewValue());
} else if ("menuText".equals(propName)) {
item.setText(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue()));
}
}
});
menu.add(item);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MainProjectActionWithHistory.this.actionPerformed(e);
}
});
org.openide.awt.Actions.connect(button, this);
menu.addPopupMenuListener(this);
return button;
}
/** Creates a new popup menu for the selected operator. */
private JPopupMenu createOperatorPopupMenu() {
JPopupMenu menu = new JPopupMenu();
menu.add(EXPAND_ALL_ACTION);
menu.add(COLLAPSE_ALL_ACTION);
menu.addSeparator();
String name = "Tree";
if (mainFrame.getProcess().getProcessLocation() != null) {
name = mainFrame.getProcess().getProcessLocation().getShortName();
}
menu.add(PrintingTools.makeExportPrintMenu(this, name));
return menu;
}
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
JPopupMenu popup = makePopupMenu();
popup.show(e.getComponent(),
e.getX(), e.getY());
}
}
public Dimension preferredLayoutSize(Container target) {
if (target instanceof JPopupMenu) {
JPopupMenu popupMenu = (JPopupMenu) target;
popupMenu.putClientProperty(
SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
}
return super.preferredLayoutSize(target);
}
public JComponent getMarkerComponent(final String name, final int measurementIndex, final int markerPairIndex, final int index) {
Dimension dim = new Dimension(MARKER_NAME_WIDTH,HEIGHT);
JTextField markerButton = new JTextField(name);
markerButton.setEditable(false);
markerButton.setHorizontalAlignment(SwingConstants.CENTER);
// Indicate marker does not exist in model's marker set with red color (though the measurement may still be invalid
// if this marker is not found in the marker data passed to the model scaler)
boolean markerInModel = measurementSetModel.getMarkerExistsInModel(name);
boolean markerInMeasurementTrial = measurementSetModel.getMarkerExistsInMeasurementTrial(name);
if(!markerInModel || !markerInMeasurementTrial) {
markerButton.setBackground(invalidColor);
if(!markerInModel && !markerInMeasurementTrial) markerButton.setToolTipText("Marker not in model or measurement marker data!");
else if(!markerInModel) markerButton.setToolTipText("Marker not in model!");
else markerButton.setToolTipText("Marker not in measurement marker data!");
} else {
markerButton.setBackground(Color.white);
markerButton.setToolTipText(null);
}
markerButton.setMinimumSize(dim);
markerButton.setMaximumSize(dim);
markerButton.setPreferredSize(dim);
markerButton.setBorder(markerInnerBorder);
markerButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
JPopupMenu popup = new JPopupMenu();
for(int i=0; i<markerNames.size(); i++) {
JRadioButtonMenuItem item = new JRadioButtonMenuItem(new ChangeMarkerPairMarkerAction(markerNames.get(i), measurementIndex, markerPairIndex, index));
if(markerNames.get(i).equals(name)) item.setSelected(true);
popup.add(item);
}
popup.setLayout(new GridLayout(25,markerNames.size()/25+1));
popup.show(evt.getComponent(),evt.getX(),evt.getY());
}
});
return markerButton;
}
private void initUI(Set<ClientUtils.SourceCodeSelection> selection) {
setLayout(new BorderLayout(0, 0));
jdbcCallsView = new JDBCTreeTableView(selection, false) {
protected void installDefaultAction() {
getResultsComponent().setDefaultAction(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
ProfilerTable t = getResultsComponent();
int row = t.getSelectedRow();
PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)t.getValueForRow(row);
if (isSQL(node)) {
showQueryImpl(node);
} else {
ClientUtils.SourceCodeSelection userValue = getUserValueForRow(row);
if (userValue != null) performDefaultAction(userValue);
}
}
});
}
protected void performDefaultAction(ClientUtils.SourceCodeSelection userValue) {
if (showSourceSupported()) showSource(userValue);
}
protected void populatePopup(JPopupMenu popup, Object value, ClientUtils.SourceCodeSelection userValue) {
LiveJDBCView.this.populatePopup(jdbcCallsView, popup, value, userValue);
}
protected void popupShowing() { LiveJDBCView.this.popupShowing(); }
protected void popupHidden() { LiveJDBCView.this.popupHidden(); }
protected boolean hasBottomFilterFindMargin() { return true; }
};
jdbcCallsView.notifyOnFocus(new Runnable() {
public void run() { lastFocused = jdbcCallsView; }
});
add(jdbcCallsView, BorderLayout.CENTER);
// // TODO: read last state?
// setView(true, false);
}
/**
* Returns the index of an item in a popup menu.
*
* @param menu the menu.
* @param text the label.
*
* @return The item index.
*/
private int getPopupMenuItem(JPopupMenu menu, String text) {
int index = -1;
for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
Component comp = menu.getComponent(i);
if (comp instanceof JMenuItem) {
JMenuItem item = (JMenuItem) comp;
if (text.equals(item.getText())) {
index = i;
}
}
}
return index;
}
/**
* Add submenus for linking texts.
*
* @param wiki Wiki.
* @param popup Popup menu.
* @param page Page.
* @param text Text.
* @param element Element.
* @param textPane Text pane.
*/
public void addLinkText(
EnumWikipedia wiki, JPopupMenu popup, Page page, String text,
Element element, JTextPane textPane) {
List<String> templates = null;
if (wiki != null) {
templates = wiki.getConfiguration().getStringList(
WPCConfigurationStringList.TEMPLATES_FOR_LINKING_TEXT);
}
if ((text != null) &&
(page != null) &&
Boolean.TRUE.equals(page.isDisambiguationPage()) &&
(templates != null) &&
(templates.size() > 0)) {
if (templates.size() > 1) {
JMenu submenu = new JMenu(GT._T("Link text"));
for (String template : templates) {
addItem(
submenu, null, GT._T("Using {0}", "{{" + template + "}}"), true,
new MarkLinkAction(
page, element,
createTextForTemplate(template, page.getTitle(), text),
textPane, null));
}
popup.add(submenu);
} else {
addItem(
popup, null, GT._T("Link text"), true,
new MarkLinkAction(
page, element,
createTextForTemplate(templates.get(0), page.getTitle(), text),
textPane, null));
}
}
}
public static void addEditorAction(JEditorPane editor, AbstractAction a, String key, String name, String keyStroke) {
KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
a.putValue(Action.ACCELERATOR_KEY, ks);
a.putValue(Action.NAME, name);
String actionName = key;
ActionMap amap = editor.getActionMap();
InputMap imap = editor.getInputMap(JTextComponent.WHEN_FOCUSED);
imap.put(ks, actionName);
amap.put(actionName, a);
JPopupMenu pmenu = editor.getComponentPopupMenu();
JMenuItem findUsagesMenu = new JMenuItem(a);
pmenu.add(findUsagesMenu);
}
public Dimension preferredLayoutSize(Container target) {
if (target instanceof JPopupMenu) {
JPopupMenu popupMenu = (JPopupMenu) target;
popupMenu.putClientProperty(
SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
}
return super.preferredLayoutSize(target);
}
@Nonnull
public static JPopupMenu makePopUp(
@Nonnull final PluginContext context,
final boolean fullScreenModeActive,
@Nullable final Topic topicUnderMouse
) {
final JPopupMenu result = UI_COMPO_FACTORY.makePopupMenu();
final List<PopUpMenuItemPlugin> pluginMenuItems = MindMapPluginRegistry.getInstance().findFor(PopUpMenuItemPlugin.class);
final List<JMenuItem> tmpList = new ArrayList<JMenuItem>();
final boolean isModelNotEmpty = context.getPanel().getModel().getRoot() != null;
putAllItemsAsSection(result, null, findPopupMenuItems(context, PopUpSection.MAIN, fullScreenModeActive, tmpList, topicUnderMouse, pluginMenuItems));
putAllItemsAsSection(result, null, findPopupMenuItems(context, PopUpSection.MANIPULATORS, fullScreenModeActive, tmpList, topicUnderMouse, pluginMenuItems));
putAllItemsAsSection(result, null, findPopupMenuItems(context, PopUpSection.EXTRAS, fullScreenModeActive, tmpList, topicUnderMouse, pluginMenuItems));
final JMenu exportMenu = UI_COMPO_FACTORY.makeMenu(BUNDLE.getString("MMDExporters.SubmenuName"));
exportMenu.setIcon(ICON_SERVICE.getIconForId(IconID.POPUP_EXPORT));
final JMenu importMenu = UI_COMPO_FACTORY.makeMenu(BUNDLE.getString("MMDImporters.SubmenuName"));
importMenu.setIcon(ICON_SERVICE.getIconForId(IconID.POPUP_IMPORT));
putAllItemsAsSection(result, importMenu, findPopupMenuItems(context, PopUpSection.IMPORT, fullScreenModeActive, tmpList, topicUnderMouse, pluginMenuItems));
if (isModelNotEmpty) {
putAllItemsAsSection(result, exportMenu, findPopupMenuItems(context, PopUpSection.EXPORT, fullScreenModeActive, tmpList, topicUnderMouse, pluginMenuItems));
}
putAllItemsAsSection(result, null, findPopupMenuItems(context, PopUpSection.TOOLS, fullScreenModeActive, tmpList, topicUnderMouse, pluginMenuItems));
putAllItemsAsSection(result, null, findPopupMenuItems(context, PopUpSection.MISC, fullScreenModeActive, tmpList, topicUnderMouse, pluginMenuItems));
return result;
}