| author | huffman |
| Mon, 15 Aug 2011 14:50:24 -0700 | |
| changeset 44215 | 786876687ef8 |
| parent 33686 | 8e33ca8832b1 |
| child 50473 | ca4088bf8365 |
| permissions | -rw-r--r-- |
| 3599 | 1 |
/*************************************************************************** |
2 |
Title: GraphBrowser/GraphBrowser.java |
|
3 |
Author: Stefan Berghofer, TU Muenchen |
|
4 |
||
5 |
This is the graph browser's main class. It contains the "main(...)" |
|
6 |
method, which is used for the stand-alone version, as well as |
|
7 |
"init(...)", "start(...)" and "stop(...)" methods which are used for |
|
8 |
the applet version. |
|
| 6541 | 9 |
Note: GraphBrowser is designed for the 1.1.x version of the JDK. |
| 3599 | 10 |
***************************************************************************/ |
11 |
||
12 |
package GraphBrowser; |
|
13 |
||
14 |
import java.awt.*; |
|
15 |
import java.applet.*; |
|
16 |
import java.io.*; |
|
17 |
import java.util.*; |
|
18 |
import java.net.*; |
|
19 |
import awtUtilities.*; |
|
20 |
||
21 |
public class GraphBrowser extends Applet {
|
|
22 |
GraphView gv; |
|
23 |
TreeBrowser tb=null; |
|
24 |
String gfname; |
|
25 |
||
26 |
static boolean isApplet; |
|
27 |
static Frame f; |
|
28 |
||
29 |
public GraphBrowser(String name) {
|
|
30 |
gfname=name; |
|
31 |
} |
|
32 |
||
33 |
public GraphBrowser() {}
|
|
34 |
||
35 |
public void showWaitMessage() {
|
|
36 |
if (isApplet) |
|
37 |
getAppletContext().showStatus("calculating layout, please wait ...");
|
|
38 |
else {
|
|
| 6541 | 39 |
f.setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
| 3599 | 40 |
} |
41 |
} |
|
42 |
||
43 |
public void showReadyMessage() {
|
|
44 |
if (isApplet) |
|
45 |
getAppletContext().showStatus("ready !");
|
|
46 |
else {
|
|
| 6541 | 47 |
f.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
| 3599 | 48 |
} |
49 |
} |
|
50 |
||
51 |
public void viewFile(String fname) {
|
|
52 |
try {
|
|
53 |
if (isApplet) |
|
| 6541 | 54 |
getAppletContext().showDocument(new URL(getDocumentBase(), fname), "_blank"); |
| 3599 | 55 |
else {
|
| 6541 | 56 |
String path = gfname.substring(0, gfname.lastIndexOf('/') + 1);
|
|
6648
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
57 |
Reader rd; |
| 6541 | 58 |
BufferedReader br; |
59 |
String line, text = ""; |
|
| 3599 | 60 |
|
|
6648
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
61 |
try {
|
|
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
62 |
rd = new BufferedReader(new InputStreamReader((new URL(fname)).openConnection().getInputStream())); |
|
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
63 |
} catch (Exception exn) {
|
|
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
64 |
rd = new FileReader(path + fname); |
|
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
65 |
} |
|
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
66 |
br = new BufferedReader(rd); |
|
d70810da5565
Added some code to enable browser to display remote documents.
berghofe
parents:
6541
diff
changeset
|
67 |
|
| 6541 | 68 |
while ((line = br.readLine()) != null) |
69 |
text += line + "\n"; |
|
| 3599 | 70 |
|
71 |
if (fname.endsWith(".html")) {
|
|
72 |
/**** convert HTML to text (just a quick hack) ****/ |
|
73 |
||
74 |
String buf=""; |
|
75 |
char[] text2,text3; |
|
76 |
int i,j=0; |
|
77 |
boolean special=false, html=false; |
|
78 |
char ctrl; |
|
79 |
||
80 |
text2 = text.toCharArray(); |
|
81 |
text3 = new char[text.length()]; |
|
82 |
for (i = 0; i < text.length(); i++) {
|
|
83 |
char c = text2[i]; |
|
84 |
if (c == '&') {
|
|
85 |
special = true; |
|
86 |
buf = ""; |
|
87 |
} else if (special) {
|
|
88 |
if (c == ';') {
|
|
89 |
special = false; |
|
90 |
if (buf.equals("lt"))
|
|
91 |
text3[j++] = '<'; |
|
92 |
else if (buf.equals("gt"))
|
|
93 |
text3[j++] = '>'; |
|
94 |
else if (buf.equals("amp"))
|
|
95 |
text3[j++] = '&'; |
|
96 |
} else |
|
97 |
buf += c; |
|
98 |
} else if (c == '<') {
|
|
99 |
html = true; |
|
100 |
ctrl = text2[i+1]; |
|
101 |
} else if (c == '>') |
|
102 |
html = false; |
|
103 |
else if (!html) |
|
104 |
text3[j++] = c; |
|
105 |
} |
|
106 |
text = String.valueOf(text3); |
|
107 |
} |
|
108 |
||
109 |
Frame f=new TextFrame(fname.substring(fname.lastIndexOf('/')+1),text);
|
|
| 6541 | 110 |
f.setSize(500,600); |
| 3599 | 111 |
f.show(); |
112 |
} |
|
113 |
} catch (Exception exn) {
|
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
114 |
System.err.println("Can't read file "+fname);
|
| 3599 | 115 |
} |
116 |
} |
|
117 |
||
118 |
public void PS(String fname,boolean printable) throws IOException {
|
|
119 |
gv.PS(fname,printable); |
|
120 |
} |
|
121 |
||
122 |
public boolean isEmpty() {
|
|
123 |
return tb==null; |
|
124 |
} |
|
125 |
||
|
11876
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
126 |
public void initBrowser(InputStream is, boolean noAWT) {
|
| 3599 | 127 |
try {
|
|
11876
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
128 |
Font font = noAWT ? null : new Font("Helvetica", Font.PLAIN, 12);
|
|
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
129 |
TreeNode tn = new TreeNode("Root", "", -1, true);
|
|
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
130 |
gv = new GraphView(new Graph(is, tn), this, font); |
|
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
131 |
tb = new TreeBrowser(tn, gv, font); |
| 3599 | 132 |
gv.setTreeBrowser(tb); |
| 6541 | 133 |
Vector v = new Vector(10,10); |
| 3599 | 134 |
tn.collapsedDirectories(v); |
135 |
gv.collapseDir(v); |
|
| 6541 | 136 |
|
137 |
ScrollPane scrollp1 = new ScrollPane(); |
|
138 |
ScrollPane scrollp2 = new ScrollPane(); |
|
139 |
scrollp1.add(gv); |
|
140 |
scrollp2.add(tb); |
|
141 |
scrollp1.getHAdjustable().setUnitIncrement(20); |
|
142 |
scrollp1.getVAdjustable().setUnitIncrement(20); |
|
143 |
scrollp2.getHAdjustable().setUnitIncrement(20); |
|
144 |
scrollp2.getVAdjustable().setUnitIncrement(20); |
|
| 6753 | 145 |
Component gv2 = new Border(scrollp1, 3); |
146 |
Component tb2 = new Border(scrollp2, 3); |
|
| 3599 | 147 |
GridBagLayout gridbag = new GridBagLayout(); |
148 |
GridBagConstraints cnstr = new GridBagConstraints(); |
|
149 |
setLayout(gridbag); |
|
150 |
cnstr.fill = GridBagConstraints.BOTH; |
|
151 |
cnstr.insets = new Insets(5,5,5,5); |
|
152 |
cnstr.weightx = 1; |
|
153 |
cnstr.weighty = 1; |
|
154 |
cnstr.gridwidth = 1; |
|
155 |
gridbag.setConstraints(tb2,cnstr); |
|
156 |
add(tb2); |
|
157 |
cnstr.weightx = 2.5; |
|
158 |
cnstr.gridwidth = GridBagConstraints.REMAINDER; |
|
159 |
gridbag.setConstraints(gv2,cnstr); |
|
160 |
add(gv2); |
|
161 |
} catch (IOException exn) {
|
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
162 |
System.err.println("\nI/O error while reading graph file.");
|
| 3599 | 163 |
} catch (ParseError exn) {
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
164 |
System.err.println("\nParse error in graph file:");
|
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
165 |
System.err.println(exn.getMessage()); |
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
166 |
System.err.println("\nSyntax:\n<vertexname> <vertexID> <dirname> [ + ] <path> [ < | > ] [ <vertexID> [ ... [ <vertexID> ] ... ] ] ;");
|
| 3599 | 167 |
} |
168 |
} |
|
169 |
||
170 |
public void init() {
|
|
171 |
isApplet=true; |
|
172 |
gfname=getParameter("graphfile");
|
|
173 |
try {
|
|
174 |
InputStream is=(new URL(getDocumentBase(), gfname)).openConnection().getInputStream(); |
|
|
11876
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
175 |
initBrowser(is, false); |
| 3599 | 176 |
is.close(); |
177 |
} catch (MalformedURLException exn) {
|
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
178 |
System.err.println("Invalid URL: "+gfname);
|
| 3599 | 179 |
} catch (IOException exn) {
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
180 |
System.err.println("I/O error while reading "+gfname+".");
|
| 3599 | 181 |
} |
182 |
} |
|
183 |
||
184 |
public static void main(String[] args) {
|
|
185 |
isApplet=false; |
|
186 |
try {
|
|
187 |
GraphBrowser gb=new GraphBrowser(args.length > 0 ? args[0] : ""); |
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
188 |
if (args.length > 0) {
|
| 3599 | 189 |
InputStream is=new FileInputStream(args[0]); |
|
11876
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
190 |
gb.initBrowser(is, args.length > 1); |
| 3599 | 191 |
is.close(); |
192 |
} |
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
193 |
if (args.length > 1) {
|
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
194 |
try {
|
|
11876
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
195 |
if (args[1].endsWith(".ps"))
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
196 |
gb.gv.PS(args[1], true); |
|
11876
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
197 |
else if (args[1].endsWith(".eps"))
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
198 |
gb.gv.PS(args[1], false); |
|
11876
6ac0627167ed
Fixed problem with batch mode layout, which caused an AWT exception when
berghofe
parents:
11812
diff
changeset
|
199 |
else |
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
200 |
System.err.println("Unknown file type: " + args[1]);
|
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
201 |
} catch (IOException exn) {
|
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
202 |
System.err.println("Unable to write file " + args[1]);
|
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
203 |
} |
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
204 |
} else {
|
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
205 |
f=new GraphBrowserFrame(gb); |
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
206 |
f.setSize(700,500); |
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
207 |
f.show(); |
|
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
208 |
} |
| 3599 | 209 |
} catch (IOException exn) {
|
|
11798
fbab70de9b0d
Added support for batch mode layout (without X11 connection).
berghofe
parents:
9459
diff
changeset
|
210 |
System.err.println("Can't open graph file "+args[0]);
|
| 3599 | 211 |
} |
212 |
} |
|
213 |
} |
|
214 |