Back to index

wims  3.65+svn20090927
ZirkelFrame.java
Go to the documentation of this file.
00001 package rene.zirkel;
00002 
00003 // file: ZirkelFrame.java
00004 
00005 import java.awt.*;
00006 import java.awt.event.*;
00007 import java.io.*;
00008 import java.util.*;
00009 import java.util.zip.*;
00010 
00011 import rene.dialogs.*;
00012 import rene.gui.*;
00013 import rene.util.*;
00014 import rene.util.parser.StringParser;
00015 import rene.util.xml.XmlWriter;
00016 import rene.zirkel.construction.*;
00017 import rene.zirkel.constructors.*;
00018 import rene.zirkel.dialogs.*;
00019 import rene.zirkel.help.*;
00020 import rene.zirkel.listener.*;
00021 import rene.zirkel.macro.*;
00022 import rene.zirkel.objects.*;
00023 import rene.zirkel.tools.*;
00024 
00025 
00026 class ZirkelFrameLoadThread implements Runnable
00027 {      String Name; 
00028        ZirkelFrame ZF; 
00029        public ZirkelFrameLoadThread (ZirkelFrame zf, String name)
00030        {      Name=name; ZF=zf; 
00031               new Thread(this).start(); 
00032        }
00033        public void run ()
00034        {      ZF.doload(Name); 
00035               ZF.setEnabled(true);
00036               ZF.ZC.requestFocus(); 
00037        }
00038 }
00039 
00040 class ShowWarning
00041        implements Runnable
00042 {      ZirkelFrame ZF;
00043        String S;
00044        public ShowWarning (ZirkelFrame zf, String s)
00045        {      ZF=zf; S=s;
00046               new Thread(this).start();
00047        }
00048        public void run ()
00049        {      try 
00050               {      Thread.sleep(1000);
00051               } 
00052               catch (InterruptedException e) 
00053               {      e.printStackTrace();
00054               }
00055               ZF.warning(S);
00056        }
00057 }
00058 
00059 public class ZirkelFrame extends CloseFrame
00060        implements StatusListener, KeyListener, IconBarListener, DoneListener,
00061               ZirkelCanvasInterface
00062 {      public ZirkelCanvas ZC; 
00063        Label Status; 
00064        public String Filename=""; 
00065        CheckboxMenuItem ShowHidden,Grid,TestJob,Partial,PartialLines,Vectors,
00066               IncludeMacros,LongNames,ShowNames,ShowValues,Visual,FullIcons,
00067               IsoScale,Obtuse,Solid,Compress,RestrictedMode,
00068               FontBold,FontLarge,RestrictIcons,Beginner,AlwaysClearMacros,
00069               LargeFont,BoldFont,PrintScalePreview,ConstructionDisplay,LeftSnap,Restricted,
00070               MacroBar,DefaultMacrosInBar; 
00071        IconBar IA,IB;
00072        MacroBar IM; 
00073        HistoryTextField Input; 
00074        String Background=""; 
00075        
00076        // color menu items:
00077        static Color DefaultColors[]={
00078               Color.black,
00079                      Color.green.darker().darker(),
00080                      Color.blue.darker(),
00081                      new Color(150,100,0),
00082                      Color.cyan.darker().darker(),
00083                      new Color(180,0,0)}; 
00084        public static Color Colors[]=DefaultColors; 
00085        public static Color LightColors[]; 
00086        public static Color BrighterLightColors[]; 
00087        public static Color BrighterColors[]; 
00088        public static Color SelectColor=Global.getParameter("colorselect",
00089               new Color(255,0,0)); 
00090        public static Color IndicateColor=Global.getParameter("colorselect",
00091               new Color(250,180,50)); 
00092        public static Color TargetColor=Global.getParameter("colortarget",Color.pink); 
00093        
00094        public static String ColorStrings[]=
00095        {      "black","green","blue","brown","cyan","red"
00096        }; 
00097        public static String PointTypes[]=
00098        {      "square","diamond","circle","dot","cross","dcross"
00099        }; 
00100        public static String ColorTypes[]=
00101        {      "normal","thick","thin"
00102        }; 
00103        public static int ColorTypeKeys[]={       KeyEvent.VK_5,KeyEvent.VK_6,KeyEvent.VK_7}; 
00104        CheckboxMenuItem ColorTypeMenuItems[]=new CheckboxMenuItem[ColorTypes.length]; 
00105        public static int ColorKeys[]={    KeyEvent.VK_1,KeyEvent.VK_2,KeyEvent.VK_3,KeyEvent.VK_4}; 
00106        CheckboxMenuItem ColorMenuItems[]=new CheckboxMenuItem[ColorStrings.length]; 
00107        CheckboxMenuItem ShowColorMenuItems[]=new CheckboxMenuItem[ColorStrings.length]; 
00108        static int PointKeys[]={KeyEvent.VK_5,KeyEvent.VK_6,KeyEvent.VK_7,KeyEvent.VK_8,KeyEvent.VK_9,KeyEvent.VK_0}; 
00109        CheckboxMenuItem PointMenuItems[]=new CheckboxMenuItem[PointTypes.length]; 
00110        
00111        // arrays for the object tools
00112        final public static String ObjectStrings[]= // names
00113        {      "point","boundedpoint","intersection",
00114               "line","ray","segment","fixedsegment",
00115               "circle","circle3","fixedcircle",
00116               "parallel","plumb","midpoint",
00117               "angle","fixedangle",
00118               "move","tracker","objecttracker","animate",
00119               "expression","area","quadric","image","text",
00120               "hide","runmacro",
00121               "edit","parameter","targets","definejob","delete","reorder",
00122               "draw","rename","zoom","animatebreak"
00123        }; 
00124        final public static String Separators[]= // names
00125        {      "point","boundedpoint","intersection",
00126               "!line","ray","segment","fixedsegment",
00127               "!circle","circle3","fixedcircle",
00128               "!parallel","plumb","midpoint",
00129               "!angle","fixedangle",
00130               "!move","tracker","objecttracker","animate",
00131               "!expression","area","quadric","image","text",
00132               "!hide","runmacro",
00133               "edit","parameter","targets","definejob","delete","reorder",
00134               "draw","rename","zoom","animatebreak"
00135        }; 
00136        final public static String MenuTitles[]=
00137        {      "points","lines","circles","complex","angles","move","decorative"
00138        }; 
00139        final public static int IconNumber=26; 
00140        final public static int NEdit=IconNumber,NParameters=IconNumber+1,
00141               NTargets=IconNumber+2,NDefineJob=IconNumber+3,
00142               NDelete=IconNumber+4,NReorder=IconNumber+5,NDraw=IconNumber+6,
00143               NRename=IconNumber+7,NZoom=IconNumber+8,NAnimateBreak=IconNumber+9; 
00144        final public static int NAnimator=18,NObjectTracker=17,NTracker=16,NMover=15; 
00145        final public static int NMacro=IconNumber-1; 
00146        public static ObjectConstructor ObjectConstructors[]= // constructors
00147        {      new PointConstructor(),
00148               new BoundedPointConstructor(),
00149               new IntersectionConstructor(),
00150               new LineConstructor(),
00151               new RayConstructor(),
00152               new SegmentConstructor(),
00153               new SegmentConstructor(true),
00154               new CircleConstructor(),
00155               new Circle3Constructor(),
00156               new CircleConstructor(true),
00157               new ParallelConstructor(),
00158               new PlumbConstructor(),
00159               new MidpointConstructor(),
00160               new AngleConstructor(),
00161               new AngleConstructor(true),
00162               new MoverTool(),
00163               new Tracker(),
00164               new ObjectTracker(),
00165               new AnimatorTool(),
00166               new ExpressionConstructor(),
00167               new AreaConstructor(),
00168               new QuadricConstructor(),
00169               new ImageConstructor(),
00170               new TextConstructor(),
00171               new HiderTool(),
00172               new MacroRunner(),
00173               new EditTool(),
00174               new SetParameterTool(),
00175               new SetTargetsTool(),
00176               new SaveJob(),
00177               new DeleteTool(),
00178               new ReorderTool(),
00179               new DrawerTool(),
00180               new RenamerTool(),
00181               new ZoomerTool(),
00182               new BreakpointAnimator(),
00183        }; 
00184        CheckboxMenuItem ObjectMenuItems[]=
00185               new CheckboxMenuItem[ObjectConstructors.length]; // menu checkbos items
00186        static char ObjectKeys[]; 
00187        int CurrentTool=0; // current tool
00188        boolean IsApplet; 
00189        
00190        Panel North,Center,MainPanel; 
00191        Panel StatusPanel,InputPanel;
00192        Panel CenterPanel;
00193        boolean Init=false;
00194        boolean SawPreviewWarning=false; 
00195        
00196        MyFileDialog FileLoad,FileSave,PicSave,HTMLSave,BackgroundLoad,
00197               ImageLoad,TemplateLoad; 
00198        // The file dialogs
00199        
00200        LogoWindow Logo;
00201        
00202        public ZirkelFrame (boolean applet)
00203        {      super(Zirkel.name("program.name")); // set window title
00204               IsApplet=applet; 
00205               if (applet)
00206               {      addWindowListener( // to close properly
00207                      new WindowAdapter ()
00208                      {      public void windowClosing (WindowEvent e)
00209                             {      close(); 
00210                             }
00211                      }
00212                      ); 
00213               }
00214               else
00215               {      addWindowListener( // to close properly
00216                      new WindowAdapter ()
00217                      {      public void windowClosed (WindowEvent e)
00218                             {      Global.saveProperties("CaR Properties"); 
00219                                    Global.exit(0); 
00220                             }
00221                      }); 
00222               }
00223               
00224               if (!applet) Logo=new LogoWindow(this);
00225               
00226               // create menu bar
00227               MenuBar menu=new MenuBar(); 
00228               setMenuBar(menu); 
00229               
00230               // file menu:
00231               Menu file=new MyMenu(Zirkel.name("menu.file")); 
00232               menuadd(file,"menu.file.new"); 
00233               menuadd(file,"menu.file.clearmacros"); 
00234               file.addSeparator(); 
00235               menuadd(file,"menu.file.load"); 
00236               menuadd(file,"menu.file.save"); 
00237               menuadd(file,"menu.file.saveas"); 
00238               file.addSeparator(); 
00239               AlwaysClearMacros=menuaddcheck(file,"menu.file.alwaysclearmacros"); 
00240               AlwaysClearMacros.setState(Global.getParameter(
00241                      "load.clearmacros",true)); 
00242               IncludeMacros=menuaddcheck(file,"menu.file.includemacros"); 
00243               IncludeMacros.setState(Global.getParameter(
00244                      "save.includemacros",true)); 
00245               Compress=menuaddcheck(file,"menu.file.compress"); 
00246               Compress.setState(Global.getParameter("save.compress",false)); 
00247               file.addSeparator(); 
00248               menuadd(file,"menu.file.loadjob"); 
00249               file.addSeparator(); 
00250               menuadd(file,"menu.file.loadrun"); 
00251               menuadd(file,"menu.file.editrun"); 
00252               file.addSeparator(); 
00253               menuadd(file,"menu.file.print"); 
00254               if (!Global.getParameter("restricted",false))
00255               {      IsoScale=menuaddcheck(file,"menu.file.print.isoscale"); 
00256                      IsoScale.setState(Global.getParameter("print.isoscale",false)); 
00257               }
00258               file.addSeparator();
00259               PrintScalePreview=menuaddcheck(file,"menu.options.printscalepreview");
00260               PrintScalePreview.setState(false); 
00261               Global.setParameter("printscalepreview",false);
00262               menuadd(file,"menu.file.savepng"); 
00263               menuadd(file,"menu.file.copypng"); 
00264               file.addSeparator(); 
00265               Menu sg=new MyMenu(Zirkel.name("menu.file.savegraphics")); 
00266               menuadd(sg,"menu.file.saveeps"); 
00267               menuadd(sg,"menu.file.savepdf"); 
00268               sg.addSeparator(); 
00269               menuadd(sg,"menu.file.savesvg"); 
00270               menuadd(sg,"menu.file.savefig"); 
00271               file.add(sg);
00272               file.addSeparator(); 
00273               menuadd(file,"menu.options.exportsettings"); 
00274               file.addSeparator(); 
00275               menuadd(file,"menu.file.exit"); 
00276               menu.add(file); 
00277               
00278               // objects menu:
00279               Menu objects=new MyMenu(Zirkel.name("menu.actions","Actions")); 
00280               int i; 
00281               ObjectKeys=new char[ObjectStrings.length]; 
00282               for (i=0; i<ObjectStrings.length; i++)
00283               {      String shortcut=Zirkel.name("shortcuts."+ObjectStrings[i]); 
00284                      ObjectMenuItems[i]=new CheckboxMenuItemAction(this,
00285                             Zirkel.name("objects."+ObjectStrings[i])
00286                             +" ("+shortcut+")",
00287                             ObjectStrings[i]); 
00288                      if (shortcut.length()>0)
00289                             ObjectKeys[i]=shortcut.charAt(0); 
00290               }
00291               int nsub=0; 
00292               Menu sub=new MyMenu(Zirkel.name("menu.actions."+MenuTitles[nsub])); 
00293               for (i=0; i<NEdit; i++)
00294               {      if (Separators[i].startsWith("!"))
00295                      {      objects.add(sub); 
00296                             nsub++; 
00297                             if (nsub>=MenuTitles.length)
00298                             {      while (i<NEdit)
00299                                    {      if (enabled(ObjectStrings[i]))
00300                                           {      objects.add(ObjectMenuItems[i]); 
00301                                           }
00302                                           i++; 
00303                                    }
00304                                    break; 
00305                             }
00306                             sub=new MyMenu(Zirkel.name("menu.actions."+MenuTitles[nsub])); 
00307                      }
00308                      if (enabled(ObjectStrings[i]))
00309                      {      sub.add(ObjectMenuItems[i]); 
00310                      }
00311               }
00312               ObjectMenuItems[CurrentTool].setState(true); 
00313               if (!Global.getParameter("restricted",false) || icon("function"))
00314                      menuadd(objects,"menu.options.function"); 
00315               if (!Global.getParameter("restricted",false) || icon("function"))
00316                      menuadd(objects,"menu.options.userfunction"); 
00317               objects.addSeparator(); 
00318               menuadd(objects,"menu.options.back"); 
00319               objects.add(ObjectMenuItems[NDelete]); 
00320               menuadd(objects,"menu.options.undo"); 
00321               objects.addSeparator(); 
00322               if (!Global.getParameter("restricted",false) || icon("rename"))
00323                      objects.add(ObjectMenuItems[NRename]); 
00324               if (!Global.getParameter("restricted",false) || icon("reorder"))
00325                      objects.add(ObjectMenuItems[NReorder]); 
00326               if (!Global.getParameter("restricted",false) || icon("objecttracker"))
00327                      menuadd(objects,"menu.options.track"); 
00328               menuadd(objects,"menu.options.hideduplicates");
00329               menuadd(objects,"menu.options.editlast"); 
00330               objects.addSeparator(); 
00331               objects.add(ObjectMenuItems[NDraw]); 
00332               menuadd(objects,"menu.options.cleardraw"); 
00333               menu.add(objects); 
00334               
00335               // options menu:
00336               Menu options=new MyMenu(Zirkel.name("menu.options","Options")); 
00337               
00338               Visual=menuaddcheck(options,"menu.options.visual"); 
00339               Visual.setState(Global.getParameter("options.visual",true)); 
00340               if (!enabled("visual")) options.remove(Visual); 
00341               else options.addSeparator(); 
00342               
00343               ShowHidden=menuaddcheck(options,"menu.options.hidden"); 
00344               if (!enabled("hidden")) options.remove(ShowHidden); 
00345               
00346               Menu oshowcolor=new MyMenu(Zirkel.name("menu.options.showcolor")); 
00347               ShowColorMenuItems[0]=
00348                      menuaddcheck(oshowcolor,Zirkel.name("menu.options.all")+" "+
00349                      Zirkel.name("shortcuts.showcolor."+0),
00350                      "scs-"+ColorStrings[0]); 
00351               for (i=1; i<ColorStrings.length; i++)
00352                      ShowColorMenuItems[i]=
00353                      menuaddcheck(oshowcolor,
00354                      Zirkel.name("colors."+ColorStrings[i])+
00355                      " "+Zirkel.name("shortcuts.showcolor."+i),
00356                      "scs-"+ColorStrings[i]); 
00357               options.add(oshowcolor); 
00358               
00359               options.addSeparator();
00360               
00361               menuadd(options,"menu.options.comment"); 
00362               // menuadd(options,"menu.options.constructiondisplay"); 
00363               
00364               options.addSeparator();
00365               Grid=menuaddcheck(options,"menu.options.grid");
00366               LeftSnap=menuaddcheck(options,"menu.options.leftsnap");
00367               LeftSnap.setState(Global.getParameter("grid.leftsnap",false));
00368               menuadd(options,"menu.options.editgrid");
00369               options.addSeparator();
00370               
00371               Menu background=new MyMenu(Zirkel.name("menu.background")); 
00372               menuadd(background,"menu.background.grab"); 
00373               menuadd(background,"menu.background.clear"); 
00374               background.addSeparator();
00375               menuadd(background,"menu.background.load"); 
00376               background.addSeparator();
00377               menuaddcheck(background,"menu.background.usesize")
00378                      .setState(Global.getParameter("background.usesize",false)); 
00379               menuaddcheck(background,"menu.background.usewidth")
00380                      .setState(Global.getParameter("background.usewidth",false)); 
00381               menuaddcheck(background,"menu.background.tile")
00382                      .setState(Global.getParameter("background.tile",true)); 
00383               menuaddcheck(background,"menu.background.center")
00384                      .setState(Global.getParameter("background.center",true)); 
00385               options.add(background); 
00386               
00387               Menu zoom=new MyMenu(Zirkel.name("menu.zoom")); 
00388               zoom.add(ObjectMenuItems[NZoom]); 
00389               menuadd(zoom,"menu.zoom.in"); 
00390               menuadd(zoom,"menu.zoom.out"); 
00391               menuadd(zoom,"menu.zoom.left"); 
00392               menuadd(zoom,"menu.zoom.right"); 
00393               menuadd(zoom,"menu.zoom.up"); 
00394               menuadd(zoom,"menu.zoom.down"); 
00395               options.add(zoom); 
00396               
00397               options.addSeparator(); 
00398               
00399               Menu ocolor=new MyMenu(Zirkel.name("menu.options.defaultcolor")); 
00400               for (i=0; i<ColorStrings.length; i++)
00401               {      String shortcut=Zirkel.name("shortcuts.color."+i); 
00402                      if (!shortcut.equals(""+i))
00403                             ColorMenuItems[i]=
00404                             menuaddcheck(ocolor,
00405                             Zirkel.name("colors."+ColorStrings[i])+" "+shortcut,
00406                             "cs-"+ColorStrings[i]); 
00407                      else
00408                             ColorMenuItems[i]=
00409                             menuaddcheck(ocolor,
00410                             Zirkel.name("colors."+ColorStrings[i]),
00411                             "cs-"+ColorStrings[i]); 
00412               }
00413               options.add(ocolor); 
00414               Menu otype=new MyMenu(Zirkel.name("menu.options.defaulttype")); 
00415               for (i=0; i<PointTypes.length; i++)
00416                      PointMenuItems[i]=
00417                      menuaddcheck(otype,
00418                      Zirkel.name("point.type."+PointTypes[i])+
00419                      " "+Zirkel.name("shortcuts.pointtype."+i),
00420                      "pt-"+PointTypes[i]); 
00421               options.add(otype); 
00422               Menu othickness=new MyMenu(Zirkel.name("menu.options.defaultthickness")); 
00423               for (i=0; i<ColorTypes.length; i++)
00424                      ColorTypeMenuItems[i]=
00425                      menuaddcheck(othickness,
00426                      Zirkel.name("color.type."+ColorTypes[i])+
00427                      " "+Zirkel.name("shortcuts.thickness."+i),
00428                      "ct-"+ColorTypes[i]); 
00429               options.add(othickness); 
00430               
00431               Menu other=new MyMenu(Zirkel.name("menu.options.other")); 
00432               Restricted=menuaddcheck(other,"menu.options.restricted"); 
00433               Partial=menuaddcheck(other,"menu.options.partial"); 
00434               PartialLines=menuaddcheck(other,"menu.options.plines"); 
00435               Vectors=menuaddcheck(other,"menu.options.arrow"); 
00436               ShowNames=menuaddcheck(other,"menu.options.shownames"); 
00437               ShowValues=menuaddcheck(other,"menu.options.showvalues"); 
00438               LargeFont=menuaddcheck(other,"menu.options.largefont"); 
00439               BoldFont=menuaddcheck(other,"menu.options.boldfont"); 
00440               LongNames=menuaddcheck(other,"menu.options.longnames"); 
00441               Obtuse=menuaddcheck(other,"menu.options.obtuse"); 
00442               Solid=menuaddcheck(other,"menu.options.solid"); 
00443               options.add(other); 
00444               
00445               if (!Global.getParameter("restricted",false))
00446                      menu.add(options); 
00447               
00448               // settings menu
00449               Menu settings=new MyMenu(Zirkel.name("menu.moresettings"));
00450               
00451               RestrictIcons=new CheckboxMenuItemAction(this,
00452                             Zirkel.name("menu.special.restricticons"),
00453                             "menu.special.restricticons"); 
00454               
00455               ConstructionDisplay=menuaddcheck(settings,"menu.settings.constructiondisplay");
00456               ConstructionDisplay.setState(Global.getParameter("options.showdisplay",true));
00457               settings.addSeparator();
00458 
00459               if (!Global.getParameter("restricted",false))
00460               {      settings.add(RestrictIcons);
00461                      menuadd(settings,"menu.options.editicons"); 
00462                      
00463                      settings.addSeparator();
00464 
00465                      menuadd(settings,"menu.options.sizes");
00466                      
00467                      settings.addSeparator();
00468                      
00469                      FontBold=menuaddcheck(settings,"menu.settings.font.bold"); 
00470                      FontBold.setState(Global.getParameter("font.bold",false)); 
00471                      FontLarge=menuaddcheck(settings,"menu.settings.font.large"); 
00472                      FontLarge.setState(Global.getParameter("font.large",false)); 
00473                      
00474                      settings.addSeparator();
00475                       
00476                      menuadd(settings,"menu.options.setdigits"); 
00477                      
00478                      settings.addSeparator();
00479                       
00480                      Menu colors=new MyMenu(Zirkel.name("menu.colors")); 
00481                      menuadd(colors,"colors.default"); 
00482                      menuadd(colors,"colors.color0"); 
00483                      menuadd(colors,"colors.color1"); 
00484                      menuadd(colors,"colors.color2"); 
00485                      menuadd(colors,"colors.color3"); 
00486                      menuadd(colors,"colors.color4"); 
00487                      menuadd(colors,"colors.color5"); 
00488                      menuadd(colors,"colors.select"); 
00489                      menuadd(colors,"colors.target"); 
00490                      menuadd(colors,"colors.background");
00491                      settings.add(colors); 
00492               
00493                      settings.addSeparator();
00494                       
00495                      menuadd(settings,"menu.settings");
00496                      
00497               }
00498 
00499               if (!Locale.getDefault().toString().startsWith("en"))
00500                      settings.add(new MenuItemAction(this,Zirkel.name("menu.settings.language")+" (Set Language)",
00501                             "menu.settings.language"));
00502               else menuadd(settings,"menu.settings.language");
00503               settings.addSeparator(); 
00504               
00505               RestrictedMode=menuaddcheck(settings,"menu.settings.restricted"); 
00506               RestrictedMode.setState(Global.getParameter("restricted",false)); 
00507               Beginner=menuaddcheck(settings,"menu.settings.beginner"); 
00508               Beginner.setState(Global.getParameter("beginner",false)); 
00509               
00510               menu.add(settings);
00511               
00512               
00513               // macro menu
00514               Menu macros=new MyMenu(Zirkel.name("menu.macros")); 
00515               macros.add(ObjectMenuItems[NParameters]); 
00516               macros.add(ObjectMenuItems[NTargets]); 
00517               menuadd(macros,"menu.special.definemacro"); 
00518               macros.add(ObjectMenuItems[NMacro]); 
00519               macros.addSeparator(); 
00520               menuadd(macros,"menu.special.loadmacros"); 
00521               menuadd(macros,"menu.special.savemacros"); 
00522               macros.addSeparator(); 
00523               menuadd(macros,"menu.special.renamemacro"); 
00524               menuadd(macros,"menu.special.deletemacros"); 
00525               macros.addSeparator(); 
00526               MacroBar=menuaddcheck(macros,"menu.special.macrobar"); 
00527               MacroBar.setState(Global.getParameter("macrobar",true));
00528               DefaultMacrosInBar=menuaddcheck(macros,"menu.special.defaultmacrosinbar"); 
00529               DefaultMacrosInBar.setState(Global.getParameter("defaultmacrosinbar",true));
00530               if (!Global.getParameter("restricted",false)) menu.add(macros);              
00531               
00532               // special menu:
00533               Menu special=new MyMenu(Zirkel.name("menu.special")); 
00534               special.add(ObjectMenuItems[NDefineJob]); 
00535               menuadd(special,"menu.special.jobcomment"); 
00536               TestJob=menuaddcheck(special,"menu.special.testjob"); 
00537               menuadd(special,"menu.file.savejob"); 
00538               special.addSeparator(); 
00539               menuadd(special,"menu.special.export"); 
00540               menuadd(special,"menu.special.exporttemplate"); 
00541               special.addSeparator(); 
00542               menuadd(special,"menu.special.replay"); 
00543               if (!Global.getParameter("restricted",false)) menu.add(special); 
00544               Menu bp=new MyMenu(Zirkel.name("menu.special.break"));
00545               menuadd(bp,"menu.bp.setbreak");
00546               menuadd(bp,"menu.bp.sethidingbreak");
00547               menuadd(bp,"menu.bp.clearbreak");
00548               bp.addSeparator();
00549               menuadd(bp,"menu.bp.animatebreak");
00550               special.add(bp);
00551               
00552               // help menu:
00553               Menu help=new MyMenu(Zirkel.name("menu.help")); 
00554               menuadd(help,"menu.help.about"); 
00555               menuadd(help,"menu.help.info"); 
00556               help.addSeparator(); 
00557               menuadd(help,"menu.help.browser"); 
00558               menuadd(help,"menu.help.configure"); 
00559               help.addSeparator(); 
00560               menuadd(help,"menu.file.loadexamples"); 
00561               help.addSeparator(); 
00562               if (haveHelp("gui.txt"))
00563               {      Menu texthelp=new MyMenu(Zirkel.name("menu.help.text")); 
00564                      menuadd(texthelp,"menu.help.help"); 
00565                      menuadd(texthelp,"menu.help.gui"); 
00566                      menuadd(texthelp,"menu.help.tools"); 
00567                      menuadd(texthelp,"menu.help.macros"); 
00568                      menuadd(texthelp,"menu.help.interactive"); 
00569                      menuadd(texthelp,"menu.help.tips"); 
00570                      help.add(texthelp); 
00571               }
00572               menuadd(help,"menu.help.welcome"); 
00573               menu.add(help); 
00574               
00575               // the canvas
00576               ZC=new ZirkelCanvas(); 
00577               if (Global.Background!=null) ZC.setBackground(Global.Background); 
00578               ZC.setBackground(Global.getParameter("colorbackground",ZC.getBackground())); 
00579               ZC.addMouseListener(ZC); 
00580               ZC.addMouseMotionListener(ZC); 
00581               ZC.setZirkelCanvasListener(this); 
00582               setLayout(new BorderLayout()); 
00583               
00584               Center=makeCenterPanel(); 
00585               
00586               ZC.setTool(ObjectConstructors[CurrentTool]); 
00587               ZC.addKeyListener(this); 
00588               ZC.setFrame(this); 
00589               
00590               // the Status line
00591               Status=new MyLabel(""); 
00592               add("South",StatusPanel=new Panel3D(Status)); 
00593               ZC.addStatusListener(this); 
00594               ZC.showStatus(); 
00595               
00596               Input=new HistoryTextField(this,"Input"); 
00597               InputPanel=new Panel3D(Input); 
00598               ZC.setTextField(Input); 
00599               
00600               // Icon Bar at North
00601               makeIconBar(); 
00602               Panel north=new MyPanel(); 
00603               north.setLayout(new GridLayout(0,1)); 
00604               north.add(IA); 
00605               if (IB!=IA) north.add(IB);
00606               if (IM!=null) north.add(IM);
00607               North=new Panel3D(north); 
00608               
00609               // add the center panel, depending on the north or south icon bar
00610               makeMainPanel(); 
00611               add("Center",MainPanel); 
00612               
00613               // Icon
00614               seticon("rene/zirkel/icon.png"); 
00615               
00616               // init various things
00617               initLightColors(); 
00618               initFileDialogs(); 
00619               
00620               // initialize choices
00621               settool(0); 
00622               setcolor(Global.getParameter("options.color",0)); 
00623               settype(Global.getParameter("options.type",2)); 
00624               setcolortype(Global.getParameter("options.colortype",0)); 
00625               showcolor(0); 
00626               sethidden(false);
00627               
00628               setRestricted(Global.getParameter("options.restricted",true));
00629               setPartial(Global.getParameter("options.partial",false)); 
00630               setPartialLines(Global.getParameter("options.plines",false)); 
00631               setVectors(Global.getParameter("options.arrow",false)); 
00632               setShowNames(Global.getParameter("options.shownames",false)); 
00633               setShowValues(Global.getParameter("options.showvalues",false)); 
00634               setLongNames(Global.getParameter("options.longnames",false)); 
00635               setLargeFont(Global.getParameter("options.largefont",false)); 
00636               setBoldFont(Global.getParameter("options.boldfont",false)); 
00637               setObtuse(Global.getParameter("options.obtuse",false)); 
00638               setSolid(Global.getParameter("options.solid",false)); 
00639               
00640               if (Global.Background!=null) setBackground(Global.Background); 
00641               
00642               // show:
00643               pack();
00644               setLocation(100,40); 
00645               setPosition("zirkelframe"); 
00646               
00647               loadDefaultMacros();
00648               updateMacroBar();
00649               
00650               Init=true; 
00651               setVisible(true); 
00652               clearsettings();
00653 
00654        }
00655        
00656        final static public String DefaultIcons=
00657               " new load save back undo delete color type thickness"+
00658               " hidden showcolor macro grid comment replay"+
00659               " point line segment ray circle fixedcircle"+
00660               " parallel plumb circle3 midpoint angle fixedangle"+
00661               " move tracker objecttracker hide expression area text quadric"+
00662               " runmacro edit animate "+
00663               " info zoom draw function rename "; 
00664        final static public String DefaultRestrictedIcons=
00665               " back undo color"+
00666               " hidden showcolor macro grid comment"+
00667               " point line segment ray circle"+
00668               " parallel plumb circle3 midpoint angle fixedangle"+
00669               " move tracker objecttracker hide area text quadric"+
00670               " runmacro zoom info "+
00671               " "; 
00672        
00677        public void makeIconBar ()
00678        {      String icons=Global.getParameter("icons",DefaultIcons); 
00679               if (RestrictIcons.getState())
00680                      Global.setParameter("icons",
00681                             Global.getParameter("restrictedicons",DefaultRestrictedIcons));
00682               else
00683                      Global.setParameter("icons",icons); 
00684               if (RestrictIcons.getState()?
00685                      Global.getParameter("icons",DefaultIcons).indexOf("twolines")>=0:
00686                      Global.getParameter("options.fullicons",true))
00687               {      IA=new IconBar(this,false); 
00688                      IA.addKeyListener(this); 
00689                      if (icon("new")) IA.addLeft("new"); 
00690                      if (icon("load")) IA.addLeft("load"); 
00691                      if (icon("save")) IA.addLeft("save"); 
00692                      IA.addSeparatorLeft(); 
00693                      if (icon("back")) IA.addLeft("back"); 
00694                      if (icon("delete")) IA.addToggleLeft("delete"); 
00695                      if (icon("undo")) IA.addLeft("undo"); 
00696                      IA.addSeparatorLeft(); 
00697                      if (icon("edit")) IA.addToggleLeft("edit"); 
00698                      if (icon("draw")) IA.addToggleLeft("draw"); 
00699                      if (icon("rename")) IA.addToggleLeft("rename");
00700                      if (icon("macro")) IA.addMultipleToggleIconLeft("macro",3); 
00701                      IA.addSeparatorLeft(); 
00702                      if (icon("comment")) IA.addLeft("comment"); 
00703                      if (icon("function")) IA.addLeft("function");
00704                      if (icon("replay")) IA.addLeft("replay"); 
00705                      if (icon("animatebreak")) IA.addToggleLeft("animatebreak"); 
00706                      IA.addSeparatorLeft(); 
00707                      if (icon("color")) IA.addMultipleIconLeft("color",6); 
00708                      if (icon("type")) IA.addMultipleIconLeft("type",6); 
00709                      if (icon("thickness")) IA.addMultipleIconLeft("thickness",3); 
00710                      if (icon("partial")) IA.addOnOffLeft("partial"); 
00711                      if (icon("plines")) IA.addOnOffLeft("plines"); 
00712                      if (icon("arrow")) IA.addOnOffLeft("arrow"); 
00713                      IA.addSeparatorLeft(); 
00714                      if (icon("showname")) IA.addOnOffLeft("showname"); 
00715                      if (icon("longnames")) IA.addOnOffLeft("longnames"); 
00716                      if (icon("large")) IA.addOnOffLeft("large"); 
00717                      if (icon("bold")) IA.addOnOffLeft("bold"); 
00718                      if (icon("showvalue")) IA.addOnOffLeft("showvalue"); 
00719                      if (icon("obtuse")) IA.addOnOffLeft("obtuse"); 
00720                      if (icon("solid")) IA.addOnOffLeft("solid"); 
00721                      IA.addSeparatorLeft(); 
00722                      if (icon("zoom")) IA.addToggleLeft("zoom"); 
00723                      if (icon("grid")) IA.addOnOffLeft("grid"); 
00724                      if (icon("grab")) IA.addOnOffLeft("grab"); 
00725                      IA.addSeparatorLeft(); 
00726                      if (icon("hidden")) IA.addOnOffLeft("hidden"); 
00727                      if (icon("showcolor")) IA.addMultipleIconLeft("showcolor",Colors.length); 
00728                      if (icon("visual")) IA.addOnOffLeft("visual");
00729                      IA.addSeparatorLeft(); 
00730                      if (icon("info")) IA.addLeft("info"); 
00731                      IA.setIconBarListener(this); 
00732                      IB=new IconBar(this,false); 
00733                      IB.addKeyListener(this); 
00734                      IB.setIconBarListener(this); 
00735                      int n=0; 
00736                      for (int i=0; i<IconNumber; i++)
00737                      {      if (Separators[i].startsWith("!")) n++; 
00738                             if (icon(ObjectStrings[i])) n++; 
00739                      }
00740                      String a[]=new String[n]; 
00741                      for (int i=0,k=0; i<IconNumber; i++)
00742                      {      if (Separators[i].startsWith("!"))
00743                             a[k++]=""; 
00744                             if (icon(ObjectStrings[i]))
00745                                    a[k++]=ObjectStrings[i]; 
00746                      }
00747                      IB.addToggleGroupLeft(a); 
00748               }
00749               else
00750               {      IB=new IconBar(this,false); 
00751                      IB.addKeyListener(this); 
00752                      IB.setIconBarListener(this); 
00753                      int n=0; 
00754                      for (int i=0; i<IconNumber; i++)
00755                      {      if (Separators[i].startsWith("!")) n++; 
00756                             if (icon(ObjectStrings[i])) n++; 
00757                      }
00758                      String a[]=new String[n]; 
00759                      for (int i=0,k=0; i<IconNumber; i++)
00760                      {      if (Separators[i].startsWith("!"))
00761                             a[k++]=""; 
00762                             if (icon(ObjectStrings[i]))
00763                                    a[k++]=ObjectStrings[i]; 
00764                      }
00765                      IB.addToggleGroupLeft(a); 
00766 
00767                      IA=IB; 
00768                      if (icon("back")) IB.addRight("back"); 
00769                      if (icon("delete")) IA.addToggleLeft("delete"); 
00770                      if (icon("undo")) IA.addLeft("undo");
00771                      IA.addSeparatorLeft(); 
00772                      if (icon("macro")) IB.addMultipleToggleIconRight("macro",3); 
00773                      if (icon("replay")) IB.addRight("replay"); 
00774                      if (icon("edit")) IA.addToggleLeft("edit"); 
00775                      if (icon("zoom")) IA.addToggleLeft("zoom"); 
00776                      if (icon("draw")) IA.addToggleLeft("draw"); 
00777                      if (icon("rename")) IA.addToggleLeft("rename");
00778                      IA.addSeparatorLeft(); 
00779                      if (icon("color")) IA.addMultipleIconLeft("color",6); 
00780                      if (icon("type")) IA.addMultipleIconLeft("type",6); 
00781                      if (icon("thickness")) IA.addMultipleIconLeft("thickness",3); 
00782                      if (icon("partial")) IA.addOnOffLeft("partial"); 
00783                      if (icon("plines")) IA.addOnOffLeft("plines"); 
00784                      if (icon("arrow")) IA.addOnOffLeft("arrow"); 
00785                      if (icon("showname")) IA.addOnOffLeft("showname"); 
00786                      if (icon("showvalue")) IA.addOnOffLeft("showvalue"); 
00787                      if (icon("longnames")) IA.addOnOffLeft("longnames"); 
00788                      if (icon("large")) IA.addOnOffLeft("large"); 
00789                      if (icon("bold")) IA.addOnOffLeft("bold"); 
00790                      if (icon("obtuse")) IA.addOnOffLeft("obtuse"); 
00791                      if (icon("solid")) IA.addOnOffLeft("solid"); 
00792 
00793                      if (icon("showcolor")) IB.addMultipleIconLeft("showcolor",Colors.length); 
00794                      if (icon("hidden")) IB.addOnOffRight("hidden"); 
00795                      if (icon("grid")) IB.addOnOffRight("grid"); 
00796                      if (icon("info")) IB.addRight("info"); 
00797               }
00798               makeMacroBar();
00799               Global.setParameter("icons",icons); 
00800        }
00801        
00802        public void makeMacroBar ()
00803        {      if (Global.getParameter("macrobar",true))
00804               {      IM=new MacroBar(this);
00805                      IM.addKeyListener(this); 
00806                      IM.setIconBarListener(this);
00807                      ZC.setMacroBar(IM);
00808               }
00809               else
00810               {      if (IM!=null)
00811                      {      IM.removeIconBarListener(this);
00812                      }
00813                      IM=null;
00814                      ZC.setMacroBar(IM);
00815               }
00816        }
00817        
00818        public void updateMacroBar ()
00819        {      ZC.updateMacroBar();
00820        }
00821        
00822        public void remakeIconBar ()
00823        {      IA.removeIconBarListener(this); 
00824               IB.removeIconBarListener(this); 
00825               remove(MainPanel); 
00826               makeIconBar();
00827               makeMacroBar();
00828               updateMacroBar();
00829               Panel north=new MyPanel(); 
00830               north.setLayout(new GridLayout(0,1)); 
00831               north.add(IA); 
00832               if (IA!=IB) north.add(IB);
00833               if (IM!=null) north.add(IM);
00834               North=new Panel3D(north); 
00835               makeMainPanel(); 
00836               add("Center",MainPanel); 
00837               validate(); 
00838               doLayout(); 
00839               clearsettings(); 
00840               repaint(); 
00841        }
00842        
00843        public boolean icon (String s)
00844        {      return Global.getParameter("icons","none").indexOf(" "+s+" ")>=0; 
00845        }
00846        
00847        public boolean enabled (String s)
00848        {      return !Global.getParameter("restricted",false) || icon(s); 
00849        }
00850        
00851        public void initFileDialogs ()
00852        {      if (Global.getParameter("options.filedialog",true))
00853               {      FileLoad=new MyFileDialog(this,
00854                             Zirkel.name("filedialog.open"),
00855                             Zirkel.name("filedialog.open.action"),
00856                             false,true); 
00857                      FileLoad.setDispose(false); 
00858                      FileLoad.setPattern("*.zir *.job *.zirz *.jobz"); 
00859                      FileLoad.loadHistories("file","","");
00860                      FileSave=new MyFileDialog(this,
00861                             Zirkel.name("filedialog.saveas"),
00862                             Zirkel.name("filedialog.saveas.action"),
00863                             true,true); 
00864                      FileSave.setPattern("*.zir *.job *.zirz *.jobz"); 
00865                      FileSave.setDispose(false); 
00866                      FileSave.loadHistories("file","","");
00867                      PicSave=new MyFileDialog(this,
00868                             Zirkel.name("filedialog.saveas"),
00869                             Zirkel.name("filedialog.saveas.action"),
00870                             true,true); 
00871                      PicSave.setPattern("*.zir *.job *.zirz *.jobz"); 
00872                      PicSave.setDispose(false); 
00873                      PicSave.loadHistories("image","","jpg");
00874                      HTMLSave=new MyFileDialog(this,
00875                             Zirkel.name("filedialog.htmlsave"),
00876                             Zirkel.name("filedialog.htmlsave.action"),
00877                             true,true); 
00878                      HTMLSave.setPattern("*.html *.htm"); 
00879                      HTMLSave.setDispose(false); 
00880                      HTMLSave.loadHistories("html","","html");
00881                      BackgroundLoad=new MyFileDialog(this,
00882                             Zirkel.name("filedialog.backgroundload"),
00883                             Zirkel.name("filedialog.backgroundload.action"),
00884                             false,true); 
00885                      BackgroundLoad.setPattern("*.gif *.jpg *.png"); 
00886                      BackgroundLoad.setDispose(false); 
00887                      BackgroundLoad.loadHistories("image","","jgp");
00888                      ImageLoad=new MyFileDialog(this,
00889                                    Zirkel.name("filedialog.imageload"),
00890                                    Zirkel.name("filedialog.imageload.action"),
00891                                    false,true); 
00892                      ImageLoad.setPattern("*.gif *.jpg *.png"); 
00893                      ImageLoad.setDispose(false); 
00894                      ImageLoad.loadHistories("image","","jgp");
00895                      TemplateLoad=new MyFileDialog(this,
00896                             Zirkel.name("templateload.open"),
00897                             Zirkel.name("templateload.open.action"),
00898                             false,true); 
00899                      TemplateLoad.setPattern("*.template"); 
00900                      TemplateLoad.setDispose(false); 
00901                      TemplateLoad.loadHistories("template","","template");
00902               }
00903               else
00904               {      FileLoad=new MyFileDialog(this,
00905                             Zirkel.name("filedialog.open"),
00906                             false); 
00907                      FileLoad.setPattern("*.zir *.job *.zirz *.jobz"); 
00908                      FileSave=new MyFileDialog(this,
00909                             Zirkel.name("filedialog.saveas"),
00910                             true); 
00911                      FileSave.setPattern("*.zir *.job *.zirz *.jobz"); 
00912                      PicSave=new MyFileDialog(this,
00913                             Zirkel.name("filedialog.saveas"),
00914                             true); 
00915                      PicSave.setPattern("*"); 
00916                      HTMLSave=new MyFileDialog(this,
00917                             Zirkel.name("filedialog.htmlsave"),
00918                             true); 
00919                      HTMLSave.setPattern("*.html *.htm"); 
00920                      BackgroundLoad=new MyFileDialog(this,
00921                             Zirkel.name("filedialog.backgroundload"),
00922                             false); 
00923                      BackgroundLoad.setPattern("*.gif *.jpg"); 
00924                      ImageLoad=new MyFileDialog(this,
00925                                    Zirkel.name("filedialog.imageload"),
00926                                    false); 
00927                             ImageLoad.setPattern("*.gif *.jpg"); 
00928                      TemplateLoad=new MyFileDialog(this,
00929                             Zirkel.name("templateload.open"),
00930                             false); 
00931                      TemplateLoad.setPattern("*.template"); 
00932               }
00933        }
00934        
00935        public static void initLightColors (Color back)
00936        {      int n=DefaultColors.length; 
00937               Colors=new Color[DefaultColors.length]; 
00938               for (int i=0; i<n; i++)
00939               {      if (Global.haveParameter("color"+i))
00940                      {      Colors[i]=Global.getParameter("color"+i,Color.black); 
00941                      }
00942                      else Colors[i]=DefaultColors[i]; 
00943               }
00944               LightColors=new Color[n]; 
00945               BrighterLightColors=new Color[n]; 
00946               BrighterColors=new Color[n]; 
00947               if (back==null) back=Color.gray.brighter(); 
00948               int red=back.getRed(),green=back.getGreen(),blue=back.getBlue(); 
00949               double lambda=0.4; 
00950               for (int i=0; i<n; i++)
00951               {      int r=(int)(red*(1-lambda)+Colors[i].getRed()*lambda); 
00952                      int g=(int)(green*(1-lambda)+Colors[i].getGreen()*lambda); 
00953                      int b=(int)(blue*(1-lambda)+Colors[i].getBlue()*lambda); 
00954                      LightColors[i]=new Color(r,g,b); 
00955                      if (i==0) BrighterColors[i]=Color.gray; 
00956                      else BrighterColors[i]=Colors[i].brighter(); 
00957                      BrighterLightColors[i]=LightColors[i].brighter(); 
00958               }
00959        }
00960        
00961        public void initLightColors ()
00962        {      initLightColors(Color.white); 
00963        }
00964        
00965        public CheckboxMenuItem menuaddcheck (Menu m, String o, String s)
00966               // adds a menu item to the Menu m
00967        {      CheckboxMenuItem item=new CheckboxMenuItemAction(this,o,s); 
00968               m.add(item); 
00969               return item; 
00970        }
00971        public CheckboxMenuItem menuaddcheck (Menu m, String o)
00972        {      return menuaddcheck(m,Zirkel.name(o),o); 
00973        }
00974        
00975        public MenuItem menuadd (Menu m, String o)
00976               // adds a menu item to the Menu m
00977        {      MenuItem item=new MenuItemAction(this,Zirkel.name(o),o); 
00978               m.add(item); 
00979               return item; 
00980        }
00981        
00982        public void doAction (String s)
00983               // interpret menu items
00984        {      if (!Init) return;
00985               ZC.pause(true); 
00986               if (s.equals("menu.file.exit"))
00987               {      setinfo("save"); 
00988                      doclose(); 
00989               }
00990               else if (s.equals("menu.file.save"))
00991               {      setinfo("save"); 
00992                      save(); 
00993               }
00994               else if (s.equals("menu.file.clearmacros"))
00995               {      setinfo("macro"); 
00996                      clearNonprotectedMacros(); 
00997               }
00998               else if (s.equals("menu.file.saveas"))
00999               {      setinfo("save"); 
01000                      saveas(); 
01001               }
01002               else if (s.equals("menu.file.load"))
01003               {      setinfo("save"); 
01004                      load(); 
01005               }
01006               else if (s.equals("menu.file.loadexamples"))
01007               {      setinfo("save"); 
01008                      loadExamples(); 
01009               }
01010               else if (s.equals("menu.file.loadrun"))
01011               {      setinfo("run"); 
01012                      loadRun(); 
01013               }
01014               else if (s.equals("menu.file.editrun"))
01015               {      setinfo("run"); 
01016                      editRun(OldRun); 
01017               }
01018               else if (s.equals("menu.file.print"))
01019               {      setinfo("print"); 
01020                      print(); 
01021               }
01022               else if (s.equals("menu.file.savepng"))
01023               {      setinfo("print"); 
01024                      savePNG(); 
01025               }
01026               else if (s.equals("menu.file.copypng"))
01027               {      setinfo("print"); 
01028                      copyPNG(); 
01029               }
01030               else if (s.equals("menu.file.savefig"))
01031               {      setinfo("print"); 
01032                      saveFIG(); 
01033               }
01034               else if (s.equals("menu.file.savesvg"))
01035               {      setinfo("print"); 
01036                      saveSVG(); 
01037               }
01038               else if (s.equals("menu.file.savepdf"))
01039               {      setinfo("print"); 
01040                      savePDF(); 
01041               }
01042               else if (s.equals("menu.file.saveeps"))
01043               {      setinfo("print"); 
01044                      saveEPS(); 
01045               }
01046               else if (s.equals("menu.special.loadmacros"))
01047               {      setinfo("macro"); 
01048                      loadMacros(); 
01049               }
01050               else if (s.equals("menu.special.savemacros"))
01051               {      setinfo("macro"); 
01052                      saveMacros(); 
01053               }
01054               else if (s.equals("menu.special.deletemacros"))
01055               {      setinfo("macro"); 
01056                      deleteMacros(); 
01057               }
01058               else if (s.equals("menu.special.renamemacro"))
01059               {      setinfo("macro"); 
01060                      renameMacro(); 
01061               }
01062               else if (s.equals("menu.file.loadjob"))
01063               {      setinfo("assignment"); 
01064                      loadJob(); 
01065               }
01066               else if (s.equals("menu.file.savejob"))
01067               {      setinfo("assignment"); 
01068                      saveJob(); 
01069               }
01070               else if (s.equals("menu.file.new"))
01071               {      setinfo("start"); 
01072                      newfile(false);
01073               }
01074               else if (s.equals("menu.options.back"))
01075               {      setinfo("delete"); 
01076                      ZC.back(); 
01077                      ZC.repaint(); 
01078               }
01079               else if (s.equals("menu.options.undo"))
01080               {      setinfo("undo"); 
01081                      ZC.undo(); 
01082                      ZC.repaint(); 
01083               }
01084               else if (s.equals("menu.options.track"))
01085               {      setinfo("tracker"); 
01086                      track(); 
01087               }
01088               else if (s.equals("menu.options.hideduplicates"))
01089               {      setinfo("hide"); 
01090                      ZC.hideDuplicates();
01091                      ZC.repaint();
01092               }
01093               else if (s.equals("menu.options.comment"))
01094               {      setinfo("comment"); 
01095                      showcomment(); 
01096               }
01097               else if (s.equals("menu.special.jobcomment"))
01098               {      setinfo("comment"); 
01099                      showjobcomment(); 
01100               }
01101               else if (s.equals("menu.special.definemacro"))
01102               {      setinfo("macro"); 
01103                      definemacro(); 
01104               }
01105               else if (s.equals("menu.special.replay"))
01106               {      setinfo("replay"); 
01107                      replay(); 
01108               }
01109               else if (s.equals("menu.options.constructiondisplay"))
01110               {      setinfo("construction"); 
01111                      showconstruction(); 
01112               }
01113               else if (s.equals("menu.options.setdigits"))
01114               {      setinfo("defaults"); 
01115                      setDigits(); 
01116               }
01117               else if (s.equals("menu.settings.language"))
01118               {      setinfo("language"); 
01119                      setLanguage(); 
01120               }
01121               else if (s.equals("menu.options.editicons"))
01122               {      setinfo("iconbar"); 
01123                      editIcons(); 
01124               }
01125               else if (s.equals("menu.options.function"))
01126               {      setinfo("function");
01127                      ZC.createCurve();
01128               }
01129               else if (s.equals("menu.options.userfunction"))
01130               {      setinfo("function");
01131                      ZC.createFunction();
01132               }
01133               else if (s.equals("menu.options.editlast"))
01134               {      setinfo("edit");
01135                      ZC.editLast();
01136               }
01137               else if (s.equals("menu.settings"))
01138               {      setinfo("settings"); 
01139                      boolean iconbartop=Global.getParameter("options.iconbartop",true); 
01140                      boolean filedialog=Global.getParameter("options.filedialog",true); 
01141                      new SettingsDialog(this); 
01142                      if (Global.getParameter("options.iconbartop",true)!=iconbartop)
01143                             itemAction("menu.settings.iconbartop",
01144                             Global.getParameter("options.iconbartop",true)); 
01145                      if (Global.getParameter("options.filedialog",true)!=filedialog)
01146                             initFileDialogs();
01147                      ZC.newImage();
01148               }
01149               else if (s.equals("menu.options.exportsettings"))
01150               {      setinfo("exportsettings"); 
01151                      new ExportSettingsDialog(this); 
01152                      ZC.newImage();
01153               }
01154               else if (s.equals("menu.help.browser"))
01155               {      setinfo("browser"); 
01156                      browser(); 
01157               }
01158               else if (s.equals("menu.help.info"))
01159               {      info();
01160                      ZC.pause(false);
01161                      return; 
01162               }
01163               else if (s.equals("menu.help.configure"))
01164               {      setinfo("browser"); 
01165                      configure(); 
01166               }
01167               else if (s.equals("menu.help.help"))
01168               {      setinfo("start"); 
01169                      new Help("schoolgeometry.txt"); 
01170                      ZC.pause(false);
01171                      return; 
01172               }
01173               else if (s.equals("menu.help.gui"))
01174               {      setinfo("start"); 
01175                      new Help("gui.txt"); 
01176                      ZC.pause(false);
01177                      return; 
01178               }
01179               else if (s.equals("menu.help.macros"))
01180               {      setinfo("start"); 
01181                      new Help("macros.txt"); 
01182                      ZC.pause(false);
01183                      return; 
01184               }
01185               else if (s.equals("menu.help.tools"))
01186               {      setinfo("start"); 
01187                      new Help("tools.txt"); 
01188                      ZC.pause(false);
01189                      return; 
01190               }
01191               else if (s.equals("menu.help.tips"))
01192               {      setinfo("start"); 
01193                      new Help("tips.txt"); 
01194                      ZC.pause(false);
01195                      return; 
01196               }
01197               else if (s.equals("menu.help.interactive"))
01198               {      setinfo("start"); 
01199                      new Help("interactiv.txt"); 
01200                      ZC.pause(false);
01201                      return; 
01202               }
01203               else if (s.equals("menu.help.about"))
01204               {      setinfo("start"); 
01205                      new AboutDialog(this); 
01206               }
01207               else if (s.equals("menu.help.welcome"))
01208               {      setinfo("start"); 
01209                      new Help("version.txt"); 
01210                      ZC.pause(false);
01211                      return; 
01212               }
01213               else if (s.equals("menu.special.export"))
01214               {      setinfo("htmlexport"); 
01215                      exportHTML(); 
01216               }
01217               else if (s.equals("menu.special.exporttemplate"))
01218               {      setinfo("htmlexporttemplate"); 
01219                      exportTemplateHTML(); 
01220               }
01221               else if (s.equals("menu.zoom.in"))
01222               {      setinfo("zoomer"); 
01223                      ZC.magnify(1/Math.sqrt(Math.sqrt(2))); 
01224               }
01225               else if (s.equals("menu.zoom.out"))
01226               {      setinfo("zoomer"); 
01227                      ZC.magnify(Math.sqrt(Math.sqrt(2))); 
01228               }
01229               else if (s.equals("menu.zoom.left"))
01230               {      setinfo("zoomer"); 
01231                      ZC.shift(-0.1,0); 
01232               }
01233               else if (s.equals("menu.zoom.right"))
01234               {      setinfo("zoomer"); 
01235                      ZC.shift(0.1,0); 
01236               }
01237               else if (s.equals("menu.zoom.up"))
01238               {      setinfo("zoomer"); 
01239                      ZC.shift(0,0.1); 
01240               }
01241               else if (s.equals("menu.zoom.down"))
01242               {      setinfo("zoomer"); 
01243                      ZC.shift(0,-0.1); 
01244               }
01245               else if (s.equals("Input"))
01246               {      try
01247                      {      ZC.getConstruction().interpret(ZC,Input.getText()); 
01248                             ZC.validate(); 
01249                             ZC.getConstruction().updateCircleDep(); 
01250                             ZC.repaint(); 
01251                             Input.remember(); 
01252                             Input.setText(""); 
01253                             loadsettings(); 
01254                             Input.requestFocus();
01255                             ZC.pause(false);
01256                             return;
01257                      }
01258                      catch (ConstructionException e)
01259                      {      warning(e.getDescription()); 
01260                      }
01261               }
01262               else if (s.equals("colors.default"))
01263               {      setinfo("colors"); 
01264                      for (int i=0; i<Colors.length; i++)
01265                             Global.removeParameter("color"+i); 
01266                      Global.removeParameter("colorbackground"); 
01267                      Global.removeParameter("colorselect"); 
01268                      Global.removeParameter("colortarget"); 
01269                      ZC.setBackground(getBackground()); 
01270                      Center.setBackground(getBackground());
01271                      if (ZC.CDP!=null)
01272                      {      ZC.CDP.setListingBackground(getBackground());
01273                             if (CenterPanel!=null)
01274                                    CenterPanel.setBackground(getBackground());
01275                      }
01276                      initLightColors(); 
01277                      SelectColor=Global.getParameter("colorselect",SelectColor); 
01278                      TargetColor=Global.getParameter("colortarget",TargetColor); 
01279                      if (ZC.CDP!=null)
01280                      {      ZC.CDP.setListingBackground(Global.getParameter("colorbackground",
01281                                    Color.white));
01282                      }
01283                      ZC.repaint(); 
01284               }
01285               else if (s.startsWith("colors.color"))
01286               {      setinfo("colors"); 
01287                      try
01288                      {      int c=Integer.parseInt(s.substring("colors.color".length())); 
01289                             ColorEditor ce=new ColorEditor(this,"color"+c,
01290                                    Colors[c]); 
01291                             ce.center(this); 
01292                             ce.setVisible(true); 
01293                             initLightColors(); 
01294                             ZC.repaint(); 
01295                      }
01296                      catch (Exception e) {       }
01297               }
01298               else if (s.equals("colors.background"))
01299               {      setinfo("colors"); 
01300                      ColorEditor ce=new ColorEditor(this,"colorbackground",
01301                             getBackground()); 
01302                      ce.center(this); 
01303                      ce.setVisible(true); 
01304                      initLightColors();
01305                      if (Global.haveParameter("colorbackground"))
01306                      {      ZC.setBackground(Global.getParameter("colorbackground",
01307                                    Color.white));
01308                             if (ZC.CDP!=null)
01309                             {      ZC.CDP.setListingBackground(Global.getParameter("colorbackground",
01310                                           Color.white));
01311                                    if (CenterPanel!=null)
01312                                           CenterPanel.setBackground(Global.getParameter("colorbackground",
01313                                                         Color.white));
01314                             }
01315                             Center.setBackground(Global.getParameter("colorbackground",
01316                                    Color.white)); 
01317                      }
01318                      ZC.repaint(); 
01319               }
01320               else if (s.equals("colors.select"))
01321               {      setinfo("colors"); 
01322                      ColorEditor ce=new ColorEditor(this,"colorselect",
01323                             SelectColor); 
01324                      ce.center(this); 
01325                      ce.setVisible(true); 
01326                      SelectColor=Global.getParameter("colorselect",SelectColor); 
01327                      ZC.repaint(); 
01328               }
01329               else if (s.equals("colors.target"))
01330               {      setinfo("colors"); 
01331                      ColorEditor ce=new ColorEditor(this,"colortarget",
01332                             SelectColor); 
01333                      ce.center(this); 
01334                      ce.setVisible(true); 
01335                      TargetColor=Global.getParameter("colortarget",TargetColor); 
01336                      ZC.repaint(); 
01337               }
01338               else if (s.equals("menu.background.grab"))
01339               {      setinfo("background"); 
01340                      dograb(true); 
01341               }
01342               else if (s.equals("menu.background.clear"))
01343               {      setinfo("background"); 
01344                      dograb(false); 
01345               }
01346               else if (s.equals("menu.background.load"))
01347               {      setinfo("background"); 
01348                      loadBackground(); 
01349               }
01350               else if (s.equals("menu.options.sizes"))
01351               {      new SizesDialog(this);
01352                      ZC.resetGraphics();
01353               }
01354               else if (s.equals("menu.options.cleardraw"))
01355               {      setinfo("draw"); 
01356                      ZC.clearDrawings(); 
01357               }
01358               else if (s.equals("menu.bp.setbreak"))
01359               {      ZC.breakpointLast(true,false);
01360               }
01361               else if (s.equals("menu.bp.clearbreak"))
01362               {      ZC.breakpointLast(false,false);
01363               }
01364               else if (s.equals("menu.bp.sethidingbreak"))
01365               {      ZC.breakpointLast(true,true);
01366               }
01367               else if (s.equals("menu.bp.animatebreak"))
01368               {      settool(NAnimateBreak);
01369               }
01370               else if (s.equals("menu.options.editgrid"))
01371               {      editGrid(); 
01372                      setinfo("grid"); 
01373               }
01374               ZC.pause(false);
01375               ZC.requestFocus();
01376        }
01377        
01378        public void clear (boolean defaults)
01379        {      ZC.clear(); 
01380               Count.resetAll(); 
01381               TestJob.setState(false); 
01382               clearsettings(defaults); 
01383               ZC.clearDrawings();
01384               ZC.repaint(); 
01385        }
01386        
01387        public void clearsettings (boolean defaults)
01388        {      if (defaults)
01389               {      settool(0); 
01390                      setcolor(0);
01391                      setcolortype(0); 
01392                      settype(2); 
01393                      showcolor(0); 
01394                      setRestricted(true); 
01395                      setPartial(false); 
01396                      setPartialLines(false); 
01397                      setVectors(false); 
01398                      setShowNames(false); 
01399                      setShowValues(false); 
01400                      setLongNames(false); 
01401                      setLargeFont(false); 
01402                      setBoldFont(false); 
01403                      setObtuse(false); 
01404                      setSolid(false); 
01405                      setVisual(true); 
01406                      sethidden(false);
01407               }
01408               else
01409               {      settool(0); 
01410                      setcolor(Global.getParameter("options.color",0));
01411                      setcolortype(Global.getParameter("options.colortype",0)); 
01412                      settype(Global.getParameter("options.type",2)); 
01413                      showcolor(0); 
01414                      setRestricted(Global.getParameter("options.restricted",true)); 
01415                      setPartial(Global.getParameter("options.partial",false)); 
01416                      setPartialLines(Global.getParameter("options.plines",false)); 
01417                      setVectors(Global.getParameter("options.arrow",false)); 
01418                      setShowNames(Global.getParameter("options.shownames",false)); 
01419                      setShowValues(Global.getParameter("options.showvalues",false)); 
01420                      setLongNames(Global.getParameter("options.longnames",false)); 
01421                      setLargeFont(Global.getParameter("options.largefont",false)); 
01422                      setBoldFont(Global.getParameter("options.boldfont",false)); 
01423                      setObtuse(Global.getParameter("options.obtuse",false)); 
01424                      setSolid(Global.getParameter("options.solid",false)); 
01425                      setVisual(Global.getParameter("options.visual",true)); 
01426                      sethidden(false);
01427               }
01428        }
01429        public void clearsettings ()
01430        {      clearsettings(false);
01431        }
01432        
01433        public void loadsettings ()
01434        {      setcolor(ZC.getDefaultColor()); 
01435               settype(ZC.getDefaultType()); 
01436               setcolortype(ZC.getDefaultColorType()); 
01437               setPartial(ZC.getPartial()); 
01438               setPartialLines(ZC.getPartialLines()); 
01439               setVectors(ZC.getVectors()); 
01440               setShowNames(ZC.getConstruction().ShowNames); 
01441               setShowValues(ZC.getConstruction().ShowValues); 
01442        }
01443        
01444        public void itemAction (String o, boolean flag)
01445               // interpret checkbox changes
01446        {      for (int i=0; i<ObjectMenuItems.length; i++)
01447               {      if (o.equals(ObjectStrings[i]))
01448                      {      if (i==NMacro)
01449                             {      setinfo("runmacro"); 
01450                                    runMacro(false); 
01451                             }
01452                             else
01453                             {      setinfo(ObjectStrings[i]); 
01454                                    settool(i);                        
01455                             }
01456                             return; 
01457                      }
01458               }
01459               for (int i=0; i<ColorMenuItems.length; i++)
01460               {      if (o.equals("cs-"+ColorStrings[i]))
01461                      {      setcolor(i); 
01462                             setinfo("defaults"); 
01463                             return; 
01464                      }
01465               }
01466               for (int i=0; i<ShowColorMenuItems.length; i++)
01467               {      if (o.equals("scs-"+ColorStrings[i]))
01468                      {      showcolor(i); 
01469                             setinfo("show"); 
01470                             return; 
01471                      }
01472               }
01473               for (int i=0; i<PointMenuItems.length; i++)
01474               {      if (o.equals("pt-"+PointTypes[i]))
01475                      {      settype(i); 
01476                             setinfo("defaults"); 
01477                             return; 
01478                      }
01479               }
01480               for (int i=0; i<ColorTypeMenuItems.length; i++)
01481               {      if (o.equals("ct-"+ColorTypes[i]))
01482                      {      setcolortype(i); 
01483                             setinfo("defaults"); 
01484                             return; 
01485                      }
01486               }
01487               if (o.equals("menu.options.hidden"))
01488               {      sethidden(flag);
01489                      ZC.reloadCD();
01490                      setinfo("hide"); 
01491               }
01492               else if (o.equals("menu.file.includemacros"))
01493               {      IncludeMacros.setState(flag); 
01494                      Global.setParameter("save.includemacros",flag); 
01495                      setinfo("save"); 
01496               }
01497               else if (o.equals("menu.file.alwaysclearmacros"))
01498               {      AlwaysClearMacros.setState(flag); 
01499                      Global.setParameter("load.clearmacros",flag); 
01500                      setinfo("save"); 
01501               }
01502               else if (o.equals("menu.options.visual"))
01503               {      setVisual(flag); 
01504                      setShowNames(!flag);
01505                      setinfo("visual"); 
01506               }
01507               else if (o.equals("menu.options.printscalepreview"))
01508               {      if (flag)
01509                      {      ExportScaler d=new ExportScaler(this,true);
01510                             if (d.isAborted()) flag=false;
01511                      } 
01512                      Global.setParameter("printscalepreview",flag);
01513                      PrintScalePreview.setState(flag);
01514                      ZC.newImage();
01515                      setinfo("print"); 
01516               }
01517               else if (o.equals("menu.file.compress"))
01518               {      Global.setParameter("save.compress",flag); 
01519                      setinfo("save"); 
01520               }
01521               else if (o.equals("menu.options.partial"))
01522               {      setPartial(flag); 
01523                      setinfo("defaults"); 
01524               }
01525               else if (o.equals("menu.options.restricted"))
01526               {      setRestricted(flag); 
01527                      setinfo("defaults"); 
01528               }
01529               else if (o.equals("menu.options.plines"))
01530               {      setPartialLines(flag); 
01531                      setinfo("defaults"); 
01532               }
01533               else if (o.equals("menu.options.arrow"))
01534               {      setVectors(flag); 
01535                      setinfo("defaults"); 
01536               }
01537               else if (o.equals("menu.options.longnames"))
01538               {      setLongNames(flag); 
01539                      setinfo("defaults"); 
01540               }
01541               else if (o.equals("menu.options.largefont"))
01542               {      setLargeFont(flag); 
01543                      setinfo("defaults"); 
01544               }
01545               else if (o.equals("menu.options.boldfont"))
01546               {      setBoldFont(flag); 
01547                      setinfo("defaults"); 
01548               }
01549               else if (o.equals("menu.options.shownames"))
01550               {      setShowNames(flag); 
01551                      setinfo("defaults"); 
01552               }
01553               else if (o.equals("menu.options.obtuse"))
01554               {      setObtuse(flag); 
01555                      setinfo("defaults"); 
01556               }
01557               else if (o.equals("menu.options.solid"))
01558               {      setSolid(flag); 
01559                      setinfo("defaults"); 
01560               }
01561               else if (o.equals("menu.options.showvalues"))
01562               {      setShowValues(flag); 
01563                      setinfo("defaults"); 
01564               }
01565               else if (o.equals("menu.options.grid"))
01566               {      toggleGrid(); 
01567                      setinfo("grid"); 
01568               }
01569               else if (o.equals("menu.options.leftsnap"))
01570               {      Global.setParameter("grid.leftsnap",flag); 
01571                      setinfo("grid"); 
01572                      ZC.repaint();
01573               }
01574               else if (o.equals("menu.background.tile"))
01575               {      Global.setParameter("background.tile",flag); 
01576                      ZC.repaint(); 
01577                      setinfo("background"); 
01578               }
01579               else if (o.equals("menu.background.usesize"))
01580               {      Global.setParameter("background.usesize",flag);
01581                      resize();
01582                      setinfo("background"); 
01583               }
01584               else if (o.equals("menu.background.usewidth"))
01585               {      Global.setParameter("background.usewidth",flag);
01586                      resize();
01587                      setinfo("background"); 
01588               }
01589               else if (o.equals("menu.background.center"))
01590               {      Global.setParameter("background.center",flag); 
01591                      ZC.repaint(); 
01592                      setinfo("background"); 
01593               }
01594               else if (o.equals("menu.background.usesize"))
01595               {      Global.setParameter("background.usesize",flag); 
01596                      if (flag)
01597                      {      resize(); 
01598                      }
01599                      setinfo("background"); 
01600               }
01601               else if (o.equals("menu.special.testjob"))
01602               {      testjob(flag); 
01603                      if (flag && !ZC.getConstruction().getComment().equals(""))
01604                             showcomment(); 
01605                      setinfo("assignments"); 
01606               }
01607               else if (o.equals("menu.settings.constructiondisplay"))
01608               {      Global.setParameter("options.showdisplay",flag);
01609                      showConstructionDisplay(flag);
01610                      setinfo("constructiondisplay");
01611               }
01612               else if (o.equals("menu.settings.font.bold"))
01613               {      Global.setParameter("font.bold",flag); 
01614                      ZC.resetGraphics(); 
01615                      setinfo("fonts"); 
01616               }
01617               else if (o.equals("menu.settings.font.large"))
01618               {      Global.setParameter("font.large",flag); 
01619                      ZC.resetGraphics(); 
01620                      setinfo("fonts"); 
01621               }
01622               else if (o.equals("menu.settings.iconbartop"))
01623               {      Global.setParameter("options.iconbartop",flag); 
01624                      remove(MainPanel); 
01625                      makeMainPanel(); 
01626                      add("Center",MainPanel); 
01627                      validate(); 
01628                      setinfo("iconbar"); 
01629               }
01630               else if (o.equals("menu.settings.restricted"))
01631               {      Global.setParameter("restricted",flag); 
01632                      warning(Zirkel.name("warning.reset")); 
01633                      setinfo("restricted"); 
01634               }
01635               else if (o.equals("menu.settings.beginner"))
01636               {      Global.setParameter("beginner",flag); 
01637                      if (flag)
01638                      {      Global.setParameter("options.indicate",true); 
01639                             Global.setParameter("options.indicate.simple",true); 
01640                             Global.setParameter("options.pointon",true); 
01641                             Global.setParameter("options.intersection",true); 
01642                             Global.setParameter("options.choice",true); 
01643                             Global.setParameter("showtips",true); 
01644                             Global.setParameter("restrictedicons",DefaultRestrictedIcons); 
01645                             Global.setParameter("saveicons",
01646                                    Global.getParameter("icons",DefaultIcons)); 
01647                             Global.setParameter("icons",DefaultRestrictedIcons); 
01648                             remakeIconBar(); 
01649                      }
01650                      else
01651                      {      Global.setParameter("options.indicate",true); 
01652                             Global.setParameter("options.indicate.simple",false); 
01653                             Global.setParameter("options.pointon",false); 
01654                             Global.setParameter("options.intersection",false); 
01655                             Global.setParameter("icons",
01656                                    Global.getParameter("saveicons",DefaultIcons)); 
01657                             remakeIconBar(); 
01658                      }
01659                      setinfo("beginner"); 
01660               }
01661               else if (o.equals("menu.special.macrobar"))
01662               {      Global.setParameter("macrobar",flag);
01663                      setinfo("macrobar");
01664                      remakeIconBar();
01665               }
01666               else if (o.equals("menu.special.defaultmacrosinbar"))
01667               {      Global.setParameter("defaultmacrosinbar",flag);
01668                      setinfo("macrobar");
01669                      updateMacroBar();
01670               }
01671               else if (o.equals("menu.file.print.isoscale"))
01672               {      Global.setParameter("print.isoscale",flag); 
01673                      setinfo("background"); 
01674               }
01675               else if (o.equals("menu.special.restricticons"))
01676               {      restrictIcons(flag); 
01677                      setinfo("restricted"); 
01678               }
01679        }
01680        
01681        public void iconPressed (String o)
01682        {      ZC.pause(true); 
01683               ZC.requestFocus();
01684               if (o.equals("load"))
01685               {      setinfo("save"); 
01686                      load(); 
01687               }
01688               else if (o.equals("save"))
01689               {      setinfo("save"); 
01690                      save(); 
01691               }
01692               else if (o.equals("new"))
01693               {      setinfo("save"); 
01694                      newfile(IA.isControlPressed()); 
01695                      IA.clearShiftControl();
01696               }
01697               else if (o.equals("hidden"))
01698               {      itemAction("menu.options.hidden",IA.getState("hidden")); 
01699                      setinfo("hide"); 
01700               }
01701               else if (o.equals("partial"))
01702               {      setPartial(IA.getState("partial")); 
01703                      setinfo("defaults"); 
01704               }
01705               else if (o.equals("plines"))
01706               {      setPartialLines(IA.getState("plines")); 
01707                      setinfo("defaults"); 
01708               }
01709               else if (o.equals("arrow"))
01710               {      setVectors(IA.getState("arrow")); 
01711                      setinfo("defaults"); 
01712               }
01713               else if (o.equals("visual"))
01714               {      setVisual(IA.getState("visual")); 
01715                      setShowNames(!IA.getState("visual"));
01716                      setinfo("visual"); 
01717               }
01718               else if (o.equals("color"))
01719               {      int n=IA.getMultipleState("color"); 
01720                      if (n>=0) setcolor(n); 
01721                      setinfo("defaults"); 
01722               }
01723               else if (o.equals("showcolor"))
01724               {      int n=IA.getMultipleState("showcolor"); 
01725                      if (n>=0) showcolor(n); 
01726                      setinfo("show"); 
01727               }
01728               else if (o.equals("type"))
01729               {      int n=IA.getMultipleState("type"); 
01730                      if (n>=0) settype(n); 
01731                      setinfo("defaults"); 
01732               }
01733               else if (o.equals("thickness"))
01734               {      int n=IA.getMultipleState("thickness"); 
01735                      if (n>=0) setcolortype(n); 
01736                      setinfo("defaults"); 
01737               }
01738               else if (o.equals("showname"))
01739               {      setShowNames(IA.getState("showname")); 
01740                      setinfo("defaults"); 
01741               }
01742               else if (o.equals("showvalue"))
01743               {      setShowValues(IA.getState("showvalue")); 
01744                      setinfo("defaults"); 
01745               }
01746               else if (o.equals("longnames"))
01747               {      setLongNames(IA.getState("longnames")); 
01748                      setinfo("defaults"); 
01749               }
01750               else if (o.equals("large"))
01751               {      setLargeFont(IA.getState("large")); 
01752                      setinfo("defaults"); 
01753               }
01754               else if (o.equals("bold"))
01755               {      setBoldFont(IA.getState("bold")); 
01756                      setinfo("defaults"); 
01757               }
01758               else if (o.equals("obtuse"))
01759               {      setObtuse(IA.getState("obtuse")); 
01760                      setinfo("defaults"); 
01761               }
01762               else if (o.equals("solid"))
01763               {      setSolid(IA.getState("solid")); 
01764                      setinfo("defaults"); 
01765               }
01766               else if (o.equals("grid"))
01767               {      toggleGrid(); 
01768                      setinfo("grid"); 
01769               }
01770               else if (o.equals("back"))
01771               {      ZC.back(); 
01772                      ZC.repaint(); 
01773                      setinfo("back"); 
01774               }
01775               else if (o.equals("undo"))
01776               {      ZC.undo(); 
01777                      ZC.repaint(); 
01778                      setinfo("undo"); 
01779               }
01780               else if (o.equals("comment"))
01781               {      setinfo("comment"); 
01782                      if (IA.isShiftPressed()) showjobcomment(); 
01783                      else showcomment(); 
01784               }
01785               else if (o.equals("grab"))
01786               {      dograb(); 
01787                      setinfo("background"); 
01788               }
01789               else if (o.equals("macro"))
01790               {      int n=IA.getMultipleState("macro"); 
01791                      switch (n)
01792                      {      case 1 :
01793                                    setinfo("parameter"); 
01794                                    settool(NParameters);
01795                             break; 
01796                             case 2 :
01797                                    setinfo("target"); 
01798                                    settool(NTargets); 
01799                             break; 
01800                             case 0 :
01801                                    setinfo("macro"); 
01802                                    definemacro(); 
01803                             break; 
01804                      }
01805                      IA.setState("macro",true);
01806               }
01807               else if (o.equals("replay"))
01808               {      setinfo("replay"); 
01809                      replay(); 
01810               }
01811               else if (o.equals("info"))
01812               {      info(); 
01813               }
01814               else if (o.equals("function"))
01815               {      setinfo("function"); 
01816                      if (IA.isControlPressed()) ZC.createFunction();
01817                      else ZC.createCurve();
01818               }
01819               else if (IB.isControlPressed())
01820               {      int i=CurrentTool;
01821                      if (o.equals("hide"))
01822                      {      ZC.hideDuplicates();
01823                             ZC.repaint();
01824                      }
01825                      else if (o.equals("runmacro"))
01826                      {      setinfo("runmacro");
01827                             runMacro(true);
01828                             return;
01829                      }
01830                      else if (o.equals("objecttracker"))
01831                      {      track();
01832                      }
01833                      settool(i);
01834               }      
01835               else if (IA.isControlPressed())
01836               {      int i=CurrentTool;
01837                      if (o.equals("edit"))
01838                      {      if (CurrentTool!=NEdit) IA.setState("edit",false);
01839                             ZC.editLast();
01840                             ZC.repaint();
01841                      }
01842                      else if (o.equals("objecttracker"))
01843                      {      track();
01844                      }
01845                      settool(i);
01846               }
01847               else 
01848               {      for (int i=0; i<ObjectMenuItems.length; i++)
01849                      {      if (o.equals(ObjectStrings[i]))
01850                             {      if (i==NMacro)
01851                                    {      setinfo("runmacro");
01852                                           runMacro(IB.isShiftPressed()); 
01853                                    }
01854                                    else
01855                                    {      settool(i); 
01856                                           setinfo(ObjectStrings[i]); 
01857                                    }
01858                                    ZC.requestFocus(); 
01859                                    return; 
01860                             }
01861                      }
01862                      if (IM!=null) // Search in the macro line
01863                      {      Macro m=IM.find(o);
01864                             if (m!=null) runMacro(m);
01865                      }
01866               }
01867               IA.clearShiftControl();
01868               IB.clearShiftControl();
01869               ZC.pause(false); 
01870               ZC.requestFocus(); 
01871        }
01872 
01876        public void settool (int i)
01877        {      if (IM!=null) IM.deselectAll();
01878               ObjectMenuItems[CurrentTool].setState(false); 
01879               CurrentTool=i; 
01880               ObjectMenuItems[i].setState(true); 
01881               ZC.setTool(ObjectConstructors[i]); 
01882               if (i<IconNumber && IB.have(ObjectStrings[i]))
01883                      IB.toggle(ObjectStrings[i]); 
01884               else
01885                      IB.unselect("point"); 
01886               ObjectConstructors[i].resetFirstTime(ZC); 
01887               if (i==NTargets) IA.setMultipleState("macro",2); 
01888               else if (i==NParameters) IA.setMultipleState("macro",1); 
01889               else if (i==NDefineJob) testjob(false); 
01890               else
01891               {      IA.setMultipleState("macro",0); 
01892                      IA.setState("macro",false);
01893               }
01894               IA.setState("delete",i==NDelete); 
01895               IA.setState("edit",i==NEdit); 
01896               IA.setState("draw",i==NDraw); 
01897               IA.setState("rename",i==NRename); 
01898               IA.setState("zoom",i==NZoom); 
01899               IA.setState("animatebreak",i==NAnimateBreak); 
01900        }
01901        
01902        public void setcolor (int c)
01903        {      for (int i=0; i<ColorMenuItems.length; i++)
01904               ColorMenuItems[i].setState(false); 
01905               ColorMenuItems[c].setState(true); 
01906               IA.setMultipleState("color",c); 
01907               ZC.setDefaultColor(c); 
01908               Global.setParameter("options.color",c); 
01909        }
01910        
01911        public void settype (int c)
01912        {      for (int i=0; i<PointMenuItems.length; i++)
01913               PointMenuItems[i].setState(false); 
01914               PointMenuItems[c].setState(true); 
01915               IA.setMultipleState("type",c); 
01916               ZC.setDefaultType(c); 
01917               Global.setParameter("options.type",c); 
01918        }
01919        
01920        public void setcolortype (int c)
01921        {      if (c>=ColorTypeMenuItems.length || c<0) c=0;
01922               for (int i=0; i<ColorTypeMenuItems.length; i++)
01923               ColorTypeMenuItems[i].setState(false); 
01924               ColorTypeMenuItems[c].setState(true); 
01925               IA.setMultipleState("thickness",c); 
01926               ZC.setDefaultColorType(c); 
01927               Global.setParameter("options.colortype",c); 
01928        }
01929        
01930        public void showcolor (int c)
01931        {      ZC.setShowColor(c); 
01932               for (int i=0; i<ShowColorMenuItems.length; i++)
01933               {      ShowColorMenuItems[i].setState(c==i); 
01934               }
01935               IA.setMultipleState("showcolor",c); 
01936        }
01937        
01938        public void showStatus (String s)
01939        {      if (Status.getText().equals(s)) return; 
01940               Status.setText(s); 
01941        }
01942        
01943        public void keyReleased (KeyEvent e) {}
01944        
01945        public void keyPressed (KeyEvent e)
01946        {      int code=e.getKeyCode(); 
01947               int i; 
01948               boolean Shift=e.isShiftDown(),Control=e.isControlDown(),Alt=e.isAltDown(); 
01949               if (Control && Alt)
01950               {      switch (code)
01951                      {      case '1' : ZC.callCDItem("Description",true); break;
01952                             case '2' : ZC.callCDItem("Size",true); break;
01953                             case '3' : ZC.callCDItem("Formula",true); break;
01954                             case '4' : ZC.callCDAction("Hide"); break;
01955                             case '5' : ZC.callCDAction("SuperHide"); break;
01956                             case '7' : ZC.callCDAction("Copy"); break;
01957                             case '9' : ZC.callCDToggleItem("Visible"); break;
01958                             case '0' : ZC.callCDToggleItem("Sort"); break;
01959                      }
01960               }
01961               else if (Control)
01962               {      switch (e.getKeyCode())
01963                      {      case KeyEvent.VK_O : load(); return; 
01964                             case KeyEvent.VK_R : loadRun(); return; 
01965                             case KeyEvent.VK_X : editRun(OldRun); return; 
01966                             case KeyEvent.VK_J : loadJob(); return; 
01967                             case KeyEvent.VK_K : saveJob(); return; 
01968                             case KeyEvent.VK_S : save(); return; 
01969                             case KeyEvent.VK_A : saveas(); return; 
01970                             case KeyEvent.VK_E : exportHTML(); return; 
01971                             case KeyEvent.VK_Z : ZC.undo(); ZC.repaint(); return; 
01972                             case KeyEvent.VK_N : doAction("menu.file.new"); return; 
01973                             case KeyEvent.VK_I :
01974                                    itemAction("menu.special.restricticons",!RestrictIcons.getState()); 
01975                             return; 
01976                      }
01977                      for (i=0; i<PointKeys.length; i++)
01978                      {      if (PointKeys[i]==code)
01979                             {      settype(i); 
01980                                    return; 
01981                             }
01982                      }
01983                      for (i=0; i<ColorKeys.length; i++)
01984                      {      if (ColorKeys[i]==code)
01985                             {      setcolor(i); 
01986                                    return; 
01987                             }
01988                      }
01989               }
01990               else if (Alt)
01991               {      for (i=0; i<ColorKeys.length; i++)
01992                      {      if (ColorKeys[i]==code)
01993                             {      showcolor(i); 
01994                                    return; 
01995                             }
01996                      }
01997                      for (i=0; i<ColorTypeKeys.length; i++)
01998                      {      if (ColorTypeKeys[i]==code)
01999                             {      setcolortype(i); 
02000                                    return; 
02001                             }
02002                      }
02003               }
02004               else
02005               {      switch (code)
02006                      {      case KeyEvent.VK_DELETE :
02007                             settool(NDelete); break; 
02008                             case KeyEvent.VK_ESCAPE :
02009                                    if (ZC.getCurrentTool() instanceof DrawerTool) ZC.clearDrawings(); 
02010                             else reset(); 
02011                             break; 
02012                             case KeyEvent.VK_SPACE :
02013                                    ZC.returnPressed(); break; 
02014                             case KeyEvent.VK_ENTER :
02015                                    if (Shift) track(); 
02016                             break; 
02017                      }
02018               }
02019               if (!e.isActionKey()) return; 
02020               switch (code)
02021               {      case KeyEvent.VK_F1 :
02022                             if (Shift || Control)
02023                             {      if (!Global.getParameter("restricted",false))
02024                                    {      TestJob.setState(!TestJob.getState()); 
02025                                           itemAction("menu.special.testjob",TestJob.getState()); 
02026                                    }
02027                             }
02028                      else info(); 
02029                      break; 
02030                      case KeyEvent.VK_F3 :
02031                             if (Shift || Control)
02032                             {      itemAction("menu.options.printscalepreview",
02033                                           !PrintScalePreview.getState());
02034                             } 
02035                      break; 
02036                      case KeyEvent.VK_F4 :
02037                             if (Alt) doclose(); 
02038                      break; 
02039                      case KeyEvent.VK_F5 :
02040                             if (Shift || Control)
02041                             {      if (enabled("macro")) definemacro(); 
02042                             }
02043                             else
02044                             {      if (enabled("runmacro")) runMacro(false); 
02045                             }
02046                      break; 
02047                      case KeyEvent.VK_F6 :
02048                             if (Shift || Control)
02049                             {      setShowNames(!ShowNames.getState()); 
02050                             }
02051                      break; 
02052                      case KeyEvent.VK_F7 :
02053                             if (Shift || Control)
02054                             {      setShowValues(!ShowValues.getState());
02055                             }      
02056                      break; 
02057                      case KeyEvent.VK_F8 :
02058                             if (Shift || Control)
02059                             {      setLongNames(!LongNames.getState());
02060                             }
02061                             else showjobcomment(); 
02062                      break; 
02063                      case KeyEvent.VK_F9 :
02064                             /*if (Shift && Control && Alt)
02065                             {      ZC.getConstruction().dovalidateDebug();
02066                             }
02067                             else */ if (Shift || Control)
02068                             {      setPartial(!Partial.getState()); 
02069                             }
02070                             else
02071                             {      ShowHidden.setState(!ShowHidden.getState()); 
02072                                    IA.setState("hidden",ShowHidden.getState()); 
02073                                    ZC.setShowHidden(ShowHidden.getState()); 
02074                             }
02075                      break; 
02076                      case KeyEvent.VK_F10 :
02077                             if (Shift || Control)
02078                             {      setPartialLines(!PartialLines.getState()); 
02079                             }
02080                      else showcomment(); 
02081                      break; 
02082                      case KeyEvent.VK_F11 :
02083                             if (Shift || Control)
02084                             {      setVectors(!Vectors.getState()); 
02085                             }
02086                      else 
02087                             {      showConstructionDisplay(
02088                                           !Global.getParameter("options.showdisplay",true));
02089                             }
02090                      break; 
02091                      case KeyEvent.VK_F12 :
02092                             if (Shift || Control)
02093                             {      setObtuse(!Obtuse.getState()); 
02094                             }
02095                      else toggleGrid(); 
02096                      break; 
02097                      case KeyEvent.VK_LEFT :
02098                             if (Shift && ZC.getCurrentTool() instanceof ObjectTracker)
02099                                    ((ObjectTracker)ZC.getCurrentTool()).decreaseOmit(); 
02100                             else if (Shift && ZC.getCurrentTool() instanceof BreakpointAnimator)
02101                                    ((BreakpointAnimator)ZC.getCurrentTool()).decreaseSpeed(); 
02102                             else if (Shift && ZC.getCurrentTool() instanceof AnimatorTool)
02103                                    ((AnimatorTool)ZC.getCurrentTool()).decreaseSpeed(); 
02104                             else ZC.shift(-0.1,0); 
02105                      break; 
02106                      case KeyEvent.VK_RIGHT :
02107                             if (Shift && ZC.getCurrentTool() instanceof ObjectTracker)
02108                                    ((ObjectTracker)ZC.getCurrentTool()).increaseOmit(); 
02109                             else if (Shift && ZC.getCurrentTool() instanceof BreakpointAnimator)
02110                                    ((BreakpointAnimator)ZC.getCurrentTool()).increaseSpeed(); 
02111                             else if (Shift && ZC.getCurrentTool() instanceof AnimatorTool)
02112                                    ((AnimatorTool)ZC.getCurrentTool()).increaseSpeed(); 
02113                             else ZC.shift(0.1,0); 
02114                      break; 
02115                      case KeyEvent.VK_UP :
02116                             ZC.shift(0,0.1); break; 
02117                      case KeyEvent.VK_DOWN :
02118                             ZC.shift(0,-0.1); break; 
02119               }
02120        }
02121        public void keyTyped (KeyEvent e)
02122        {      char c=e.getKeyChar(); 
02123               int i; 
02124               if (e.isControlDown() || e.isAltDown()) return; 
02125               for (i=0; i<ObjectKeys.length; i++)
02126               {      if (c==ObjectKeys[i])
02127                      {      if (enabled(ObjectStrings[i]))
02128                             {      if (i==NMacro) runMacro(false); 
02129                                    else settool(i); 
02130                             }
02131                             return; 
02132                      }
02133               }
02134               switch (c)
02135               {      case KeyEvent.VK_BACK_SPACE :
02136                      ZC.back(); 
02137                      ZC.repaint(); 
02138                      return; 
02139                      case '+' :
02140                             if (e.isControlDown() &&
02141                             ZC.getCurrentTool() instanceof ObjectTracker)
02142                             ((ObjectTracker)ZC.getCurrentTool()).increaseOmit(); 
02143                      else ZC.magnify(1/Math.sqrt(Math.sqrt(2))); 
02144                      break; 
02145                      case '-' :
02146                             ZC.magnify(Math.sqrt(Math.sqrt(2))); 
02147                      break; 
02148               }
02149        }
02150        
02151        public void save ()
02152        {      testjob(false); 
02153               if (!haveFile()) saveas(); 
02154               else dosave(Filename,true,Global.getParameter("save.includemacros",false),false,
02155                      ZC.getMacros()); 
02156        }
02157        
02158        public static boolean isCompressed (String filename)
02159        {      return FileName.extension(filename).endsWith("z"); 
02160        }
02161        
02162        public boolean dosave (String Filename,
02163               boolean construction, boolean macros, boolean protectedmacros, Vector v)
02164        {      if (Global.getParameter("options.backups",true) && exists(Filename))
02165               {      File F=new File(Filename);
02166                      File Back=new File(Filename+".bak");
02167                      try
02168                      {      if (Back.exists())
02169                             {      Back.delete();
02170                             }
02171                             F.renameTo(Back);
02172                      }
02173                      catch (Exception e)
02174                      {      Warning w=new Warning(this,Zirkel.name("warning.save.backup"),
02175                                    FileName.chop(32,e.toString(),64),
02176                             Zirkel.name("warning"),true); 
02177                             w.center(this); 
02178                             w.setVisible(true); 
02179                             return false; 
02180                      }
02181               }
02182               try
02183               {      OutputStream o=new FileOutputStream(Filename); 
02184                      if (isCompressed(Filename))
02185                             o=new GZIPOutputStream(o,10000); 
02186                      ZC.getConstruction().BackgroundFile=Background;
02187                      ZC.getConstruction().ResizeBackground=
02188                             Global.getParameter("background.usesize",false);
02189                      if (RestrictIcons.getState())
02190                      {      String icons=Global.getParameter("restrictedicons",DefaultIcons); 
02191                             ZC.save(o,construction,macros,protectedmacros,v,icons); 
02192                      }
02193                      else ZC.save(o,construction,macros,protectedmacros,v,""); 
02194                      o.close(); 
02195                      if (construction)
02196                             setTitle(Zirkel.name("program.name")+" : "+FileName.chop(Filename)); 
02197               }
02198               catch (Exception e)
02199               {      Warning w=new Warning(this,Zirkel.name("warning.save"),
02200                             FileName.chop(32,e.toString(),64),
02201                      Zirkel.name("warning"),true); 
02202                      w.center(this); 
02203                      w.setVisible(true); 
02204                      return false; 
02205               }
02206               return true; 
02207        }
02208        
02209        public boolean saveas (String pattern, String ext)
02210        {      testjob(false); 
02211               FileSave.center(this); 
02212               if (haveFile())
02213               {      FileSave.setDirectory(FileName.path(Filename)); 
02214                      FileSave.setFilePath(FileName.filename(Filename)); 
02215               }
02216               FileSave.setPattern(
02217                      Global.getParameter("pattern",pattern)); 
02218               FileSave.update(!haveFile()); 
02219               FileSave.setVisible(true); 
02220               if (FileSave.isAborted()) return false; 
02221               String filename=FileSave.getFilePath(); 
02222               if (FileName.extension(filename).equals(""))
02223                      filename=filename+ext; 
02224               if (Global.getParameter("options.filedialog",true) && exists(filename))
02225               {      Question d=new Question(this,
02226                      FileName.filename(filename)+" : "+
02227                             Zirkel.name("file.exists.overwrite"),
02228                             Zirkel.name("file.exists.title"),
02229                             this,false,true); 
02230                      d.center(this); 
02231                      d.setVisible(true); 
02232                      if (!d.yes()) return false; 
02233               }
02234               Filename=filename; 
02235               return dosave(Filename,true,Global.getParameter("save.includemacros",false),false,
02236                      ZC.getMacros()); 
02237        }
02238        public boolean saveas ()
02239        {      return saveas("*.zir *.zirz *.job *.jobz",
02240               Global.getParameter("save.compress",false)?".zirz":".zir"); 
02241        }
02242        
02243        public boolean exists (String filename)
02244        {      File f=new File(filename); 
02245               return f.exists(); 
02246        }
02247        
02248        public boolean savefile ()
02249        {      testjob(false); 
02250               if (!haveFile()) return saveas(); 
02251               else return dosave(Filename,true,Global.getParameter("save.includemacros",false),false,
02252                      ZC.getMacros()); 
02253        }
02254        
02255        public void saveMacros ()
02256        {      testjob(false); 
02257               Vector v=ZC.chooseMacros(); 
02258               if (v==null || v.size()==0) return; 
02259               FileSave.center(this); 
02260               FileSave.setPattern(Global.getParameter(
02261                      "pattern.macro","*.mcr *mcrz")); 
02262               FileSave.update(); 
02263               FileSave.setVisible(true); 
02264               if (FileSave.isAborted()) return; 
02265               String Filename=FileSave.getFilePath(); 
02266               if (FileName.extension(Filename).equals(""))
02267                      Filename=Filename+
02268                      (Global.getParameter("save.compress",false)?".mcrz":".mcr"); 
02269               if (Global.getParameter("options.filedialog",true) && exists(Filename))
02270               {      Question d=new Question(this,
02271                      FileName.filename(Filename)+" : "+
02272                             Zirkel.name("file.exists.overwrite"),
02273                             Zirkel.name("file.exists.title"),
02274                             this,false,true); 
02275                      d.center(this); 
02276                      d.setVisible(true); 
02277                      if (!d.yes()) return; 
02278               }
02279               dosave(Filename,false,true,true,v); 
02280        }
02281        
02282        public void deleteMacros ()
02283        {      Vector v=ZC.chooseMacros(); 
02284               if (v==null || v.size()==0) return; 
02285               ZC.deleteMacros(v); 
02286        }
02287        
02288        public void renameMacro ()
02289        {      Macro m=ZC.chooseMacro(); 
02290               if (m==null) return; 
02291               if (ZC.MacroCurrentComment!=null) m.setComment(ZC.MacroCurrentComment);
02292               RenameMacroDialog d=new RenameMacroDialog(this,m); 
02293               d.center(this); 
02294               d.setVisible(true); 
02295               if (d.isAborted()) return; 
02296               if (!d.getName().equals(""))
02297                      ZC.renameMacro(m,d.getName());
02298               m.setComment(d.getComment());
02299               updateMacroBar();
02300        }
02301        
02302        public void clearMacros ()
02303        {      if (!ZC.haveMacros()) return; 
02304               if (!Global.getParameter("options.sure",true) ||
02305                      Sure.ask(this,Zirkel.name("sure.macros"))) ZC.clearMacros(); 
02306               updateMacroBar();
02307        }
02308        
02309        public void clearNonprotectedMacros ()
02310        {      if (!ZC.haveNonprotectedMacros()) return; 
02311               if (!Global.getParameter("options.sure",true) ||
02312                      Sure.ask(this,Zirkel.name("sure.macros"))) ZC.clearNonprotectedMacros(); 
02313               updateMacroBar();
02314        }
02315        
02316        public void loadExamples ()
02317        {      String dir=System.getProperty("user.dir");
02318               if (new File(dir+System.getProperty("file.separator")+"Data").exists())
02319                      dir=dir+System.getProperty("file.separator")+"Data";
02320               loadInDir(dir);
02321        }
02322        
02323        public void loadInDir (String dir)
02324        {      testjob(false); 
02325               if (ZC.changed())
02326               {      Question q=new Question(this,Zirkel.name("savequestion.qsave"),
02327                      Zirkel.name("savequestion.title"),true); 
02328                      q.center(this); 
02329                      q.setVisible(true); 
02330                      if (q.yes() && !savefile()) return; 
02331                      if (q.isAborted()) return; 
02332               }
02333               FileLoad.setPattern(Global.getParameter(
02334                      "pattern","*.zir *.job *.zirz *.jobz")); 
02335               FileLoad.center(this); 
02336               if (dir!=null)
02337               {      FileLoad.setDirectory(dir);
02338                      FileLoad.updateFiles();
02339                      FileLoad.updateDir();
02340               }
02341               FileLoad.update(dir==null); 
02342               FileLoad.setVisible(true); 
02343               if (FileLoad.isAborted()) return; 
02344               Filename=FileLoad.getFilePath(); 
02345               if (Global.getParameter("load.clearmacros",true))
02346                      clearNonprotectedMacros();
02347               if (!new File(Filename).exists())
02348               {      if (new File(Filename+".zir").exists())
02349                             Filename=Filename+".zir";
02350                      else if (new File(Filename+".zirz").exists())
02351                             Filename=Filename+".zirz";
02352               }
02353               reset();
02354               load(Filename); 
02355        }
02356        public void load ()
02357        {      loadInDir(null);
02358        }
02359        
02360        public void loadRun ()
02361        {      testjob(false); 
02362               FileLoad.setPattern(Global.getParameter(
02363                      "pattern.run","*.run")); 
02364               FileLoad.center(this); 
02365               FileLoad.update(); 
02366               FileLoad.setVisible(true); 
02367               if (FileLoad.isAborted()) return; 
02368               String filename=FileLoad.getFilePath(); 
02369               if (Global.getParameter("load.clearmacros",true))
02370                      clearNonprotectedMacros();
02371               loadRun(filename); 
02372               Filename=""; 
02373        }
02374        
02375        public void loadRun (String name)
02376        {      try
02377               {      InputStream o=new FileInputStream(name); 
02378                      if (isCompressed(name))
02379                             o=new GZIPInputStream(o); 
02380                      clear(false); 
02381                      ZC.loadRun(o); 
02382                      o.close(); 
02383                      setTitle(Zirkel.name("program.name")+" : "+FileName.chop(name)); 
02384                      if (!ZC.getConstruction().getComment().equals("")) showcomment(); 
02385                      loadsettings(); 
02386               }
02387               catch (Exception e)
02388               {      Warning w=new Warning(this,Zirkel.name("warning.load"),
02389                             FileName.chop(32,e.toString(),64),
02390                      Zirkel.name("warning"),true); 
02391                      w.center(this); 
02392                      w.setVisible(true); 
02393                      ZC.endWaiting(); 
02394                      e.printStackTrace();
02395               }
02396               settool(NMover);
02397               updateMacroBar();
02398        }
02399        
02400        String OldRun=""; 
02401        
02402        public void editRun (String oldrun)
02403        {      testjob(false); 
02404               if (oldrun.equals(""))
02405               {      FileLoad.setPattern(Global.getParameter("pattern.run","*.run")); 
02406                      FileLoad.center(this); 
02407                      FileLoad.update(); 
02408                      FileLoad.setVisible(true); 
02409                      if (FileLoad.isAborted()) return; 
02410                      OldRun=FileLoad.getFilePath(); 
02411               }
02412               else OldRun=oldrun; 
02413               EditRunDialog d=new EditRunDialog(this,OldRun); 
02414               d.setVisible(true); 
02415        }
02416        
02417        public void load (String name)
02418        {      setEnabled(false); 
02419               new ZirkelFrameLoadThread(this,name); 
02420        }
02421        
02422        public void doload (String name)
02423        {      // System.out.println("load "+name);
02424               try
02425               {      InputStream o=new FileInputStream(name); 
02426                      if (isCompressed(name))
02427                             o=new GZIPInputStream(o); 
02428                      clear(false); 
02429                      ZC.startWaiting();
02430                      ZC.load(o);
02431                      ZC.endWaiting(); 
02432                      o.close(); 
02433                      setTitle(Zirkel.name("program.name")+" : "+FileName.chop(name)); 
02434                      setEnabled(true);
02435                      if (!ZC.getConstruction().getComment().equals("")
02436                             && !ZC.isJob())
02437                             showcomment(); 
02438                      Filename=name; 
02439                      Grid.setState(ZC.showGrid()); 
02440                      IA.setState("grid",ZC.showGrid()); 
02441               }
02442               catch (Exception e)
02443               {      Warning w=new Warning(this,Zirkel.name("warning.load"),
02444                             FileName.chop(32,e.toString(),64),
02445                      Zirkel.name("warning"),true); 
02446                      w.center(this); 
02447                      w.setVisible(true);
02448                      ZC.endWaiting(); 
02449                      //e.printStackTrace();
02450                      return;
02451               }
02452               // System.out.println("finished loading "+name);
02453               String icons=ZC.getConstruction().Icons; 
02454               if (!icons.equals(""))
02455               {      // System.out.println("setting restricted icons");
02456                      Global.setParameter("restrictedicons",icons); 
02457                      RestrictIcons.setState(true); 
02458                      showDefaultIcons(false);
02459                      remakeIconBar(); 
02460               }
02461               else if (RestrictIcons.getState())
02462               {      // System.out.println("no restricted icons");
02463                      RestrictIcons.setState(false); 
02464                      showDefaultIcons(true);
02465                      remakeIconBar(); 
02466               }
02467               // System.out.println("finished setting icons");
02468               if (ZC.getConstruction().BackgroundFile!=null)
02469               {      // System.out.println("setting background");
02470                      String backgroundfile=ZC.getConstruction().BackgroundFile;
02471                      String file=backgroundfile;
02472                      if (FileName.path(backgroundfile).equals(""))
02473                             file=FileName.path(name)+
02474                                    File.separator+backgroundfile;
02475                      Global.setParameter("background.usesize",ZC.getConstruction().ResizeBackground);
02476                      doloadBackground(file);
02477               }
02478               Construction C=ZC.getConstruction(); 
02479               if (C.TrackP!=null)
02480               {      // System.out.println("setting track");
02481                      try
02482                      {      ConstructionObject P=C.find(C.TrackP); 
02483                             if (P==null || !((P instanceof PointObject)
02484                                    || (P instanceof PrimitiveLineObject)))
02485                                    throw new ConstructionException("");
02486                             PointObject PM=null;
02487                             if (C.find(C.TrackPM)!=null)
02488                                    PM=(PointObject)C.find(C.TrackPM); 
02489                             ConstructionObject po[]=
02490                                    new ConstructionObject[C.TrackPO.size()]; 
02491                             for (int i=0; i<po.length; i++)
02492                             {      ConstructionObject o=C.find(
02493                                    (String)C.TrackPO.elementAt(i)); 
02494                                    if (o==null || !((o instanceof PointObject)
02495                                           || (o instanceof PrimitiveLineObject)))
02496                                           throw new ConstructionException(""); 
02497                                    po[i]=o; 
02498                             }
02499                             if (C.TrackO!=null)
02500                             {      ConstructionObject O=C.find(C.TrackO); 
02501                                    if (P==null || (PM==null && !(O instanceof ExpressionObject)) || O==null)
02502                                           throw new ConstructionException(""); 
02503                                    settool(NObjectTracker); 
02504                                    ObjectTracker TR=new ObjectTracker(P,PM,O,ZC,C.Animate,C.Paint,po); 
02505                                    if (C.Omit>0) TR.setOmit(C.Omit); 
02506                                    ZC.setTool(TR); 
02507                                    ZC.validate(); 
02508                                    ZC.repaint(); 
02509                             }
02510                             else
02511                             {      if (P==null)
02512                                    throw new ConstructionException(""); 
02513                                    settool(NTracker); 
02514                                    ZC.setTool(new Tracker(P,po)); 
02515                                    if (PM!=null) PM.setSelected(true); 
02516                                    ZC.validate(); 
02517                                    ZC.repaint(); 
02518                             }
02519                      }
02520                      catch (Exception e)
02521                      {      warning(Zirkel.name("exception.track")); 
02522                      }
02523               }
02524               else if (C.AnimateP!=null)
02525               {      // System.out.println("setting animation");
02526                      try
02527                      {      PointObject P=(PointObject)C.find(C.AnimateP); 
02528                             if (P==null)
02529                                    throw new ConstructionException(""); 
02530                             Enumeration e=C.AnimateV.elements(); 
02531                             while (e.hasMoreElements())
02532                             {      String s=(String)e.nextElement(); 
02533                                    ConstructionObject o=C.find(s); 
02534                                    if (o==null || !(o instanceof SegmentObject
02535                                           || o instanceof PrimitiveCircleObject
02536                                           || o instanceof PointObject))
02537                                           throw new ConstructionException(""); 
02538                             }
02539                             settool(NAnimator); 
02540                             ZC.setTool(new AnimatorTool(P,C.AnimateV,ZC,C.AnimateNegative,
02541                                                  C.AnimateOriginal,C.AnimateDelay)); 
02542                      }
02543                      catch (Exception e)
02544                      {      warning(Zirkel.name("exception.animate")); 
02545                      }
02546               }
02547               else if (C.AnimateBreakpoints)
02548               {      // System.out.println("setting animation with brakpoints");
02549                      BreakpointAnimator bp=new BreakpointAnimator();
02550                      bp.setLoop(C.AnimateLoop);
02551                      bp.setSpeed(C.AnimateTime);
02552                      ZC.setTool(bp);
02553                      bp.reset(ZC);
02554               }
02555               else
02556               {      // System.out.println("setting mover");
02557                      settool(NMover); 
02558               }
02559               updateMacroBar();
02560               // System.out.println("finished loading");
02561        }
02562        
02563        public void loadMacros ()
02564        {      FileLoad.setPattern("*.mcr *.mcrz"); 
02565               FileLoad.center(this); 
02566               FileLoad.update(); 
02567               FileLoad.setVisible(true); 
02568               if (FileLoad.isAborted()) return; 
02569               String Filename=FileLoad.getFilePath(); 
02570               try
02571               {      InputStream o=new FileInputStream(Filename); 
02572                      if (isCompressed(Filename))
02573                             o=new GZIPInputStream(o); 
02574                      ZC.load(o,false,true); 
02575                      o.close(); 
02576               }
02577               catch (Exception e)
02578               {      Warning w=new Warning(this,Zirkel.name("warning.loadmacros"),
02579                             FileName.chop(32,e.toString(),64),
02580                      Zirkel.name("warning"),true); 
02581                      w.center(this); 
02582                      w.setVisible(true); 
02583               }
02584               updateMacroBar();
02585        }
02586        
02587        public void loadJob ()
02588        {      testjob(false); 
02589               FileLoad.setPattern("*.job *.jobz"); 
02590               FileLoad.center(this); 
02591               FileLoad.update(); 
02592               FileLoad.setVisible(true); 
02593               if (FileLoad.isAborted()) return; 
02594               Filename=FileLoad.getFilePath(); 
02595               try
02596               {      InputStream o=new FileInputStream(Filename); 
02597                      if (isCompressed(Filename))
02598                             o=new GZIPInputStream(o); 
02599                      clear(false); 
02600                      ZC.load(o); 
02601                      o.close(); 
02602                      setTitle(Zirkel.name("program.name")+" : "+FileName.chop(Filename)); 
02603                      String icons=ZC.getConstruction().Icons; 
02604                      if (!icons.equals(""))
02605                      {      Global.setParameter("restrictedicons",icons); 
02606                             RestrictIcons.setState(true); 
02607                             showDefaultIcons(false);
02608                             remakeIconBar(); 
02609                      }
02610                      else if (RestrictIcons.getState())
02611                      {      RestrictIcons.setState(false); 
02612                             showDefaultIcons(true);
02613                             remakeIconBar(); 
02614                      }
02615                      if (ZC.isJob()) testjob(true); 
02616                      if (!ZC.getConstruction().getComment().equals("")) showcomment(); 
02617               }
02618               catch (Exception e)
02619               {      Warning w=new Warning(this,Zirkel.name("warning.load"),
02620                             FileName.chop(32,e.toString(),64),
02621                      Zirkel.name("warning"),true); 
02622                      w.center(this); 
02623                      w.setVisible(true); 
02624               }
02625               updateMacroBar();
02626        }
02627        
02628        public void saveJob ()
02629        {      testjob(false); 
02630               if (!ZC.isJob())
02631               {      warning(Zirkel.name("warning.nojob")); 
02632                      TestJob.setState(false); 
02633                      return; 
02634               }
02635               saveas("*.job *.jobz",
02636                      Global.getParameter("save.compress",false)?".jobz":".job"); 
02637        }
02638        
02639        public void showcomment ()
02640        {      CommentDialog d=new CommentDialog(this,
02641               ZC.getComment(),Zirkel.name("comment.title"),ZC.displayJob()); 
02642               ZC.setComment(d.getText()); 
02643        }
02644        
02645        public void showjobcomment ()
02646        {      CommentDialog d=new CommentDialog(this,
02647               ZC.getJobComment(),Zirkel.name("jobcomment.title"),false); 
02648               ZC.setJobComment(d.getText()); 
02649        }
02650        
02651        public void showconstruction ()
02652        {      new ConstructionDisplay(this,ZC); 
02653        }
02654        
02655        public boolean close ()
02656        {      if (Zirkel.IsApplet) return true; 
02657               if (ZC.changed())
02658               {      Question q=new Question(this,Zirkel.name("savequestion.qsave"),
02659                      Zirkel.name("savequestion.title"),true); 
02660                      q.center(this); 
02661                      q.setVisible(true); 
02662                      if (q.yes()) return savefile(); 
02663                      return q.getResult()!=Question.ABORT; 
02664               }
02665               return true; 
02666        }
02667        
02668        public void doclose ()
02669        {      notePosition("zirkelframe"); 
02670               super.doclose(); 
02671        }
02672        
02673        public void windowActivated (WindowEvent e)
02674        {      if (ZC!=null) ZC.requestFocus();
02675               // It seems Linux may call this before the constructor. Strange!
02676        }
02677        
02678        public void toggleGrid ()
02679        {      ZC.toggleShowGrid(); 
02680               Grid.setState(ZC.showGrid()); 
02681               IA.setState("grid",ZC.showGrid()); 
02682        }
02683        
02684        /* (non-Javadoc)
02685         * @see rene.zirkel.DoneListener#notifyDone()
02686         * Display a message for the user.
02687         */
02688        public void notifyDone ()
02689        {      repaint(); 
02690               try
02691               {      Thread.sleep(500); 
02692               }
02693               catch (Exception e) {       }
02694               warning(Zirkel.name("done")); 
02695        }
02696        
02703        public void testjob (boolean flag)
02704        {      if (flag==ZC.displayJob()) return; // nothing to do 
02705               if (flag && !ZC.isJob()) // user error!
02706               {      warning(Zirkel.name("warning.nojob")); 
02707                      TestJob.setState(false); 
02708                      ZC.reloadCD();
02709                      return; 
02710               }
02711               // else:
02712               ZC.displayJob(flag); // main action is in ZC. 
02713               if (flag) ZC.setDoneListener(this); 
02714               else ZC.setDoneListener(null); 
02715               TestJob.setState(flag); 
02716               ZC.reloadCD();
02717        }
02718        
02719        public void exportHTML ()
02720        {      testjob(false); 
02721               if (!haveFile())
02722               {      warning(Zirkel.name("export.savefirst")); 
02723                      return; 
02724               }
02725               ExportDialog d=new ExportDialog(this,ZC.getConstruction(),
02726                      RestrictIcons.getState()); 
02727               d.center(this); 
02728               if (!Background.equals("") &&
02729                      Global.getParameter("background.usesize",false) &&
02730                      ZC.Background.getWidth(this)==ZC.IW &&
02731                      ZC.Background.getHeight(this)==ZC.IH)
02732               {      d.setDimensions(ZC.IW,ZC.IH); 
02733               }
02734               d.setVisible(true); 
02735               if (d.isAborted()) return; 
02736               doexport(d,false); 
02737               if (!d.getSolution().equals("") && d.saveSolution())
02738                      doexport(d,true); 
02739        }
02740        
02741        public void doexport (ExportDialog d, boolean solution)
02742        {      HTMLSave.center(this); 
02743               HTMLSave.setDirectory(FileName.path(Filename)); 
02744               if (solution)
02745               {      HTMLSave.setFilePath(d.getSolution()); 
02746               }
02747               else
02748               {      HTMLSave.setFilePath(FileName.purefilename(Filename)+".html"); 
02749               }
02750               HTMLSave.update(false); 
02751               HTMLSave.setVisible(true); 
02752               if (HTMLSave.isAborted()) return; 
02753               String filename=HTMLSave.getFilePath();
02754               if (FileName.extension(filename).equals(""))
02755                      filename=filename+".html"; 
02756               if (Global.getParameter("options.filedialog",true) &&
02757                      exists(filename))
02758               {      Question q=new Question(this,
02759                      FileName.filename(filename)+" : "+
02760                             Zirkel.name("file.exists.overwrite"),
02761                             Zirkel.name("file.exists.title"),
02762                             this,false,true); 
02763                      q.center(this); 
02764                      q.setVisible(true); 
02765                      if (!q.yes()) return; 
02766               }
02767               boolean utf=Global.getParameter("options.utf",true); 
02768               try
02769               {      PrintWriter out; 
02770                      if (utf)
02771                      {      out=new PrintWriter(
02772                             new OutputStreamWriter(
02773                                    new FileOutputStream(filename),
02774                                    "UTF8")); 
02775                      }
02776                      else
02777                      {      out=new PrintWriter(
02778                             new OutputStreamWriter(
02779                                    new FileOutputStream(filename))); 
02780                      }
02781                      out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">");
02782                             out.println("<HTML>"); 
02783                      out.println("<HEAD>"); 
02784                      if (utf)
02785                      {      out.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; CHARSET=utf-8\">"); 
02786                      }
02787                      else
02788                      {      out.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html\">"); 
02789                      }
02790                      out.println("<META NAME=\"GENERATOR\" Content=\"Z.u.L. (C.a.R.)\">"); 
02791                      if (solution)
02792                             out.println("<TITLE>"+d.getPageTitle()+
02793                             ", "+Zirkel.name("export.soltext","Solution")+"</TITLE>"); 
02794                      else
02795                             out.println("<TITLE>"+d.getPageTitle()+"</TITLE>"); 
02796                      if (!d.getStyleSheet().equals(""))
02797                             out.println("<LINK REL=\"stylesheet\" TYPE=\"text/css\""+
02798                             " HREF=\""+d.getStyleSheet()+"\">"); 
02799                      out.println("</HEAD>"); 
02800                      if (d.useForBackground())
02801                             out.println("<BODY BGCOLOR="+d.getHexColor()+">"); 
02802                      else
02803                             out.println("<BODY>"); 
02804                      if (solution)
02805                             out.println("<H1>"+d.getPageTitle()+
02806                             ", "+Zirkel.name("export.soltext","Solution")+"</H1>"); 
02807                      else
02808                             out.println("<H1>"+d.getPageTitle()+"</H1>"); 
02809                      out.println("<CENTER>"); 
02810                      out.println("<P>"); 
02811                      String jar=d.getJar(); 
02812                      String jarname=FileName.filename(jar); 
02813                      String jardir=FileName.path(jar); 
02814                      if (jardir.equals(""))
02815                             out.println("<APPLET ARCHIVE=\""+jar+"\" "+
02816                             "CODE=\"rene.zirkel.ZirkelApplet.class\" "+
02817                             "WIDTH=\""+d.getWidth()+"\" HEIGHT=\""+
02818                             d.getHeight()+"\" ALIGN=\"CENTER\">");
02819                             else
02820                             out.println("<APPLET "+
02821                             "CODEBASE=\""+jardir+"\" "+
02822                             "ARCHIVE=\""+jarname+"\" "+
02823                             "CODE=\"rene.zirkel.ZirkelApplet.class\" "+
02824                             "WIDTH=\""+d.getWidth()+"\" HEIGHT=\""+
02825                             d.getHeight()+"\" ALIGN=\"CENTER\">");
02826                      if (!d.getFile().equals(""))
02827                      {      if (d.isJob() && !solution)
02828                             out.println("<PARAM NAME=\"job\" VALUE=\""+d.getFile()+"\">"); 
02829                             else
02830                                    out.println("<PARAM NAME=\"file\" VALUE=\""+d.getFile()+"\">"); 
02831                      }
02832                      if (d.useForApplet())
02833                             out.println("<PARAM NAME=\"color\" VALUE=\""+
02834                             d.getDezimalColor()+"\">");
02835                      if (d.saveBackground() && Global.haveParameter("colorbackground"))
02836                             out.println("<PARAM NAME=\"colorbackground\" VALUE=\""+
02837                             Global.getParameter("colorbackground","")+"\">");
02838                      if (d.saveColors())
02839                      {      if (Global.haveParameter("colorselect"))
02840                                    out.println("<PARAM NAME=\"colorselect\" VALUE=\""+
02841                                    Global.getParameter("colorselect","")+"\">");
02842                                    if (Global.haveParameter("colortarget"))
02843                                    out.println("<PARAM NAME=\"colortarget\" VALUE=\""+
02844                                    Global.getParameter("colortarget","")+"\">");
02845                                    for (int i=0; i<Colors.length; i++)
02846                             {      if (Global.haveParameter("color"+i))
02847                                    out.println("<PARAM NAME=\"color"+i+"\" VALUE=\""+
02848                                           Global.getParameter("color"+i,"")+"\">");
02849                             }
02850                      }
02851                      /*// now saved in the construction file
02852                      if (Global.getParameter("grid.fine",false))
02853                      {      out.println("<PARAM NAME=\"grid\" VALUE=\"coordinates\">");
02854                      }
02855                      */
02856                      if (Global.getParameter("grid.leftsnap",false))
02857                      {      out.println("<PARAM NAME=\"snap\" VALUE=\"left\">");
02858                      }
02859                      String style=d.getStyle(); 
02860                      if (solution) style="3D"; 
02861                      out.println("<PARAM NAME=\"style\" VALUE=\""+style+"\">"); 
02862                      if (!style.equals("plain") && !style.equals("3D"))
02863                      {      String s=d.getIcons(); 
02864                             out.println("<PARAM NAME=\"tools\" VALUE=\""+s+"\">"); 
02865                             s=d.getTools(); 
02866                             out.println("<PARAM NAME=\"options\" VALUE=\""+s+"\">"); 
02867                      }
02868                      String sol=d.getSolution(); 
02869                      if (!sol.equals("") && d.jumpSolution() && !solution)
02870                             out.println("<PARAM NAME=\"solution\" VALUE=\""+sol+"\">"); 
02871                      if (ZC.showHidden())
02872                             out.println("<PARAM NAME=\"showhidden\" VALUE=\"true\">"); 
02873                      if (Global.getParameter("options.movename",false))
02874                             out.println("<PARAM NAME=\"movename\" VALUE=\"true\">"); 
02875                      if (Global.getParameter("options.movefixname",true))
02876                             out.println("<PARAM NAME=\"movefixname\" VALUE=\"true\">"); 
02877                      if (Global.getParameter("options.smallicons",false))
02878                             out.println("<PARAM NAME=\"smallicons\" VALUE=\"true\">"); 
02879                      if (Global.getParameter("options.oldicons",false))
02880                             out.println("<PARAM NAME=\"oldicons\" VALUE=\"true\">"); 
02881                      if (!d.allowZoom())
02882                             out.println("<PARAM NAME=\"nomousezoom\" VALUE=\"true\">");                         
02883                      if (!d.allowPopup())
02884                             out.println("<PARAM NAME=\"nopopupmenu\" VALUE=\"true\">");                         
02885                      if (d.restrictedMove())
02886                             out.println("<PARAM NAME=\"restrictedmove\" VALUE=\"true\">");                             
02887                      String s=""; 
02888                      if (Global.getParameter("font.bold",false)) s=s+"bold"; 
02889                      if (Global.getParameter("font.large",false)) s=s+" large"; 
02890                      if (!s.equals("")) out.println("<PARAM NAME=\"font\" VALUE=\""+s+"\">"); 
02891                      if (d.saveDigits())
02892                      {      out.println("<PARAM NAME=\"editdigits\" VALUE=\""+
02893                             getDigits(ZirkelCanvas.EditFactor)+"\">");
02894                                    out.println("<PARAM NAME=\"displaydigits\" VALUE=\""+
02895                                    getDigits(ZirkelCanvas.LengthsFactor)+"\">");
02896                                    out.println("<PARAM NAME=\"angledigits\" VALUE=\""+
02897                                    getDigits(ZirkelCanvas.AnglesFactor)+"\">");
02898                      }
02899                      if (Global.getParameter("minpointsize",3)!=3)
02900                             out.println("<PARAM NAME=\"minpointsize\" VALUE=\""+
02901                             Global.getParameter("minpointsize",3)+"\">");
02902                      if (Global.getParameter("minlinesize",1.0)!=1.0)
02903                             out.println("<PARAM NAME=\"minlinewidth\" VALUE=\""+
02904                             Global.getParameter("minlinesize",1.0)+"\">");
02905                      if (Global.getParameter("minfontsize",12)!=12)
02906                             out.println("<PARAM NAME=\"minfontsize\" VALUE=\""+
02907                             Global.getParameter("minfontsize",12)+"\">");
02908                      if (Global.getParameter("options.germanpoints",true))
02909                             out.println("<PARAM NAME=\"germanpoints\" VALUE=\"true\">");
02910                      if (!Background.equals(""))
02911                             out.println("<PARAM NAME=\"background\" VALUE=\""+Background+"\">"); 
02912                      out.println("</APPLET>"); 
02913                      out.println("</P>"); 
02914                      out.println("</CENTER>"); 
02915                      
02916                      s=ZC.getComment(); 
02917                      if (d.isJob() && !solution) s=ZC.getJobComment(); 
02918                      if (!s.equals("") && d.saveComment())
02919                      {      XmlWriter xml=new XmlWriter(out); 
02920                             xml.printParagraphs(s,60); 
02921                      }
02922                      
02923                      if (!sol.equals("") && !solution && d.linkSolution())
02924                      {      out.println("<P>"); 
02925                             out.println("<A href=\""+sol+"\">"+
02926                                    Zirkel.name("export.soltext","Solution")+"</A>"); 
02927                             out.println("</P>"); 
02928                      }
02929                      
02930                      out.println("<HR>"); 
02931                      out.println("<P>"); 
02932                      out.println(Zirkel.name("export.signature")); 
02933                      out.println("</P>"); 
02934                      
02935                      out.println("</BODY>"); 
02936                      out.println("</HTML>"); 
02937                      
02938                      out.close(); 
02939               }
02940               catch (Exception e)
02941               {      Warning w=new Warning(this,Zirkel.name("warning.save"),
02942                             FileName.chop(32,e.toString(),64),
02943                      Zirkel.name("warning"),true); 
02944                      w.center(this); 
02945                      w.setVisible(true); 
02946                      //e.printStackTrace();
02947               }
02948        }
02949        
02950        public void exportTemplateHTML ()
02951        {      testjob(false); 
02952               if (!haveFile())
02953               {      warning(Zirkel.name("export.savefirst")); 
02954                      return; 
02955               }             
02956               TemplateLoad.center(this); 
02957               TemplateLoad.update(); 
02958               TemplateLoad.setVisible(true); 
02959               if (TemplateLoad.isAborted()) return; 
02960               String Template=TemplateLoad.getFilePath();
02961               ExportTemplateDialog d=new ExportTemplateDialog(this,ZC.getConstruction(),
02962                      RestrictIcons.getState()); 
02963               d.center(this); 
02964               d.setVisible(true); 
02965               if (d.isAborted()) return; 
02966               doexporttemplate(d,Template); 
02967        }
02968        
02969        public void doexporttemplate (ExportTemplateDialog d, String template)
02970        {      HTMLSave.center(this); 
02971               HTMLSave.setDirectory(FileName.path(Filename)); 
02972               HTMLSave.setFilePath(FileName.purefilename(Filename)+".html"); 
02973               HTMLSave.update(false); 
02974               HTMLSave.setVisible(true); 
02975               if (HTMLSave.isAborted()) return; 
02976               String filename=HTMLSave.getFilePath();
02977               if (FileName.extension(filename).equals(""))
02978                      filename=filename+".html"; 
02979               if (Global.getParameter("options.filedialog",true) &&
02980                      exists(filename))
02981               {      Question q=new Question(this,
02982                      FileName.filename(filename)+" : "+
02983                             Zirkel.name("file.exists.overwrite"),
02984                             Zirkel.name("file.exists.title"),
02985                             this,false,true); 
02986                      q.center(this); 
02987                      q.setVisible(true); 
02988                      if (!q.yes()) return; 
02989               }
02990               boolean utf=Global.getParameter("options.utf",true); 
02991               try
02992               {      PrintWriter out;                   
02993                      if (utf)
02994                      {      out=new PrintWriter(
02995                             new OutputStreamWriter(
02996                                    new FileOutputStream(filename),
02997                                    "UTF8")); 
02998                      }
02999                      else
03000                      {      out=new PrintWriter(
03001                             new OutputStreamWriter(
03002                                    new FileOutputStream(filename))); 
03003                      }
03004                      BufferedReader in;
03005                      if (utf)
03006                      {      in=
03007                             new BufferedReader(
03008                             new InputStreamReader(new FileInputStream(template),"UTF8"));
03009                      }
03010                      else
03011                      {      in=
03012                             new BufferedReader(
03013                             new InputStreamReader(new FileInputStream(template)));
03014                      }
03015                      while (true)
03016                      {      String s=readTemplateLine(in);
03017                             if (s==null) break;
03018                             if (s.startsWith("#"))
03019                             {      if (s.equals("#title"))
03020                                    {      printCheck(out,d.getPageTitle());
03021                                    }
03022                                    else if (s.equals("#file"))
03023                                    {      out.println("<PARAM NAME=\"file\" VALUE=\""
03024                                                  +d.getFile()+"\">"); 
03025                                    }
03026                                    else if (s.startsWith("#comment"))                      
03027                                    {      String com=ZC.getComment(); 
03028                                           if (ZC.isJob()) com=ZC.getJobComment(); 
03029                                           if (!s.equals("#comment"))
03030                                           {      try
03031                                                  {      int n=Integer.parseInt(s.substring(8));
03032                                                         StringTokenizer t=new StringTokenizer(com,"~");
03033                                                         int i=1;
03034                                                         com="";
03035                                                         while (t.hasMoreTokens())
03036                                                         {      String h=t.nextToken();
03037                                                                if (i==n)
03038                                                                {      com=h; break;
03039                                                                }
03040                                                                i++;
03041                                                         }
03042                                                  }
03043                                                  catch (Exception e) { System.out.println(e); }
03044                                           }
03045                                           if (!com.equals(""))
03046                                           {      printParagraphs(out,com,60); 
03047                                           }
03048                                    }
03049                                    else if (s.startsWith("#text"))                         
03050                                    {      String com=ZC.getComment(); 
03051                                           if (ZC.isJob()) com=ZC.getJobComment(); 
03052                                           if (!s.equals("#text"))
03053                                           {      try
03054                                                  {      int n=Integer.parseInt(s.substring(5));
03055                                                         StringTokenizer t=new StringTokenizer(com,"~");
03056                                                         int i=1;
03057                                                         while (t.hasMoreTokens())
03058                                                         {      String h=t.nextToken();
03059                                                                if (i==n)
03060                                                                {      com=h; break;
03061                                                                }
03062                                                                i++;
03063                                                         }
03064                                                  }
03065                                                  catch (Exception e) { System.out.println(e); }
03066                                                  if (com.startsWith("\n"))
03067                                                         com=com.substring(1);
03068                                                  if (com.endsWith("\n") && com.length()>1)
03069                                                         com=com.substring(0,com.length()-1);
03070                                           }
03071                                           if (!com.equals(""))
03072                                           {      printCheck(out,com);
03073                                           }
03074                                    }
03075                                    else if (s.equals("#parameter"))
03076                                    {      if (!d.getFile().equals(""))
03077                                           {      if (ZC.isJob() && d.isJob())
03078                                                         out.println("<PARAM NAME=\"job\" VALUE=\""
03079                                                                +d.getFile()+"\">"); 
03080                                                  else
03081                                                         out.println("<PARAM NAME=\"file\" VALUE=\""
03082                                                                +d.getFile()+"\">"); 
03083                                           }
03084                                           String style=d.getStyle(); 
03085                                           out.println("<PARAM NAME=\"style\" VALUE=\""+style+"\">"); 
03086                                           if (!style.equals("plain") && !style.equals("3D"))
03087                                           {      String ss=d.getIcons(); 
03088                                                  out.println("<PARAM NAME=\"tools\" VALUE=\""+ss+"\">"); 
03089                                                  ss=d.getTools(); 
03090                                                  out.println("<PARAM NAME=\"options\" VALUE=\""+ss+"\">"); 
03091                                           }
03092                                           if (ZC.showHidden())
03093                                                  out.println("<PARAM NAME=\"showhidden\" VALUE=\"true\">"); 
03094                                           if (Global.getParameter("options.movename",false))
03095                                                  out.println("<PARAM NAME=\"movename\" VALUE=\"true\">"); 
03096                                           if (Global.getParameter("options.movefixname",true))
03097                                                  out.println("<PARAM NAME=\"movefixname\" VALUE=\"true\">"); 
03098                                           if (Global.getParameter("options.smallicons",false))
03099                                                  out.println("<PARAM NAME=\"smallicons\" VALUE=\"true\">"); 
03100                                           if (Global.getParameter("options.oldicons",false))
03101                                                  out.println("<PARAM NAME=\"oldicons\" VALUE=\"true\">"); 
03102                                           if (Global.getParameter("options.germanpoints",true))
03103                                                  out.println("<PARAM NAME=\"germanpoints\" VALUE=\"true\">");
03104                                           /*// now saved in the construction file
03105                                           if (Global.getParameter("grid.fine",false))
03106                                                  out.println("<PARAM NAME=\"grid\" VALUE=\"coordinates\">");
03107                                           */
03108                                           if (Global.getParameter("grid.leftsnap",false))
03109                                                  out.println("<PARAM NAME=\"snap\" VALUE=\"left\">");
03110                                    }
03111                                    else if (s.equals("#color"))
03112                                    {      if (Global.haveParameter("colorselect"))
03113                                                  out.println("<PARAM NAME=\"colorselect\" VALUE=\""+
03114                                                         Global.getParameter("colorselect","")+"\">");
03115                                           if (Global.haveParameter("colortarget"))
03116                                                  out.println("<PARAM NAME=\"colortarget\" VALUE=\""+
03117                                                         Global.getParameter("colortarget","")+"\">");
03118                                           for (int i=0; i<Colors.length; i++)
03119                                           {      if (Global.haveParameter("color"+i))
03120                                                         out.println("<PARAM NAME=\"color"+i+"\" VALUE=\""+
03121                                                                Global.getParameter("color"+i,"")+"\">");
03122                                           }      
03123                                    }
03124                                    else if (s.equals("#font"))
03125                                    {      String ss=""; 
03126                                           if (Global.getParameter("font.bold",false)) ss=ss+"bold"; 
03127                                           if (Global.getParameter("font.large",false)) ss=ss+" large"; 
03128                                           if (!ss.equals("")) 
03129                                                  out.println("<PARAM NAME=\"font\" VALUE=\""+ss+"\">"); 
03130                                           out.println("<PARAM NAME=\"editdigits\" VALUE=\""+
03131                                                  getDigits(ZirkelCanvas.EditFactor)+"\">");
03132                                           out.println("<PARAM NAME=\"displaydigits\" VALUE=\""+
03133                                                  getDigits(ZirkelCanvas.LengthsFactor)+"\">");
03134                                           out.println("<PARAM NAME=\"angledigits\" VALUE=\""+
03135                                                  getDigits(ZirkelCanvas.AnglesFactor)+"\">");
03136                                           if (Global.getParameter("minpointsize",3)!=3)
03137                                                  out.println("<PARAM NAME=\"minpointsize\" VALUE=\""+
03138                                                         Global.getParameter("minpointsize",3)+"\">");
03139                                           if (Global.getParameter("minfontsize",12)!=12)
03140                                                  out.println("<PARAM NAME=\"minfontsize\" VALUE=\""+
03141                                                         Global.getParameter("minfontsize",12)+"\">");
03142                                           if (Global.getParameter("minlinesize",1.0)!=1.0)
03143                                                  out.println("<PARAM NAME=\"minlinewidth\" VALUE=\""+
03144                                                         Global.getParameter("minlinesize",1.0)+"\">");
03145                                           if (!Background.equals(""))
03146                                                  out.println("<PARAM NAME=\"background\" VALUE=\""
03147                                                         +Background+"\">"); 
03148                                    }
03149                                    else if (s.equals("#codebase"))
03150                                    {      String cb=d.getCodebase();
03151                                           if (!cb.equals(""))
03152                                                  out.print(" CODEBASE=\""+cb+"\" ");
03153                                    }
03154                                    }
03155                                    else
03156                                    {      printCheck(out,s);
03157                                    }
03158                      }
03159                      in.close();
03160                      out.close(); 
03161               }
03162               catch (Exception e)
03163               {      Warning w=new Warning(this,Zirkel.name("warning.template"),
03164                             FileName.chop(32,e.toString(),64),
03165                      Zirkel.name("warning"),true); 
03166                      w.center(this); 
03167                      w.setVisible(true); 
03168                      e.printStackTrace();
03169               }
03170               
03171        }
03172 
03173        MyVector TB=new MyVector();
03174        int TBN=0;
03175 
03176        public void printCheck (PrintWriter out, String s)
03177        {      if (TBN==0) out.println(s);
03178               else out.print(s);
03179        }
03180 
03181        public String readTemplateLine (BufferedReader in)
03182               throws IOException
03183        {      if (TB.size()>0)
03184                      // Still strings in the buffer
03185               {      String h=(String)TB.elementAt(TBN);
03186                      TBN++;
03187                      if (TBN>=TB.size())
03188                      {      TBN=0; TB.removeAllElements();
03189                      }
03190                      return h;
03191               }
03192               String h=in.readLine();
03193               if (h==null) return h;      
03194               if (h.indexOf('#')<0) return h;    
03195               bufferTemplate(h);
03196               if (TB.size()>0) return readTemplateLine(in);
03197               else return h;
03198        }
03199        
03200        public void bufferTemplate (String s)
03201        {      int n=s.indexOf('#');
03202               if (n<0)
03203               {      TB.addElement(s);
03204                      return;
03205               }
03206               String h=s.substring(n);
03207               if (h.startsWith("#title")) bufferTemplate(s,n,h,"#title");
03208               else if (h.startsWith("#parameter")) bufferTemplate(s,n,h,"#parameter");
03209               else if (h.startsWith("#color")) bufferTemplate(s,n,h,"#color");
03210               else if (h.startsWith("#font")) bufferTemplate(s,n,h,"#font");
03211               else if (h.startsWith("#codebase")) bufferTemplate(s,n,h,"#codebase");
03212               else if (h.startsWith("#comment"))
03213               {      for (int i=0; i<10; i++)
03214                      {      String t="#comment"+i;
03215                             if (h.startsWith(t))
03216                             {      bufferTemplate(s,n,h,t); return;
03217                             }
03218                      }
03219                      bufferTemplate(s,n,h,"#comment");
03220               }
03221               else if (h.startsWith("#text"))
03222               {      for (int i=0; i<10; i++)
03223                      {      String t="#text"+i;
03224                             if (h.startsWith(t))
03225                             {      bufferTemplate(s,n,h,t); return;
03226                             }
03227                      }
03228                      bufferTemplate(s,n,h,"#text");
03229               }
03230        }
03231        
03232        public void bufferTemplate (String s, int n, String h, String ph)
03233        {      if (n>0) TB.addElement(s.substring(0,n));
03234               TB.addElement(ph);
03235               h=h.substring(ph.length());
03236               if (!h.equals("")) bufferTemplate(h);
03237        }
03238 
03239        public void printParagraphs (PrintWriter out, String s, int linelength)
03240        {      StringParser p=new StringParser(s);
03241               Vector v=p.wrapwords(linelength);
03242               for (int i=0; i<v.size(); i++)
03243               {      out.println("<P>");
03244                      s=(String)v.elementAt(i);
03245                      StringParser q=new StringParser(s);
03246                      Vector w=q.wraplines(linelength);
03247                      for (int j=0; j<w.size(); j++)
03248                      {      if (j>0) out.println();
03249                             s=(String)w.elementAt(j);
03250                             out.print(s);
03251                      }
03252                      out.println("</P>");
03253               }
03254        }
03255        
03256        public int getDigits (double x)
03257        {      return (int)(Math.log(x)/Math.log(10)+0.5); 
03258        }
03259        
03260        public void setPartial (boolean flag)
03261        {      IA.setState("partial",flag); 
03262               Partial.setState(flag); 
03263               Global.setParameter("options.partial",flag); 
03264               ZC.setPartial(flag); 
03265        }
03266        
03267        public void setRestricted (boolean flag)
03268        {      Restricted.setState(flag); 
03269               Global.setParameter("options.restricted",flag); 
03270               ZC.setRestricted(flag); 
03271        }
03272        
03273        public void setPartialLines (boolean flag)
03274        {      IA.setState("plines",flag); 
03275               PartialLines.setState(flag); 
03276               Global.setParameter("options.plines",flag); 
03277               ZC.setPartialLines(flag); 
03278        }
03279        
03280        public void setVectors (boolean flag)
03281        {      IA.setState("arrow",flag); 
03282               Vectors.setState(flag); 
03283               Global.setParameter("options.arrow",flag); 
03284               ZC.setVectors(flag); 
03285        }
03286        
03287        public void setLongNames (boolean flag)
03288        {      LongNames.setState(flag); 
03289               IA.setState("longnames",flag); 
03290               Global.setParameter("options.longnames",flag); 
03291               ZC.setLongNames(flag); 
03292        }
03293        
03294        public void setBoldFont (boolean flag)
03295        {      BoldFont.setState(flag); 
03296               IA.setState("bold",flag); 
03297               Global.setParameter("options.boldfont",flag); 
03298               ZC.setBoldFont(flag); 
03299        }
03300        
03301        public void setLargeFont (boolean flag)
03302        {      LargeFont.setState(flag); 
03303               IA.setState("large",flag); 
03304               Global.setParameter("options.largefont",flag); 
03305               ZC.setLargeFont(flag); 
03306        }
03307        
03308        public void setObtuse (boolean flag)
03309        {      Obtuse.setState(flag); 
03310               IA.setState("obtuse",flag); 
03311               Global.setParameter("options.obtuse",flag); 
03312               ZC.setObtuse(flag); 
03313        }
03314        
03315        public void setSolid (boolean flag)
03316        {      Solid.setState(flag); 
03317               IA.setState("solid",flag); 
03318               Global.setParameter("options.solid",flag); 
03319               ZC.setSolid(flag); 
03320        }
03321        
03322        public void setShowNames (boolean flag)
03323        {      ShowNames.setState(flag); 
03324               IA.setState("showname",flag); 
03325               Global.setParameter("options.shownames",flag);
03326               ZC.setShowNames(flag); 
03327        }
03328        
03329        
03330        public void setShowValues (boolean flag)
03331        {      ShowValues.setState(flag); 
03332               IA.setState("showvalue",flag); 
03333               Global.setParameter("options.showvalue",flag); 
03334               ZC.setShowValues(flag); 
03335        }
03336        
03337        void definemacro ()
03338        {      ZC.defineMacro(); 
03339               updateMacroBar();
03340               settool(NParameters); 
03341               ZC.getOC().reset(ZC); 
03342        }
03343        
03344        String OldMacro=null; 
03345        
03346        public void runMacro (boolean shift)
03347        {      Macro m=ZC.chooseMacro(OldMacro); 
03348               if (!shift || m==null) m=ZC.chooseMacro(); 
03349               if (m==null)
03350               {      settool(CurrentTool); return; 
03351               }
03352               runMacro(m); 
03353        }
03354        
03355        public void runMacro (Macro m)
03356        {      ((MacroRunner)ObjectConstructors[NMacro]).setMacro(m,ZC); 
03357               settool(NMacro); 
03358               if (IM!=null) IM.select(m);
03359               IB.setMultipleState("macro",0); 
03360               OldMacro=m.getName(); 
03361        }
03362        
03363        public void replayChosen ()
03364        {
03365        }
03366        
03367        public void setDigits ()
03368        {      new DigitsDialog(this); 
03369               ZC.updateDigits(); 
03370               ZC.repaint(); 
03371        }
03372        
03373        public void setLanguage ()
03374        {      GetParameter.InputLength=20; 
03375               GetParameter g=new GetParameter(this,
03376                      Zirkel.name("language.title"),
03377                      Zirkel.name("language.prompt"),
03378                      Zirkel.name("ok"),"language"); 
03379               g.set("default"); 
03380               g.center(this); 
03381               g.setVisible(true); 
03382               if (!g.aborted())
03383                      Global.setParameter("language",g.getResult()); 
03384        }
03385        
03386        public void print ()
03387        {      Toolkit toolkit=getToolkit(); 
03388               Properties printrefs=new Properties(); 
03389               PrintJob job=toolkit.getPrintJob(this,
03390                      Zirkel.name("program.name")+" "+FileName.filename(Filename),
03391                      printrefs); 
03392               if (job!=null)
03393               {      Graphics g=job.getGraphics(); 
03394                      Dimension dim=job.getPageDimension(); 
03395                      double res=job.getPageResolution()/2.54; 
03396                      int w=dim.width,h=dim.height; 
03397                      int d=w/10; 
03398                      w-=2*d; h-=2*d; 
03399                      double format=(double)ZC.height()/ZC.width(); 
03400                      int W=w; 
03401                      int H=(int)(W*format); 
03402                      if (H>h)
03403                      {      W=(int)(h/format); 
03404                             H=h; 
03405                      }
03406                      double xw=ZC.maxX()-ZC.minX(); 
03407                      int dd=0; 
03408                      if (Global.getParameter("print.isoscale",false) && res>0)
03409                      {      if (W/res<=xw)
03410                             {      warning(Zirkel.name("exception.printsize")); 
03411                             }
03412                             double scale=xw*res/W; 
03413                             W=(int)(W*scale); 
03414                             H=(int)(H*scale); 
03415                             dd=(w-W)/2; 
03416                      }
03417                      g.setClip(d+dd,d,W,H); 
03418                      g.translate(d+dd,d); 
03419                      Font font=g.getFont(); 
03420                      Font f; 
03421                      if (font!=null)
03422                             f=new Font(font.getName(),
03423                             Global.getParameter("font.bold",false)?Font.BOLD:Font.PLAIN,
03424                             font.getSize()*H/ZC.height()*3/
03425                             (Global.getParameter("font.large",false)?2:3)); 
03426                      else
03427                             f=new Font("Courier",
03428                             Global.getParameter("font.bold",false)?Font.BOLD:Font.PLAIN,
03429                             10*H/ZC.height()*3/
03430                             (Global.getParameter("font.large",false)?2:3)); 
03431                      g.setFont(f); 
03432                      ZC.print(g,W,H); 
03433                      job.end(); 
03434                      job.finalize(); 
03435               }
03436               else
03437               {      warning(Zirkel.name("warning.print")); 
03438               }
03439        }
03440        
03441        public void savePNG ()
03442        {      ExportScaler d=new ExportScaler(this,true);
03443               if (d.isAborted()) return;
03444               if (Global.getParameter("printscale.latex",false))
03445               {      LatexSettingsDialog lsd=new LatexSettingsDialog(this);
03446                      lsd.setVisible(true);
03447                      if (lsd.isAborted()) return;
03448               }
03449               PicSave.center(this); 
03450               if (haveFile())
03451               {      PicSave.setDirectory(FileName.path(Filename)); 
03452                      PicSave.setFilePath(FileName.purefilename(Filename)+".png"); 
03453               }
03454               PicSave.setPattern(
03455                      Global.getParameter("pattern.bitmap","*.png")); 
03456               PicSave.update(!haveFile()); 
03457               PicSave.setVisible(true); 
03458               if (PicSave.isAborted()) return; 
03459               String filename=PicSave.getFilePath(); 
03460               if (FileName.extension(filename).equals(""))
03461                      filename=filename+".png"; 
03462               if (Global.getParameter("options.filedialog",true) &&
03463                      exists(filename))
03464               {      Question qd=new Question(this,
03465                      FileName.filename(filename)+" : "+
03466                             Zirkel.name("file.exists.overwrite"),
03467                             Zirkel.name("file.exists.title"),
03468                             this,false,true); 
03469                      qd.center(this); 
03470                      qd.setVisible(true); 
03471                      if (!qd.yes()) return; 
03472               }
03473               try
03474               {      ZC.startWaiting();
03475                      ZC.savePNG(filename,Global.getParameter("printscale.latex",false));
03476               } 
03477               catch (Exception e) {}
03478               ZC.endWaiting();
03479        }
03480        
03484        public void copyPNG()
03485        {      ExportScaler d=new ExportScaler(this,true);
03486               if (d.isAborted()) return;
03487               try
03488               {      ZC.startWaiting();
03489                      if (!ZC.savePNG("",false))
03490                             warning(Global.name("exception.clipboardcopy"));
03491               } 
03492               catch (Exception e) {}
03493               ZC.endWaiting();
03494        }
03495        
03496        public void saveFIG ()
03497        {      PicSave.center(this); 
03498               if (haveFile())
03499               {      PicSave.setDirectory(FileName.path(Filename)); 
03500                      PicSave.setFilePath(FileName.purefilename(Filename)+".fig"); 
03501               }
03502               PicSave.setPattern(
03503                      Global.getParameter("pattern.fig","*.fig")); 
03504               PicSave.update(!haveFile()); 
03505               PicSave.setVisible(true); 
03506               if (PicSave.isAborted()) return; 
03507               String filename=PicSave.getFilePath(); 
03508               if (FileName.extension(filename).equals(""))
03509                      filename=filename+".fig"; 
03510               if (Global.getParameter("options.filedialog",true) &&
03511                      exists(filename))
03512               {      Question d=new Question(this,
03513                      FileName.filename(filename)+" : "+
03514                             Zirkel.name("file.exists.overwrite"),
03515                             Zirkel.name("file.exists.title"),
03516                             this,false,true); 
03517                      d.center(this); 
03518                      d.setVisible(true); 
03519                      if (!d.yes()) return; 
03520               }
03521               ZC.saveFIG(filename); 
03522        }
03523        
03524        public void saveSVG ()
03525        {      PicSave.center(this); 
03526               if (haveFile())
03527               {      PicSave.setDirectory(FileName.path(Filename)); 
03528                      PicSave.setFilePath(FileName.purefilename(Filename)+".svg"); 
03529               }
03530               PicSave.setPattern("*.svg *.svgz"); 
03531               PicSave.update(!haveFile()); 
03532               PicSave.setVisible(true); 
03533               if (PicSave.isAborted()) return; 
03534               String filename=PicSave.getFilePath(); 
03535               if (FileName.extension(filename).equals(""))
03536                      filename=filename+
03537                      (Global.getParameter("save.compress",false)?".svgz":".svg"); 
03538               if (Global.getParameter("options.filedialog",true) &&
03539                      exists(filename))
03540               {      Question d=new Question(this,
03541                      FileName.filename(filename)+" : "+
03542                             Zirkel.name("file.exists.overwrite"),
03543                             Zirkel.name("file.exists.title"),
03544                             this,false,true); 
03545                      d.center(this); 
03546                      d.setVisible(true); 
03547                      if (!d.yes()) return; 
03548               }
03549               try
03550               {      ZC.startWaiting();
03551                      ZC.saveSVG(filename);
03552               } 
03553               catch (Exception e) {}
03554               ZC.endWaiting(); 
03555        }
03556        
03557        public void savePDF ()
03558        {      ExportScaler d=new ExportScaler(this,false);
03559               if (d.isAborted()) return;
03560               PicSave.center(this); 
03561               if (haveFile())
03562               {      PicSave.setDirectory(FileName.path(Filename)); 
03563                      PicSave.setFilePath(FileName.purefilename(Filename)+".pdf"); 
03564               }
03565               PicSave.setPattern("*.pdf"); 
03566               PicSave.update(!haveFile()); 
03567               PicSave.setVisible(true); 
03568               if (PicSave.isAborted()) return; 
03569               String filename=PicSave.getFilePath(); 
03570               if (FileName.extension(filename).equals(""))
03571                      filename=filename+".pdf"; 
03572               if (Global.getParameter("options.filedialog",true) &&
03573                      exists(filename))
03574               {      Question qd=new Question(this,
03575                      FileName.filename(filename)+" : "+
03576                             Zirkel.name("file.exists.overwrite"),
03577                             Zirkel.name("file.exists.title"),
03578                             this,false,true); 
03579                      qd.center(this); 
03580                      qd.setVisible(true); 
03581                      if (!qd.yes()) return; 
03582               }
03583               try
03584               {      ZC.startWaiting();
03585                      ZC.savePDF(filename); 
03586               } 
03587               catch (Exception e) {}
03588               ZC.endWaiting(); 
03589        }
03590        
03591        public void saveEPS ()
03592        {      ExportScaler d=new ExportScaler(this,false);
03593               if (d.isAborted()) return;
03594               PicSave.center(this); 
03595               if (haveFile())
03596               {      PicSave.setDirectory(FileName.path(Filename)); 
03597                      PicSave.setFilePath(FileName.purefilename(Filename)+".eps"); 
03598               }
03599               PicSave.setPattern("*.eps *.epsz"); 
03600               PicSave.update(!haveFile()); 
03601               PicSave.setVisible(true); 
03602               if (PicSave.isAborted()) return; 
03603               String filename=PicSave.getFilePath(); 
03604               if (FileName.extension(filename).equals(""))
03605                      filename=filename+
03606                      (Global.getParameter("save.compress",false)?".epsz":".eps"); 
03607               if (Global.getParameter("options.filedialog",true) &&
03608                      exists(filename))
03609               {      Question qd=new Question(this,
03610                      FileName.filename(filename)+" : "+
03611                             Zirkel.name("file.exists.overwrite"),
03612                             Zirkel.name("file.exists.title"),
03613                             this,false,true); 
03614                      qd.center(this); 
03615                      qd.setVisible(true); 
03616                      if (!qd.yes()) return; 
03617               }
03618               try
03619               {      ZC.startWaiting();
03620                      ZC.saveEPS(filename); 
03621               } 
03622               catch (Exception e) {}
03623               ZC.endWaiting(); 
03624        }
03625        
03626        public void setVisual (boolean flag)
03627        {      Visual.setState(flag); 
03628               Global.setParameter("options.visual",flag); 
03629               ZC.Visual=flag; 
03630               IA.setState("visual",flag); 
03631               if (!flag)
03632               {      remove(StatusPanel); 
03633                      add("South",InputPanel); 
03634                      validate(); 
03635                      Input.requestFocus(); 
03636               }
03637               else
03638               {      remove(InputPanel); 
03639                      add("South",StatusPanel); 
03640                      validate(); 
03641                      String s=Status.getText(); 
03642                      Status.setText(""); 
03643                      Status.setText(s); 
03644                      ZC.getConstruction().Hidden=false; 
03645               }
03646        }
03647        
03648        public void replay ()
03649        {      ZC.OC.invalidate(ZC);
03650               ZC.getConstruction().setOriginalOrder(true);
03651               Replay r=new Replay(this,ZC); 
03652               r.setVisible(true);
03653               ZC.getConstruction().setOriginalOrder(false);
03654               ZC.validate();
03655               ZC.repaint();
03656        }
03657        
03658        public void editIcons ()
03659        {      EditIconBar b=new EditIconBar(this,
03660               RestrictIcons.getState()); 
03661               if (!b.isAbort()) remakeIconBar(); 
03662        }
03663        
03664        public void makeMainPanel ()
03665        {      MainPanel=new MyPanel(); 
03666               MainPanel.setLayout(new BorderLayout()); 
03667               if (Global.getParameter("options.iconbartop",true))
03668               {      MainPanel.add("North",North); 
03669                      MainPanel.add("Center",Center); 
03670               }
03671               else
03672               {      MainPanel.add("Center",Center); 
03673                      MainPanel.add("South",North); 
03674               }
03675        }
03676        
03677        Panel CDP3D;
03678        MouseAdapter CDPMA;
03679        
03680        public Panel makeCenterPanel ()
03681        {      if (Global.getParameter("options.showdisplay",true))
03682               {      Panel center=new MyPanel();
03683                      center.setLayout(new BorderLayout());
03684                      ZC.CDP=new ConstructionDisplayPanel(ZC);
03685                      ZC.CDP.setListingBackground(Global.getParameter("colorbackground",
03686                             Color.white));
03687                      ZC.reloadCD();
03688                      CDP3D=new Panel3D(ZC.CDP);
03689                      center.add("West",CDP3D);
03690                      center.add("Center",CenterPanel=new Panel3D(ZC,ZC.getBackground()));
03691                      CDP3D.addMouseListener(CDPMA=new MouseAdapter ()
03692                                    {      public void mousePressed (MouseEvent e) 
03693                                           {      centerResizeStart(e.getX());
03694                                           }
03695                                           public void mouseReleased (MouseEvent e)
03696                                           {      centerResizeEnd(e.getX());
03697                                           }
03698                                    }
03699                             );
03700                      return center;
03701               }
03702               else
03703               {      ZC.CDP=null;
03704                      return new Panel3D(ZC,ZC.getBackground());
03705               }
03706        }
03707        
03708        public int resizeCol;
03709        boolean resizeFlag=false;
03710        
03711        public void centerResizeStart (int col)
03712        {      if (CDP3D.getSize().width-col>10) return;
03713               resizeCol=col; resizeFlag=true;
03714               setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
03715        }
03716        
03717        public void centerResizeEnd (int col)
03718        {      if (!resizeFlag) return;
03719               setCursor(Cursor.getDefaultCursor());
03720               int c=Global.getParameter("options.constructiondisplay.width",200);
03721               c=c+(col-resizeCol);
03722               if (c<10) c=10;
03723               if (c>600) c=600;
03724               Global.setParameter("options.constructiondisplay.width",c);
03725               CDP3D.removeMouseListener(CDPMA);
03726               Center=makeCenterPanel();
03727               remove(MainPanel); 
03728               makeMainPanel(); 
03729               add("Center",MainPanel); 
03730               validate(); 
03731               repaint();
03732               ZC.requestFocus();
03733        }
03734        
03735        public void reset ()
03736        {      ZC.reset(); 
03737               if (CurrentTool==NTargets) settool(NParameters); 
03738        }
03739        
03740        public void browser ()
03741        {      try
03742               {      Runtime R=Runtime.getRuntime(); 
03743                      String user=Global.getParameter("browser.user",""); 
03744                      if (user.equals(""))
03745                      {      String file=Zirkel.name("homefile"); 
03746                             if (!new File(file).exists())
03747                                    file=Zirkel.name("homepage")+file; 
03748                             String os=System.getProperty("os.name"); 
03749                             String browser="netscape"; 
03750                             if (os.indexOf("Windows")>=0)
03751                             {      browser="explorer"; 
03752                             }
03753                             exec(R,"\""+browser+"\" \""+file+"\""); 
03754                      }
03755                      else
03756                             exec(R,user); 
03757               }
03758               catch (Exception e)
03759               {      e.printStackTrace(); configure(); 
03760               }
03761        }
03762        
03763        public void exec (Runtime r, String s)
03764               throws Exception
03765        {      Vector v=new Vector();
03766               int pos=0;
03767               s=s.trim();
03768               while (pos<s.length())
03769               {      if (s.charAt(pos)==' ')
03770                      {      pos++;
03771                      }
03772                      else if (s.charAt(pos)=='\"')
03773                      {      pos++;
03774                             int n=s.indexOf('\"',pos);
03775                             if (n>=0)
03776                             {      v.addElement(s.substring(pos,n));
03777                                    pos=n+1;
03778                             }
03779                             else
03780                             {      v.addElement(s.substring(pos));
03781                                    break;
03782                             }
03783                      }
03784                      else
03785                      {      int n=s.indexOf(' ',pos);
03786                             if (n>=0)
03787                             {      v.addElement(s.substring(pos,n));
03788                                    pos=n+1;
03789                             }
03790                             else
03791                             {      v.addElement(s.substring(pos));
03792                                    break;
03793                             }
03794                      }
03795               }
03796               String c[]=new String[v.size()];
03797               for (int i=0; i<c.length; i++)
03798               {      c[i]=(String)v.elementAt(i);
03799               }
03800               r.exec(c);
03801        }
03802        
03803        public void configure ()
03804        {      GetParameter.InputLength=50; 
03805               GetParameter g=new GetParameter(this,
03806                      Zirkel.name("configure.title"),
03807                      Zirkel.name("configure.prompt"),
03808                      Zirkel.name("ok"),"browser"); 
03809               String user=Global.getParameter("browser.user",""); 
03810               if (user.equals(""))
03811               {      String file=Zirkel.name("homefile"); 
03812                      if (!new File(file).exists())
03813                             file=Zirkel.name("homepage")+file; 
03814                      String browser="netscape"; 
03815                      String os=System.getProperty("os.name"); 
03816                      if (os.indexOf("Windows")>=0) browser="explorer";
03817                      user="\""+browser+"\" \""+file+"\"";
03818               }
03819               g.set(user); 
03820               g.center(this); 
03821               g.setVisible(true); 
03822               if (!g.aborted())
03823                      Global.setParameter("browser.user",g.getResult()); 
03824        }
03825        
03826        public void dograb ()
03827        {      if (IA.getState("grab")) ZC.grab(true); 
03828               else ZC.grab(false); 
03829               Background=""; 
03830        }
03831        
03832        public void dograb (boolean flag)
03833        {      ZC.grab(flag); 
03834               IA.setState("grag",flag); 
03835               Background=""; 
03836        }
03837        
03838        public String loadImage ()
03839        {      ImageLoad.center(this); 
03840               ImageLoad.update(); 
03841               ImageLoad.setVisible(true); 
03842               if (ImageLoad.isAborted()) return ""; 
03843               return ImageLoad.getFilePath();
03844        }
03845        
03846        public Image doLoadImage (String filename)
03847        {      filename=FileName.path(Filename)+System.getProperty("file.separator")+filename;
03848               try
03849               {      Image i=getToolkit().getImage(filename); 
03850                      MediaTracker mt=new MediaTracker(this); 
03851                      mt.addImage(i,0); 
03852                      mt.waitForID(0); 
03853                      if (mt.checkID(0) && !mt.isErrorAny())
03854                      {      return i; 
03855                      }
03856                      else throw new Exception(Zirkel.name("error.image")); 
03857               }
03858               catch (Exception e)
03859               {      new ShowWarning(this,e.toString()); 
03860                      return null; 
03861               }
03862        }      
03863        
03867        public void loadBackground ()
03868        {      BackgroundLoad.center(this); 
03869               BackgroundLoad.update(); 
03870               BackgroundLoad.setVisible(true); 
03871               if (BackgroundLoad.isAborted()) return; 
03872               String filename=BackgroundLoad.getFilePath();
03873               doloadBackground(filename);
03874        }
03875        
03876        public void doloadBackground (String filename)
03877        {      try
03878               {      Image i=getToolkit().getImage(filename); 
03879                      MediaTracker mt=new MediaTracker(this); 
03880                      mt.addImage(i,0); 
03881                      mt.waitForID(0); 
03882                      if (mt.checkID(0) && !mt.isErrorAny())
03883                      {      ZC.setBackground(i); 
03884                             IA.setState("grab",true); 
03885                             if (Global.getParameter("background.usesize",false)) resize(); 
03886                      }
03887                      else throw new Exception(Zirkel.name("background.loaderror")); 
03888                      Background=FileName.filename(filename); 
03889               }
03890               catch (Exception e)
03891               {      warning(e.toString()); 
03892                      Background=""; 
03893               }
03894        }      
03895        
03896        public void resize   ()
03897        {      pack(); 
03898        }
03899        
03900        public void track ()
03901        {      if (ZC.getCurrentTool() instanceof ObjectTracker &&
03902               ((ObjectTracker)ZC.getCurrentTool()).isComplete())
03903               {      Question q=new Question(this,
03904                      Zirkel.name("trackquestion.keep"),
03905                             Zirkel.name("trackquestion.title"),true); 
03906                      q.center(this); 
03907                      q.setVisible(true); 
03908                      if (q.yes()) ((ObjectTracker)ZC.getCurrentTool()).keep(ZC); 
03909               }
03910        }
03911        
03912        public void restrictIcons (boolean flag)
03913        {      if (flag)
03914               {      RestrictIcons.setState(true); 
03915                      showDefaultIcons(false);
03916                      remakeIconBar(); 
03917               }
03918               else
03919               {      RestrictIcons.setState(false); 
03920                      showDefaultIcons(true);
03921                      remakeIconBar(); 
03922               }
03923        }
03924        
03925        Info InfoWindow; 
03926        
03927        public synchronized void removeInfo ()
03928        {      InfoWindow=null; 
03929        }
03930        
03931        public synchronized void info ()
03932        {      if (InfoWindow!=null)
03933               {      InfoWindow.doclose(); 
03934               }
03935               else 
03936               {      InfoWindow=new Info(this); 
03937               }
03938        }
03939        
03940        public void setinfo (String s)
03941        {      Info.Subject=s; 
03942               if (InfoWindow!=null) InfoWindow.fill(); 
03943        }
03944        
03950        public void loadDefaultMacros ()
03951        {      String Filename=".default.mcr";
03952               if (new File("."+Zirkel.name("language","")+"default.mcr").exists())
03953                      Filename="."+Zirkel.name("language","")+"default.mcr";
03954               if (new File(Filename).exists())
03955               {      try
03956                      {      InputStream o=new FileInputStream(Filename); 
03957                             if (isCompressed(Filename))
03958                                    o=new GZIPInputStream(o); 
03959                             ZC.ProtectMacros=true;
03960                             ZC.load(o,false,true); 
03961                             ZC.ProtectMacros=false;
03962                             o.close();
03963                      }
03964                      catch (Exception e)
03965                      {      warning(Zirkel.name("warning.load"));
03966                      }
03967                      return;
03968               }
03969               try
03970               {      InputStream o=
03971                             getClass().getResourceAsStream("/"+
03972                                    Zirkel.name("language","")+"default.mcr"); 
03973                      ZC.ProtectMacros=true;
03974                      ZC.load(o,false,true); 
03975                      ZC.ProtectMacros=false;
03976                      o.close();           
03977                      return;       
03978               }
03979               catch (Exception e) {}
03980               try
03981               {      InputStream o=
03982                             getClass().getResourceAsStream("/default.mcr"); 
03983                      ZC.ProtectMacros=true;
03984                      ZC.load(o,false,true); 
03985                      ZC.ProtectMacros=false;
03986                      o.close();
03987                      return;                     
03988               }
03989               catch (Exception e) {}
03990        }
03991 
03992        public void showDefaultIcons (boolean flag)
03993        {      if (!flag) ZC.clearProtectedMacros();
03994               else loadDefaultMacros();
03995        }      
03996 
04004        public boolean haveHelp (String subject)  
04005        {      String lang=Zirkel.name("language","");
04006               try
04007               {      BufferedReader in=new BufferedReader(new InputStreamReader(
04008                             getClass().getResourceAsStream("/rene/zirkel/docs/"+lang+subject)));
04009                      in.close();
04010               }
04011               catch (Exception e)
04012               {      return false;
04013               }
04014               return true;
04015        }
04016        
04021        public boolean haveFile ()
04022        {      return !Filename.equals("");
04023        }
04024        
04025        public void newfile (boolean defaults)
04026        {      if (ZC.changed())
04027               {      Question q=new Question(this,Zirkel.name("savequestion.qsave"),
04028                      Zirkel.name("savequestion.title"),true); 
04029                      q.center(this); 
04030                      q.setVisible(true); 
04031                      if (q.yes() && !savefile()) return; 
04032                      if (q.isAborted()) return; 
04033               }
04034               clear(defaults); 
04035               if (RestrictIcons.getState())
04036               {      RestrictIcons.setState(false); 
04037                      showDefaultIcons(true);
04038                      remakeIconBar(); 
04039               }
04040               Filename=""; 
04041               clearNonprotectedMacros();
04042               setTitle(Zirkel.name("program.name")); 
04043        }
04044 
04045        public void warning (String s)
04046        {      Warning w=new Warning(this,s,
04047                             "",true);
04048               w.center(this);
04049               w.setVisible(true);
04050        }
04051 
04056        public void showConstructionDisplay (boolean flag)
04057        {      Global.setParameter("options.showdisplay",flag);
04058               notePosition("zirkelframe");
04059               ConstructionDisplay.setState(flag);
04060               Center=makeCenterPanel();
04061               ZC.UseSize=ZC.getSize();
04062               remove(MainPanel); 
04063               makeMainPanel(); 
04064               add("Center",MainPanel); 
04065               validate();
04066               // resize();
04067               ZC.UseSize=null;
04068               repaint();
04069               ZC.requestFocus();
04070        }
04071 
04076        public void sethidden (boolean flag)
04077        {      ZC.setShowHidden(flag); 
04078               IA.setState("hidden",flag); 
04079               ShowHidden.setState(flag);
04080        }
04081 
04082        public void editGrid ()
04083        {      EditGridDialog d=new EditGridDialog(this);
04084               ZC.setGrid();
04085               ZC.repaint();
04086        }
04087 }