use of org.magic.gui.components.dialog.TipsOfTheDayDialog 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");
}
}
Aggregations