/**
   * React to changes in model by requesting new intersection of the model.
   *
   * @param model
   */
  public void modelUpdated(algs.example.gui.model.Model<E> model) {
    Model<E> mod = (Model<E>) model;
    int numK = mod.intersections().size();

    message("Number of intersections:" + numK);
    message("Time to compute:" + mod.algorithmTime());

    getCanvas().redrawState();
    getCanvas().repaint();
  }
  /**
   * If there is a line being dragged (ActiveLineSegmentDecorator) we want to add that line to the
   * objects b
   */
  protected void refreshObjects() {
    if (model.items() == null) {
      error("Invalid Model!");
      return;
    }

    message(model.items().length + " entities constructed");

    int numK = model.computeIntersections(algorithm);

    message("Number of intersections:" + numK);
    message("Time to compute:" + algorithm.time());

    getCanvas().redrawState();
    getCanvas().repaint();
  }
  // Properly refresh display with items.
  private void updateDisplay(E[] items) {
    // nothing to do.
    if (items == null) {
      return;
    }

    // transform into AWT coordinates
    int width = getCanvas().getWidth();
    int height = getCanvas().getHeight();

    // create set of entities proportional to the image
    nativeItems = items;
    items = transform(items, width, height);

    model.setItems(items);
    model.setDynamicEntity(null); // clear away...
    refreshObjects();

    // force redraw since state has changed...
    getCanvas().redrawState();
  }
 /** Instantiate GUI with reasonable title. */
 private void initialize() {
   this.setSize(850, 600);
   this.setContentPane(getPanel());
   this.setTitle("Algorithms in a Nutshell: Intersection Example for " + model.types());
 }