lib/browser/GraphBrowser/GraphBrowser.java
changeset 11798 fbab70de9b0d
parent 9459 259349bb8397
child 11812 8d191eaf7fc4
equal deleted inserted replaced
11797:1e29b79db3dc 11798:fbab70de9b0d
     1 /***************************************************************************
     1 /***************************************************************************
     2   Title:      GraphBrowser/GraphBrowser.java
     2   Title:      GraphBrowser/GraphBrowser.java
     3   ID:         $Id$
     3   ID:         $Id$
     4   Author:     Stefan Berghofer, TU Muenchen
     4   Author:     Stefan Berghofer, TU Muenchen
     5   Copyright   1997  TU Muenchen
     5   License:    GPL (GNU GENERAL PUBLIC LICENSE)
     6 
     6 
     7   This is the graph browser's main class. It contains the "main(...)"
     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
     8   method, which is used for the stand-alone version, as well as
     9   "init(...)", "start(...)" and "stop(...)" methods which are used for
     9   "init(...)", "start(...)" and "stop(...)" methods which are used for
    10   the applet version.
    10   the applet version.
   113 				Frame f=new TextFrame(fname.substring(fname.lastIndexOf('/')+1),text);
   113 				Frame f=new TextFrame(fname.substring(fname.lastIndexOf('/')+1),text);
   114 				f.setSize(500,600);
   114 				f.setSize(500,600);
   115 				f.show();
   115 				f.show();
   116 			}
   116 			}
   117 		} catch (Exception exn) {
   117 		} catch (Exception exn) {
   118 			System.out.println("Can't read file "+fname);
   118 			System.err.println("Can't read file "+fname);
   119 		}
   119 		}
   120 	}
   120 	}
   121 				
   121 				
   122 	public void PS(String fname,boolean printable) throws IOException {
   122 	public void PS(String fname,boolean printable) throws IOException {
   123 		gv.PS(fname,printable);
   123 		gv.PS(fname,printable);
   160 			cnstr.weightx = 2.5;
   160 			cnstr.weightx = 2.5;
   161 			cnstr.gridwidth = GridBagConstraints.REMAINDER;
   161 			cnstr.gridwidth = GridBagConstraints.REMAINDER;
   162 			gridbag.setConstraints(gv2,cnstr);
   162 			gridbag.setConstraints(gv2,cnstr);
   163 			add(gv2);
   163 			add(gv2);
   164 		} catch (IOException exn) {
   164 		} catch (IOException exn) {
   165 			System.out.println("\nI/O error while reading graph file.");
   165 			System.err.println("\nI/O error while reading graph file.");
   166 		} catch (ParseError exn) {
   166 		} catch (ParseError exn) {
   167 			System.out.println("\nParse error in graph file:");
   167 			System.err.println("\nParse error in graph file:");
   168 			System.out.println(exn.getMessage());
   168 			System.err.println(exn.getMessage());
   169 			System.out.println("\nSyntax:\n<vertexname> <vertexID> <dirname> [ + ] <path> [ < | > ] [ <vertexID> [ ... [ <vertexID> ] ... ] ] ;");
   169 			System.err.println("\nSyntax:\n<vertexname> <vertexID> <dirname> [ + ] <path> [ < | > ] [ <vertexID> [ ... [ <vertexID> ] ... ] ] ;");
   170 		}
   170 		}
   171 	}		
   171 	}		
   172 
   172 
   173 	public void init() {
   173 	public void init() {
   174 		isApplet=true;
   174 		isApplet=true;
   176 		try {
   176 		try {
   177 			InputStream is=(new URL(getDocumentBase(), gfname)).openConnection().getInputStream();
   177 			InputStream is=(new URL(getDocumentBase(), gfname)).openConnection().getInputStream();
   178 			initBrowser(is);
   178 			initBrowser(is);
   179 			is.close();
   179 			is.close();
   180 		} catch (MalformedURLException exn) {
   180 		} catch (MalformedURLException exn) {
   181 			System.out.println("Invalid URL: "+gfname);
   181 			System.err.println("Invalid URL: "+gfname);
   182 		} catch (IOException exn) {
   182 		} catch (IOException exn) {
   183 			System.out.println("I/O error while reading "+gfname+".");
   183 			System.err.println("I/O error while reading "+gfname+".");
   184 		}
   184 		}
   185 	}
   185 	}
   186 
   186 
   187 	public static void main(String[] args) {
   187 	public static void main(String[] args) {
   188 		isApplet=false;
   188 		isApplet=false;
   189 		try {
   189 		try {
   190 			GraphBrowser gb=new GraphBrowser(args.length > 0 ? args[0] : "");
   190 			GraphBrowser gb=new GraphBrowser(args.length > 0 ? args[0] : "");
   191 			if (args.length>0) {
   191 			if (args.length > 0) {
   192 				InputStream is=new FileInputStream(args[0]);
   192 				InputStream is=new FileInputStream(args[0]);
   193 				gb.initBrowser(is);
   193 				gb.initBrowser(is);
   194 				is.close();
   194 				is.close();
   195 			}
   195 			}
   196 			f=new GraphBrowserFrame(gb);
   196 			if (args.length > 1) {
   197 			f.setSize(700,500);
   197 			    gb.gv.getGraph().layout(null);
   198 			f.show();
   198                             try {
       
   199 			      if (args[1].endsWith(".ps")) {
       
   200                                 gb.gv.PS(args[1], true);
       
   201                               } else if (args[1].endsWith(".eps")) {
       
   202                                 gb.gv.PS(args[1], false);
       
   203                               } else {
       
   204                                 System.err.println("Unknown file type: " + args[1]);
       
   205                               }
       
   206                             } catch (IOException exn) {
       
   207                               System.err.println("Unable to write file " + args[1]);
       
   208                             }
       
   209                         } else {
       
   210 			    f=new GraphBrowserFrame(gb);
       
   211 			    f.setSize(700,500);
       
   212 			    f.show();
       
   213                         }
   199 		} catch (IOException exn) {
   214 		} catch (IOException exn) {
   200 			System.out.println("Can't open graph file "+args[0]);
   215 			System.err.println("Can't open graph file "+args[0]);
   201 		}
   216 		}
       
   217 		System.exit(0);
   202 	}
   218 	}
   203 }
   219 }
   204 
   220