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