use of javax.swing.JMenuItem in project gephi by gephi.
the class ImportDB method getMenuPresenter.
@Override
public JMenuItem getMenuPresenter() {
JMenu menu = new JMenu(NbBundle.getMessage(ImportDB.class, "CTL_ImportDB"));
final ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController != null) {
for (final DatabaseImporterBuilder dbb : Lookup.getDefault().lookupAll(DatabaseImporterBuilder.class)) {
ImporterUI ui = importController.getImportController().getUI(dbb.buildImporter());
String menuName = dbb.getName();
if (ui != null) {
menuName = ui.getDisplayName();
}
JMenuItem menuItem = new JMenuItem(new AbstractAction(menuName) {
@Override
public void actionPerformed(ActionEvent e) {
importController.importDatabase(dbb.buildImporter());
}
});
menu.add(menuItem);
}
}
return menu;
}
use of javax.swing.JMenuItem in project gephi by gephi.
the class Export method getMenuPresenter.
@Override
public JMenuItem getMenuPresenter() {
for (final ExporterClassUI ui : Lookup.getDefault().lookupAll(ExporterClassUI.class)) {
String menuName = ui.getName();
JMenuItem menuItem = new JMenuItem(new AbstractAction(menuName) {
@Override
public void actionPerformed(ActionEvent e) {
ui.action();
}
});
menu.add(menuItem);
menuItem.setEnabled(ui.isEnable());
}
return menu;
}
use of javax.swing.JMenuItem in project gephi by gephi.
the class LayoutPanel method initEvents.
private void initEvents() {
layoutCombobox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (layoutCombobox.getSelectedItem().equals(NO_SELECTION) && model.getSelectedLayout() != null) {
setSelectedLayout(null);
} else if (layoutCombobox.getSelectedItem() instanceof LayoutBuilderWrapper) {
LayoutBuilder builder = ((LayoutBuilderWrapper) layoutCombobox.getSelectedItem()).getLayoutBuilder();
if (model.getSelectedLayout() == null || model.getSelectedBuilder() != builder) {
setSelectedLayout(builder);
}
}
}
});
infoLabel.addMouseListener(new MouseAdapter() {
RichTooltip richTooltip;
@Override
public void mouseEntered(MouseEvent e) {
if (infoLabel.isEnabled() && model != null && model.getSelectedLayout() != null) {
richTooltip = buildTooltip(model.getSelectedBuilder());
richTooltip.showTooltip(infoLabel, e.getLocationOnScreen());
}
}
@Override
public void mouseExited(MouseEvent e) {
if (richTooltip != null) {
richTooltip.hideTooltip();
richTooltip = null;
}
}
});
presetsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPopupMenu menu = new JPopupMenu();
List<Preset> presets = layoutPresetPersistence.getPresets(model.getSelectedLayout());
if (presets != null && !presets.isEmpty()) {
for (final Preset p : presets) {
JMenuItem item = new JMenuItem(p.toString());
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
layoutPresetPersistence.loadPreset(p, model.getSelectedLayout());
refreshProperties();
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.loadPreset", model.getSelectedBuilder().getName(), p.toString()));
}
});
menu.add(item);
}
} else {
menu.add("<html><i>" + NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.nopreset") + "</i></html>");
}
JMenuItem saveItem = new JMenuItem(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset"));
saveItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String lastPresetName = NbPreferences.forModule(LayoutPanel.class).get("LayoutPanel.lastPresetName", "");
NotifyDescriptor.InputLine question = new NotifyDescriptor.InputLine(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input"), NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input.name"));
question.setInputText(lastPresetName);
if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
String input = question.getInputText();
if (input != null && !input.isEmpty()) {
layoutPresetPersistence.savePreset(input, model.getSelectedLayout());
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.savePreset", model.getSelectedBuilder().getName(), input));
NbPreferences.forModule(LayoutPanel.class).put("LayoutPanel.lastPresetName", input);
}
}
}
});
menu.add(new JSeparator());
menu.add(saveItem);
menu.show(layoutToolbar, 0, -menu.getPreferredSize().height);
}
});
}
use of javax.swing.JMenuItem in project gephi by gephi.
the class RecentFiles method getMenuPresenter.
@Override
public JMenuItem getMenuPresenter() {
JMenu menu = new JMenu(NbBundle.getMessage(RecentFiles.class, "CTL_OpenRecentFiles"));
MostRecentFiles mru = Lookup.getDefault().lookup(MostRecentFiles.class);
for (String filePath : mru.getMRUFileList()) {
final File file = new File(filePath);
if (file.exists()) {
final String fileName = file.getName();
JMenuItem menuItem = new JMenuItem(new AbstractAction(fileName) {
@Override
public void actionPerformed(ActionEvent e) {
FileObject fileObject = FileUtil.toFileObject(file);
if (fileObject.hasExt(GEPHI_EXTENSION)) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
try {
pc.openProject(file);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
} else {
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController.getImportController().isFileSupported(file)) {
importController.importFile(fileObject);
}
}
}
});
menu.add(menuItem);
}
}
return menu;
}
use of javax.swing.JMenuItem in project processing by processing.
the class Base method populateToolsMenu.
public void populateToolsMenu(JMenu toolsMenu) {
// If this is the first run, need to build out the lists
if (internalTools == null) {
rebuildToolList();
}
// coreTools = ToolContribution.loadAll(Base.getToolsFolder());
// contribTools = ToolContribution.loadAll(Base.getSketchbookToolsFolder());
// Collections.sort(coreTools);
// Collections.sort(contribTools);
// Collections.sort(coreTools, new Comparator<ToolContribution>() {
// @Override
// public int compare(ToolContribution o1, ToolContribution o2) {
// return o1.getMenuTitle().compareTo(o2.getMenuTitle());
// }
// });
toolsMenu.removeAll();
for (Tool tool : internalTools) {
toolsMenu.add(createToolItem(tool));
}
toolsMenu.addSeparator();
if (coreTools.size() > 0) {
for (Tool tool : coreTools) {
toolsMenu.add(createToolItem(tool));
}
toolsMenu.addSeparator();
}
if (contribTools.size() > 0) {
for (Tool tool : contribTools) {
toolsMenu.add(createToolItem(tool));
}
toolsMenu.addSeparator();
}
JMenuItem item = new JMenuItem(Language.text("menu.tools.add_tool"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ContributionManager.openTools();
}
});
toolsMenu.add(item);
}
Aggregations