/*
   * Setup the colouring engine.
   */
  private void setupEngine() {

    engine = ReoPreferences.getColouringEngine();
    if (engine == null) {
      engine = new StepwiseColouringEngine();
    }

    engine.setColours(ReoPreferences.getColours());
    engine.setMaxSteps(ReoPreferences.getMaxAnimationLength());
    engine.setIgnoreNoFlow(!ReoPreferences.showNoFlowAnims());

    // Reo.debug("Setting engine properties: colours=" + ReoPreferences.getColours() +
    //					", maxSteps=" + ReoPreferences.getMaxAnimationLength() +
    //					", noFlow=" + ReoPreferences.showNoFlowAnims() +
    //					", multiCore=" + ReoPreferences.enableMultiCoreSupport());

    if (engine instanceof AbstractColouringEngine) {
      ((AbstractColouringEngine) engine).setTraversalType(ReoPreferences.getTraversalType());
    }

    if (engine instanceof DefaultColouringEngine) {
      ((DefaultColouringEngine) engine).setMultiThreaded(ReoPreferences.enableMultiCoreSupport());
    }

    cached.clear();
  }
  /**
   * Compute an animation table.
   *
   * @param elements Elements to be used.
   * @param border Border elements (not to be used).
   * @param engine Engine to be used (can be null).
   * @param monitor Monitor.
   * @return The compiled table.
   */
  public static AnimationTable computeAnimations(
      List<Colourable> elements,
      List<Connectable> border,
      ColouringEngine engine,
      ColouringCache cache,
      IProgressMonitor monitor) {

    monitor.beginTask("Compute animations", 5);
    if (engine == null) {
      engine = new StepwiseColouringEngine();
    }
    engine.setElements(elements);

    // Try to set the border elements.
    if (border == null) border = new ArrayList<Connectable>();
    if (engine instanceof AbstractColouringEngine) {
      ((AbstractColouringEngine) engine).setBorderElements(border);
    } else if (!border.isEmpty()) {
      Reo.logWarning(engine + " does not support border elements!");
    }

    if (cache == null) {
      cache = new ColouringCache();
    }
    engine.setCache(cache);

    // Compute the colouring table.
    ColouringTable table = engine.computeColouringTable(new SubProgressMonitor(monitor, 4));

    if (monitor.isCanceled()) return new AnimationTable();

    // Compile the animation table.
    CompiledAnimationTable compiled = new CompiledAnimationTable();
    compiled.setColouringTable(table);
    compiled.setColouringCache(cache);
    compiled.setBorderElements(border);
    compiled.compile();

    monitor.worked(1);
    monitor.done();

    return compiled;
  }