Search in sources :

Example 1 with MkmPanel

use of org.mkm.gui.MkmPanel in project MtgDesktopCompanion by nicho92.

the class MagicGUI method initGUI.

public void initGUI() throws ClassNotFoundException, IOException, SQLException, AWTException {
    JMenuBar mtgMnuBar;
    JMenu mnFile;
    JMenu mnuAbout;
    JMenuItem mntmExit;
    logger.info("init Main GUI");
    setSize(new Dimension(1420, 900));
    setTitle(MTGConstants.MTG_APP_NAME + " ( v" + MTGControler.getInstance().getVersion() + ")");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setIconImage(MTGConstants.IMAGE_LOGO);
    getContentPane().setLayout(new BorderLayout());
    try {
        tray = SystemTray.getSystemTray();
    } catch (Exception e) {
        logger.error(e);
    }
    mtgMnuBar = new JMenuBar();
    setJMenuBar(mtgMnuBar);
    mnFile = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("FILE"));
    mnuAbout = new JMenu("?");
    mntmExit = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("EXIT"));
    JMenuItem mntmHelp = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("READ_MANUAL"));
    JMenuItem mntmThreadItem = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("THREADS"));
    JMenuItem mntmLogsItem = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("LOGS"));
    JMenuItem mntmAboutMagicDesktop = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("ABOUT"));
    JMenuItem mntmReportBug = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("REPORT_BUG"));
    JMenuItem mntmFileOpen = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("OPEN"));
    mtgMnuBar.add(mnFile);
    mnFile.add(mntmFileOpen);
    mnFile.add(mntmExit);
    mtgMnuBar.add(mnuAbout);
    mnuAbout.add(mntmThreadItem);
    mnuAbout.add(mntmLogsItem);
    mnuAbout.add(mntmHelp);
    mnuAbout.add(mntmAboutMagicDesktop);
    mnuAbout.add(mntmReportBug);
    mntmLogsItem.addActionListener(ae -> SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame(MTGControler.getInstance().getLangService().getCapitalize("LOGS"));
        f.getContentPane().add(new LoggerViewPanel());
        f.setLocationRelativeTo(null);
        f.setVisible(true);
        f.pack();
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }));
    mntmThreadItem.addActionListener(e -> SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame(MTGControler.getInstance().getLangService().getCapitalize("THREADS"));
        f.getContentPane().add(new ThreadMonitorPanel());
        f.setLocationRelativeTo(null);
        f.setVisible(true);
        f.pack();
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }));
    mntmExit.addActionListener(e -> System.exit(0));
    mntmHelp.addActionListener(e -> {
        String url = MTGConstants.MTG_DESKTOP_WIKI_URL;
        try {
            Desktop.getDesktop().browse(new URI(url));
        } catch (Exception e1) {
            logger.error(e1);
        }
    });
    mntmAboutMagicDesktop.addActionListener(ae -> new AboutDialog().setVisible(true));
    mntmReportBug.addActionListener(ae -> {
        try {
            String url = MTGConstants.MTG_DESKTOP_ISSUES_URL;
            Desktop.getDesktop().browse(new URI(url));
        } catch (Exception e) {
            logger.error(e);
        }
    });
    mntmFileOpen.addActionListener(ae -> {
        JFileChooser choose = new JFileChooser();
        int returnVal = choose.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = choose.getSelectedFile();
            MTGCardsExport exp = MTGControler.getInstance().getAbstractExporterFromExt(f);
            if (exp != null) {
                ThreadManager.getInstance().execute(() -> {
                    try {
                        if (cardSearchPanel == null)
                            throw new NullPointerException(MTGControler.getInstance().getLangService().getCapitalize("MUST_BE_LOADED", MTGControler.getInstance().getLangService().get("SEARCH_MODULE")));
                        cardSearchPanel.loading(true, MTGControler.getInstance().getLangService().getCapitalize("LOADING_FILE", f.getName(), exp));
                        MagicDeck d = exp.importDeck(f);
                        cardSearchPanel.open(d.getAsList());
                        cardSearchPanel.loading(false, "");
                        tabbedPane.setSelectedIndex(0);
                    } catch (Exception e) {
                        logger.error(e);
                    }
                }, "open " + f);
            } else {
                JOptionPane.showMessageDialog(null, "NO EXPORTER AVAILABLE", MTGControler.getInstance().getLangService().getError(), JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    if (serviceUpdate.hasNewVersion()) {
        JMenuItem newversion = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("DOWNLOAD_LAST_VERSION") + " : " + serviceUpdate.getOnlineVersion());
        newversion.addActionListener(e -> {
            try {
                Desktop.getDesktop().browse(new URI(MTGConstants.MTG_DESKTOP_APP_ZIP));
            } catch (Exception e1) {
                logger.error(e1.getMessage());
            }
        });
        mnuAbout.add(newversion);
    }
    tabbedPane = new JTabbedPane(MTGConstants.MTG_DESKTOP_TABBED_POSITION);
    if (MTGControler.getInstance().get("modules/search").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("SEARCH_MODULE"), MTGConstants.ICON_SEARCH_2, CardSearchPanel.getInstance(), null);
    if (MTGControler.getInstance().get("modules/deckbuilder").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("DECK_MODULE"), MTGConstants.ICON_DECK, new DeckBuilderGUI(), null);
    if (MTGControler.getInstance().get("modules/game").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("GAME_MODULE"), MTGConstants.ICON_COLLECTION_SMALL, new GameGUI(), null);
    if (MTGControler.getInstance().get("modules/collection").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("COLLECTION_MODULE"), MTGConstants.ICON_COLLECTION, new CollectionPanelGUI(), null);
    if (MTGControler.getInstance().get("modules/stock").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("STOCK_MODULE"), MTGConstants.ICON_STOCK, new StockPanelGUI(), null);
    if (MTGControler.getInstance().get("modules/dashboard").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("DASHBOARD_MODULE"), MTGConstants.ICON_DASHBOARD, new DashBoardGUI2(), null);
    if (MTGControler.getInstance().get("modules/shopper").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("SHOPPING_MODULE"), MTGConstants.ICON_SHOP, new ShopperGUI(), null);
    if (MTGControler.getInstance().get("modules/alarm").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("ALERT_MODULE"), MTGConstants.ICON_ALERT, new AlarmGUI(), null);
    if (MTGControler.getInstance().get("modules/cardbuilder").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("BUILDER_MODULE"), MTGConstants.ICON_BUILDER, new CardBuilder2GUI(), null);
    if (MTGControler.getInstance().get("modules/rss").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("RSS_MODULE"), MTGConstants.ICON_RSS, new RssGUI(), null);
    if (MTGControler.getInstance().get("modules/history").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("HISTORY_MODULE"), MTGConstants.ICON_STORY, new StoriesGUI(), null);
    if (MTGControler.getInstance().get("modules/wallpaper").equals("true"))
        tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("WALLPAPER"), MTGConstants.ICON_WALLPAPER, new WallpaperGUI(), null);
    if (MTGControler.getInstance().get("modules/mkm").equals("true"))
        tabbedPane.addTab("MKM", MTGConstants.ICON_SHOP, new MkmPanel(), null);
    getContentPane().add(tabbedPane, BorderLayout.CENTER);
    if (SystemTray.isSupported()) {
        tray.add(trayNotifier);
        trayNotifier.addActionListener(e -> {
            if (!isVisible())
                setVisible(true);
            else
                setVisible(false);
        });
        PopupMenu menuTray = new PopupMenu();
        for (int index_tab = 0; index_tab < tabbedPane.getTabCount(); index_tab++) {
            final int index = index_tab;
            MenuItem it = new MenuItem(tabbedPane.getTitleAt(index_tab));
            it.addActionListener(e -> {
                setVisible(true);
                setSelectedTab(index);
            });
            menuTray.add(it);
        }
        trayNotifier.setPopupMenu(menuTray);
        trayNotifier.setToolTip("MTG Desktop Companion");
        if (serviceUpdate.hasNewVersion())
            trayNotifier.displayMessage(getTitle(), MTGControler.getInstance().getLangService().getCapitalize("NEW_VERSION") + " " + serviceUpdate.getOnlineVersion() + " " + MTGControler.getInstance().getLangService().get("AVAILABLE"), TrayIcon.MessageType.INFO);
        ThreadManager.getInstance().execute(() -> {
            try {
                new TipsOfTheDayDialog().show();
            } catch (IOException e) {
                logger.error(e);
            }
        }, "launch tooltip");
    }
}
Also used : AboutDialog(org.magic.gui.components.dialog.AboutDialog) ThreadMonitorPanel(org.magic.gui.components.ThreadMonitorPanel) MTGCardsExport(org.magic.api.interfaces.MTGCardsExport) JTabbedPane(javax.swing.JTabbedPane) TipsOfTheDayDialog(org.magic.gui.components.dialog.TipsOfTheDayDialog) URI(java.net.URI) LoggerViewPanel(org.magic.gui.components.LoggerViewPanel) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JMenuItem(javax.swing.JMenuItem) MagicDeck(org.magic.api.beans.MagicDeck) MkmPanel(org.mkm.gui.MkmPanel) JMenuItem(javax.swing.JMenuItem) MenuItem(java.awt.MenuItem) Dimension(java.awt.Dimension) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) AWTException(java.awt.AWTException) JFileChooser(javax.swing.JFileChooser) File(java.io.File) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) PopupMenu(java.awt.PopupMenu)

Aggregations

AWTException (java.awt.AWTException)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 MenuItem (java.awt.MenuItem)1 PopupMenu (java.awt.PopupMenu)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 SQLException (java.sql.SQLException)1 JFileChooser (javax.swing.JFileChooser)1 JFrame (javax.swing.JFrame)1 JMenu (javax.swing.JMenu)1 JMenuBar (javax.swing.JMenuBar)1 JMenuItem (javax.swing.JMenuItem)1 JTabbedPane (javax.swing.JTabbedPane)1 MagicDeck (org.magic.api.beans.MagicDeck)1 MTGCardsExport (org.magic.api.interfaces.MTGCardsExport)1 LoggerViewPanel (org.magic.gui.components.LoggerViewPanel)1 ThreadMonitorPanel (org.magic.gui.components.ThreadMonitorPanel)1 AboutDialog (org.magic.gui.components.dialog.AboutDialog)1