Back to index

wims  3.65+svn20090927
EditRunDialog.java
Go to the documentation of this file.
00001 package rene.zirkel.dialogs;
00002 
00003 import java.awt.*;
00004 import java.io.*;
00005 
00006 import rene.gui.*;
00007 import rene.zirkel.Zirkel;
00008 import rene.zirkel.ZirkelFrame;
00009 import rene.dialogs.*;
00010 
00011 public class EditRunDialog extends HelpCloseDialog
00012 {      String Filename;
00013        ZirkelFrame ZF;
00014        TextArea Text;
00015 
00016        public EditRunDialog (ZirkelFrame zf, String filename)
00017        {      super(zf,Zirkel.name("editrun.title"),true);
00018               Filename=filename;
00019               ZF=zf;
00020               setLayout(new BorderLayout());
00021               
00022               Panel north=new MyPanel();
00023               north.add(new MyLabel(filename));
00024               add("North",new Panel3D(north));
00025               
00026               add("Center",new Panel3D(Text=new TextArea(30,60)));
00027               if (Global.FixedFont!=null) Text.setFont(Global.FixedFont);
00028               
00029               load(filename);
00030               
00031               Panel south=new MyPanel();
00032               south.add(new ButtonAction(this,Zirkel.name("editrun.run"),"Run"));
00033               south.add(new ButtonAction(this,Zirkel.name("editrun.load"),"Load"));
00034               south.add(new ButtonAction(this,Zirkel.name("abort"),"Close"));
00035               addHelp(south,"visual");
00036               add("South",new Panel3D(south));
00037               
00038               setSize("editrun");
00039               center(zf);
00040        }
00041        
00042        public void doAction (String s)
00043        {      noteSize("editrun");
00044               if (s.equals("Run"))
00045               {      doclose();
00046                      try
00047                      {      save(Filename);
00048                      }
00049                      catch (Exception e)
00050                      {      Warning w=new Warning(ZF,Zirkel.name("editrun.error"),
00051                                    Zirkel.name("warning"),true);
00052                             w.center(ZF);
00053                             w.setVisible(true);
00054                             return; 
00055                      }
00056                      ZF.loadRun(Filename);
00057               }
00058               else if (s.equals("Load"))
00059               {      doclose();
00060                      ZF.editRun("");
00061               }
00062               else super.doAction(s);
00063        }
00064        
00065        public void load (String filename)
00066        {      Text.setText("");
00067               Text.setEnabled(false);
00068               try
00069               {      BufferedReader in=new BufferedReader(
00070                             new InputStreamReader(new FileInputStream(filename)));
00071                      while (true)
00072                      {      String line=in.readLine();
00073                             if (line==null) break;
00074                             Text.append(line+"\n");
00075                      }
00076                      in.close();
00077               }
00078               catch (Exception e) {}
00079               Text.setEnabled(true);
00080               Text.repaint();
00081        }
00082        
00083        public void save (String filename)
00084               throws IOException
00085        {      String text=Text.getText();
00086               PrintWriter out=new PrintWriter(
00087                      new OutputStreamWriter(new FileOutputStream(filename)));
00088               out.print(text);
00089               out.close();
00090        }
00091        
00092 }