use of com.igormaznitsa.sciareto.notifications.MessagesService in project netbeans-mmd-plugin by raydac.
the class Main method main.
public static void main(@Nonnull @MustNotContainNull final String... args) {
// -- Properties for MAC OSX --
// NOI18N
System.setProperty("apple.awt.fileDialogForDirectories", "true");
// NOI18N
System.setProperty("apple.laf.useScreenMenuBar", "true");
// NOI18N
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "SciaReto");
// ----------------------------
SystemUtils.setDebugLevelForJavaLogger(Level.WARNING);
PlatformProvider.getPlatform().init();
final String selectedLookAndFeel = PreferencesManager.getInstance().getPreferences().get(PROPERTY_LOOKANDFEEL, PlatformProvider.getPlatform().getDefaultLFClassName());
// NOI18N
LOGGER.info("java.vendor = " + System.getProperty("java.vendor", "unknown"));
// NOI18N
LOGGER.info("java.version = " + System.getProperty("java.version", "unknown"));
// NOI18N
LOGGER.info("os.name = " + System.getProperty("os.name", "unknown"));
// NOI18N
LOGGER.info("os.arch = " + System.getProperty("os.arch", "unknown"));
// NOI18N
LOGGER.info("os.version = " + System.getProperty("os.version", "unknown"));
final AtomicReference<SplashScreen> splash = new AtomicReference<>();
final long timeTakenBySplashStart;
if (args.length == 0) {
final long splashTimerStart = System.currentTimeMillis();
try {
// NOI18N
final Image splashImage = Assertions.assertNotNull(UiUtils.loadIcon("splash.png"));
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
splash.set(new SplashScreen(splashImage));
splash.get().setVisible(true);
} catch (Exception ex) {
// NOI18N
LOGGER.error("Splash can't be shown", ex);
if (splash.get() != null) {
splash.get().dispose();
splash.set(null);
}
}
}
});
} catch (final Exception ex) {
// NOI18N
LOGGER.error("Error during splash processing", ex);
}
timeTakenBySplashStart = System.currentTimeMillis() - splashTimerStart;
} else {
timeTakenBySplashStart = 0L;
}
if ((System.currentTimeMillis() - PreferencesManager.getInstance().getPreferences().getLong(MetricsService.PROPERTY_METRICS_SENDING_LAST_TIME, System.currentTimeMillis() + STATISTICS_DELAY)) >= STATISTICS_DELAY) {
// NOI18N
LOGGER.info("Statistics scheduled");
final Timer timer = new Timer(45000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MetricsService.getInstance().sendStatistics();
}
});
timer.setRepeats(false);
timer.start();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
final Preferences prefs = PreferencesManager.getInstance().getPreferences();
prefs.putLong(PROPERTY_TOTAL_UPSTART, prefs.getLong(PROPERTY_TOTAL_UPSTART, 0L) + (System.currentTimeMillis() - UPSTART));
PreferencesManager.getInstance().flush();
} finally {
PlatformProvider.getPlatform().dispose();
}
}
});
try {
for (final LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if (selectedLookAndFeel.equals(info.getClassName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
// NOI18N
LOGGER.error("Can't set L&F", e);
}
loadPlugins();
boolean doShowGUI = true;
if (args.length > 0) {
if ("--help".equalsIgnoreCase(args[0]) || "--?".equals(args[0])) {
// NOI18N
doShowGUI = false;
MindMapPluginRegistry.getInstance().registerPlugin(new LocalMMDExporter());
MindMapPluginRegistry.getInstance().registerPlugin(new LocalMMDImporter());
printCliHelp(System.out);
System.exit(0);
} else if ("--importsettings".equalsIgnoreCase(args[0])) {
// NOI18N
doShowGUI = false;
final File file = args.length > 1 ? new File(args[1]) : null;
if (file == null) {
// NOI18N
LOGGER.error("Settings file not provided");
System.exit(1);
}
if (!importSettings(file)) {
System.exit(1);
}
} else if ("--exportsettings".equalsIgnoreCase(args[0])) {
// NOI18N
doShowGUI = false;
// NOI18N
final File file = args.length > 1 ? new File(args[1]) : new File("sciaretosettings.properties");
if (!exportSettings(file)) {
System.exit(1);
}
} else if ("--convert".equalsIgnoreCase(args[0])) {
// NOI18N
doShowGUI = false;
if (!convertData(args)) {
// NOI18N
LOGGER.error("Conversion failed for error");
printConversionHelp(System.out);
System.exit(1);
}
}
}
if (doShowGUI) {
SystemUtils.setDebugLevelForJavaLogger(Level.INFO);
MindMapPluginRegistry.getInstance().registerPlugin(new PrinterPlugin());
MindMapPluginRegistry.getInstance().unregisterPluginForClass(AboutPlugin.class);
MindMapPluginRegistry.getInstance().unregisterPluginForClass(OptionsPlugin.class);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
final int width = gd.getDisplayMode().getWidth();
final int height = gd.getDisplayMode().getHeight();
if (PlatformProvider.isErrorDetected()) {
JOptionPane.showMessageDialog(null, "Can't init the Platform dependent layer, the default one will be used instead.\n" + "Check that you have installed Java correctly to avoid the warning", "Warning", JOptionPane.WARNING_MESSAGE);
}
MAIN_FRAME = new MainFrame(args);
MAIN_FRAME.setSize(Math.round(width * 0.75f), Math.round(height * 0.75f));
if (splash.get() != null) {
final long delay = (2000L + timeTakenBySplashStart) - (System.currentTimeMillis() - UPSTART);
if (delay > 0L) {
final Timer timer = new Timer((int) delay, new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
splash.get().dispose();
splash.set(null);
}
});
timer.setRepeats(false);
timer.start();
} else {
splash.get().dispose();
splash.set(null);
}
}
MAIN_FRAME.setVisible(true);
MAIN_FRAME.setExtendedState(MAIN_FRAME.getExtendedState() | JFrame.MAXIMIZED_BOTH);
final JHtmlLabel label = new JHtmlLabel("<html>You use the application already for some time. If you like it then you could support its author and <a href=\"http://www.google.com\"><b>make some donation</b></a>.</html>");
label.addLinkListener(new JHtmlLabel.LinkListener() {
@Override
public void onLinkActivated(@Nonnull final JHtmlLabel source, @Nonnull final String link) {
try {
UiUtils.browseURI(new URI(link), false);
} catch (URISyntaxException ex) {
// NOI18N
LOGGER.error("Can't make URI", ex);
}
}
});
}
});
new MessagesService().execute();
}
}
Aggregations