lib/browser/GraphBrowser/GraphBrowser.java
changeset 6541 d3ac35b2bfbf
parent 3641 f52a8342e944
child 6648 d70810da5565
equal deleted inserted replaced
6540:eaf90f6806df 6541:d3ac35b2bfbf
     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.
    11   Note: GraphBrowser is designed for the 1.0.2 version of the JDK.
    11   Note: GraphBrowser is designed for the 1.1.x version of the JDK.
    12 ***************************************************************************/
    12 ***************************************************************************/
    13 
    13 
    14 package GraphBrowser;
    14 package GraphBrowser;
    15 
    15 
    16 import java.awt.*;
    16 import java.awt.*;
    36 
    36 
    37 	public void showWaitMessage() {
    37 	public void showWaitMessage() {
    38 		if (isApplet)
    38 		if (isApplet)
    39 			getAppletContext().showStatus("calculating layout, please wait ...");
    39 			getAppletContext().showStatus("calculating layout, please wait ...");
    40 		else {
    40 		else {
    41 			f.setCursor(Frame.WAIT_CURSOR);
    41 			f.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    42 		}
    42 		}
    43 	}
    43 	}
    44 
    44 
    45 	public void showReadyMessage() {
    45 	public void showReadyMessage() {
    46 		if (isApplet)
    46 		if (isApplet)
    47 			getAppletContext().showStatus("ready !");
    47 			getAppletContext().showStatus("ready !");
    48 		else {
    48 		else {
    49 			f.setCursor(Frame.DEFAULT_CURSOR);
    49 			f.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    50 		}
    50 		}
    51 	}
    51 	}
    52 
    52 
    53 	public void viewFile(String fname) {
    53 	public void viewFile(String fname) {
    54 		try {
    54 		try {
    55 			if (isApplet)
    55 			if (isApplet)
    56 				getAppletContext().showDocument(new URL(getDocumentBase(), fname),"_blank");
    56 				getAppletContext().showDocument(new URL(getDocumentBase(), fname), "_blank");
    57 			else {
    57 			else {
    58 				String path=gfname.substring(0,gfname.lastIndexOf('/')+1);
    58 				String path = gfname.substring(0, gfname.lastIndexOf('/') + 1);
    59 				InputStream is;
    59 				BufferedReader br;
    60 				String line, text="";
    60 				String line, text = "";
    61 				DataInputStream di;
       
    62 
    61 
    63 				is=new FileInputStream(path+fname);
    62 				br = new BufferedReader(new FileReader(path + fname));
    64 				di=new DataInputStream(is);
    63 				while ((line = br.readLine()) != null)
    65 				while ((line=di.readLine())!=null)
    64 					text += line + "\n";
    66 					text+=line+"\n";
       
    67 
    65 
    68 				if (fname.endsWith(".html")) {
    66 				if (fname.endsWith(".html")) {
    69 					/**** convert HTML to text (just a quick hack) ****/
    67 					/**** convert HTML to text (just a quick hack) ****/
    70 
    68 
    71 					String buf="";
    69 					String buf="";
   104 					}
   102 					}
   105 					text = String.valueOf(text3);
   103 					text = String.valueOf(text3);
   106 				}
   104 				}
   107 							
   105 							
   108 				Frame f=new TextFrame(fname.substring(fname.lastIndexOf('/')+1),text);
   106 				Frame f=new TextFrame(fname.substring(fname.lastIndexOf('/')+1),text);
   109 				f.resize(500,600);
   107 				f.setSize(500,600);
   110 				f.show();
   108 				f.show();
   111 			}
   109 			}
   112 		} catch (Exception exn) {
   110 		} catch (Exception exn) {
   113 			System.out.println("Can't read file "+fname);
   111 			System.out.println("Can't read file "+fname);
   114 		}
   112 		}
   126 		try {
   124 		try {
   127 			TreeNode tn=new TreeNode("Directories","",-1,true);
   125 			TreeNode tn=new TreeNode("Directories","",-1,true);
   128 			gv=new GraphView(new Graph(is,tn),this);
   126 			gv=new GraphView(new Graph(is,tn),this);
   129 			tb=new TreeBrowser(tn,gv);
   127 			tb=new TreeBrowser(tn,gv);
   130 			gv.setTreeBrowser(tb);
   128 			gv.setTreeBrowser(tb);
   131 			Vector v=new Vector(10,10);
   129 			Vector v = new Vector(10,10);
   132 			tn.collapsedDirectories(v);
   130 			tn.collapsedDirectories(v);
   133 			gv.collapseDir(v);
   131 			gv.collapseDir(v);
   134 			Component gv2=new Border(gv,5);
   132 
   135 			Component tb2=new Border(tb,5);
   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);
   136 			GridBagLayout gridbag = new GridBagLayout();
   143 			GridBagLayout gridbag = new GridBagLayout();
   137 			GridBagConstraints cnstr = new GridBagConstraints();
   144 			GridBagConstraints cnstr = new GridBagConstraints();
   138 			setLayout(gridbag);
   145 			setLayout(gridbag);
   139 			cnstr.fill = GridBagConstraints.BOTH;
   146 			cnstr.fill = GridBagConstraints.BOTH;
   140 			cnstr.insets = new Insets(5,5,5,5);
   147 			cnstr.insets = new Insets(5,5,5,5);
   178 				InputStream is=new FileInputStream(args[0]);
   185 				InputStream is=new FileInputStream(args[0]);
   179 				gb.initBrowser(is);
   186 				gb.initBrowser(is);
   180 				is.close();
   187 				is.close();
   181 			}
   188 			}
   182 			f=new GraphBrowserFrame(gb);
   189 			f=new GraphBrowserFrame(gb);
   183 			f.resize(700,500);
   190 			f.setSize(700,500);
   184 			f.show();
   191 			f.show();
   185 		} catch (IOException exn) {
   192 		} catch (IOException exn) {
   186 			System.out.println("Can't open graph file "+args[0]);
   193 			System.out.println("Can't open graph file "+args[0]);
   187 		}
   194 		}
   188 	}
   195 	}