001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package com.artenum.so6.dataflow.graph;
034:
035: import com.artenum.graph.interfaces.GraphModel;
036: import com.artenum.graph.interfaces.LayoutManager;
037:
038: import java.awt.Point;
039:
040: import java.io.FileInputStream;
041: import java.io.FileOutputStream;
042: import java.io.IOException;
043: import java.io.ObjectInputStream;
044: import java.io.ObjectOutputStream;
045:
046: import java.util.ArrayList;
047: import java.util.Hashtable;
048: import java.util.Iterator;
049:
050: /**
051: * @author Smack
052: */
053: public class So6LayoutManager implements LayoutManager {
054: private GraphModel model;
055: private Hashtable positionList;
056:
057: public So6LayoutManager() {
058: positionList = new Hashtable();
059: }
060:
061: public void setModel(GraphModel model) {
062: this .model = model;
063: }
064:
065: public void applyLayout() {
066: ArrayList connectionList = new ArrayList();
067:
068: for (Iterator i = model.getCellList().iterator(); i.hasNext();) {
069: So6Node node = (So6Node) i.next();
070:
071: if (node instanceof ConnectionNode) {
072: connectionList.add(node);
073: } else {
074: Point p = (Point) positionList.get(node.getId());
075:
076: if (p == null) {
077: p = new Point(10, 10);
078: positionList.put(node.getId(), p);
079: }
080:
081: node.setPosition(p);
082: }
083: }
084:
085: // Update connection pos
086: for (Iterator i = connectionList.iterator(); i.hasNext();) {
087: ((ConnectionNode) i.next()).updateConnectionPosition();
088: }
089: }
090:
091: public void loadPosition(String path) throws IOException,
092: ClassNotFoundException {
093: ObjectInputStream ois = null;
094:
095: try {
096: ois = new ObjectInputStream(new FileInputStream(path));
097: positionList = (Hashtable) ois.readObject();
098: } finally {
099: ois.close();
100: }
101: }
102:
103: public void savePosition(String path) throws IOException {
104: // Update hashtable
105: for (Iterator i = model.getCellList().iterator(); i.hasNext();) {
106: So6Node node = (So6Node) i.next();
107:
108: if (!(node instanceof ConnectionNode)) {
109: positionList.put(node.getId(), node.getPosition());
110: }
111: }
112:
113: //
114: ObjectOutputStream oos = null;
115:
116: try {
117: oos = new ObjectOutputStream(new FileOutputStream(path));
118: oos.writeObject(positionList);
119: } finally {
120: oos.close();
121: }
122: }
123: }
|