]> gerrit.simantics Code Review - simantics/platform.git/blob - graphviz/Subgraph.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / graphviz / Subgraph.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.graphviz;
13
14 import java.io.PrintStream;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.Collections;
18
19 /**
20  * A hierarchial part of a graph.  
21  * 
22  * @author Hannu Niemistö
23  */
24 public class Subgraph extends AbstractIdentifiableGraphPart implements IGraph {
25     Collection<IGraphPart> parts = new ArrayList<IGraphPart>();
26     int curId = 0;
27
28     public Subgraph(IGraph parent) {
29         super(parent);
30     }
31
32     @Override
33     public void addPart(IGraphPart part) {
34         parts.add(part);        
35     }
36
37     @Override
38     public String newId() {
39         return getId() + "_" + (++curId);
40     }
41
42     @Override
43     public Collection<IGraphPart> getParts() {
44         return Collections.unmodifiableCollection(parts);
45     }
46
47     @Override
48     public void write(PrintStream s) {
49         s.print("subgraph ");
50         s.print(id);
51         s.println(" {");
52         s.print("graph");
53         writeAttributes(s);
54         for(IGraphPart part : parts)
55             part.write(s);
56         s.println("};");        
57     }
58
59 }