Search in sources :

Example 1 with OperationalPlugin

use of jack.rm.plugins.OperationalPlugin in project rom-manager by Jakz.

the class MainFrame method buildMenu.

private void buildMenu(final GameSet set) {
    MenuElement.clearListeners();
    romsMenu.removeAll();
    if (set != null) {
        romsMenu.add(MenuElement.ROMS_SCAN_FOR_ROMS.item);
        romsMenu.add(MenuElement.ROMS_SCAN_FOR_NEW_ROMS.item);
        JMenuItem refreshStatus = new JMenuItem("Refresh status");
        refreshStatus.addActionListener(e -> {
            for (Game game : set) game.updateStatus();
            SwingUtilities.invokeLater(() -> repaint());
        });
        romsMenu.add(refreshStatus);
        romsMenu.addSeparator();
        JMenuItem renameRoms = new JMenuItem(Text.MENU_ROMS_RENAME.text());
        renameRoms.addActionListener(e -> {
            MyGameSetFeatures helper = set.helper();
            helper.organizer().organize();
            rebuildGameList();
        });
        romsMenu.add(renameRoms);
        JMenuItem cleanupRoms = new JMenuItem(Text.MENU_ROMS_CLEANUP.text());
        cleanupRoms.addActionListener(e -> {
            MyGameSetFeatures helper = set.helper();
            helper.organizer().cleanup();
        });
        romsMenu.add(cleanupRoms);
        romsMenu.addSeparator();
        romsMenu.add(romsExportSubmenu);
        JMenuItem exportFavorites = new JMenuItem("Export favourites");
        exportFavorites.addActionListener(e -> {
            exportList(r -> r.isFavourite());
        });
        romsExportSubmenu.add(exportFavorites);
        JMenuItem exportFound = new JMenuItem(Text.MENU_ROMS_EXPORT_FOUND.text());
        exportFound.addActionListener(e -> {
            exportList(r -> r.getStatus().isComplete());
        });
        romsExportSubmenu.add(exportFound);
        JMenuItem exportMissing = new JMenuItem(Text.MENU_ROMS_EXPORT_MISSING.text());
        exportMissing.addActionListener(e -> {
            exportList(r -> !r.getStatus().isComplete());
        });
        romsExportSubmenu.add(exportMissing);
        romsMenu.addSeparator();
        MenuElement.addListeners();
    }
    JMenuItem menuExit = new JMenuItem(Text.MENU_ROMS_EXIT.text());
    romsMenu.add(menuExit);
    menuExit.addActionListener(e -> java.lang.System.exit(0));
    viewMenu.clear();
    viewMenu.rebuild(set, gameListPanel.data().getMode(), gameListPanel.isTreeMode());
    toolsMenu.removeAll();
    MenuElement.TOOLS_GLOBAL_SETTINGS.item.addActionListener(e -> Main.gsettingsView.showMe());
    toolsMenu.add(MenuElement.TOOLS_GLOBAL_SETTINGS.item);
    if (set != null) {
        MenuElement.TOOLS_OPTIONS.item.addActionListener(e -> optionsFrame.showMe());
        toolsMenu.add(MenuElement.TOOLS_OPTIONS.item);
        MenuElement.TOOLS_SHOW_MESSAGES.item.addActionListener(e -> toggleLogPanel(((JMenuItem) e.getSource()).isSelected()));
        toolsMenu.add(MenuElement.TOOLS_SHOW_MESSAGES.item);
        MenuElement.TOOLS_CONSOLE.item.addActionListener(e -> toggleConsole(((JMenuItem) e.getSource()).isSelected()));
        toolsMenu.add(MenuElement.TOOLS_CONSOLE.item);
        JMenu assetsMenu = new JMenu(Text.MENU_TOOLS_ASSETS.text());
        assetsMenu.add(MenuElement.TOOLS_DOWNLOAD_ASSETS.item);
        MenuElement.TOOLS_DOWNLOAD_ASSETS.item.addActionListener(e -> Main.downloader.start());
        assetsMenu.add(MenuElement.TOOLS_PACK_ASSETS.item);
        MenuElement.TOOLS_PACK_ASSETS.item.addActionListener(e -> AssetPacker.packAssets(set));
        toolsMenu.addSeparator();
        toolsMenu.add(assetsMenu);
        // TODO: localize
        JMenu pluginsMenu = new JMenu("Plugins");
        Map<String, List<OperationalPlugin>> plugins = new TreeMap<>();
        getGameSetSettings().plugins.stream().filter(p -> p.isEnabled() && p instanceof OperationalPlugin).map(p -> (OperationalPlugin) p).forEach(p -> {
            String key = p.getSubmenuCaption();
            plugins.computeIfAbsent(key, k -> new ArrayList<>()).add(p);
        });
        plugins.values().forEach(l -> Collections.sort(l, new Comparator<OperationalPlugin>() {

            @Override
            public int compare(OperationalPlugin o1, OperationalPlugin o2) {
                return o1.getMenuCaption().compareTo(o2.getMenuCaption());
            }
        }));
        plugins.entrySet().forEach(e -> {
            JMenu menu = new JMenu(e.getKey());
            e.getValue().forEach(p -> {
                JMenuItem item = new JMenuItem(p.getMenuCaption());
                item.addActionListener(ee -> p.execute(set));
                menu.add(item);
            });
            pluginsMenu.add(menu);
        });
        if (pluginsMenu.getItemCount() != 0) {
            toolsMenu.addSeparator();
            toolsMenu.add(pluginsMenu);
        }
    }
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) OperationalPlugin(jack.rm.plugins.OperationalPlugin) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) ItemListener(java.awt.event.ItemListener) Platforms(com.github.jakz.romlib.data.platforms.Platforms) Organizer(jack.rm.files.Organizer) GameSet(com.github.jakz.romlib.data.set.GameSet) GameListPanel(jack.rm.gui.gamelist.GameListPanel) WindowListener(java.awt.event.WindowListener) Map(java.util.Map) Text(jack.rm.i18n.Text) MouseAdapter(java.awt.event.MouseAdapter) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) GameListData(jack.rm.gui.gamelist.GameListData) Feature(com.github.jakz.romlib.data.set.Feature) JMenuBar(javax.swing.JMenuBar) ItemEvent(java.awt.event.ItemEvent) Predicate(java.util.function.Predicate) InfoPanel(jack.rm.gui.gameinfo.InfoPanel) JMenu(javax.swing.JMenu) SearchPanel(com.github.jakz.romlib.ui.SearchPanel) Collectors(java.util.stream.Collectors) WindowEvent(java.awt.event.WindowEvent) Dimension(java.awt.Dimension) List(java.util.List) Drawable(com.github.jakz.romlib.data.game.Drawable) GameClone(com.github.jakz.romlib.data.game.GameClone) GlobalSettings(jack.rm.GlobalSettings) JPanel(javax.swing.JPanel) CardLayout(java.awt.CardLayout) JSplitPane(javax.swing.JSplitPane) Game(com.github.jakz.romlib.data.game.Game) GameListModel(jack.rm.gui.gamelist.GameListModel) ArrayList(java.util.ArrayList) GridLayout(java.awt.GridLayout) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) GameCellRenderer(jack.rm.gui.gamelist.GameCellRenderer) ButtonGroup(javax.swing.ButtonGroup) CountPanel(jack.rm.gui.gamelist.CountPanel) PluginRealType(jack.rm.plugins.PluginRealType) IOException(java.io.IOException) MouseEvent(java.awt.event.MouseEvent) AssetPacker(jack.rm.files.AssetPacker) ListCellRenderer(javax.swing.ListCellRenderer) Platform(com.github.jakz.romlib.data.platforms.Platform) TreeMap(java.util.TreeMap) Comparator(java.util.Comparator) Collections(java.util.Collections) Main(jack.rm.Main) GameSetManager(jack.rm.data.romset.GameSetManager) Settings(jack.rm.data.romset.Settings) Game(com.github.jakz.romlib.data.game.Game) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) OperationalPlugin(jack.rm.plugins.OperationalPlugin) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) TreeMap(java.util.TreeMap) JMenu(javax.swing.JMenu) Comparator(java.util.Comparator)

