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