Example usage for javax.swing SwingUtilities invokeLater

List of usage examples for javax.swing SwingUtilities invokeLater

Introduction

In this page you can find the example usage for javax.swing SwingUtilities invokeLater.

Prototype

public static void invokeLater(Runnable doRun) 

Source Link

Document

Causes doRun.run() to be executed asynchronously on the AWT event dispatching thread.

Usage

From source file:edu.umich.robot.ViewerApplication.java

public static void main(final String[] args) {
    SwingTools.initializeLookAndFeel();/*from   www  . j a v a2  s .  c om*/
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new ViewerApplication(args);
        }
    });

}

From source file:hermes.browser.HermesBrowser.java

public static void main(String[] args) {
    log.debug("Hermes Browser " + Hermes.VERSION + " starting...");
    log.debug("working directory: " + new File(".").getAbsolutePath());

    Hermes.events.addConnectionListener(new ConnectionListener() {
        public void onConnectionOpen(Hermes hermes) {
            log.debug("Connection " + hermes.getId() + " opened");
        }//from  w  w  w . ja va 2  s  .  co m

        public void onConnectionClosed(Hermes hermes) {
            log.debug("Connection " + hermes.getId() + " closed");
        }
    });

    //
    // Need to bootstrap objects into the singleton manager... hack for now.

    JVMUtils.forceInit(SingletonManager.class);
    JVMUtils.forceInit(ThreadPool.class);
    JVMUtils.forceInit(SimpleClassLoaderManager.class);

    //
    // Commented out as this is for debug use only.
    // RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager());

    //
    // Note this is the license for the JIDE Framework, it is licenced
    // to Colin Crist and the Hermes project and should not be used for any
    // other purpose
    //

    Lm.verifyLicense("Colin Crist", "Hermes", "9vkNAfxF1lvVyW7uZXYjpxFskycSGLw1");

    //
    // See http://www.jidesoft.com for licensing terms.

    //
    // Register a converter from a String to a File with PropertyUtils.

    ConvertUtils.register(new Converter() {
        public Object convert(Class arg0, Object filename) {
            return new File((String) filename);
        }
    }, File.class);

    SplashScreen.create(IconCache.getIcon("hermes.splash"));
    SplashScreen.show();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                ui = new HermesBrowser(HERMES_TITLE);

                ui.initJIDE();

                try {
                    ui.loadConfig();
                } catch (NamingException ex) {
                    log.fatal("cannot initialise hermes: " + ex.getMessage(), ex);

                    System.exit(1);
                } catch (HeadlessException ex) {
                    log.fatal("cannot initialise hermes browser, no head: " + ex.getMessage(), ex);
                    System.exit(1);
                }

                ui.initUI();
                ui.init();

                ui.getLayoutPersistence().setProfileKey(ui.getUserProfileName());
                ui.getLayoutPersistence().loadLayoutData();

                // This must be done after the layout has been set otherwise
                // the
                // frames are hidden.

                final ArrayList<WatchConfig> tmpList = new ArrayList<WatchConfig>(ui.getConfig().getWatch());

                ui.getLoader().getConfig().getWatch().clear();

                for (WatchConfig wConfig : tmpList) {
                    ui.createWatch(wConfig);
                }

                ui.firstLoad = false;
            } catch (Exception ex) {
                log.fatal("cannot initialise hermes browser: " + ex.getMessage(), ex);
            }
        }
    });
}

From source file:de.hstsoft.sdeep.view.MainWindow.java

