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