Search in sources :

Example 1 with PrinterPlugin

use of com.igormaznitsa.sciareto.plugins.services.PrinterPlugin 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();
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) URISyntaxException(java.net.URISyntaxException) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) URI(java.net.URI) MainFrame(com.igormaznitsa.sciareto.ui.MainFrame) GraphicsDevice(java.awt.GraphicsDevice) SplashScreen(com.igormaznitsa.sciareto.ui.UiUtils.SplashScreen) PropertiesPreferences(com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences) Preferences(java.util.prefs.Preferences) LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) Nonnull(javax.annotation.Nonnull) MessagesService(com.igormaznitsa.sciareto.notifications.MessagesService) AtomicReference(java.util.concurrent.atomic.AtomicReference) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JHtmlLabel(com.igormaznitsa.sciareto.ui.misc.JHtmlLabel) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) PrinterPlugin(com.igormaznitsa.sciareto.plugins.services.PrinterPlugin) File(java.io.File)

Aggregations

PropertiesPreferences (com.igormaznitsa.mindmap.swing.panel.utils.PropertiesPreferences)1 MessagesService (com.igormaznitsa.sciareto.notifications.MessagesService)1 PrinterPlugin (com.igormaznitsa.sciareto.plugins.services.PrinterPlugin)1 MainFrame (com.igormaznitsa.sciareto.ui.MainFrame)1 SplashScreen (com.igormaznitsa.sciareto.ui.UiUtils.SplashScreen)1 JHtmlLabel (com.igormaznitsa.sciareto.ui.misc.JHtmlLabel)1 GraphicsDevice (java.awt.GraphicsDevice)1 Image (java.awt.Image)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Preferences (java.util.prefs.Preferences)1 Nonnull (javax.annotation.Nonnull)1 Timer (javax.swing.Timer)1 LookAndFeelInfo (javax.swing.UIManager.LookAndFeelInfo)1