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

com.mxgraph.io.graphml.mxGraphMlShapeEdge 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: mxGraphMlShapeEdge.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 org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * This class represents the properties of a JGraph edge.
 */
public class mxGraphMlShapeEdge
{
	private String text = "";

	private String style = "";

	private String edgeSource;

	private String edgeTarget;

	/**
	 * Construct a Shape Edge with text and style.
	 * @param text
	 * @param style
	 */
	public mxGraphMlShapeEdge(String text, String style)
	{
		this.text = text;
		this.style = style;
	}

	/**
	 * Constructs a ShapeEdge from a xml shapeEdgeElement.
	 * @param shapeEdgeElement
	 */
	public mxGraphMlShapeEdge(Element shapeEdgeElement)
	{
		Element labelElement = mxGraphMlUtils.childsTag(shapeEdgeElement,
				mxGraphMlConstants.JGRAPH + mxGraphMlConstants.LABEL);
		
		if (labelElement != null)
		{
			this.text = labelElement.getAttribute(mxGraphMlConstants.TEXT);
		}

		Element styleElement = mxGraphMlUtils.childsTag(shapeEdgeElement,
				mxGraphMlConstants.JGRAPH + mxGraphMlConstants.STYLE);
		
		if (styleElement != null)
		{
			this.style = styleElement.getAttribute(mxGraphMlConstants.PROPERTIES);

		}
	}

	/**
	 * Construct an empty Shape Edge Element.
	 */
	public mxGraphMlShapeEdge()
	{
	}

	/**
	 * Generates a ShapeEdge 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 dataEdge = document.createElementNS(mxGraphMlConstants.JGRAPH_URL,
				mxGraphMlConstants.JGRAPH + mxGraphMlConstants.SHAPEEDGE);

		if (!this.text.equals(""))
		{
			Element dataEdgeLabel = document.createElementNS(
					mxGraphMlConstants.JGRAPH_URL, mxGraphMlConstants.JGRAPH
							+ mxGraphMlConstants.LABEL);
			dataEdgeLabel.setAttribute(mxGraphMlConstants.TEXT, this.text);
			dataEdge.appendChild(dataEdgeLabel);
		}
		
		if (!this.style.equals(""))
		{
			Element dataEdgeStyle = document.createElementNS(
					mxGraphMlConstants.JGRAPH_URL, mxGraphMlConstants.JGRAPH
							+ mxGraphMlConstants.STYLE);

			dataEdgeStyle.setAttribute(mxGraphMlConstants.PROPERTIES, this.style);
			dataEdge.appendChild(dataEdgeStyle);
		}

		return dataEdge;
	}

	public String getText()
	{
		return text;
	}

	public void setText(String text)
	{
		this.text = text;
	}

	public String getStyle()
	{
		return style;
	}

	public void setStyle(String style)
	{
		this.style = style;
	}

	public String getEdgeSource()
	{
		return edgeSource;
	}

	public void setEdgeSource(String edgeSource)
	{
		this.edgeSource = edgeSource;
	}

	public String getEdgeTarget()
	{
		return edgeTarget;
	}

	public void setEdgeTarget(String edgeTarget)
	{
		this.edgeTarget = edgeTarget;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy