Beispiel #1
0
  public void actionPerformed(ActionEvent evt) {
    if (model.names().isEmpty() || model.files().isEmpty()) {
      return;
    }

    BackgroundMatcher backgroundMatcher =
        new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
    backgroundMatcher.execute();

    Window window = getWindow(evt.getSource());
    window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    try {
      // wait a for little while (matcher might finish in less than a second)
      backgroundMatcher.get(2, TimeUnit.SECONDS);
    } catch (TimeoutException ex) {
      // matcher will probably take a while
      ProgressDialog dialog = createProgressDialog(window, backgroundMatcher);
      dialog.setLocation(getOffsetLocation(dialog.getOwner()));

      // display progress dialog and stop blocking EDT
      dialog.setVisible(true);
    } catch (Exception e) {
      Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
    } finally {
      window.setCursor(Cursor.getDefaultCursor());
    }
  }
Beispiel #2
0
  protected ProgressDialog createProgressDialog(Window parent, final BackgroundMatcher worker) {
    final ProgressDialog progressDialog = new ProgressDialog(parent, worker);

    // configure dialog
    progressDialog.setTitle("Matching...");
    progressDialog.setNote("Processing...");
    progressDialog.setIcon((Icon) getValue(SMALL_ICON));

    // close progress dialog when worker is finished
    worker.addPropertyChangeListener(
        new SwingWorkerPropertyChangeAdapter() {

          @Override
          protected void done(PropertyChangeEvent evt) {
            progressDialog.close();
          }
        });

    return progressDialog;
  }