use of javax.swing.JMenuItem in project omegat by omegat-org.
the class ExternalFinderItemMenuGenerator method generate.
@Override
public List<JMenuItem> generate() {
List<ExternalFinderItem> finderItems = ExternalFinder.getItems();
if (finderItems.isEmpty()) {
return Collections.emptyList();
}
List<JMenuItem> menuItems = new ArrayList<>();
// generate menu
for (ExternalFinderItem finderItem : finderItems) {
if (popup && finderItem.isNopopup()) {
continue;
}
if (target == ExternalFinderItem.TARGET.ASCII_ONLY && finderItem.isNonAsciiOnly()) {
continue;
} else if (target == ExternalFinderItem.TARGET.NON_ASCII_ONLY && finderItem.isAsciiOnly()) {
continue;
}
JMenuItem item = new JMenuItem();
Mnemonics.setLocalizedText(item, finderItem.getName());
// set keyboard shortcut
if (!popup) {
item.setAccelerator(finderItem.getKeystroke());
}
item.addActionListener(new ExternalFinderItemActionListener(finderItem));
menuItems.add(item);
}
return menuItems;
}
use of javax.swing.JMenuItem in project omegat by omegat-org.
the class RecentProjects method updateMenu.
public static void updateMenu() {
IMainWindow window = Core.getMainWindow();
if (window == null) {
return;
}
JMenuItem recentMenu = window.getMainMenu().getProjectRecentMenuItem();
if (recentMenu == null) {
return;
}
recentMenu.removeAll();
synchronized (RECENT_PROJECTS) {
for (final String project : RECENT_PROJECTS) {
JMenuItem recentProjectMenuItem = new JMenuItem(project);
recentProjectMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
ProjectUICommands.projectOpen(new File(project), true);
}
});
recentMenu.add(recentProjectMenuItem);
}
recentMenu.setEnabled(!RECENT_PROJECTS.isEmpty());
}
}
use of javax.swing.JMenuItem in project omegat by omegat-org.
the class MachineTranslateTextArea method populatePaneMenu.
@Override
public void populatePaneMenu(JPopupMenu menu) {
final JMenuItem prefs = new JMenuItem(OStrings.getString("GUI_MACHINETRANSLATESWINDOW_OPEN_PREFS"));
prefs.addActionListener(e -> new PreferencesWindowController().show(Core.getMainWindow().getApplicationFrame(), MachineTranslationPreferencesController.class));
menu.add(prefs);
}
use of javax.swing.JMenuItem in project omegat by omegat-org.
the class ProjectFilesListController method addContextMenuItem.
private void addContextMenuItem(JPopupMenu menu, boolean isSource, List<File> files) {
long presentFiles = files.stream().filter(File::isFile).count();
String defaultTitle, modTitle;
if (presentFiles > 1) {
defaultTitle = StringUtil.format(OStrings.getString(isSource ? "PF_OPEN_SOURCE_FILES" : "PF_OPEN_TARGET_FILES"), presentFiles);
modTitle = StringUtil.format(OStrings.getString(isSource ? "PF_OPEN_SOURCE_FILES" : "PF_OPEN_TARGET_FILES"), presentFiles);
} else {
defaultTitle = OStrings.getString(isSource ? "PF_OPEN_SOURCE_FILE" : "PF_OPEN_TARGET_FILE");
modTitle = OStrings.getString(isSource ? "PF_REVEAL_SOURCE_FILE" : "PF_REVEAL_TARGET_FILE");
}
JMenuItem item = menu.add(defaultTitle);
item.addActionListener(e -> {
boolean openParent = (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
Stream<File> stream;
if (openParent) {
stream = files.stream().map(File::getParentFile).distinct().filter(File::isDirectory);
} else {
stream = files.stream().filter(File::isFile);
}
stream.forEach(f -> {
try {
Desktop.getDesktop().open(f);
} catch (IOException ex) {
Log.log(ex);
}
});
});
item.setEnabled(presentFiles > 0);
item.addMenuKeyListener(new MenuKeyListener() {
@Override
public void menuKeyTyped(MenuKeyEvent e) {
}
@Override
public void menuKeyReleased(MenuKeyEvent e) {
if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0 || e.getKeyCode() == KeyEvent.VK_META || e.getKeyCode() == KeyEvent.VK_CONTROL) {
setText(defaultTitle);
}
}
@Override
public void menuKeyPressed(MenuKeyEvent e) {
if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
setText(modTitle);
}
}
private void setText(String text) {
item.setText(text);
menu.pack();
}
});
}
use of javax.swing.JMenuItem in project omegat by omegat-org.
the class TagIssue method getMenuComponents.
@Override
public List<? extends JMenuItem> getMenuComponents() {
String fixText = TagValidationTool.fixErrors(report);
if (fixText == null) {
return Collections.emptyList();
} else {
JMenuItem doFix = new JMenuItem();
org.openide.awt.Mnemonics.setLocalizedText(doFix, OStrings.getString("ISSUES_TAGS_BUTTON_APPLY_FIX"));
doFix.addActionListener(getFixActionListener(fixText));
return Arrays.asList(doFix);
}
}
Aggregations