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

net.sourceforge.plantuml.statediagram.StateDiagram Maven / Gradle / Ivy

Go to download

PlantUML is a component that allows to quickly write : * sequence diagram, * use case diagram, * class diagram, * activity diagram, * component diagram, * state diagram * object diagram

There is a newer version: 8059
Show newest version
/* ========================================================================
 * PlantUML : a free UML diagram generator
 * ========================================================================
 *
 * (C) Copyright 2009-2013, Arnaud Roques
 *
 * Project Info:  http://plantuml.sourceforge.net
 * 
 * This file is part of PlantUML.
 *
 * PlantUML is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PlantUML distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 *
 * Original Author:  Arnaud Roques
 * 
 * Revision $Revision: 11160 $
 *
 */
package net.sourceforge.plantuml.statediagram;

import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
import net.sourceforge.plantuml.cucadiagram.Code;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.EntityUtils;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.LeafType;

public class StateDiagram extends AbstractEntityDiagram {

	public IEntity getOrCreateLeaf1(Code code, LeafType type) {
		if (type == null) {
			if (code.getCode().startsWith("[*]")) {
				throw new IllegalArgumentException();
			}
			if (isGroup(code)) {
				return getGroup(code);
			}
			return getOrCreateLeaf1Default(code, LeafType.STATE);
		}
		return getOrCreateLeaf1Default(code, type);
	}


	public IEntity getStart() {
		final IGroup g = getCurrentGroup();
		if (EntityUtils.groupRoot(g)) {
			return getOrCreateLeaf1(Code.of("*start"), LeafType.CIRCLE_START);
		}
		return getOrCreateLeaf1(Code.of("*start*" + g.getCode().getCode()), LeafType.CIRCLE_START);
	}

	public IEntity getEnd() {
		final IGroup p = getCurrentGroup();
		if (EntityUtils.groupRoot(p)) {
			return getOrCreateLeaf1(Code.of("*end"), LeafType.CIRCLE_END);
		}
		return getOrCreateLeaf1(Code.of("*end*" + p.getCode().getCode()), LeafType.CIRCLE_END);
	}

	public IEntity getHistorical() {
		final IGroup g = getCurrentGroup();
		if (EntityUtils.groupRoot(g)) {
			return getOrCreateLeaf1(Code.of("*historical"), LeafType.PSEUDO_STATE);
		}
		return getOrCreateLeaf1(Code.of("*historical*" + g.getCode().getCode()), LeafType.PSEUDO_STATE);
	}

	public IEntity getHistorical(Code codeGroup) {
		final IEntity g = getOrCreateGroup(codeGroup, Display.getWithNewlines(codeGroup), null, GroupType.STATE,
				getRootGroup());
		final IEntity result = getOrCreateLeaf1(Code.of("*historical*" + g.getCode().getCode()), LeafType.PSEUDO_STATE);
		endGroup();
		return result;
	}

	public boolean concurrentState() {
		final IGroup cur = getCurrentGroup();
		// printlink("BEFORE");
		if (EntityUtils.groupRoot(cur) == false && cur.zgetGroupType() == GroupType.CONCURRENT_STATE) {
			super.endGroup();
		}
		final IGroup conc1 = getOrCreateGroup(UniqueSequence.getCode("CONC"), Display.asList(""), null,
				GroupType.CONCURRENT_STATE, getCurrentGroup());
		if (EntityUtils.groupRoot(cur) == false && cur.zgetGroupType() == GroupType.STATE) {
			cur.zmoveEntitiesTo(conc1);
			super.endGroup();
			getOrCreateGroup(UniqueSequence.getCode("CONC"), Display.asList(""), null, GroupType.CONCURRENT_STATE,
					getCurrentGroup());
		}
		// printlink("AFTER");
		return true;
	}

	// private void printlink(String comment) {
	// Log.println("COMMENT="+comment);
	// for (Link l : getLinks()) {
	// Log.println(l);
	// }
	// }

	@Override
	public void endGroup() {
		final IGroup cur = getCurrentGroup();
		if (EntityUtils.groupRoot(cur) == false && cur.zgetGroupType() == GroupType.CONCURRENT_STATE) {
			super.endGroup();
		}
		super.endGroup();
	}

	@Override
	public UmlDiagramType getUmlDiagramType() {
		return UmlDiagramType.STATE;
	}

	private boolean hideEmptyDescription = false;

	public final void setHideEmptyDescription(boolean hideEmptyDescription) {
		this.hideEmptyDescription = hideEmptyDescription;
	}

	public final boolean isHideEmptyDescriptionForState() {
		return hideEmptyDescription;
	}

	// public Link isEntryPoint(IEntity ent) {
	// final Stereotype stereotype = ent.getStereotype();
	// if (stereotype == null) {
	// return null;
	// }
	// final String label = stereotype.getLabel();
	// if ("<>".equalsIgnoreCase(label) == false) {
	// return null;
	// }
	// Link inLink = null;
	// Link outLink = null;
	// for (Link link : getLinks()) {
	// if (link.getEntity1() == ent) {
	// if (outLink != null) {
	// return null;
	// }
	// outLink = link;
	// }
	// if (link.getEntity2() == ent) {
	// if (inLink != null) {
	// return null;
	// }
	// inLink = link;
	// }
	// }
	// if (inLink == null || outLink == null) {
	// return null;
	// }
	// final Link result = Link.mergeForEntryPoint(inLink, outLink);
	// result.setEntryPoint(ent.getContainer());
	// return result;
	// }
	//
	// public void manageExitAndEntryPoints() {
	// for (IEntity ent : getEntities().values()) {
	// final Link entryPointLink = isEntryPoint(ent);
	// if (entryPointLink != null) {
	// addLink(entryPointLink);
	// for (Link link : new ArrayList(getLinks())) {
	// if (link.contains(ent)) {
	// removeLink(link);
	// }
	// }
	// }
	// }
	//
	// }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy