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:utybo.branchingstorytree.swing.OpenBSTGUI.java
public void openStory(File f) { if (f != null) { final TabClient client = new TabClient(instance); loadFile(f, client, new Consumer<BranchingStory>() { private StoryPanel sp; @Override/*from w w w . j a v a 2 s.com*/ public void accept(BranchingStory bs) { if (bs != null) { try { SwingUtilities.invokeAndWait(() -> sp = addStory(bs, f, client)); if (sp != null) { try { client.getBRMHandler().load(); if (Boolean.parseBoolean(bs.getTagOrDefault("img_requireinternal", "false"))) IMGClient.initInternal(); } catch (BSTException e) { LOG.error("Exception caught while loading resources", e); showException(Lang.get("file.resourceerror").replace("$e", whichCause(e)) .replace("$m", whichMessage(e)), e); } SwingUtilities.invokeAndWait(() -> sp.setupStory()); } } catch (InvocationTargetException | InterruptedException e) { LOG.warn("Swing invocation exception", e); } } } private String whichMessage(BSTException e) { if (e.getCause() != null) { return e.getCause().getMessage(); } else { return e.getMessage(); } } private String whichCause(BSTException e) { if (e.getCause() != null) { return e.getCause().getClass().getSimpleName(); } else { return e.getClass().getSimpleName(); } } }); } }
From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java
private void openEditor(File f) { if (f != null) { final TabClient client = new TabClient(instance); loadFile(f, client, new Consumer<BranchingStory>() { @Override/* w w w .j a v a 2s . c om*/ public void accept(BranchingStory bs) { try { SwingUtilities.invokeAndWait(() -> { try { StoryEditor se = new StoryEditor(bs); container.addTab(se.getTitle(), se); container.setSelectedComponent(se); } catch (Exception e) { LOG.error("Error on story editor init", e); Messagers.showException(OpenBSTGUI.this, "Error while creating the Story Editor (" + e.getClass().getSimpleName() + " : " + e.getMessage() + ")", e); } }); } catch (Exception e) { LOG.error(e); } } }); } }
From source file:VASSAL.launch.ModuleManager.java
protected String execute(Object req) { if (req instanceof LaunchRequest) { final LaunchRequest lr = (LaunchRequest) req; if (lr.key != key) { // FIXME: translate return "incorrect key"; }/*from w w w . j a v a 2 s. c om*/ final LaunchRequestHandler handler = new LaunchRequestHandler(lr); try { SwingUtilities.invokeAndWait(handler); } catch (InterruptedException e) { return "interrupted"; // FIXME } catch (InvocationTargetException e) { ErrorDialog.bug(e); return null; } return handler.getResult(); } else { return "unrecognized command"; // FIXME } }