1 | /**
|
---|
2 | * DotGraphWriter.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.io;
|
---|
20 |
|
---|
21 | import java.io.IOException;
|
---|
22 | import java.io.Writer;
|
---|
23 |
|
---|
24 | import org.expeditee.gui.Frame;
|
---|
25 | import org.expeditee.gui.FrameIO;
|
---|
26 | import org.expeditee.gui.FrameUtils;
|
---|
27 | import org.expeditee.items.Item;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Writes a file that can be opened in an app such as Gephi or GraphViz in order to visualize/graph the links between frames in a frameset.
|
---|
31 | * Only maps the frameset that it is called from, although links from within the frameset to other framesets will be shown/included
|
---|
32 | *
|
---|
33 | * @author ngw8
|
---|
34 | *
|
---|
35 | */
|
---|
36 | public class DotGraphWriter extends DefaultFrameWriter {
|
---|
37 |
|
---|
38 | private String framesetName;
|
---|
39 |
|
---|
40 | private Frame currentFrame;
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | protected void initialise(Frame start, Writer writer) throws IOException {
|
---|
44 |
|
---|
45 |
|
---|
46 | _format = ".dot";
|
---|
47 |
|
---|
48 | framesetName = start.getFramesetName();
|
---|
49 |
|
---|
50 | currentFrame = FrameUtils.getFrame(framesetName + "0");
|
---|
51 |
|
---|
52 | super.initialise(currentFrame, writer);
|
---|
53 |
|
---|
54 | _writer.write("digraph " + currentFrame.getFramesetName() + "{");
|
---|
55 | _writer.newLine();
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public String writeFrame(Frame toWrite) throws IOException {
|
---|
61 |
|
---|
62 | initialise(toWrite, null);
|
---|
63 |
|
---|
64 | while (currentFrame != null) {
|
---|
65 | super.outputFrame(currentFrame);
|
---|
66 |
|
---|
67 | currentFrame = FrameIO.LoadNext(currentFrame);
|
---|
68 | }
|
---|
69 |
|
---|
70 | return this.finalise();
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | protected void writeItem(Item toWrite) throws IOException {
|
---|
75 | if (toWrite.hasLink()) {
|
---|
76 | _writer.write(toWrite.getParentOrCurrentFrame().getName() + "->" + toWrite.getAbsoluteLink() + ";");
|
---|
77 |
|
---|
78 | _writer.newLine();
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | protected String finalise() throws IOException {
|
---|
84 | _writer.write("}");
|
---|
85 | _running = false;
|
---|
86 | return super.finalise();
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|