public static void main(String[] args) {
    try {/*ww  w. j  ava2s. c  o m*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            MainWindow mainWindow = new MainWindow();
            mainWindow.createUI();
            mainWindow.setSize(1024, 768);
            mainWindow.loadConfiguration();
            mainWindow.setVisible(true);
        }
    });

}

From source file:com.github.lucapino.sheetmaker.PreviewJFrame.java

public static void main(String[] args) {
    System.setProperty("awt.useSystemAAFontSettings", "on");
    System.setProperty("swing.aatext", "true");
    SwingUtilities.invokeLater(new Runnable() {

        @Override//from   w  ww .  j a v  a 2s  .co  m
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                File tmpFolder = new File("/tmp/images");
                tmpFolder.mkdir();

                String coverPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/cover.jpg";
                String backdropPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/backdrop.jpg";
                String fanart1Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart1.jpg";
                String fanart2Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart2.jpg";
                String fanart3Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart3.jpg";

                PreviewJFrame frame = new PreviewJFrame();
                logger.info("Creating parser...");
                InfoRetriever parser = new MediaInfoRetriever();
                MovieInfo movieInfo = parser.getMovieInfo("/media/tagliani/Elements/Film/JackRyan.mkv");
                logger.info("Retrieving movie file info...");
                logger.info("Creating dataretriever...");
                DataRetriever retriever = new DataRetrieverImpl();
                logger.info("Retrieving movie data...");
                Movie movie = retriever.retrieveMovieFromImdbID("tt1205537", "IT");
                logger.info("Retrieving backdrops and fanart...");
                List<Artwork> images = movie.getBackdrops();
                // background
                logger.info("Saving backdrop...");
                IOUtils.copyLarge(new URL(images.get(0).getImageURL()).openStream(),
                        new FileOutputStream(backdropPath));
                for (int i = 1; i < 4; i++) {
                    // fanart1
                    // fanart2
                    // fanart3
                    String imageURL = images.get(i).getImageURL();
                    logger.info("Saving fanart{}...", i);
                    IOUtils.copyLarge(new URL(imageURL).openStream(),
                            new FileOutputStream(tmpFolder.getAbsolutePath() + "/fanart" + i + ".jpg"));
                }
                // cover
                logger.info("Retrieving cover...");
                Artwork cover = movie.getPosters().get(0);
                String imageURL = cover.getImageURL();
                logger.info("Saving cover...");
                IOUtils.copyLarge(new URL(imageURL).openStream(), new FileOutputStream(coverPath));

                Map<String, String> tokenMap = TemplateFilter.createTokenMap(movie, movieInfo, null);

                logger.info("Creating renderer...");
                JavaTemplateRenderer renderer = new JavaTemplateRenderer();
                JPanel imagePanel = null;
                try {
                    logger.info("Rendering image...");
                    imagePanel = renderer.renderTemplate(
                            this.getClass().getResource("/templates/simplicity/template.xml"), tokenMap,
                            backdropPath, fanart1Path, fanart2Path, fanart3Path, coverPath);
                    logger.info("Adding image to frame...");
                    frame.add(imagePanel);

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                imagePanel.setPreferredSize(new Dimension(imagePanel.getWidth(), imagePanel.getHeight()));
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                frame.setVisible(true);
                frame.pack();
                logger.info("Creating image for save...");
                BufferedImage imageTosave = ScreenImage.createImage(imagePanel);
                logger.info("Saving image...");
                ScreenImage.writeImage(imageTosave, "/tmp/images/final.png");
                logger.info("Image saved...");
            } catch (Exception ex) {
                logger.error("Error: ", ex);
            }
        }

    });

}

From source file:TopLevelTransferHandlerDemo.java

public static void main(final String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            //Turn off metal's use of bold fonts
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            createAndShowGUI(args);//from  w  w  w  .  ja va2 s.c  o  m
        }
    });
}

From source file:Main.java

public static void updateUI() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from  w w w .  ja  v a2  s. c om*/
        public void run() {
            // TODO Auto-generated method stub
            Window windows[] = Window.getWindows();
            for (int i = 0; i < windows.length; i++) {
                if (windows[i].isDisplayable()) {
                    SwingUtilities.updateComponentTreeUI(windows[i]);
                }
            }
        }
    });
}

From source file:Main.java

public static void run(final JFrame f) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();/*from   w  w  w.j  a va 2 s. co  m*/
            f.setVisible(true);
            f.setExtendedState(f.getExtendedState() | JFrame.MAXIMIZED_BOTH);

        }
    });
}

From source file:modnlp.capte.AlignmentInterfaceWS.java

public static void main(String args[]) {
    try {//from www  .j  a  v a2 s. c  o  m
        //set splitting action equal to true
        //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        doSplit = true;
        //default AlreadyRun to false
        AlreadyRun = false;
        //lineConvert = true;
        lineConvert = true;
        // Read config file
        boolean isMac = false;
        boolean isWin = false;
        boolean isUnix = false;
        String tmp = "";
        String winsep = "\\";
        String unixsep = "/";
        String ostype = System.getProperty("os.name").toLowerCase();
        System.out.println("Operating system type =>" + ostype);
        if (ostype.indexOf("win") >= 0) {
            isWin = true;
            isUnix = false;
            isMac = false;
        } else if ((ostype.indexOf("nix") >= 0) || (ostype.indexOf("nux") >= 0)) {
            isUnix = true;
            isWin = false;
            isMac = false;
        } else if (ostype.indexOf("mac") >= 0) {
            isWin = false;
            isUnix = false;
            isMac = true;
        } else {
            throw new UnsupportedOperationException("your OS is not supported!");
        }
        //creating and showing this application's GUI.
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                //Turn off metal's use of bold fonts
                UIManager.put("swing.boldMetal", Boolean.FALSE);
                createAndShowGUI();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void repaint(final Component component) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override//from www  .j a va2 s  . com
        public void run() {
            component.repaint();
        }
    });
}

From source file:Main.java

public static void requestFocus(final JComponent component) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            component.requestFocus();//from   w  w w .j av  a  2  s. co m
        }
    });
}