All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgrapht.io.VisioExporter Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
/*
 * (C) Copyright 2003-2017, by Avner Linder and Contributors.
 *
 * JGraphT : a free Java graph-theory library
 *
 * This program and the accompanying materials are dual-licensed under
 * either
 *
 * (a) the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation, or (at your option) any
 * later version.
 *
 * or (per the licensee's choosing)
 *
 * (b) the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation.
 */
package org.jgrapht.io;

import java.io.*;

import org.jgrapht.*;

/**
 * Exports a graph to a CSV format that can be imported into MS Visio.
 *
 * 

* Tip: By default, the exported graph doesn't show link directions. To show link * directions:
* *

    *
  1. Select All (Ctrl-A)
  2. *
  3. Right Click the selected items
  4. *
  5. Format/Line...
  6. *
  7. Line ends: End: (choose an arrow)
  8. *
* * @param the graph vertex type * @param the graph edge type * * @author Avner Linder */ public class VisioExporter extends AbstractBaseExporter implements GraphExporter { /** * Creates a new VisioExporter with the specified naming policy. * * @param vertexIDProvider the vertex id provider to be used for naming the Visio shapes */ public VisioExporter(ComponentNameProvider vertexIDProvider) { super(vertexIDProvider); } /** * Creates a new VisioExporter. */ public VisioExporter() { this(new StringComponentNameProvider<>()); } /** * Exports the specified graph into a Visio CSV file format. * * @param g the graph to be exported. * @param writer the writer to which the graph to be exported. */ @Override public void exportGraph(Graph g, Writer writer) { PrintWriter out = new PrintWriter(writer); for (V v : g.vertexSet()) { exportVertex(out, v); } for (E e : g.edgeSet()) { exportEdge(out, e, g); } out.flush(); } private void exportEdge(PrintWriter out, E edge, Graph g) { String sourceName = vertexIDProvider.getName(g.getEdgeSource(edge)); String targetName = vertexIDProvider.getName(g.getEdgeTarget(edge)); out.print("Link,"); // create unique ShapeId for link out.print(sourceName); out.print("-->"); out.print(targetName); // MasterName and Text fields left blank out.print(",,,"); out.print(sourceName); out.print(","); out.print(targetName); out.print("\n"); } private void exportVertex(PrintWriter out, V vertex) { String name = vertexIDProvider.getName(vertex); out.print("Shape,"); out.print(name); out.print(",,"); // MasterName field left empty out.print(name); out.print("\n"); } } // End VisioExporter.java




© 2015 - 2024 Weber Informatics LLC | Privacy Policy