com.mxgraph.io.graphml.mxGraphMlPort Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jgraphx Show documentation
Show all versions of jgraphx Show documentation
JGraphX Swing Component - Java Graph Visualization Library
This is a binary & source redistribution of the original, unmodified JGraphX library originating from:
"https://github.com/jgraph/jgraphx/archive/v3.4.1.3.zip".
The purpose of this redistribution is to make the library available to other Maven projects.
/**
* $Id: mxGraphMlPort.java,v 1.1 2011/09/19 15:10:46 gaudenz Exp $
* Copyright (c) 2010 David Benson, Gaudenz Alder
*/
package com.mxgraph.io.graphml;
import java.util.HashMap;
import java.util.List;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Represents a Port element in the GML Structure.
*/
public class mxGraphMlPort
{
private String name;
private HashMap portDataMap = new HashMap();
/**
* Construct a Port with name.
* @param name Port Name
*/
public mxGraphMlPort(String name)
{
this.name = name;
}
/**
* Construct a Port from a xml port Element.
* @param portElement Xml port Element.
*/
public mxGraphMlPort(Element portElement)
{
this.name = portElement.getAttribute(mxGraphMlConstants.PORT_NAME);
//Add data elements
List dataList = mxGraphMlUtils.childsTags(portElement,
mxGraphMlConstants.DATA);
for (Element dataElem : dataList)
{
mxGraphMlData data = new mxGraphMlData(dataElem);
String key = data.getDataKey();
portDataMap.put(key, data);
}
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public HashMap getPortDataMap()
{
return portDataMap;
}
public void setPortDataMap(HashMap nodeDataMap)
{
this.portDataMap = nodeDataMap;
}
/**
* Generates a Key Element from this class.
* @param document Document where the key Element will be inserted.
* @return Returns the generated Elements.
*/
public Element generateElement(Document document)
{
Element node = document.createElement(mxGraphMlConstants.PORT);
node.setAttribute(mxGraphMlConstants.PORT_NAME, name);
for (mxGraphMlData data : portDataMap.values())
{
Element dataElement = data.generateNodeElement(document);
node.appendChild(dataElement);
}
return node;
}
}