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

com.salesforce.jgrapht.ext.VisioExporter Maven / Gradle / Ivy

Go to download

This project contains the apt processor that implements all the checks enumerated in @Verify. It is a self contained, and shaded jar.

There is a newer version: 2.0.7
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 com.salesforce.jgrapht.ext;

import java.io.*;

import com.salesforce.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 implements GraphExporter { private ComponentNameProvider vertexNameProvider; /** * Creates a new VisioExporter with the specified naming policy. * * @param vertexNameProvider the vertex name provider to be used for naming the Visio shapes. */ public VisioExporter(ComponentNameProvider vertexNameProvider) { this.vertexNameProvider = vertexNameProvider; } /** * 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 = vertexNameProvider.getName(g.getEdgeSource(edge)); String targetName = vertexNameProvider.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 = vertexNameProvider.getName(vertex); out.print("Shape,"); out.print(name); out.print(",,"); // MasterName field left empty out.print(name); out.print("\n"); } } // End VisioExporter.java




© 2015 - 2025 Weber Informatics LLC | Privacy Policy