/* (non-Javadoc)
  * @see edu.uci.ics.jung.visualization.VisualizationServer#setGraphLayout(edu.uci.ics.jung.visualization.layout.Layout)
  */
 public void setGraphLayout(Layout<V, E> layout) {
   Dimension viewSize = getPreferredSize();
   if (this.isShowing()) {
     viewSize = getSize();
   }
   model.setGraphLayout(layout, viewSize);
 }
  protected void renderGraph(Graphics2D g2d) {
    if (renderContext.getGraphicsContext() == null) {
      renderContext.setGraphicsContext(new GraphicsDecorator(g2d));
    } else {
      renderContext.getGraphicsContext().setDelegate(g2d);
    }
    renderContext.setScreenDevice(this);
    Layout<V, E> layout = model.getGraphLayout();

    g2d.setRenderingHints(renderingHints);

    // the size of the VisualizationViewer
    Dimension d = getSize();

    // clear the offscreen image
    g2d.setColor(getBackground());
    g2d.fillRect(0, 0, d.width, d.height);

    AffineTransform oldXform = g2d.getTransform();
    AffineTransform newXform = new AffineTransform(oldXform);
    // AffineTransform newXform = new AffineTransform();
    newXform.concatenate(
        renderContext.getMultiLayerTransformer().getTransformer(Layer.VIEW).getTransform());
    //        		viewTransformer.getTransform());

    g2d.setTransform(newXform);

    // if there are  preRenderers set, paint them
    for (Paintable paintable : preRenderers) {

      if (paintable.useTransform()) {
        paintable.paint(g2d);
      } else {
        g2d.setTransform(oldXform);
        paintable.paint(g2d);
        g2d.setTransform(newXform);
      }
    }

    if (layout instanceof Caching) {
      ((Caching) layout).clear();
    }

    renderer.render(renderContext, layout);

    // if there are postRenderers set, do it
    for (Paintable paintable : postRenderers) {

      if (paintable.useTransform()) {
        paintable.paint(g2d);
      } else {
        g2d.setTransform(oldXform);
        paintable.paint(g2d);
        g2d.setTransform(newXform);
      }
    }
    g2d.setTransform(oldXform);
  }
 @Override
 public void setVisible(boolean aFlag) {
   super.setVisible(aFlag);
   if (aFlag == true) {
     Dimension d = this.getSize();
     if (d.width <= 0 || d.height <= 0) {
       d = this.getPreferredSize();
     }
     model.getGraphLayout().setSize(d);
   }
 }
  /**
   * Create an instance with passed parameters.
   *
   * @param model
   * @param renderer
   * @param preferredSize initial preferred size of the view
   */
  @SuppressWarnings("unchecked")
  public BasicVisualizationServer(VisualizationModel<V, E> model, Dimension preferredSize) {
    this.model = model;
    //        renderContext.setScreenDevice(this);
    model.addChangeListener(this);
    setDoubleBuffered(false);
    this.addComponentListener(new VisualizationListener(this));

    setPickSupport(new ShapePickSupport<V, E>(this));
    setPickedVertexState(new MultiPickedState<V>());
    setPickedEdgeState(new MultiPickedState<E>());

    renderContext.setEdgeDrawPaintTransformer(
        new PickableEdgePaintTransformer<E>(getPickedEdgeState(), Color.black, Color.cyan));
    renderContext.setVertexFillPaintTransformer(
        new PickableVertexPaintTransformer<V>(getPickedVertexState(), Color.red, Color.yellow));

    setPreferredSize(preferredSize);
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    renderContext.getMultiLayerTransformer().addChangeListener(this);
  }
 public Layout<V, E> getGraphLayout() {
   return model.getGraphLayout();
 }