/Users/lyon/j4p/src/graphics/dclap/PictFrame.java

1    package graphics.dclap; 
2     
3    import ip.gui.frames.ShortCutFrame; 
4     
5    import java.awt.*; 
6    import java.awt.event.ActionEvent; 
7    import java.io.FileOutputStream; 
8    import java.io.IOException; 
9    import java.io.OutputStream; 
10    
11   public class PictFrame extends ShortCutFrame { 
12       private static final String args[] = {""}; 
13    
14       private MenuBar mb = getMenuBar(); 
15       private Menu m = new Menu("Save Menu"); 
16       private MenuItem save_mi = 
17               new MenuItem("[S]save as pict"); 
18    
19       public PictFrame() { 
20           super("PictFrame"); 
21           if (mb == null) { 
22               mb = new MenuBar(); 
23               setMenuBar(mb); 
24           } 
25           m.add(save_mi); 
26           mb.add(m); 
27    
28       } 
29    
30       public PictFrame(String name) { 
31           super(name); 
32           if (mb == null) { 
33               mb = new MenuBar(); 
34               setMenuBar(mb); 
35           } 
36           m.add(save_mi); 
37           mb.add(m); 
38    
39       } 
40    
41       public static FileOutputStream getFileOutputStream() { 
42           FileOutputStream fos = null; 
43           try { 
44               fos = 
45                       new FileOutputStream(getWriteFileName()); 
46           } catch (IOException e) { 
47               System.out.println("futil:Could not create file"); 
48           } 
49           return fos; 
50       } 
51    
52       public static String getWriteFileName() { 
53           FileDialog dialog = new FileDialog(new Frame(), "Enter file name", FileDialog.SAVE); 
54           dialog.show(); 
55           String fs = dialog.getDirectory() + dialog.getFile(); 
56           System.out.println("Opening file: " + fs); 
57           dialog.dispose(); 
58           return FilterFileNameBug(fs); 
59       } 
60   // Some versions of windows will 
61   // create a .* suffix on a file name 
62   // The following code will strip it: 
63       public static String FilterFileNameBug(String fname) { 
64           if (fname.endsWith(".*.*")) { 
65               fname = fname.substring(0, fname.length() - 4); 
66           } 
67           return fname; 
68       } 
69    
70       public void actionPerformed(ActionEvent e) { 
71    
72    
73           if (match(e, save_mi)) { 
74               Component c = this; 
75               OutputStream os = getFileOutputStream(); 
76               //SavePICT p = new SavePICT(); 
77               //p.saveAsPict( c,os); 
78               return; 
79           } 
80           super.actionPerformed(e); 
81       } 
82   }