1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.diagram.impl;
14 import java.util.Collection;
16 import org.simantics.g2d.diagram.DiagramClass;
17 import org.simantics.g2d.diagram.DiagramHints;
18 import org.simantics.g2d.diagram.IDiagram;
19 import org.simantics.g2d.element.IElement;
20 import org.simantics.g2d.element.impl.Element;
21 import org.simantics.utils.datastructures.hints.HintContext;
24 * @author Toni Kalajainen
26 public class Diagram extends AbstractDiagram implements IDiagram {
28 public static final IDiagram EMPTY_DIAGRAM = spawnNew(DiagramClass.DEFAULT);
31 * Spawn a new diagram to the world
35 public static IDiagram spawnNew(DiagramClass clazz)
37 Diagram d = new Diagram(clazz);
38 AbstractDiagram.fireCreated(d);
43 * Instantiate new diagram for purpose of loading from file...
47 static Diagram instantiate(DiagramClass clazz)
49 Diagram d = new Diagram(clazz);
50 AbstractDiagram.fireCreated(d);
55 * Creates an identical clone of a diagram.
59 public static IDiagram clone(IDiagram src)
62 DiagramClass clazz = src.getDiagramClass();
63 Diagram d = new Diagram(clazz);
65 d.setHints(src.getHints());
67 for (IElement e : src.getElements())
68 d.addElement( Element.clone(e) );
70 AbstractDiagram.fireLoaded(d);
75 * Creates an identical clone of a diagram.
79 public static IDiagram clone(IDiagram src, Collection<IElement> elements)
82 DiagramClass clazz = src.getDiagramClass();
83 Diagram d = new Diagram(clazz);
85 d.setHints(src.getHints());
87 for (IElement e : elements) {
88 d.addElement( Element.clone(e) );
90 AbstractDiagram.fireLoaded(d);
95 Diagram(DiagramClass clazz)
97 super(clazz, new HintContext());
101 public String toString() {
102 String name = getHint(DiagramHints.KEY_TEXT);
103 if (name==null) name = super.toString();