author | wenzelm |
Mon, 29 Oct 2001 14:09:10 +0100 | |
changeset 11980 | 98a1bb0bfd3a |
parent 11931 | a5d1c9b34900 |
child 14981 | e73f8140af78 |
permissions | -rw-r--r-- |
3599 | 1 |
/*************************************************************************** |
2 |
Title: GraphBrowser/GraphBrowserFrame.java |
|
3 |
ID: $Id$ |
|
4 |
Author: Stefan Berghofer, TU Muenchen |
|
11875 | 5 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
3599 | 6 |
|
7 |
This class is the frame for the stand-alone application. It contains |
|
8 |
methods for handling menubar events. |
|
9 |
***************************************************************************/ |
|
10 |
||
11 |
package GraphBrowser; |
|
12 |
||
13 |
import java.awt.*; |
|
6541 | 14 |
import java.awt.event.*; |
3599 | 15 |
import java.io.*; |
16 |
import awtUtilities.*; |
|
17 |
||
6541 | 18 |
public class GraphBrowserFrame extends Frame implements ActionListener { |
3599 | 19 |
GraphBrowser gb; |
6541 | 20 |
MenuItem i1, i2; |
21 |
String graphDir, psDir; |
|
3599 | 22 |
|
23 |
public void checkMenuItems() { |
|
24 |
if (gb.isEmpty()) { |
|
6541 | 25 |
i1.setEnabled(false); |
26 |
i2.setEnabled(false); |
|
3599 | 27 |
} else { |
6541 | 28 |
i1.setEnabled(true); |
29 |
i2.setEnabled(true); |
|
3599 | 30 |
} |
31 |
} |
|
32 |
||
6541 | 33 |
public void actionPerformed(ActionEvent evt) { |
34 |
String label = evt.getActionCommand(); |
|
35 |
if (label.equals("Quit")) |
|
36 |
System.exit(0); |
|
37 |
else if (label.equals("Export to PostScript")) { |
|
38 |
PS(true, label); |
|
39 |
return; |
|
40 |
} else if (label.equals("Export to EPS")) { |
|
41 |
PS(false, label); |
|
42 |
return; |
|
43 |
} else if (label.equals("Open ...")) { |
|
44 |
FileDialog fd = new FileDialog(this, "Open graph file", FileDialog.LOAD); |
|
45 |
if (graphDir != null) |
|
46 |
fd.setDirectory(graphDir); |
|
47 |
fd.setVisible(true); |
|
48 |
if (fd.getFile() == null) return; |
|
49 |
graphDir = fd.getDirectory(); |
|
50 |
String fname = graphDir + fd.getFile(); |
|
51 |
GraphBrowser gb2 = new GraphBrowser(fname); |
|
52 |
try { |
|
53 |
InputStream is = new FileInputStream(fname); |
|
11875 | 54 |
gb2.initBrowser(is, false); |
6541 | 55 |
is.close(); |
56 |
} catch (IOException exn) { |
|
57 |
String button[] = {"OK"}; |
|
58 |
MessageDialog md = new MessageDialog(this, "Error", |
|
59 |
"Can't open file " + fname + ".", button); |
|
60 |
md.setSize(350, 200); |
|
61 |
md.setVisible(true); |
|
62 |
return; |
|
3599 | 63 |
} |
6541 | 64 |
remove(gb); |
65 |
add("Center", gb2); |
|
66 |
gb = gb2; |
|
67 |
checkMenuItems(); |
|
68 |
validate(); |
|
3599 | 69 |
} |
70 |
} |
|
71 |
||
72 |
public void PS(boolean printable,String label) { |
|
73 |
FileDialog fd=new FileDialog(this,label,FileDialog.SAVE); |
|
74 |
if (psDir!=null) |
|
75 |
fd.setDirectory(psDir); |
|
6541 | 76 |
fd.setVisible(true); |
3599 | 77 |
if (fd.getFile()==null) return; |
78 |
psDir=fd.getDirectory(); |
|
79 |
String fname=psDir+fd.getFile(); |
|
80 |
||
81 |
if ((new File(fname)).exists()) { |
|
82 |
String buttons[]={"Overwrite","Cancel"}; |
|
83 |
MessageDialog md=new MessageDialog(this,"Warning", |
|
84 |
"Warning: File "+fname+" already exists. Overwrite?", |
|
85 |
buttons); |
|
6541 | 86 |
md.setSize(350,200); |
87 |
md.setVisible(true); |
|
3599 | 88 |
if (md.getText().equals("Cancel")) return; |
89 |
} |
|
90 |
||
91 |
try { |
|
92 |
gb.PS(fname,printable); |
|
93 |
} catch (IOException exn) { |
|
94 |
String button[]={"OK"}; |
|
95 |
MessageDialog md=new MessageDialog(this,"Error", |
|
96 |
"Unable to write file "+fname+".",button); |
|
6541 | 97 |
md.setSize(350,200); |
98 |
md.setVisible(true); |
|
3599 | 99 |
} |
100 |
} |
|
101 |
||
102 |
public GraphBrowserFrame(GraphBrowser br) { |
|
103 |
super("GraphBrowser"); |
|
6541 | 104 |
MenuItem i3, i4; |
105 |
gb = br; |
|
106 |
MenuBar mb = new MenuBar(); |
|
107 |
Menu m1 = new Menu("File"); |
|
108 |
m1.add(i3 = new MenuItem("Open ...")); |
|
109 |
m1.add(i1 = new MenuItem("Export to PostScript")); |
|
110 |
m1.add(i2 = new MenuItem("Export to EPS")); |
|
111 |
m1.add(i4 = new MenuItem("Quit")); |
|
112 |
i1.addActionListener(this); |
|
113 |
i2.addActionListener(this); |
|
114 |
i3.addActionListener(this); |
|
115 |
i4.addActionListener(this); |
|
3599 | 116 |
checkMenuItems(); |
117 |
mb.add(m1); |
|
118 |
setMenuBar(mb); |
|
6541 | 119 |
add("Center", br); |
11931
a5d1c9b34900
added windowlistener (can now close the frame by window controls)
kleing
parents:
11875
diff
changeset
|
120 |
addWindowListener( new WindowAdapter() { |
a5d1c9b34900
added windowlistener (can now close the frame by window controls)
kleing
parents:
11875
diff
changeset
|
121 |
public void windowClosing(WindowEvent e) { |
a5d1c9b34900
added windowlistener (can now close the frame by window controls)
kleing
parents:
11875
diff
changeset
|
122 |
System.exit(0); |
a5d1c9b34900
added windowlistener (can now close the frame by window controls)
kleing
parents:
11875
diff
changeset
|
123 |
} |
a5d1c9b34900
added windowlistener (can now close the frame by window controls)
kleing
parents:
11875
diff
changeset
|
124 |
}); |
3599 | 125 |
} |
126 |
} |