List of usage examples for javax.swing SwingUtilities invokeAndWait
public static void invokeAndWait(final Runnable doRun) throws InterruptedException, InvocationTargetException
doRun.run()
to be executed synchronously on the AWT event dispatching thread. From source file:TextPaneElements.java
public static void main(String[] args) { try {//w ww.j a va 2s . c o m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Text Pane Elements"); // Create the StyleContext, the document and the pane final StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); final JTextPane pane = new JTextPane(doc); // Build the styles createDocumentStyles(sc); try { // Add the text and apply the styles SwingUtilities.invokeAndWait(new Runnable() { public void run() { // Add the text addText(pane, sc, sc.getStyle(mainStyleName), content); // Dump the element structure ((AbstractDocument) pane.getDocument()).dump(System.out); } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(500, 300); f.setVisible(true); }
From source file:CheckThreadViolationRepaintManager.java
public static void main(String[] args) throws Exception { // set CheckThreadViolationRepaintManager RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager()); // Valid code SwingUtilities.invokeAndWait(new Runnable() { public void run() { test();// w w w .j a v a2 s . c om } }); System.out.println("Valid code passed..."); repaintTest(); System.out.println("Repaint test - correct code"); // Invalide code (stack trace expected) test(); }
From source file:ExtendedParagraphExample.java
public static void main(String[] args) { try {// w w w .j a v a 2 s . co m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Extended Paragraph Example"); // Create the StyleContext, the document and the pane final StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); final JTextPane pane = new JTextPane(doc); pane.setEditorKit(new ExtendedStyledEditorKit()); try { // Add the text and apply the styles SwingUtilities.invokeAndWait(new Runnable() { public void run() { // Build the styles createDocumentStyles(sc); // Add the text addText(pane, sc, sc.getStyle(mainStyleName), content); } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); }
From source file:edu.mit.fss.examples.ISSFederate.java
/** * The main method. This configures the Orekit data path, creates the * ISS federate objects and launches the associated graphical user * interface.//from w w w . ja va2 s . co m * * @param args the arguments * @throws RTIexception the RTI exception * @throws URISyntaxException */ public static void main(String[] args) throws RTIexception, URISyntaxException { BasicConfigurator.configure(); boolean headless = false; logger.debug("Setting Orekit data path."); System.setProperty(DataProvidersManager.OREKIT_DATA_PATH, new File(ISSFederate.class.getResource("/orekit-data.zip").toURI()).getAbsolutePath()); logger.trace("Creating federate instance."); final ISSFederate federate = new ISSFederate(); logger.trace("Setting minimum step duration and time step."); long timeStep = 60 * 1000, minimumStepDuration = 100; federate.setMinimumStepDuration(minimumStepDuration); federate.setTimeStep(timeStep); try { logger.debug("Loading TLE data from file."); BufferedReader br = new BufferedReader(new InputStreamReader( federate.getClass().getClassLoader().getResourceAsStream("edu/mit/fss/examples/data.tle"))); final SpaceSystem satellite; final SurfaceSystem station1, station2, station3; while (br.ready()) { if (br.readLine().matches(".*ISS.*")) { logger.debug("Found ISS data."); logger.trace("Adding FSS supplier space system."); satellite = new SpaceSystem("FSS Supplier", new TLE(br.readLine(), br.readLine()), 5123e3); federate.addObject(satellite); logger.trace("Adding Keio ground station."); station1 = new SurfaceSystem("Keio", new GeodeticPoint(FastMath.toRadians(35.551929), FastMath.toRadians(139.647119), 300), satellite.getState().getDate(), 5123e3, 5); federate.addObject(station1); logger.trace("Adding SkolTech ground station."); station2 = new SurfaceSystem("SkolTech", new GeodeticPoint(FastMath.toRadians(55.698679), FastMath.toRadians(37.571994), 200), satellite.getState().getDate(), 5123e3, 5); federate.addObject(station2); logger.trace("Adding MIT ground station."); station3 = new SurfaceSystem("MIT", new GeodeticPoint(FastMath.toRadians(42.360184), FastMath.toRadians(-71.093742), 100), satellite.getState().getDate(), 5123e3, 5); federate.addObject(station3); try { logger.trace("Setting inital time."); federate.setInitialTime( satellite.getInitialState().getDate().toDate(TimeScalesFactory.getUTC()).getTime()); } catch (IllegalArgumentException | OrekitException e) { logger.error(e.getMessage()); e.printStackTrace(); } if (!headless) { logger.debug("Launching the graphical user interface."); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { MemberFrame frame = new MemberFrame(federate, new MultiComponentPanel( Arrays.asList(new SpaceSystemPanel(federate, satellite), new SurfaceSystemPanel(federate, station1), new SurfaceSystemPanel(federate, station2), new SurfaceSystemPanel(federate, station3)))); frame.pack(); frame.setVisible(true); } }); } break; } } br.close(); } catch (InvocationTargetException | InterruptedException | OrekitException | IOException e) { e.printStackTrace(); logger.fatal(e); } logger.trace("Setting federate name, type, and FOM path."); federate.getConnection().setFederateName("ISS"); federate.getConnection().setFederateType("FSS Supplier"); federate.getConnection().setFederationName("FSS"); federate.getConnection().setFomPath( new File(federate.getClass().getClassLoader().getResource("edu/mit/fss/hla/fss.xml").toURI()) .getAbsolutePath()); federate.getConnection().setOfflineMode(false); federate.connect(); if (headless) { federate.setMinimumStepDuration(10); federate.initialize(); federate.run(); } }
From source file:de.codesourcery.eve.skills.ui.Main.java
public static void main(String[] args) throws Exception { setLookAndFeel();// w ww.j ava 2s .c om SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { SpringUtil.getInstance().getMain().startUp(); } catch (Exception e) { throw new RuntimeException(e); } } }); }
From source file:edu.mit.fss.examples.TDRSSFederate.java
/** * The main method. This configures the Orekit data path, creates the * SaudiComsat federate objects and launches the associated graphical user * interface.//from w ww . ja v a 2 s. c o m * * @param args the arguments * @throws RTIexception the RTI exception * @throws URISyntaxException */ public static void main(String[] args) throws RTIexception, URISyntaxException { BasicConfigurator.configure(); logger.debug("Setting Orekit data path."); System.setProperty(DataProvidersManager.OREKIT_DATA_PATH, new File(TDRSSFederate.class.getResource("/orekit-data.zip").toURI()).getAbsolutePath()); logger.trace("Creating federate instance."); final TDRSSFederate federate = new TDRSSFederate(); logger.trace("Setting minimum step duration and time step."); long timeStep = 60 * 1000, minimumStepDuration = 100; federate.setMinimumStepDuration(minimumStepDuration); federate.setTimeStep(timeStep); logger.debug("Loading TLE data from file."); final List<Component> panels = new ArrayList<Component>(); for (String satName : Arrays.asList("TDRS 3", "TDRS 5", "TDRS 6", "TDRS 7", "TDRS 8", "TDRS 9", "TDRS 10", "TDRS 11")) { try { BufferedReader br = new BufferedReader(new InputStreamReader( federate.getClass().getClassLoader().getResourceAsStream("edu/mit/fss/examples/data.tle"))); while (br.ready()) { if (br.readLine().matches(".*" + satName + ".*")) { logger.debug("Found " + satName + " data."); logger.trace("Adding " + satName + " supplier space system."); SpaceSystem system = new SpaceSystem(satName, new TLE(br.readLine(), br.readLine()), 5123e3); federate.addObject(system); panels.add(new SpaceSystemPanel(federate, system)); try { logger.trace("Setting inital time."); federate.setInitialTime(system.getInitialState().getDate() .toDate(TimeScalesFactory.getUTC()).getTime()); } catch (IllegalArgumentException | OrekitException e) { logger.error(e.getMessage()); e.printStackTrace(); } break; } } br.close(); } catch (IllegalArgumentException | OrekitException | IOException e) { e.printStackTrace(); logger.fatal(e); } } try { logger.trace("Adding WSGT ground station."); SurfaceSystem wsgt = new SurfaceSystem("WSGT", new GeodeticPoint(FastMath.toRadians(32.5007), FastMath.toRadians(-106.6086), 1474), new AbsoluteDate(), 5123e3, 5); federate.addObject(wsgt); panels.add(new SurfaceSystemPanel(federate, wsgt)); logger.trace("Adding STGT ground station."); SurfaceSystem stgt = new SurfaceSystem("STGT", new GeodeticPoint(FastMath.toRadians(32.5430), FastMath.toRadians(-106.6120), 1468), new AbsoluteDate(), 5123e3, 5); federate.addObject(stgt); panels.add(new SurfaceSystemPanel(federate, stgt)); logger.trace("Adding GRGT ground station."); SurfaceSystem grgt = new SurfaceSystem("GRGT", new GeodeticPoint(FastMath.toRadians(13.6148), FastMath.toRadians(144.8565), 142), new AbsoluteDate(), 5123e3, 5); federate.addObject(grgt); panels.add(new SurfaceSystemPanel(federate, grgt)); } catch (OrekitException e) { logger.error(e.getMessage()); e.printStackTrace(); } logger.debug("Launching the graphical user interface."); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { MemberFrame frame = new MemberFrame(federate, new MultiComponentPanel(panels)); frame.pack(); frame.setVisible(true); } }); } catch (InvocationTargetException | InterruptedException e) { logger.error(e.getMessage()); e.printStackTrace(); } logger.trace("Setting federate name, type, and FOM path."); federate.getConnection().setFederateName("TDRSS"); federate.getConnection().setFederateType("FSS Supplier"); federate.getConnection().setFederationName("FSS"); federate.getConnection().setFomPath( new File(federate.getClass().getClassLoader().getResource("edu/mit/fss/hla/fss.xml").toURI()) .getAbsolutePath()); federate.getConnection().setOfflineMode(false); federate.connect(); }
From source file:Main.java
public static void invokeAndWait(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();/*w w w. j a v a 2s. c om*/ return; } try { SwingUtilities.invokeAndWait(r); } catch (Exception e) { throw new IllegalStateException("Unable to invoke/wait for task", e); } }
From source file:Main.java
static void invokeAndWait(Runnable task) { if (SwingUtilities.isEventDispatchThread()) { task.run();//from w ww. j a v a 2s .com } else { try { SwingUtilities.invokeAndWait(task); } catch (Exception ex) { ex.printStackTrace(); ex.getLocalizedMessage(); } } }
From source file:Main.java
public static void invokeAndWait(Runnable task) { if (SwingUtilities.isEventDispatchThread()) { task.run();/*from w w w .ja va 2s. c o m*/ } else { try { SwingUtilities.invokeAndWait(task); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:Main.java
public static void runOnEventDispatchThread(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run();//from www.java 2s . c o m } else try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }