lib/browser/GraphBrowser/GraphBrowserFrame.java
author paulson
Wed, 02 Dec 1998 15:53:05 +0100
changeset 6006 d2e271b8d651
parent 3599 89cbba12863d
child 6541 d3ac35b2bfbf
permissions -rw-r--r--
new rule rev_bexI
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3599
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     1
/***************************************************************************
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     2
  Title:      GraphBrowser/GraphBrowserFrame.java
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     3
  ID:         $Id$
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     4
  Author:     Stefan Berghofer, TU Muenchen
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     5
  Copyright   1997  TU Muenchen
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     6
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     7
  This class is the frame for the stand-alone application. It contains
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     8
  methods for handling menubar events.
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
     9
***************************************************************************/
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    10
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    11
package GraphBrowser;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    12
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    13
import java.awt.*;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    14
import java.io.*;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    15
import awtUtilities.*;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    16
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    17
public class GraphBrowserFrame extends Frame {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    18
	GraphBrowser gb;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    19
	MenuItem i1,i2;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    20
	String graphDir,psDir;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    21
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    22
	public void checkMenuItems() {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    23
		if (gb.isEmpty()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    24
			i1.disable();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    25
			i2.disable();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    26
		} else {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    27
			i1.enable();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    28
			i2.enable();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    29
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    30
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    31
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    32
	public boolean action(Event evt, Object arg) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    33
		if (evt.target instanceof MenuItem) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    34
			String label=(String)arg;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    35
			if (label.equals("Quit"))
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    36
				System.exit(0);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    37
			else if (label.equals("Export to PostScript")) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    38
				PS(true,label);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    39
				return true;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    40
			} else if (label.equals("Export to EPS")) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    41
				PS(false,label);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    42
				return true;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    43
			} else if (label.equals("Open ...")) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    44
				FileDialog fd=new FileDialog(this,"Open graph file",FileDialog.LOAD);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    45
				if (graphDir!=null)
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    46
					fd.setDirectory(graphDir);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    47
				fd.show();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    48
				if (fd.getFile()==null) return true;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    49
				graphDir=fd.getDirectory();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    50
				String fname=graphDir+fd.getFile();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    51
				GraphBrowser gb2=new GraphBrowser(fname);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    52
				try {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    53
					InputStream is=new FileInputStream(fname);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    54
					gb2.initBrowser(is);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    55
					is.close();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    56
				} catch (IOException exn) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    57
					String button[]={"OK"};
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    58
					MessageDialog md=new MessageDialog(this,"Error","Can't open file "+fname+".",button);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    59
					md.resize(350,200);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    60
					md.show();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    61
					return true;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    62
				}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    63
				remove(gb);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    64
				add("Center",gb2);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    65
				gb=gb2;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    66
				checkMenuItems();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    67
				validate();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    68
				return true;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    69
			}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    70
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    71
		return false;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    72
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    73
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    74
	public void PS(boolean printable,String label) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    75
		FileDialog fd=new FileDialog(this,label,FileDialog.SAVE);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    76
		if (psDir!=null)
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    77
			fd.setDirectory(psDir);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    78
		fd.show();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    79
		if (fd.getFile()==null) return;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    80
		psDir=fd.getDirectory();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    81
		String fname=psDir+fd.getFile();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    82
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    83
		if ((new File(fname)).exists()) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    84
			String buttons[]={"Overwrite","Cancel"};
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    85
			MessageDialog md=new MessageDialog(this,"Warning",
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    86
			      "Warning: File "+fname+" already exists. Overwrite?",
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    87
			      buttons);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    88
			md.resize(350,200);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    89
			md.show();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    90
			if (md.getText().equals("Cancel")) return;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    91
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    92
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    93
		try {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    94
			gb.PS(fname,printable);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    95
		} catch (IOException exn) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    96
			String button[]={"OK"};
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    97
			MessageDialog md=new MessageDialog(this,"Error",
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    98
			      "Unable to write file "+fname+".",button);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
    99
			md.resize(350,200);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   100
			md.show();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   101
		}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   102
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   103
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   104
	public GraphBrowserFrame(GraphBrowser br) {
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   105
		super("GraphBrowser");
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   106
		gb=br;
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   107
		MenuBar mb=new MenuBar();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   108
		Menu m1=new Menu("File");
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   109
		m1.add(new MenuItem("Open ..."));
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   110
		m1.add(i1=new MenuItem("Export to PostScript"));
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   111
		m1.add(i2=new MenuItem("Export to EPS"));
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   112
		m1.add(new MenuItem("Quit"));
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   113
		checkMenuItems();
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   114
		mb.add(m1);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   115
		setMenuBar(mb);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   116
		add("Center",br);
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   117
	}
89cbba12863d Source files for Isabelle theory graph browser.
berghofe
parents:
diff changeset
   118
}