Search in sources :

Example 11 with GameSet

use of com.github.jakz.romlib.data.set.GameSet 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)

Example 12 with GameSet

use of com.github.jakz.romlib.data.set.GameSet in project rom-manager by Jakz.

the class RomSetListCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    JLabel c = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    GameSet set = (GameSet) value;
    if (set != null)
        c.setIcon(set.platform().getIcon());
    return c;
}
Also used : JLabel(javax.swing.JLabel) GameSet(com.github.jakz.romlib.data.set.GameSet)

Aggregations

GameSet (com.github.jakz.romlib.data.set.GameSet)12 Arrays (java.util.Arrays)8 List (java.util.List)7 Feature (com.github.jakz.romlib.data.set.Feature)6 ArrayList (java.util.ArrayList)6 Game (com.github.jakz.romlib.data.game.Game)5 MyGameSetFeatures (jack.rm.data.romset.MyGameSetFeatures)5 IOException (java.io.IOException)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Drawable (com.github.jakz.romlib.data.game.Drawable)4 Platforms (com.github.jakz.romlib.data.platforms.Platforms)4 Main (jack.rm.Main)4 Predicate (java.util.function.Predicate)4 Attribute (com.github.jakz.romlib.data.game.attributes.Attribute)3 GameAttribute (com.github.jakz.romlib.data.game.attributes.GameAttribute)3 GameSetManager (jack.rm.data.romset.GameSetManager)3 Settings (jack.rm.data.romset.Settings)3 GameListData (jack.rm.gui.gamelist.GameListData)3 Text (jack.rm.i18n.Text)3