--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.graphviz;\r
+\r
+import java.io.PrintStream;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+/**\r
+ * A hierarchial part of a graph. \r
+ * \r
+ * @author Hannu Niemistö\r
+ */\r
+public class Subgraph extends AbstractIdentifiableGraphPart implements IGraph {\r
+ Collection<IGraphPart> parts = new ArrayList<IGraphPart>();\r
+ int curId = 0;\r
+\r
+ public Subgraph(IGraph parent) {\r
+ super(parent);\r
+ }\r
+\r
+ @Override\r
+ public void addPart(IGraphPart part) {\r
+ parts.add(part); \r
+ }\r
+\r
+ @Override\r
+ public String newId() {\r
+ return getId() + "_" + (++curId);\r
+ }\r
+\r
+ @Override\r
+ public Collection<IGraphPart> getParts() {\r
+ return Collections.unmodifiableCollection(parts);\r
+ }\r
+\r
+ @Override\r
+ public void write(PrintStream s) {\r
+ s.print("subgraph ");\r
+ s.print(id);\r
+ s.println(" {");\r
+ s.print("graph");\r
+ writeAttributes(s);\r
+ for(IGraphPart part : parts)\r
+ part.write(s);\r
+ s.println("};"); \r
+ }\r
+\r
+}\r