Aggregations

Drawable (com.github.jakz.romlib.data.game.Drawable)1 Game (com.github.jakz.romlib.data.game.Game)1 GameClone (com.github.jakz.romlib.data.game.GameClone)1 Platform (com.github.jakz.romlib.data.platforms.Platform)1 Platforms (com.github.jakz.romlib.data.platforms.Platforms)1 Feature (com.github.jakz.romlib.data.set.Feature)1 GameSet (com.github.jakz.romlib.data.set.GameSet)1 SearchPanel (com.github.jakz.romlib.ui.SearchPanel)1 GlobalSettings (jack.rm.GlobalSettings)1 Main (jack.rm.Main)1 GameSetManager (jack.rm.data.romset.GameSetManager)1 MyGameSetFeatures (jack.rm.data.romset.MyGameSetFeatures)1 Settings (jack.rm.data.romset.Settings)1 AssetPacker (jack.rm.files.AssetPacker)1 Organizer (jack.rm.files.Organizer)1 InfoPanel (jack.rm.gui.gameinfo.InfoPanel)1 CountPanel (jack.rm.gui.gamelist.CountPanel)1 GameCellRenderer (jack.rm.gui.gamelist.GameCellRenderer)1 GameListData (jack.rm.gui.gamelist.GameListData)1 GameListModel (jack.rm.gui.gamelist.GameListModel)1