| author | oheimb | 
| Thu, 31 May 2001 16:52:35 +0200 | |
| changeset 11347 | 4e41f71179ed | 
| parent 9459 | 259349bb8397 | 
| child 11798 | fbab70de9b0d | 
| permissions | -rw-r--r-- | 
| 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);
 | 
| 6648 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 59 | Reader rd; | 
| 6541 | 60 | BufferedReader br; | 
| 61 | String line, text = ""; | |
| 3599 | 62 | |
| 6648 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 63 | 				try {
 | 
| 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 64 | rd = new BufferedReader(new InputStreamReader((new URL(fname)).openConnection().getInputStream())); | 
| 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 65 | 				} catch (Exception exn) {
 | 
| 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 66 | rd = new FileReader(path + fname); | 
| 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 67 | } | 
| 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 68 | br = new BufferedReader(rd); | 
| 
d70810da5565
Added some code to enable browser to display remote documents.
 berghofe parents: 
6541diff
changeset | 69 | |
| 6541 | 70 | while ((line = br.readLine()) != null) | 
| 71 | text += line + "\n"; | |
| 3599 | 72 | |
| 73 | 				if (fname.endsWith(".html")) {
 | |
| 74 | /**** convert HTML to text (just a quick hack) ****/ | |
| 75 | ||
| 76 | String buf=""; | |
| 77 | char[] text2,text3; | |
| 78 | int i,j=0; | |
| 79 | boolean special=false, html=false; | |
| 80 | char ctrl; | |
| 81 | ||
| 82 | text2 = text.toCharArray(); | |
| 83 | text3 = new char[text.length()]; | |
| 84 | 					for (i = 0; i < text.length(); i++) {
 | |
| 85 | char c = text2[i]; | |
| 86 | 						if (c == '&') {
 | |
| 87 | special = true; | |
| 88 | buf = ""; | |
| 89 | 						} else if (special) {
 | |
| 90 | 							if (c == ';') {
 | |
| 91 | special = false; | |
| 92 | 								if (buf.equals("lt"))
 | |
| 93 | text3[j++] = '<'; | |
| 94 | 								else if (buf.equals("gt"))
 | |
| 95 | text3[j++] = '>'; | |
| 96 | 								else if (buf.equals("amp"))
 | |
| 97 | text3[j++] = '&'; | |
| 98 | } else | |
| 99 | buf += c; | |
| 100 | 						} else if (c == '<') {
 | |
| 101 | html = true; | |
| 102 | ctrl = text2[i+1]; | |
| 103 | if ((ctrl == 'P') || (ctrl == 'B')) | |
| 104 | text3[j++] = '\n'; | |
| 105 | } else if (c == '>') | |
| 106 | html = false; | |
| 107 | else if (!html) | |
| 108 | text3[j++] = c; | |
| 109 | } | |
| 110 | text = String.valueOf(text3); | |
| 111 | } | |
| 112 | ||
| 113 | 				Frame f=new TextFrame(fname.substring(fname.lastIndexOf('/')+1),text);
 | |
