예제 #1
0
  public void show(NotificationWindow notification) {
    SwingUI.checkEventDispatchThread();

    if (layout.size() < limit) {
      layout.add(notification);
      notification.addWindowListener(new RemoveListener());
      notification.setVisible(true);
    }
  }
예제 #2
0
    @Override
    public void listChanged(ListEvent<Object> listChanges) {
      updates.beginEvent(true);

      while (listChanges.next()) {
        int index = listChanges.getIndex();
        int type = listChanges.getType();

        if (type == ListEvent.INSERT || type == ListEvent.UPDATE) {
          Match<Object, File> match = getMatch(index);

          // create new future
          final FormattedFuture future =
              new FormattedFuture(match, getFormatter(match), getMatchContext());

          // update data
          if (type == ListEvent.INSERT) {
            futures.add(index, future);
            updates.elementInserted(index, future);
          } else if (type == ListEvent.UPDATE) {
            // set new future, dispose old future
            FormattedFuture obsolete = futures.set(index, future);

            cancel(obsolete);

            // Don't update view immediately, to avoid irritating flickering,
            // caused by a rapid succession of change events.
            // The worker may only need a couple of milliseconds to complete,
            // so the view will be notified of the change soon enough.
            SwingUI.invokeLater(
                50,
                new Runnable() {

                  @Override
                  public void run() {
                    // task has not been started, no change events have been sent as of yet,
                    // fire change event now
                    if (future.getState() == StateValue.PENDING) {
                      future.firePropertyChange("state", null, StateValue.PENDING);
                    }
                  }
                });
          }

          // observe and enqueue worker task
          submit(future);
        } else if (type == ListEvent.DELETE) {
          // remove future from data and formatter queue
          FormattedFuture obsolete = futures.remove(index);
          cancel(obsolete);
          updates.elementDeleted(index, obsolete);
        }
      }

      updates.commitEvent();
    }