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

com.mxgraph.io.graphml.mxGraphMlPort Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.4.1.3
Show newest version
/**
 * $Id: mxGraphMlPort.java,v 1.1 2012/11/15 13:26:45 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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy