View Javadoc
1 /*
2 * PROJECT : DAR Runtime and Tools
3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org
4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE
5 * Version 2.1, February 1999
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 package org.enableit.db.darrt.visualise;
23
24 import java.io.Reader;
25 import java.util.ArrayList;
26 import java.util.Hashtable;
27 import java.util.List;
28
29 import org.enableit.db.beans.Database;
30 import org.enableit.db.beans.Schema;
31 import org.enableit.db.beans.Table;
32 import org.enableit.db.darrt.AbstractSchemaHandler;
33 import org.enableit.db.darrt.SchemaHandlingException;
34 import org.jgraph.JGraph;
35 import org.jgraph.graph.ConnectionSet;
36 import org.jgraph.graph.DefaultGraphCell;
37 import org.jgraph.graph.DefaultGraphModel;
38 import org.jgraph.graph.DefaultPort;
39 import org.jgraph.graph.GraphModel;
40 import org.w3c.dom.Document;
41
42 /***
43 * @author TimSt
44 *
45 * To change the template for this generated type comment go to
46 * Window>Preferences>Java>Code Generation>Code and Comments
47 */
48 public class SchemaViz extends AbstractSchemaHandler {
49
50 public Document toSVG(Reader reader) throws SchemaHandlingException {
51 Document svg = null ;
52
53 // Construct the graph to hold the ettributes
54 JGraph graph = new JGraph(new DefaultGraphModel());
55
56 // Read the darrt file into the model
57 try {
58 Database db = Database.unmarshal(reader) ;
59 read(db, graph.getModel());
60 } catch (Exception e) {
61 e.printStackTrace() ;
62 throw new SchemaHandlingException() ;
63 }
64
65 // Apply Layout
66 //layout(graph);
67
68 // Resize (Otherwise not Visible)
69 graph.setSize(graph.getPreferredSize());
70
71 // Write the SVG file
72 //FileWriter out = new FileWriter() ;
73 //write(graph, out);
74 return svg ;
75 }
76
77 public void read(Database db, GraphModel model) {
78
79 // List for the new Cells
80 List newCells = new ArrayList();
81 // ConnectionSet to Specify Connections
82 ConnectionSet cs = new ConnectionSet();
83 // Map from Cells to AttributesHashtable
84 //attributes = new Hashtable();
85 // Map from ID to Vertex
86 //Map ids = new Hashtable();
87
88 for (int i = 0 ; i < db.getSchemaCount() ; i++) {
89 Schema schema = db.getSchema(i) ;
90 for (int j = 0 ; j < schema.getTableCount() ; j++) {
91 Table table = schema.getTable(j) ;
92 // Create Vertex with label
93 DefaultGraphCell v = new DefaultGraphCell(table.getName());
94 // Add One Floating Port
95 v.add(new DefaultPort());
96 // Add ID, Vertex pair to Hashtable
97 //ids.put(id, v);
98 // Add Default Attributes
99 //attributes.put(v, createDefaultAttributes());
100 // Update New Cell List
101 newCells.add(v);
102 }
103 }
104
105 // Insert the cells (View stores attributes)
106 //model.insert.insert(newCells.toArray(), cs, null, new Hashtable());
107 }
108 }
This page was automatically generated by Maven