Example usage for javax.swing SwingUtilities invokeAndWait

List of usage examples for javax.swing SwingUtilities invokeAndWait

Introduction

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

Prototype

public static void invokeAndWait(final Runnable doRun) throws InterruptedException, InvocationTargetException 

Source Link

Document

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

Usage

From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

public void stepFinished(final TestStepContext context) {
    try {//from   w  ww  .  j  av a  2s.  c o m
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                actionComponents.doneStepping();
                DebugStep debugStep = steps.get(currentRunningStep);
                if (debugStep != null) {
                    debugStep.setExitVariables(context.getVariables().getVaribleValues());
                    debugStep.setRequest(context.getRequest());
                    debugStep.setResponse(context.getResponse());
                }
                try {
                    if (context.getResponse() != null && (context.getResponse().getHttpCode() >= 400
                            || context.getResponse().getHttpCode() == -1)) {
                        // highlight the line
                        int lineStartOffset = scriptEditorTA.getLineStartOffset(currentRunningStep);
                        int lineEndOffset = scriptEditorTA.getLineEndOffset(currentRunningStep);

                        scriptEditorTA.getHighlighter().addHighlight(lineStartOffset, lineEndOffset,
                                new SquiggleUnderlineHighlightPainter(Color.RED));
                    }
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
                if (!context.getErrors().isEmpty()) {
                    try {
                        debugStep.setErrors(context.getErrors());
                        scriptEditorScrollPane.getGutter().addOffsetTrackingIcon(
                                scriptEditorTA.getLineStartOffset(currentRunningStep), errorIcon);
                    } catch (BadLocationException e) {
                        e.printStackTrace();
                    }
                }
                fireStepExited(context.getTestStep().getStepIndex());
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:be.agiv.security.demo.Main.java

public void requestingIPSTSToken() {
    try {/*from   w  ww  .  jav  a2s  .c  om*/
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                Main.this.statusBar.setStatus("Requesting IP-STS Token...");
            }
        });
    } catch (Exception e) {
    }
}

From source file:be.agiv.security.demo.Main.java

public void requestingRSTSToken() {
    try {/*from  w  w  w. java2s  .c  om*/
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                Main.this.statusBar.setStatus("Requesting R-STS Token...");
            }
        });
    } catch (Exception e) {
    }
}

From source file:be.agiv.security.demo.Main.java

public void requestingSecureConversationToken() {
    try {//from w w  w. j  av  a 2  s .  c o m
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                Main.this.statusBar.setStatus("Requesting Secure Conversation Token...");
            }
        });
    } catch (Exception e) {
    }
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

/**
 * Add a rows to the list that is shown//from   ww  w .  j  a v a  2 s  .co  m
 *
 * @param rows
 */
public void addAllRows(final List rows) {
    if (logger.isDebugEnabled()) {
        logger.debug("Adding rows to the JTable:<" + rows.size() + ">");
    }
    if (SwingUtilities.isEventDispatchThread()) {
        addAllRowsInternal(rows);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    addAllRowsInternal(rows);
                }
            });
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

/**
 * Update the row in the jtable//  w ww  . j a v  a 2 s. c  o  m
 *
 * @param index
 * @param row
 */
public void updateRow(final int index, final Object row) {
    if (SwingUtilities.isEventDispatchThread()) {
        updateRowInternal(index, row);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    updateRowInternal(index, row);
                }
            });
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

@Override
public Collection<Throwable> call() throws Exception {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    List<BamFileRef> bams = new ArrayList<BamFileRef>();

    final List<String> args = getInputFiles();
    List<File> IN = new ArrayList<File>();

    if (args.isEmpty()) {
        LOG.info("NO BAM provided; Opening dialog");
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileFilter() {
            @Override/*from ww w. jav a2  s .  co m*/
            public String getDescription() {
                return "Indexed BAM files.";
            }

            @Override
            public boolean accept(File f) {
                if (f.isDirectory())
                    return true;
                return acceptBam(f);
            };
        });
        chooser.setMultiSelectionEnabled(true);
        if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
            return wrapException("user pressed cancel");
        }
        File fs[] = chooser.getSelectedFiles();
        if (fs != null)
            IN.addAll(Arrays.asList(chooser.getSelectedFiles()));
    } else {
        for (String arg : args) {
            File filename = new File(arg);
            if (!acceptBam(filename)) {
                return wrapException(
                        "Cannot use " + filename + " as input Bam. bad extenstion ? index missing ?");
            }
            IN.add(filename);
        }
    }

    for (File in : IN) {
        try {
            bams.add(create(in));
        } catch (Exception err) {
            return wrapException(err);
        }
    }
    if (bams.isEmpty()) {
        return wrapException("No Bam file");
    }
    LOG.info("showing BAM frame");
    final BamFrame frame = new BamFrame(bams);
    frame.igvIP = super.IGV_HOST;
    frame.igvPort = super.IGV_PORT;
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
                frame.setBounds(50, 50, screen.width - 100, screen.height - 100);
                frame.setVisible(true);
            }
        });
    } catch (Exception err) {
        err.printStackTrace();
        System.exit(-1);
    }

    return RETURN_OK;
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Run the provided runnable in the application's event dispatcher thread,
 * and wait for the action to complete before returning.
 *
 * @param runnable/* ww w . j  a va  2s .  c o m*/
 * @return
 */
private synchronized boolean runInDispatcherThreadImmediately(Runnable runnable) {
    try {
        SwingUtilities.invokeAndWait(runnable);
        return true;
    } catch (Exception e) {
        log.error("Error displaying graphical elements", e);
        return false;
    }
}

From source file:edu.ku.brc.specify.dbsupport.SpecifySchemaUpdateService.java

/**
 * Creates and attaches the UnhandledException handler for piping them to the dialog
 *//*  w w w.ja va2s. co  m*/
@SuppressWarnings("unused")
private static void attachUnhandledException() {
    log.debug("attachUnhandledException " + Thread.currentThread().getName() + " "
            + Thread.currentThread().hashCode());

    Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            processUnhandledException(e);
        }
    });

    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                log.debug("attachUnhandledException " + Thread.currentThread().getName() + " "
                        + Thread.currentThread().hashCode());
                Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                    public void uncaughtException(Thread t, Throwable e) {
                        processUnhandledException(e);
                    }
                });
            }
        });
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    } catch (InvocationTargetException e1) {
        e1.printStackTrace();
    }

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            processUnhandledException(e);
        }
    });

}

From source file:de.cismet.verdis.CidsAppBackend.java

/**
 * DOCUMENT ME!/*w ww.  ja  v a2 s.co  m*/
 *
 * @param  title      DOCUMENT ME!
 * @param  message    DOCUMENT ME!
 * @param  exception  DOCUMENT ME!
 */
public void showError(final String title, final String message, final Exception exception) {
    if (SwingUtilities.isEventDispatchThread()) {
        final ErrorInfo errorInfo = new ErrorInfo(title, message, null, "", exception, null, null);
        JXErrorPane.showDialog(Main.getInstance(), errorInfo);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    showError(title, message, exception);
                }
            });
        } catch (final Exception ex) {
            LOG.error(ex, ex);
        }
    }
}