| 6541 | 114 | f.setSize(500,600); | 
| 3599 | 115 | f.show(); | 
| 116 | } | |
| 117 | 		} catch (Exception exn) {
 | |
| 118 | 			System.out.println("Can't read file "+fname);
 | |
| 119 | } | |
| 120 | } | |
| 121 | ||
| 122 | 	public void PS(String fname,boolean printable) throws IOException {
 | |
| 123 | gv.PS(fname,printable); | |
| 124 | } | |
| 125 | ||
| 126 | 	public boolean isEmpty() {
 | |
| 127 | return tb==null; | |
| 128 | } | |
| 129 | ||
| 130 | 	public void initBrowser(InputStream is) {
 | |
| 131 | 		try {
 | |
| 9459 | 132 | 			TreeNode tn=new TreeNode("Root","",-1,true);
 | 
| 3599 | 133 | gv=new GraphView(new Graph(is,tn),this); | 
| 134 | tb=new TreeBrowser(tn,gv); | |
| 135 | gv.setTreeBrowser(tb); | |
| 6541 | 136 | Vector v = new Vector(10,10); | 
| 3599 | 137 | tn.collapsedDirectories(v); | 
| 138 | gv.collapseDir(v); | |
| 6541 | 139 | |
| 140 | ScrollPane scrollp1 = new ScrollPane(); | |
| 141 | ScrollPane scrollp2 = new ScrollPane(); | |
| 142 | scrollp1.add(gv); | |
| 143 | scrollp2.add(tb); | |
| 144 | scrollp1.getHAdjustable().setUnitIncrement(20); | |
| 145 | scrollp1.getVAdjustable().setUnitIncrement(20); | |
| 146 | scrollp2.getHAdjustable().setUnitIncrement(20); | |
| 147 | scrollp2.getVAdjustable().setUnitIncrement(20); | |
| 6753 | 148 | Component gv2 = new Border(scrollp1, 3); | 
| 149 | Component tb2 = new Border(scrollp2, 3); | |
| 3599 | 150 | GridBagLayout gridbag = new GridBagLayout(); | 
| 151 | GridBagConstraints cnstr = new GridBagConstraints(); | |
| 152 | setLayout(gridbag); | |
| 153 | cnstr.fill = GridBagConstraints.BOTH; | |
| 154 | cnstr.insets = new Insets(5,5,5,5); | |
| 155 | cnstr.weightx = 1; | |
| 156 | cnstr.weighty = 1; | |
| 157 | cnstr.gridwidth = 1; | |
| 158 | gridbag.setConstraints(tb2,cnstr); | |
| 159 | add(tb2); | |
| 160 | cnstr.weightx = 2.5; | |
| 161 | cnstr.gridwidth = GridBagConstraints.REMAINDER; | |
| 162 | gridbag.setConstraints(gv2,cnstr); | |
| 163 | add(gv2); | |
| 164 | 		} catch (IOException exn) {
 | |
| 165 | 			System.out.println("\nI/O error while reading graph file.");
 | |
| 166 | 		} catch (ParseError exn) {
 | |
| 167 | 			System.out.println("\nParse error in graph file:");
 | |
| 168 | System.out.println(exn.getMessage()); | |
| 3641 | 169 | 			System.out.println("\nSyntax:\n<vertexname> <vertexID> <dirname> [ + ] <path> [ < | > ] [ <vertexID> [ ... [ <vertexID> ] ... ] ] ;");
 | 
| 3599 | 170 | } | 
| 171 | } | |
| 172 | ||
| 173 | 	public void init() {
 | |
| 174 | isApplet=true; | |
| 175 | 		gfname=getParameter("graphfile");
 | |
| 176 | 		try {
 | |
| 177 | InputStream is=(new URL(getDocumentBase(), gfname)).openConnection().getInputStream(); | |
| 178 | initBrowser(is); | |
| 179 | is.close(); | |
| 180 | 		} catch (MalformedURLException exn) {
 | |
| 181 | 			System.out.println("Invalid URL: "+gfname);
 | |
| 182 | 		} catch (IOException exn) {
 | |
| 183 | 			System.out.println("I/O error while reading "+gfname+".");
 | |
| 184 | } | |
| 185 | } | |
| 186 | ||
| 187 | 	public static void main(String[] args) {
 | |
| 188 | isApplet=false; | |
| 189 | 		try {
 | |
| 190 | GraphBrowser gb=new GraphBrowser(args.length > 0 ? args[0] : ""); | |
| 191 | 			if (args.length>0) {
 | |
| 192 | InputStream is=new FileInputStream(args[0]); | |
| 193 | gb.initBrowser(is); | |
| 194 | is.close(); | |
| 195 | } | |
| 196 | f=new GraphBrowserFrame(gb); | |
| 6541 | 197 | f.setSize(700,500); | 
| 3599 | 198 | f.show(); | 
| 199 | 		} catch (IOException exn) {
 | |
| 200 | 			System.out.println("Can't open graph file "+args[0]);
 | |
| 201 | } | |
| 202 | } | |
| 203 | } | |
| 204 |