Ejemplo n.º 1
0
  /**
   * Constructs a new JGraph model adapter for the specified JGraphT graph.
   *
   * @param jGraphTGraph the JGraphT graph for which JGraph model adapter to be created. <code>null
   *     </code> is NOT permitted.
   * @param defaultVertexAttributes a default map of JGraph attributes to format vertices. <code>
   *     null</code> is NOT permitted.
   * @param defaultEdgeAttributes a default map of JGraph attributes to format edges. <code>null
   *     </code> is NOT permitted.
   * @param cellFactory a {@link CellFactory} to be used to create the JGraph cells. <code>null
   *     </code> is NOT permitted.
   * @throws IllegalArgumentException
   */
  public JGraphModelAdapter(
      Graph<V, E> jGraphTGraph,
      AttributeMap defaultVertexAttributes,
      AttributeMap defaultEdgeAttributes,
      CellFactory<V, E> cellFactory) {
    super();

    if ((jGraphTGraph == null)
        || (defaultVertexAttributes == null)
        || (defaultEdgeAttributes == null)
        || (cellFactory == null)) {
      throw new IllegalArgumentException("null is NOT permitted");
    }

    jtGraph = new ShieldedGraph(jGraphTGraph);
    setDefaultVertexAttributes(defaultVertexAttributes);
    setDefaultEdgeAttributes(defaultEdgeAttributes);
    this.cellFactory = cellFactory;

    if (jGraphTGraph instanceof ListenableGraph<?, ?>) {
      ListenableGraph<V, E> g = (ListenableGraph<V, E>) jGraphTGraph;
      g.addGraphListener(new JGraphTListener());
    }

    for (Iterator<V> i = jGraphTGraph.vertexSet().iterator(); i.hasNext(); ) {
      handleJGraphTAddedVertex(i.next());
    }

    for (Iterator<E> i = jGraphTGraph.edgeSet().iterator(); i.hasNext(); ) {
      handleJGraphTAddedEdge(i.next());
    }

    this.addGraphModelListener(new JGraphListener());
  }
Ejemplo n.º 2
0
  /**
   * Creates a new iterator for the specified graph. Iteration will start at the specified start
   * vertex. If the specified start vertex is <code>
   * null</code>, Iteration will start at an arbitrary graph vertex.
   *
   * @param g the graph to be iterated.
   * @param startVertex the vertex iteration to be started.
   * @throws IllegalArgumentException if <code>g==null</code> or does not contain <code>startVertex
   *     </code>
   */
  public CrossComponentIterator(Graph<V, E> g, V startVertex) {
    super();

    if (g == null) {
      throw new IllegalArgumentException("graph must not be null");
    }
    graph = g;

    specifics = createGraphSpecifics(g);
    vertexIterator = g.vertexSet().iterator();
    setCrossComponentTraversal(startVertex == null);

    reusableEdgeEvent = new FlyweightEdgeEvent<V, E>(this, null);
    reusableVertexEvent = new FlyweightVertexEvent<V>(this, null);

    if (startVertex == null) {
      // pick a start vertex if graph not empty
      if (vertexIterator.hasNext()) {
        this.startVertex = vertexIterator.next();
      } else {
        this.startVertex = null;
      }
    } else if (g.containsVertex(startVertex)) {
      this.startVertex = startVertex;
    } else {
      throw new IllegalArgumentException("graph must contain the start vertex");
    }
  }
Ejemplo n.º 3
0
    E addEdge(V jtSource, V jtTarget) {
      E jtEdge = graph.getEdgeFactory().createEdge(jtSource, jtTarget);
      jtElementsBeingAdded.add(jtEdge);

      boolean added = graph.addEdge(jtSource, jtTarget, jtEdge);
      jtElementsBeingAdded.remove(jtEdge);

      return added ? jtEdge : null;
    }
Ejemplo n.º 4
0
 void removeVertex(V jtVertex) {
   jtElementsBeingRemoved.add(jtVertex);
   graph.removeVertex(jtVertex);
   jtElementsBeingRemoved.remove(jtVertex);
 }
Ejemplo n.º 5
0
 void removeEdge(E jtEdge) {
   jtElementsBeingRemoved.add(jtEdge);
   graph.removeEdge(jtEdge);
   jtElementsBeingRemoved.remove(jtEdge);
 }
Ejemplo n.º 6
0
 boolean removeAllEdges(Collection<E> edges) {
   return graph.removeAllEdges(edges);
 }
Ejemplo n.º 7
0
 Set<E> edgesOf(V vertex) {
   return graph.edgesOf(vertex);
 }
Ejemplo n.º 8
0
 void addVertex(V jtVertex) {
   jtElementsBeingAdded.add(jtVertex);
   graph.addVertex(jtVertex);
   jtElementsBeingAdded.remove(jtVertex);
 }
Ejemplo n.º 9
0
 V getEdgeTarget(E e) {
   return graph.getEdgeTarget(e);
 }
Ejemplo n.º 10
0
 V getEdgeSource(E e) {
   return graph.getEdgeSource(e);
 }
Ejemplo n.º 11
0
 /** @see CrossComponentIterator.Specifics#edgesOf(Object) */
 public Set<EE> edgesOf(VV vertex) {
   return graph.edgesOf(vertex);
 }