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

org.yaoqiang.graph.io.graphml.GraphMLCodec Maven / Gradle / Ivy

package org.yaoqiang.graph.io.graphml;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.yaoqiang.graph.swing.GraphComponent;
import org.yaoqiang.graph.view.Graph;

/**
 * GraphMLCodec
 * 
 * @author Shi Yaoqiang([email protected])
 */
public class GraphMLCodec {

	protected GraphComponent graphComponent;

	protected Graph graph;

	protected Document document;

	public GraphMLCodec(GraphComponent graphComponent, Document document) {
		this.graphComponent = graphComponent;
		this.graph = graphComponent.getGraph();
		this.document = document;
	}

	public void decode() {
		graph.clearBpmnModel();
		graph.getModel().clear();
		graphComponent.zoomTo(0.85, true);
		Object parent = graph.getDefaultParent();

		graph.getModel().beginUpdate();
		NodeList graphs = document.getElementsByTagName(GraphMLConstants.GRAPH);
		if (graphs.getLength() > 0) {
			Element graphElement = (Element) graphs.item(0);
			GraphMLGraph gmlGraph = new GraphMLGraph(graphElement);
			gmlGraph.addGraph(graph, parent);
		}
		graph.getModel().endUpdate();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy