Back to index

wims  3.65+svn20090927
ZirkelApplet.java
Go to the documentation of this file.
00001 package rene.zirkel;
00002 //
00003 import java.awt.datatransfer.*;                                                                                                            
00004 import rene.util.xml.*;                                                                                                                    
00005 import rene.dialogs.*;                                                                                                                     
00006 import rene.zirkel.expression.*;                                                                                                           
00007 import rene.zirkel.graphics.*;                                                                                                             
00008 import rene.zirkel.structures.*;                                                                                                           
00009 import rene.util.sort.*;
00010 //
00011 import java.applet.*;
00012 import java.awt.*;
00013 import java.awt.event.*;
00014 import java.io.*;
00015 import java.net.*;
00016 import java.util.*;
00017 import java.util.zip.*;
00018 import rene.dialogs.Warning;
00019 import rene.gui.*;
00020 import rene.util.*;
00021 import rene.util.parser.StringParser;
00022 import rene.zirkel.construction.*;
00023 import rene.zirkel.constructors.*;
00024 import rene.zirkel.dialogs.*;
00025 import rene.zirkel.listener.*;
00026 import rene.zirkel.macro.*;
00027 import rene.zirkel.objects.*;
00028 import rene.zirkel.tools.*;
00029 
00030 public class ZirkelApplet extends Applet
00031        implements IconBarListener, StatusListener, KeyListener, DoneListener,
00032        DoActionListener, ZirkelCanvasInterface
00033 {      ZirkelCanvas ZC;
00034        IconBar IA,IB,IC;
00035        MacroBar IM;
00036        String filename="test.zir";
00037        Label Status;
00038        Color C,CC;
00039        Frame F;
00040        // jm.evers
00041        public static String xaxis_text="x-axis";
00042        public static String yaxis_text="y-axis";
00043        public static boolean yaxis_text_vertical=false;
00044        public static String xaxis_variable="X";
00045        public static String yaxis_variable="Y";
00046        public static int decimals=2;
00047        // end jm.evers
00048        String FirstConstructor="point",Tools="all",Options="";
00049        int CurrentTool=0;
00050        HistoryTextField Input;
00051        ConstructionObject Last=null;
00052        boolean edit;
00053        boolean jumptostart; // for applets with replay buttons and start()
00054        
00055        final static public String DefaultIcons=
00056               " point line segment area ray circle fixedcircle"+
00057               " parallel plumb circle3 midpoint angle fixedangle"+
00058               " move tracker objecttracker hide expression text quadric"+
00059               " runmacro animate ";
00060        final static public String DefaultOptions=
00061               " back undo delete color type thickness"+
00062               " hidden showcolor macro grid "+
00063               " draw twolines indicate "
00064               ;
00065        
00066        public void init ()
00067        {      
00068               
00069               String lang=getParameter("language");   
00070               if (lang!=null){
00071                   System.out.println("lang="+getParameter("language"));
00072                   try
00073                   {  
00074                      Locale.setDefault(new Locale(lang,""));
00075                   }
00076                   catch (RuntimeException e) {}
00077                   //jm.evers
00078                   Global.initBundle("rene/zirkel/docs/ZirkelProperties_"+lang);
00079               }
00080               else
00081               {
00082                   Global.initBundle("rene/zirkel/docs/ZirkelProperties");
00083               }
00084 
00085               Count.resetAll();
00086               CC=C=Global.Background;
00087               initLightColors();
00088               initObjectKeys();
00089               Dimension dscreen=getToolkit().getScreenSize();
00090               F=new Frame();
00091               F.setSize(dscreen);
00092               
00093               if (getParameter("oldicons")==null)
00094               {      Global.setParameter("iconpath","/rene/zirkel/newicons/");
00095                      Global.setParameter("iconsize",getParameter("smallicons")==null?32:24);
00096                      Global.setParameter("icontype","png");
00097               }
00098               else
00099               {      Global.setParameter("iconpath","/rene/zirkel/icons/");
00100                      Global.setParameter("iconsize",20);
00101               }      
00102               
00103               String color=getParameter("color");
00104               if (color!=null)
00105               {      StringParser p=new StringParser(getParameter("color"));
00106                      p.replace(',',' ');
00107                      int red,green,blue;
00108                      red=p.parseint(); green=p.parseint(); blue=p.parseint();
00109                      C=new Color(red,green,blue);
00110                      Global.Background=C;
00111                      Global.ControlBackground=C;
00112                      CC=C;
00113               }
00114               
00115               color=getParameter("colorbackground");
00116               if (color!=null) Global.setParameter("colorbackground",color);
00117               else Global.removeParameter("colorbackground");
00118               color=getParameter("colorselect");
00119               if (color!=null) Global.setParameter("colorselect",color);
00120               else Global.removeParameter("colorselect");
00121               ZirkelFrame.SelectColor=Global.getParameter("colorselect",Color.red);
00122               color=getParameter("colortarget");
00123               if (color!=null) Global.setParameter("colortarget",color);
00124               else Global.removeParameter("colortarget");
00125               ZirkelFrame.TargetColor=Global.getParameter("colorselect",Color.pink);
00126               ZirkelFrame.initLightColors(Color.white);                      
00127               
00128               
00129               String font=getParameter("font");
00130               if (font!=null)
00131               {      if (font.indexOf("bold")>=0)
00132                             Global.setParameter("font.bold",true);
00133                      if (font.indexOf("large")>=0)
00134                             Global.setParameter("font.large",true);                        
00135               }
00136               
00137               if (getParameter("demo")!=null)
00138               {      initDemo();
00139                      return;
00140               }
00141               
00142               String style=getParameter("style");
00143               if (style==null) style="plain";
00144               
00145               boolean simple=(style.equals("plain") || style.equals("3D") ||
00146                      style.equals("breaks"));
00147               edit=!simple;
00148               boolean status=(style.equals("full") || style.equals("status"));
00149               boolean icons=(style.equals("full") || style.equals("nonvisual")
00150                      || style.equals("icons") );
00151               boolean breaks=(style.equals("breaks"));
00152               
00153               if (getParameter("edit")!=null) edit=true;
00154               
00155               for (int i=0; i<ZirkelFrame.Colors.length; i++)
00156               {      color=getParameter("color"+i);
00157                      if (color!=null) Global.setParameter("color"+i,color);
00158                      else Global.removeParameter("color"+i);
00159               }
00160               
00161               ZirkelFrame.initLightColors(Color.white);                      
00162               setLayout(new BorderLayout());
00163 
00164               Tools=getParameter("tools");
00165               if (Tools==null || Tools.equals("defaults")) Tools=DefaultIcons;
00166               
00167               Options=getParameter("options");
00168               if (Options==null || Options.equals("defaults")) Options=DefaultOptions;
00169               
00170               Global.setParameter("macrobar",Options.indexOf("macrobar")>=0);
00171               makeMacroBar();
00172               
00173               if (icons)
00174               {      IB=new IconBar(F);
00175                      IB.setBackground(CC);
00176                      IB.setIconBarListener(this);
00177                      StringTokenizer t=new StringTokenizer(Tools);
00178                      int count=0;
00179                      while (t.hasMoreTokens())
00180                      {      t.nextToken(); count++;
00181                      }
00182                      String a[]=new String[count];
00183                      t=new StringTokenizer(Tools);
00184                      count=0;
00185                      while (t.hasMoreTokens())
00186                      {      a[count++]=t.nextToken();
00187                      }
00188                      if (count>0) FirstConstructor=a[0];
00189                      IB.addToggleGroupLeft(a);
00190                      IB.addSeparatorLeft();
00191                      if (Options.indexOf("twolines")>=0 || Options.indexOf("defaults")>=0)
00192                      {      IA=new IconBar(F);
00193                             IA.setBackground(CC);
00194                             IA.setIconBarListener(this);
00195                             setIA(IA,Options);
00196                             Panel north=new Panel();
00197                             north.setBackground(CC);
00198                             north.setLayout(new GridLayout(0,1));
00199                             north.add(IA);
00200                             north.add(IB);
00201                             if (IM!=null) north.add(IM);
00202                             add("North",new Panel3D(north,CC));
00203                      }
00204                      else
00205                      {      IA=IB;
00206                             setIA(IB,Options);
00207                             if (IM!=null)
00208                             {      Panel north=new Panel();
00209                                    north.setBackground(CC);
00210                                    north.setLayout(new GridLayout(0,1));
00211                                    north.add(IA);
00212                                    if (IM!=null) north.add(IM);
00213                                    add("North",new Panel3D(north,CC));                                   
00214                             }
00215                             else
00216                             {      add("North",new Panel3D(IB,CC));
00217                             }
00218                      }
00219               }
00220               else IA=IB=null;
00221               
00222               Global.setParameter("options.intersection",false);
00223               Global.setParameter("options.pointon",false);
00224               Global.setParameter("options.choice",false);
00225               
00226               if (Options.indexOf("qchoice")>=0)
00227               {      Global.setParameter("options.choice",true);
00228               }
00229               if (Options.indexOf("qintersection")>=0)
00230               {      Global.setParameter("options.intersection",true);
00231               }
00232               if (Options.indexOf("qpointon")>=0)
00233               {      Global.setParameter("options.pointon",true);
00234               }
00235               Global.setParameter("options.indicate",true);
00236               Global.setParameter("options.indicate.simple",Options.indexOf("noindicate")>=0);
00237               
00238               if (getParameter("selectionsize")!=null)
00239               {      try
00240                      {      double x=new Double(getParameter("selectionsize")).doubleValue();
00241                             Global.setParameter("selectionsize",x);
00242                      }
00243                      catch (Exception e) {}
00244               }
00245 
00246               ZC=new ZirkelCanvas(!edit,!breaks,!breaks);
00247               ZC.addMouseListener(ZC);
00248               ZC.addMouseMotionListener(ZC);
00249               ZC.setBackground(Global.getParameter("colorbackground",C));
00250               ZC.setFrame(F);
00251               ZC.setZirkelCanvasListener(this);
00252               if (getParameter("showhidden")!=null) ZC.setShowHidden(true);
00253               if (style.equals("plain")) add("Center",ZC);
00254               else add("Center",new Panel3D(ZC,ZC.getBackground()));
00255               ZC.addStatusListener(this);
00256               ZC.addKeyListener(this);
00257               
00258               setShowNames(false);
00259               
00260               if (status)
00261               {      Status=new Label("");
00262                      Status.setBackground(CC);
00263                      add("South",new Panel3D(Status,Status.getBackground()));
00264               }
00265               else if (style.equals("nonvisual"))
00266               {      Input=new HistoryTextField(this,"Input");
00267                      ZC.setTextField(Input);
00268                      ZC.Visual=false;
00269                      setShowNames(true);
00270                      add("South",new Panel3D(Input));
00271               }
00272               
00273               try
00274               {      Global.setParameter("digits.edit",
00275                             Integer.parseInt(getParameter("editdigits")));
00276               }
00277               catch (Exception e) {}
00278               try
00279               {      Global.setParameter("digits.lengths",
00280                             Integer.parseInt(getParameter("displaydigits")));
00281               }
00282               catch (Exception e) {}
00283               try
00284               {      Global.setParameter("digits.angles",
00285                             Integer.parseInt(getParameter("angledigits")));
00286               }
00287               catch (Exception e) {}
00288               
00289               setOption("movename");
00290               setOption("movefixname");
00291               ZC.updateDigits();
00292               
00293               setOption("nopopupmenu");
00294               setOption("nomousezoom");
00295                             
00296               try
00297               {      Global.setParameter("minpointsize",
00298                             new Double(getParameter("minpointsize")).doubleValue());
00299               }
00300               catch (Exception e) {}
00301               try
00302               {      Global.setParameter("minlinesize",
00303                             new Double(getParameter("minlinewidth")).doubleValue());
00304               }
00305               catch (Exception e) {}
00306               try
00307               {      Global.setParameter("minfontsize",
00308                             new Double(getParameter("minfontsize")).doubleValue());
00309               }
00310               catch (Exception e) {}
00311               try
00312               {      Global.setParameter("arrowsize",
00313                             new Double(getParameter("arrowsize")).doubleValue());
00314               }
00315               catch (Exception e) {}
00316 
00317               try
00318               {      String grid=getParameter("grid");
00319                      ZC.ShowGrid=!grid.equals("none");
00320                      Global.setParameter("grid.fine",grid.equals("coordinates"));
00321                      if ( getParameter("snap").equalsIgnoreCase("left") || getParameter("snap").equalsIgnoreCase("yes") ){
00322                             Global.setParameter("grid.leftsnap",true);
00323                      }
00324                      else
00325                      {
00326                          Global.setParameter("grid.leftsnap",false);
00327                      }
00328               }
00329               catch (Exception e) {}
00330 
00331               if (getParameter("interactive")!=null && 
00332                      getParameter("interactive").equals("false"))
00333                             ZC.setInteractive(false);
00334 
00335               boolean job=false;
00336 
00337               ZC.IW=getSize().width;
00338               ZC.IH=getSize().height;
00339               
00340               if (getParameter("germanpoints")!=null
00341                      && getParameter("germanpoints").equals("true"))
00342                             Global.setParameter("options.germanpoints",true);
00343               // jm.evers          
00344               String c=getParameter("background_image");
00345               if (c!=null && c.length()>0) {
00346                   URL url;
00347                   try {url=new URL(c);}
00348                   catch (MalformedURLException e) {url=null;}
00349                   if(url!=null){
00350                      //System.out.println("trying:"+url);
00351                      try{
00352                          Image i=getToolkit().getImage(url);
00353                          MediaTracker mt=new MediaTracker(this);
00354                          mt.addImage(i,0);
00355                          mt.waitForID(0);
00356                          if (mt.checkID(0) && !mt.isErrorAny()){
00357                             ZC.setBackground(i);ZC.repaint();
00358                             Global.setParameter("background.usesize",true);  
00359                          }
00360                      }
00361                      catch (Exception e) { System.out.println("Image could not be loaded"); }            
00362                   }
00363               }
00364 
00365               c=getParameter("x_axis_text");
00366               if(c!=null && c.length()>0){xaxis_text=c;}
00367               c=getParameter("y_axis_text");
00368               if(c!=null && c.length()>0){yaxis_text=c;}
00369               c=getParameter("y_axis_text_vertical");
00370               if(c!=null && c.length()>0){
00371                   if(c.equalsIgnoreCase("yes") || c.equalsIgnoreCase("true") ){yaxis_text_vertical=true;}else{yaxis_text_vertical=false;}
00372               }
00373               c=getParameter("xaxis_variable");
00374               if(c!=null && c.length()>0){xaxis_variable=c;}
00375               c=getParameter("yaxis_variable");
00376               if(c!=null && c.length()>0){yaxis_variable=c;}
00377               c=getParameter("decimals");
00378               if(c!=null && c.length()>0){decimals=Integer.parseInt(c,10);}
00379               
00380               // end jm.evers
00381                             
00382               filename=getParameter("file");
00383               if (filename==null)
00384               {      filename=getParameter("job");
00385                      job=true;
00386               }
00387               if (filename!=null)
00388               {      boolean firsttry=true;
00389                      while (true)
00390                      {      try
00391                             {      URL url;
00392                                    if (filename.toUpperCase().startsWith("HTTP"))
00393                                           url=new URL(
00394                                                  firsttry?FileName.toURL(filename):filename);
00395                                    else
00396                                           url=new URL(getCodeBase(),
00397                                                  firsttry?FileName.toURL(filename):filename);
00398                                    
00399                                    ZC.clear();
00400                                    InputStream in=url.openStream();
00401                                    if (ZirkelFrame.isCompressed(filename))
00402                                           in=new GZIPInputStream(in);
00403                                    showStatus(Global.name("loading"));
00404                                    ZC.load(in);
00405                                    toggleGrid(ZC.ShowGrid);
00406                                    if (job)
00407                                    {      ZC.displayJob(true);
00408                                           ZC.setDoneListener(this);
00409                                    }
00410                                    if (icons) iconPressed(FirstConstructor);
00411                                    in.close();
00412                                    if (getParameter("background")!=null)
00413                                    {
00414                                        Image i=getToolkit().getImage(new URL(getCodeBase(),
00415                                                  getParameter("background")));
00416                                           MediaTracker mt=new MediaTracker(this);
00417                                           mt.addImage(i,0);
00418                                           mt.waitForID(0);
00419                                           if (mt.checkID(0) && !mt.isErrorAny())
00420                                           {      ZC.setBackground(i);
00421                                           }
00422                                    }
00423                                    ZC.repaint();
00424                             }
00425                             catch (Exception e)
00426                             {      if (firsttry)
00427                                    {      firsttry=false; continue;
00428                                    }
00429                                    Warning w=new Warning(F,FileName.chop(32,""+e,64),
00430                                           Zirkel.name("message"),true);
00431                                    w.center(F);
00432                                    w.setVisible(true);
00433                                    showStatus(""+e);
00434                                    e.printStackTrace();
00435                                    System.out.println(e);
00436                             }
00437                             break;
00438                      }
00439               }
00440 
00441               if (breaks)
00442               {      IC=new IconBar(F);
00443                      IC.setBackground(CC);
00444                      IC.setIconBarListener(this);
00445                      IC.addLeft("allback");
00446                      if (haveBreaks()) IC.addLeft("nextbreak");
00447                      else IC.addLeft("oneforward");
00448                      IC.addLeft("allforward");
00449                      Panel pic=new Panel3D(IC);
00450                      add("South",pic);
00451                      IC.setEnabled("nextbreak",false);
00452                      IC.setEnabled("oneforward",false);
00453                      IC.setEnabled("allforward",false);
00454                      ZC.getConstruction().setOriginalOrder(true);
00455                      jumptostart=(getParameter("jumptostart")!=null);
00456               }
00457 
00458               if (getParameter("restrictedmove")!=null)
00459               {      Global.setParameter("restrictedmove",true);
00460               }
00461               
00462               if (getParameter("noconfirmation")!=null)
00463               {      Global.setParameter("confirmation",false);
00464               }
00465               
00466               if (IA!=null) settype(2);
00467               ZC.setMacroBar(IM);
00468               ZC.updateMacroBar();
00469               ZC.recompute();
00470               ZC.repaint();
00471        }
00472        
00473        public void setOption (String option)
00474        {      try
00475               {      Global.setParameter("options."+option,
00476                             getParameter(option).equals("true"));
00477               }
00478               catch (Exception e) {}
00479        }
00480 
00481        DemoRunner DR=null;
00482        
00483        void initDemo ()
00484        {      setLayout(new BorderLayout());
00485 
00486               ZC=new ZirkelCanvas(false,false,false);
00487               ZC.setBackground(Global.getParameter("colorbackground",C));
00488               ZC.setFrame(F);
00489               ZC.setZirkelCanvasListener(this);
00490               if (getParameter("showhidden")!=null) ZC.setShowHidden(true);
00491               add("Center",new Panel3D(ZC,ZC.getBackground()));
00492 
00493               Status=new Label("",Label.CENTER);
00494               Status.setBackground(C);
00495               add("South",new Panel3D(Status,Status.getBackground()));
00496               
00497        }
00498 
00499        void setIA (IconBar IA, String set)
00500        {      if (set.indexOf("back")>=0)
00501                      IA.addLeft("back");
00502               if (set.indexOf("delete")>=0)
00503                      IA.addToggleLeft("delete");
00504               if (set.indexOf("undo")>=0)
00505                      IA.addLeft("undo");
00506               if (set.indexOf("hidden")>=0)
00507                      IA.addOnOffLeft("hidden");
00508               if (set.indexOf("showcolor")>=0)
00509                      IA.addMultipleIconLeft("showcolor",ZirkelFrame.Colors.length);
00510               if (set.indexOf("color")>=0)
00511                      IA.addMultipleIconLeft("color",6);
00512               if (set.indexOf("type")>=0)
00513                      IA.addMultipleIconLeft("type",4);
00514               if (set.indexOf("thickness")>=0)
00515                      IA.addMultipleIconLeft("thickness",3);
00516               if (set.indexOf("partial")>=0)
00517                      IA.addOnOffLeft("partial");
00518               if (set.indexOf("plines")>=0)
00519                      IA.addOnOffLeft("plines");
00520               if (set.indexOf("arrow")>=0)
00521                      IA.addOnOffLeft("arrow");
00522               if (set.indexOf("showname")>=0)
00523                      IA.addOnOffLeft("showname");
00524               if (set.indexOf("showvalue")>=0)
00525                      IA.addOnOffLeft("showvalue");
00526               if (set.indexOf("edit")>=0)
00527                      IA.addToggleLeft("edit");
00528               if (set.indexOf("obtuse")>=0)
00529                      IA.addOnOffLeft("obtuse");
00530               if (set.indexOf("solid")>=0)
00531                      IA.addOnOffLeft("solid");
00532               if (set.indexOf("grid")>=0)
00533                      IA.addOnOffLeft("grid");
00534               if (set.indexOf("macro")>=0)
00535                      IA.addMultipleToggleIconLeft("macro",3);
00536               if (set.indexOf("replay")>=0)
00537                      IA.addLeft("replay");
00538               if (set.indexOf("zoom")>=0)
00539                      IA.addToggleLeft("zoom");
00540               if (set.indexOf("comment")>=0)
00541                      IA.addLeft("comment");
00542               if (set.indexOf("function")>=0)
00543                      IA.addLeft("function");
00544               if (set.indexOf("draw")>=0)
00545                      IA.addToggleLeft("draw");
00546        }
00547        
00548        public void makeMacroBar ()
00549        {      if (Global.getParameter("macrobar",true))
00550               {      IM=new MacroBar(F);
00551                      IM.addKeyListener(this); 
00552                      IM.setIconBarListener(this);
00553                      IM.setBackground(CC);
00554               }
00555        }
00556        
00557        public void updateMacroBar ()
00558        {      ZC.updateMacroBar();
00559        }
00560        
00561        Replay RD=null;
00562 
00563        public void iconPressed (String o)
00564        {      if (RD!=null) RD.doclose();
00565               ZC.requestFocus();
00566               if (IA!=null && IA.isControlPressed())
00567               {      if (o.equals("edit"))
00568                      {      if (CurrentTool!=ZirkelFrame.NEdit) IA.setState("edit",false);
00569                             ZC.editLast();
00570                             ZC.repaint();
00571                      }
00572                      IA.clearShiftControl();
00573                      return;
00574               }
00575               for (int i=0; i<ZirkelFrame.ObjectStrings.length; i++)
00576                      if (o.equals(ZirkelFrame.ObjectStrings[i]))
00577                      {      if (i==ZirkelFrame.NMacro) runmacro(IB.isShiftPressed());
00578                             else settool(i);
00579                             return;
00580                      }
00581               if (IM!=null) // Search in the macro line
00582               {      Macro m=IM.find(o);
00583                      if (m!=null) 
00584                      {      runMacro(m);
00585                             return;
00586                      }
00587               }
00588               if (o.equals("hidden"))
00589               {      ZC.setShowHidden(IA.getState("hidden"));
00590               }
00591               else if (o.equals("partial"))
00592               {      ZC.setPartial(IA.getState("partial"));
00593               }
00594               else if (o.equals("plines"))
00595               {      ZC.setPartialLines(IA.getState("plines"));
00596               }
00597               else if (o.equals("arrow"))
00598               {      ZC.setVectors(IA.getState("arrow"));
00599               }
00600               else if (o.equals("color"))
00601               {      int n=IA.getMultipleState("color");
00602                      if (n>=0) setcolor(n);
00603               }
00604               else if (o.equals("showcolor"))
00605               {      int n=IA.getMultipleState("showcolor");
00606                      if (n>=0) showcolor(n);
00607               }
00608               else if (o.equals("showname"))
00609               {      setShowNames(IA.getState("showname"));
00610               }
00611               else if (o.equals("obtuse"))
00612               {      setObtuse(IA.getState("obtuse"));
00613               }
00614               else if (o.equals("solid"))
00615               {      setSolid(IA.getState("solid"));
00616               }
00617               else if (o.equals("showvalue"))
00618               {      setShowValues(IA.getState("showvalue"));
00619               }
00620               else if (o.equals("longnames"))
00621               {      setLongNames(IA.getState("longnames"));
00622               }
00623               else if (o.equals("grid"))
00624               {      toggleGrid(IA.getState("grid"));
00625               }
00626               else if (o.equals("comment"))
00627               {      showcomment();
00628               }
00629               else if (o.equals("function"))
00630               {      if (IA.isControlPressed()) ZC.createFunction();
00631                      else ZC.createCurve();
00632               }
00633               else if (o.equals("type"))
00634               {      int n=IA.getMultipleState("type");
00635                      if (n>=0) settype(n);
00636               }
00637               else if (o.equals("thickness"))
00638               {      int n=IA.getMultipleState("thickness");
00639                      if (n>=0) setcolortype(n);
00640               }
00641               else if (o.equals("edit"))
00642               {      settool(ZirkelFrame.NEdit);
00643               }
00644               else if (o.equals("back"))
00645               {      ZC.back();
00646                      ZC.repaint();
00647               }
00648               else if (o.equals("undo"))
00649               {      ZC.undo();
00650                      ZC.repaint();
00651               }
00652               else if (o.equals("replay"))
00653               {      replay();
00654               }
00655               else if (o.equals("macro"))
00656               {      int n=IA.getMultipleState("macro");
00657                      switch (n)
00658                      {      case 1 :
00659                                    settool(ZirkelFrame.NParameters);
00660                                    break;
00661                             case 2 :
00662                                    settool(ZirkelFrame.NTargets);
00663                                    break;
00664                             case 0 :
00665                                    definemacro();
00666                                    break;
00667                      }
00668                      IA.setState("macro",true);
00669               }
00670               else if (o.equals("allback"))
00671               {      if (Last!=null && Last instanceof TextObject)
00672                             ((TextObject)Last).setDoShow(false);
00673                      Enumeration e=ZC.getConstruction().elements();
00674                      if (e.hasMoreElements())
00675                      {      Last=(ConstructionObject)e.nextElement();
00676                             ZC.paintUntil(Last);
00677                             if ((Last instanceof TextObject) && Last.valid()
00678                                    && !Last.isSuperHidden())
00679                             {      ((TextObject)Last).setDoShow(true);
00680                             }
00681                      }
00682                      IC.setEnabled("allforward",true);
00683                      IC.setEnabled("nextbreak",true);
00684                      IC.setEnabled("oneforward",true);
00685                      IC.setEnabled("allback",false);
00686                      if (haveBreaks() && !Last.isBreak()) iconPressed("nextbreak");
00687               }
00688               else if (o.equals("allforward"))
00689               {      if (Last!=null && Last instanceof TextObject)
00690                             ((TextObject)Last).setDoShow(false);
00691                      ZC.paintUntil(null);
00692                      Last=null;
00693                      IC.setEnabled("allforward",false);
00694                      IC.setEnabled("nextbreak",false);
00695                      IC.setEnabled("oneforward",false);
00696                      IC.setEnabled("allback",true);
00697               }
00698               else if (o.equals("nextbreak"))
00699               {      if (Last!=null && Last instanceof TextObject)
00700                             ((TextObject)Last).setDoShow(false);
00701                      Enumeration e=ZC.getConstruction().elements();
00702                      outer: while (e.hasMoreElements())
00703                      {      ConstructionObject next=(ConstructionObject)e.nextElement();
00704                             if (next==Last)
00705                                    while (e.hasMoreElements())
00706                                    {      Last=(ConstructionObject)e.nextElement();
00707                                           if (Last==null || Last.isBreak()) break outer;
00708                                    }
00709                      }
00710                      IC.setEnabled("allback",true);
00711                      if ((Last instanceof TextObject) && Last.valid()
00712                             && !Last.isSuperHidden())
00713                      {      ((TextObject)Last).setDoShow(true);
00714                      }
00715                      ZC.paintUntil(Last);
00716                      IC.setEnabled("allback",true);
00717                      IC.setEnabled("nextbreak",e.hasMoreElements());
00718                      IC.setEnabled("allforward",e.hasMoreElements());
00719               }
00720               else if (o.equals("oneforward"))
00721               {      if (Last!=null && Last instanceof TextObject)
00722                             ((TextObject)Last).setDoShow(false);
00723                      Enumeration e=ZC.getConstruction().elements();
00724                      outer: while (e.hasMoreElements())
00725                      {      ConstructionObject next=(ConstructionObject)e.nextElement();
00726                             if (next==Last)
00727                                    while (e.hasMoreElements())
00728                                    {      Last=(ConstructionObject)e.nextElement();
00729                                           if (Last==null || !Last.isHidden()) break outer;
00730                                           if ((Last instanceof TextObject) && Last.valid()
00731                                                  && !Last.isSuperHidden())
00732                                           {      ((TextObject)Last).setDoShow(true);
00733                                                  break outer;
00734                                           }
00735                                    }
00736                      }
00737                      IC.setEnabled("allback",true);
00738                      ZC.paintUntil(Last);
00739                      if (!e.hasMoreElements())
00740                      {      ZC.paintUntil(null);
00741                             IC.setEnabled("allforward",false);
00742                             IC.setEnabled("oneforward",false);
00743                             IC.setEnabled("allback",true);
00744                      }
00745               }
00746               else if (IB.isControlPressed() || IA.isControlPressed())
00747               {      int i=CurrentTool;
00748                      if (o.equals("objecttracker"))
00749                      {      track();
00750                      }
00751                      settool(i);
00752               }      
00753               IA.clearShiftControl();
00754               IB.clearShiftControl();
00755        }
00756        
00757        public ObjectConstructor ObjectConstructors[]= // constructors
00758               {      new PointConstructor(),
00759                      new BoundedPointConstructor(),
00760                      new IntersectionConstructor(),
00761                      new LineConstructor(),
00762                      new RayConstructor(),
00763                      new SegmentConstructor(),
00764                      new SegmentConstructor(true),
00765                      new CircleConstructor(),
00766                      new Circle3Constructor(),
00767                      new CircleConstructor(true),
00768                      new ParallelConstructor(),
00769                      new PlumbConstructor(),
00770                      new MidpointConstructor(),
00771                      new AngleConstructor(),
00772                      new AngleConstructor(true),
00773                      new MoverTool(),
00774                      new Tracker(),
00775                      new ObjectTracker(),
00776                      new AnimatorTool(),
00777                      new ExpressionConstructor(),
00778                      new AreaConstructor(),
00779                      new QuadricConstructor(),
00780                      new ImageConstructor(),
00781                      new TextConstructor(),
00782                      new HiderTool(),
00783                      new MacroRunner(),
00784                      new EditTool(),
00785                      new SetParameterTool(),
00786                      new SetTargetsTool(),
00787                      new SaveJob(),
00788                      new DeleteTool(),
00789                      new ReorderTool(),
00790                      new DrawerTool(),
00791                      new RenamerTool(),
00792                      new ZoomerTool(),
00793               };
00794 
00795        public void settool (int i)
00796        {      if (IM!=null) IM.deselectAll();
00797               ZC.setTool(ObjectConstructors[i]);
00798               CurrentTool=i;
00799               if (i<ZirkelFrame.IconNumber  && IB.have(ZirkelFrame.ObjectStrings[i]))
00800                      IB.toggle(ZirkelFrame.ObjectStrings[i]);
00801               else
00802                      IB.unselect(FirstConstructor);
00803               ObjectConstructors[i].resetFirstTime(ZC); 
00804               if (i==ZirkelFrame.NTargets) IA.setMultipleState("macro",2);
00805               else if (i==ZirkelFrame.NParameters) IA.setMultipleState("macro",1);
00806               else
00807               {      IA.setMultipleState("macro",0);
00808                      IA.setState("macro",false);
00809               }
00810               IA.setState("delete",i==ZirkelFrame.NDelete);
00811               IA.setState("edit",i==ZirkelFrame.NEdit);
00812               IA.setState("draw",i==ZirkelFrame.NDraw);
00813               IA.setState("rename",i==ZirkelFrame.NRename);
00814               IA.setState("zoom",i==ZirkelFrame.NZoom);
00815        }
00816        
00817        
00818        public void setcolor (int c)
00819        {      IA.setMultipleState("color",c);
00820               ZC.setDefaultColor(c);
00821        }
00822        
00823        public void settype (int c)
00824        {      IA.setMultipleState("type",c);
00825               ZC.setDefaultType(c);
00826        }
00827        
00828        public void setcolortype (int c)
00829        {      IA.setMultipleState("thickness",c);
00830               ZC.setDefaultColorType(c);
00831        }
00832        
00833        public void showStatus (String s)
00834        {      super.showStatus(s);
00835               if (Status!=null) Status.setText(s);
00836        }
00837 
00838        public void keyPressed (KeyEvent e) {}
00839        public void keyReleased (KeyEvent e)
00840        {      int code=e.getKeyCode();
00841               int i;
00842               boolean Shift=e.isShiftDown(),Control=e.isControlDown(),Alt=e.isAltDown();
00843               if (Control)
00844               {      if (Options.indexOf("type")>0)
00845                             for (i=0; i<ZirkelFrame.PointKeys.length; i++)
00846                             {      if (ZirkelFrame.PointKeys[i]==code)
00847                                    {      settype(i);
00848                                           return;
00849                                    }
00850                             }
00851                      if (Options.indexOf("color")>0)
00852                             for (i=0; i<ZirkelFrame.ColorKeys.length; i++)
00853                             {      if (ZirkelFrame.ColorKeys[i]==code)
00854                                    {      setcolor(i);
00855                                           return;
00856                                    }
00857                             }
00858               }
00859               else if (Alt)
00860               {      if (Options.indexOf("showcolor")>0)
00861                             for (i=0; i<ZirkelFrame.ColorKeys.length; i++)
00862                             {      if (ZirkelFrame.ColorKeys[i]==code)
00863                                    {      showcolor(i);
00864                                           return;
00865                                    }
00866                             }
00867                      if (Options.indexOf("thickness")>0)
00868                             for (i=0; i<ZirkelFrame.ColorTypeKeys.length; i++)
00869                             {      if (ZirkelFrame.ColorTypeKeys[i]==code)
00870                                    {      setcolortype(i);
00871                                           return;
00872                                    }
00873                             }
00874               }
00875               else
00876               {      switch (code)
00877                      {      case KeyEvent.VK_ESCAPE :
00878                                    if (ZC.getCurrentTool() instanceof DrawerTool) ZC.clearDrawings();
00879                                    else ZC.reset(); 
00880                                    break;
00881                             case KeyEvent.VK_ENTER :
00882                                    if (Shift) track(); 
00883                                    break;
00884                      }
00885               }
00886               if (!e.isActionKey()) return;
00887               switch (code)
00888               {      case KeyEvent.VK_F1 :
00889                             showVersion();
00890                             break;
00891                      case KeyEvent.VK_F7 :
00892                             if (Shift || Control)
00893                             {      setShowNames(!IA.getState("showname"));
00894                             }
00895                             break;
00896                      case KeyEvent.VK_F8 :
00897                             if (Shift || Control)
00898                             {      setLongNames(!IA.getState("longnames"));
00899                             }
00900                             break;
00901                      case KeyEvent.VK_F9 :
00902                             if (Shift || Control)
00903                             {      IA.setState("partial",!IA.getState("partial"));
00904                                    ZC.setPartial(IA.getState("partial"));
00905                             }
00906                             else
00907                             {      if (Options.indexOf("hidden")<0) break;
00908                                    IA.setState("hidden",!IA.getState("hidden"));
00909                                    ZC.setShowHidden(IA.getState("hidden"));
00910                             }
00911                             break;
00912                      case KeyEvent.VK_F10 :
00913                             if (Shift || Control)
00914                             {      IA.setState("plines",!IA.getState("plines"));
00915                                    ZC.setPartial(IA.getState("plines"));
00916                             }
00917                             else showcomment();
00918                             break;
00919                      case KeyEvent.VK_F11 :
00920                             if (Shift || Control)
00921                             {      IA.setState("arrow",!IA.getState("arrow"));
00922                                    ZC.setPartial(IA.getState("arrow"));
00923                             }
00924                             else showconstruction();
00925                             break;
00926                      case KeyEvent.VK_F12 :
00927                             if (Shift || Control)
00928                             {      IA.setState("obtuse",!IA.getState("obtuse"));
00929                                    ZC.setObtuse(IA.getState("obtuse"));
00930                             }
00931                             else toggleGrid();
00932                             break;
00933                      case KeyEvent.VK_LEFT :
00934                             if (Shift && ZC.getCurrentTool() instanceof ObjectTracker)
00935                                    ((ObjectTracker)ZC.getCurrentTool()).increaseOmit();
00936                             else if (Shift && ZC.getCurrentTool() instanceof BreakpointAnimator)
00937                                    ((BreakpointAnimator)ZC.getCurrentTool()).decreaseSpeed(); 
00938                             else if (Shift && ZC.getCurrentTool() instanceof AnimatorTool)
00939                                    ((AnimatorTool)ZC.getCurrentTool()).decreaseSpeed(); 
00940                             else ZC.shift(-0.2,0); 
00941                             break;
00942                      case KeyEvent.VK_RIGHT :
00943                             if (Shift && ZC.getCurrentTool() instanceof ObjectTracker)
00944                                    ((ObjectTracker)ZC.getCurrentTool()).decreaseOmit();
00945                             else if (Shift && ZC.getCurrentTool() instanceof BreakpointAnimator)
00946                                    ((BreakpointAnimator)ZC.getCurrentTool()).increaseSpeed(); 
00947                             else if (Shift && ZC.getCurrentTool() instanceof AnimatorTool)
00948                                    ((AnimatorTool)ZC.getCurrentTool()).increaseSpeed(); 
00949                             else ZC.shift(0.2,0); 
00950                             break;
00951                      case KeyEvent.VK_UP :
00952                             ZC.shift(0,0.2); break;
00953                      case KeyEvent.VK_DOWN :
00954                             ZC.shift(0,-0.2); break;
00955               }
00956        }
00957        public void keyTyped (KeyEvent e)
00958        {      char c=e.getKeyChar();
00959               if (e.isControlDown() || e.isAltDown()) return;
00960               int i;
00961               for (i=0; i<ZirkelFrame.ObjectKeys.length; i++)
00962               {      if (c==ZirkelFrame.ObjectKeys[i])
00963                      {      if (Tools.indexOf(ZirkelFrame.ObjectStrings[i])>=0)
00964                                    settool(i);
00965                             return;
00966                      }
00967               }
00968               switch (c)
00969               {      case KeyEvent.VK_BACK_SPACE :
00970                             ZC.undo();
00971                             ZC.repaint();
00972                             return;
00973                      case '+' : ZC.magnify(1/Math.sqrt(Math.sqrt(2))); break;
00974                      case '-' : ZC.magnify(Math.sqrt(Math.sqrt(2))); break;
00975               }
00976        }
00977 
00978        public void initLightColors ()
00979        {      int n=ZirkelFrame.Colors.length;
00980               ZirkelFrame.LightColors=new Color[n];
00981               Color back=C;
00982               int red=back.getRed(),green=back.getGreen(),blue=back.getBlue();
00983               double lambda=0.4;
00984               for (int i=0; i<n; i++)
00985               {      int r=(int)(red*(1-lambda)+ZirkelFrame.Colors[i].getRed()*lambda);
00986                      int g=(int)(green*(1-lambda)+ZirkelFrame.Colors[i].getGreen()*lambda);
00987                      int b=(int)(blue*(1-lambda)+ZirkelFrame.Colors[i].getBlue()*lambda);
00988                      ZirkelFrame.LightColors[i]=new Color(r,g,b);
00989               }
00990        }
00991 
00992        public void initObjectKeys ()
00993        {      ZirkelFrame.ObjectKeys=new char[ZirkelFrame.ObjectStrings.length];
00994               for (int i=0; i<ZirkelFrame.ObjectStrings.length; i++)
00995               {      String shortcut=Zirkel.name("shortcuts."+ZirkelFrame.ObjectStrings[i]);
00996                      if (shortcut.length()>0)
00997                             ZirkelFrame.ObjectKeys[i]=shortcut.charAt(0);
00998               }
00999        }
01000 
01001 
01002        public void notifyDone ()
01003        {      repaint();
01004               try
01005               {      Thread.sleep(500);
01006               }
01007               catch (Exception e) {}
01008               if (Global.getParameter("confirmation",true))
01009               {      Warning w=new Warning(F,Zirkel.name("done"),
01010                             Zirkel.name("message"),true);
01011                      w.center(F);
01012                      w.setVisible(true);
01013               }
01014               String sol=getParameter("solution");
01015               if (sol!=null)
01016               {      try
01017                      {      AppletContext ac=getAppletContext();
01018                             ac.showDocument(new URL(getCodeBase(),FileName.toURL(sol)));
01019                      }
01020                      catch (Exception e)
01021                      {      System.out.println(e);
01022                             e.printStackTrace();
01023                      }
01024               }
01025        }
01026 
01027        public void showcolor (int c)
01028        {      ZC.setShowColor(c);
01029        }
01030 
01031        public void showcomment ()
01032        {      if (F==null) return;
01033               CommentDialog d=new CommentDialog(F,
01034                      ZC.getComment(),Zirkel.name("comment.title"),ZC.displayJob());
01035               ZC.setComment(d.getText());
01036        }
01037 
01038        public void showconstruction ()
01039        {      if (F==null) return;
01040        }
01041 
01042        public void toggleGrid ()
01043        {      ZC.toggleShowGrid();
01044        }
01045 
01046        void definemacro ()
01047        {      if (!ZC.defineMacro()) return; 
01048               if (ZC.getOC() instanceof SetTargetsTool)
01049                      settool(ZirkelFrame.NParameters);
01050               else ZC.getOC().reset(ZC);
01051        }
01052 
01053 
01054        String OldMacro=null;
01055 
01056        public void runmacro (boolean shift)
01057        {      Macro m=null;
01058               if (OldMacro==null && ZC.getMacros().size()==1)
01059                      m=((MacroItem)ZC.getMacros().elementAt(0)).M;
01060               else
01061               {      m=ZC.chooseMacro(OldMacro);
01062                      if (!shift || m==null) m=ZC.chooseMacro();
01063               }
01064               if (m==null)
01065               {      settool(CurrentTool); return;
01066               }
01067               runMacro(m);
01068        }
01069        
01070        public void runMacro (Macro m)
01071        {      ((MacroRunner)ObjectConstructors[ZirkelFrame.NMacro]).
01072                      setMacro(m,ZC);
01073               settool(ZirkelFrame.NMacro);
01074               if (IM!=null) IM.select(m);
01075               IB.setMultipleState("macro",0);
01076               OldMacro=m.getName();
01077        }
01078 
01079        public void setShowNames (boolean flag)
01080        {      if (IA!=null) IA.setState("showname",flag);
01081               Global.setParameter("options.shownames",flag);
01082               ZC.setShowNames(flag);
01083        }
01084 
01085        public void setObtuse (boolean flag)
01086        {      IA.setState("obtuse",flag);
01087               Global.setParameter("options.obtuse",flag);
01088               ZC.setObtuse(flag);
01089        }
01090 
01091        public void setSolid (boolean flag)
01092        {      IA.setState("solid",flag);
01093               Global.setParameter("options.solid",flag);
01094               ZC.setSolid(flag);
01095        }
01096 
01097        public void setShowValues (boolean flag)
01098        {      IA.setState("showvalue",flag);
01099               Global.setParameter("options.showvalue",flag);
01100               ZC.setShowValues(flag);
01101        }
01102 
01103        public void setLongNames (boolean flag)
01104        {      IA.setState("longnames",flag);
01105               Global.setParameter("options.longnames",flag);
01106               ZC.setLongNames(flag);
01107        }
01108 
01109        public void toggleGrid (boolean grid)
01110        {      ZC.setShowGrid(grid);
01111               if (IA!=null) IA.setState("grid",grid);
01112        }
01113 
01114        public void loadsettings ()
01115        {      setcolor(ZC.getDefaultColor());
01116               settype(ZC.getDefaultType());
01117               setcolortype(ZC.getDefaultColorType());
01118               IA.setState("partial",ZC.getPartial());
01119               IA.setState("plines",ZC.getPartialLines());
01120               IA.setState("arrow",ZC.getVectors());
01121               ZC.setHidden(false);
01122        }
01123 
01124        public void doAction (String o)
01125        {      if (o.equals("Input"))
01126               {      try
01127                      {      ZC.getConstruction().interpret(ZC,Input.getText(),"");
01128                             Input.remember();
01129                             Input.setText("");
01130                             loadsettings();
01131                             ZC.validate();
01132                             ZC.getConstruction().updateCircleDep();
01133                      }
01134                      catch (ConstructionException e)
01135                      {      ZC.warning(e.getDescription());
01136                      }
01137               }
01138        }
01139        public void itemAction (String o, boolean flag)
01140        {      
01141        }
01142 
01143        AnimatorTool A=null;
01144        
01145        public void start ()
01146        {      if (getParameter("demo")!=null)
01147               {      DR=new DemoRunner(ZC,this,getParameter("demo"),Status);
01148                      return;
01149               }
01150               Construction C=ZC.getConstruction();
01151               ZC.paint(ZC.getGraphics());
01152               ZC.allowRightMouse(true);
01153               if (C.TrackP!=null)
01154               {      try
01155                      {      ConstructionObject
01156                                    P=C.find(C.TrackP);
01157                             if (!((P instanceof PointObject) 
01158                                    || (P instanceof PrimitiveLineObject)))
01159                                           throw new ConstructionException("");                           
01160                             ConstructionObject po[]=
01161                                    new ConstructionObject[C.TrackPO.size()];
01162                             for (int i=0; i<po.length; i++)
01163                             {      ConstructionObject o=C.find(
01164                                           (String)C.TrackPO.elementAt(i));
01165                                    if (o==null || !((o instanceof PointObject) 
01166                                           || (o instanceof PrimitiveLineObject)))
01167                                                  throw new ConstructionException("");
01168                                    po[i]=o;
01169                             }
01170                             PointObject PM=null;
01171                             if (C.TrackPM!=null)
01172                                    PM=(PointObject)C.find(C.TrackPM);
01173                             if (C.TrackO!=null)
01174                             {      ConstructionObject O=C.find(C.TrackO);
01175                                    if (P==null || (PM==null && (O instanceof ExpressionObject)) || O==null)
01176                                           throw new ConstructionException("");
01177                                    ObjectTracker ot=new ObjectTracker(P,PM,O,ZC,
01178                                           C.Animate,C.Paint,po);
01179                                    if (C.Animate) ot.Interactive=false;
01180                                    ot.setOmit(C.Omit);
01181                                    ZC.setTool(ot);
01182                                    if (!edit) ZC.allowRightMouse(false);
01183                                    ZC.validate();
01184                                    ZC.repaint();
01185                             }
01186                             else
01187                             {      if (P==null)
01188                                           throw new ConstructionException("");
01189                                    ZC.setTool(new Tracker(P,po));
01190                                    if (PM!=null) PM.setSelected(true);
01191                                    ZC.validate();
01192                                    ZC.repaint();
01193                             }
01194                      }
01195                      catch (Exception e)
01196                      {      
01197                      }                    
01198               }
01199               else if (C.AnimateP!=null)
01200               {      try
01201                      {      PointObject
01202                                    P=(PointObject)C.find(C.AnimateP);
01203                             if (P==null || !P.moveable())
01204                                    throw new ConstructionException("");
01205                             Enumeration e=C.AnimateV.elements();
01206                             while (e.hasMoreElements())
01207                             {      String s=(String)e.nextElement();
01208                                    ConstructionObject o=C.find(s);
01209                                    if (o==null || !(o instanceof SegmentObject
01210                                           || o instanceof PrimitiveCircleObject
01211                                           || o instanceof PointObject))
01212                                                  throw new ConstructionException("");                           
01213                             }
01214                             ZC.setTool(A=new AnimatorTool(P,C.AnimateV,ZC,C.AnimateNegative,
01215                                           C.AnimateOriginal,C.AnimateDelay));
01216                             ZC.allowRightMouse(false);
01217                             A.setInteractive(false);
01218                      }
01219                      catch (Exception e)
01220                      {      // e.printStackTrace();
01221                      }                    
01222               }
01223               else if (C.AnimateBreakpoints)
01224               {      BreakpointAnimator bp=new BreakpointAnimator();
01225                      bp.setLoop(C.AnimateLoop);
01226                      bp.setSpeed(C.AnimateTime);
01227                      ZC.allowRightMouse(false);
01228                      ZC.setTool(bp);
01229                      bp.reset(ZC);
01230               }
01231               else if (jumptostart)
01232               {      System.out.println("here");
01233                      iconPressed("allback");
01234               }
01235        }
01236        
01237        public void showVersion ()
01238        {      showStatus(
01239                      Zirkel.name("program.name")+" "+Zirkel.name("program.version")
01240                      +" "+Zirkel.name("program.date"));
01241        }
01242 
01243        public void stop ()
01244        {      ZC.invalidate();
01245               if (DR!=null) DR.stop();
01246        }
01247        
01248        public void destroy ()
01249        {      ZC.invalidate();
01250               if (DR!=null) DR.stop();
01251        }
01252        
01253        public void replay ()
01254        {      if (RD!=null) return;
01255               RD=new Replay(F,ZC)
01256                      {      public void doclose ()
01257                             {      RD=null;
01258                                    super.doclose();
01259                             }
01260                      };
01261               Dimension d=getToolkit().getScreenSize();
01262               RD.setLocation(d.width-100-RD.getSize().width,100);
01263               ZC.OC.invalidate(ZC);
01264               RD.setVisible(true);
01265        }
01266        
01267        public void replayChosen ()
01268        {      replay();
01269        }
01270 
01271        public boolean enabled (String function)
01272        {      if (Tools.indexOf("all")>=0) return true;
01273               return Tools.indexOf(function)>=0;
01274        }      
01275 
01276        public boolean haveBreaks ()
01277        {      Enumeration e=ZC.getConstruction().elements();
01278               while (e.hasMoreElements())
01279               {      if (((ConstructionObject)e.nextElement()).isBreak())
01280                             return true;
01281               }
01282               return false;
01283        }
01284 
01285        public String loadImage() {
01286               return null;
01287        }
01288 
01289        public Image doLoadImage(String filename) 
01290        {      Image i;
01291               try 
01292               {      i = getToolkit().getImage(new URL(getCodeBase(),filename));
01293                      MediaTracker mt=new MediaTracker(this);
01294                      mt.addImage(i,0);
01295                      mt.waitForID(0);
01296                      if (mt.checkID(0) && !mt.isErrorAny())
01297                      {      return i;
01298                      }
01299               }
01300               catch (Exception e)
01301               {      showStatus(e.toString());
01302               }
01303               return null;
01304        }
01305 
01312        public boolean interpret (String s)
01313        {      try
01314               {      ZC.getConstruction().interpret(ZC,s);
01315                      ZC.repaint();
01316                      return true;
01317               }
01318               catch (ConstructionException e) 
01319               {      return false;
01320               }
01321        }
01322 
01328        public String getConstruction ()
01329        {      ByteArrayOutputStream out=new ByteArrayOutputStream();
01330               try
01331               {      ZC.save(out,true,true,false,ZC.getMacros(),"");
01332                      return out.toString("utf-8");
01333               }
01334               catch (Exception e)
01335               {      return "Error";
01336               }
01337        }
01338        
01339        
01340        
01341        
01342     /*
01343     * jm.evers 28/12/2007
01344     * test to retreive data from the applet without using XML-javascript methods ...
01345     * javascript-functions must be of type: function getDrawing(type,name); 
01346     * types: point,line,segment,circle,area,function,angle
01347     * example: getDrawing("line","line1,line2,line3");
01348     * array's as argument give trouble only in InternetExplorer
01349     * example: getDrawing("line1","line2","line3"); will not do !
01350     *
01351     * jm.evers 31/1/2008
01352     * added getAllObjects() to retreive all objects, excluded the ones with prefix "my_"
01353     */
01354     public static double roundit(double x){
01355        int rounder=(int) Math.pow((double)10,(double)decimals);
01356        double rounded=(int)(Math.round(rounder*x));
01357        return rounded/rounder;
01358     }
01359     
01360     public String getAllObjects(){
01361        String result="";String name="";String type="";
01362        Enumeration t=ZC.Drawings.elements();
01363        // is the drawing tool used? 
01364        // the resulting string will be all freehand drawings 
01365        // [they do not have names, e.g a collection of seperate points]
01366        if(t.hasMoreElements()){
01367            while (t.hasMoreElements()){
01368               Drawing d=(Drawing)t.nextElement();
01369               Enumeration ec=d.elements();
01370               if (ec.hasMoreElements()){
01371                   CoordinatesXY xy=(CoordinatesXY)ec.nextElement();
01372                   while (ec.hasMoreElements()){
01373                      xy=(CoordinatesXY)ec.nextElement();                                                                
01374                      //System.out.println("X="+xy.X+"  Y="+xy.Y);
01375                      result=result+"freehand_point:noname:x="+xy.X+":y="+xy.Y+"\n,";  
01376                   }                                                                                                          
01377               }                                                                                                                  
01378            }                                                                                                                          
01379         } 
01380        Construction C = ZC.getConstruction();
01381        Enumeration e=C.elements();
01382        while (e.hasMoreElements()){
01383            ConstructionObject o=(ConstructionObject)e.nextElement();
01384            name=o.getName().toString().toLowerCase();
01385            if(name.indexOf("my_") == -1 ){
01386               // only use object not protected by prefix "my_
01387               type=o.getTag().toString().toLowerCase();
01388               // I hope "getTag()" is not too language dependant...must check this !!
01389               // make use of my own function...don't know a quicker way of doing this.
01390               result=getDrawing(type,name)+","+result;
01391            }
01392        }
01393        
01394        return result;
01395     }  
01396 
01397     public static String[] StringToArray(String str)
01398     {
01399         StringTokenizer t = new StringTokenizer(str, ",");
01400         String array[] = new String[t.countTokens()];
01401         for(int i = 0; t.hasMoreTokens(); i++)
01402             array[i] = t.nextToken();
01403 
01404         return array;
01405     }
01406 
01407     public String ConvertLineNotation(String parameter)
01408     {
01409         int i = parameter.indexOf("x=");
01410         if(i != -1)
01411             return parameter + ":perpendicular";
01412         i = parameter.indexOf("x");
01413         if(i == -1)
01414             return parameter + ":horizontal";
01415         i = parameter.indexOf("=");
01416         //System.out.println("parameter" + parameter + "i=" + i);
01417         if(i != -1)
01418         {
01419             int t = parameter.length();
01420             String links = parameter.substring(0, i);
01421             String c = parameter.substring(i + 1, t);
01422             t = links.length();
01423             i = links.indexOf("x");
01424             String mx = links.substring(0, i);
01425             if(mx.length() == 0)
01426                 mx = "1";
01427             String by = links.substring(i + 1, t);
01428             by = by.replace('y',' ');
01429             by = by.replace('*',' ');
01430             by = by.replace('+',' ');
01431             if(by.length() == 0)
01432                 by = "1";
01433             mx = mx.replace('*',' ');
01434             return "slope=-1*(" + mx + ")/(" + by + "):constant=" + "(" + c + ")/(" + by + "):affine";
01435         } else
01436         {
01437             return "error: line not correct";
01438         }
01439     }
01440 
01441     private String getthisintersection(String name)
01442     {
01443         String result = "";
01444         int check = 0;
01445         Construction C = ZC.getConstruction();
01446         for(Enumeration r = C.elements(); r.hasMoreElements();)
01447             try
01448             {
01449                 IntersectionObject c = (IntersectionObject)r.nextElement();
01450                 if(c.getName().equalsIgnoreCase(name))
01451                     try
01452                     {
01453                         double x = roundit(c.getX());
01454                         double y = roundit(c.getY());
01455                         result = "point=" + name + ":" + "x=" + x + ":y=" + y + "\n";
01456                         check++;
01457                     }
01458                     catch(Exception e)
01459                     {
01460                         result = "point=" + name + " no value error \n";
01461                     }
01462             }
01463             catch(Exception exception) { }
01464 
01465         if(check == 0)
01466             result = "point=" + name + " not present error\n";
01467         return result;
01468     }
01469 
01470 
01471     private String getthispoint(String name)
01472     {
01473         String result = "";
01474         int check = 0;
01475         Construction C = ZC.getConstruction();
01476         for(Enumeration r = C.elements(); r.hasMoreElements();)
01477             try
01478             {
01479                 PointObject c = (PointObject)r.nextElement();
01480                 if(c.getName().equalsIgnoreCase(name))
01481                     try
01482                     {
01483                         double x = roundit(c.getX());
01484                         double y = roundit(c.getY());
01485                         result = "point=" + name + ":" + "x=" + x + ":y=" + y + "\n";
01486                         check++;
01487                     }
01488                     catch(Exception e)
01489                     {
01490                         result = "point=" + name + " no value error \n";
01491                     }
01492             }
01493             catch(Exception exception) { }
01494 
01495         if(check == 0)
01496             result = "point=" + name + " not present error\n";
01497         return result;
01498     }
01499 
01500 
01501     private String getthisray(String name)
01502     {
01503         String result = "";
01504        String raypoints = "";
01505         int check = 0;
01506         Construction C = ZC.getConstruction();
01507         for(Enumeration s = C.elements(); s.hasMoreElements();)
01508             try
01509             {
01510                 RayObject c = (RayObject)s.nextElement();
01511                 if(c.getName().equalsIgnoreCase(name))
01512                     try
01513                     {
01514                      for( Enumeration point = c.depending(); point.hasMoreElements();)
01515                          try
01516                          {
01517                             PointObject p = (PointObject)point.nextElement();
01518                             double x = roundit(p.getX());double y = roundit(p.getY());
01519                             raypoints = "x=" + x + ":y=" + y +":"+ raypoints;
01520                          }
01521                             catch(Exception e){}
01522                      result = "ray=" + name + ":" + raypoints + "length="+ c.getLength();
01523                         check++;
01524 
01525                     }
01526                     catch(Exception e)
01527                     {
01528                         result = "ray=" + name + " no value error";
01529                     }
01530             }
01531             catch(Exception exception) { }
01532 
01533         if(check == 0)
01534             result = "ray=" + name + " not present error";
01535         return result;
01536     }
01537 
01538     private String getthissegment(String name)
01539     {
01540         String result = "";
01541        String segmentpoints = "";
01542         int check = 0;
01543         Construction C = ZC.getConstruction();
01544         for(Enumeration s = C.elements(); s.hasMoreElements();)
01545             try
01546             {
01547                 SegmentObject c = (SegmentObject)s.nextElement();
01548                 if(c.getName().equalsIgnoreCase(name))
01549                     try
01550                     {
01551                      for( Enumeration point = c.depending(); point.hasMoreElements();)
01552                          try
01553                          {
01554                             PointObject p = (PointObject)point.nextElement();
01555                             double x = roundit(p.getX());double y = roundit(p.getY());
01556                             segmentpoints = "x=" + x + ":y=" + y +":"+ segmentpoints;
01557                          }
01558                             catch(Exception e){}
01559                      result = "segment=" + name + ":" + segmentpoints + "length="+ c.getLength();
01560                         check++;
01561 
01562                     }
01563                     catch(Exception e)
01564                     {
01565                         result = "segment=" + name + " no value error";
01566                     }
01567             }
01568             catch(Exception exception) { }
01569 
01570         if(check == 0)
01571             result = "segment=" + name + " not present error";
01572         return result;
01573     }
01574     private String getthisarea(String name)
01575     {
01576         String result = "";
01577        String surface ="";
01578        String polypoints = "";
01579         int check = 0;
01580         Construction C = ZC.getConstruction();
01581         for(Enumeration z = C.elements(); z.hasMoreElements();)
01582             try
01583             {
01584                 AreaObject c = (AreaObject)z.nextElement();
01585                 if(c.getName().equalsIgnoreCase(name))
01586                     try
01587                     {
01588                      polypoints="";
01589                      for( Enumeration point = c.depending(); point.hasMoreElements();)
01590                          try
01591                          {
01592                             PointObject p = (PointObject)point.nextElement();
01593                             double x = roundit(p.getX());double y = roundit(p.getY());
01594                             polypoints = "x=" + x + ":y=" + y +":"+ polypoints;
01595                          }
01596                             catch(Exception e){}
01597                      surface=c.getDisplayValue();
01598                      //System.out.println("result="+result+"  name="+name);
01599                      result = "polygon=" + polypoints + "area="+ surface + "\n" + result;
01600                         check++;
01601                     }
01602                     catch(Exception e)
01603                     {
01604                         result = "polygon=" + name + " no value error";
01605                     }
01606             }
01607             catch(Exception exception) { }
01608 
01609         if(check == 0)
01610             result = "polygon=" + name + " not present error";
01611         return result;
01612     }
01613 
01614 
01615     private String getthisline(String name)
01616     {
01617         String result = "";
01618         int check = 0;
01619         Construction C = ZC.getConstruction();
01620         for(Enumeration l = C.elements(); l.hasMoreElements();)
01621             try
01622             {
01623                 LineObject c = (LineObject)l.nextElement();
01624                 if(c.getName().equalsIgnoreCase(name))
01625                     try
01626                     {
01627                         check++;
01628                         result = c.getEquation();
01629                         result = ConvertLineNotation(result);
01630                         result = "line=" + name + ":" + result;
01631                     }
01632                     catch(Exception e)
01633                     {
01634                         result = "line=" + name + " no value error";
01635                     }
01636             }
01637             catch(Exception exception) { }
01638 
01639         if(check == 0)
01640             result = "line=" + name + " not present error";
01641         return result;
01642     }
01643 
01644     private String getthiscircle(String name)
01645     {
01646         String result = "";
01647         int check = 0;
01648         Construction C = ZC.getConstruction();
01649         for(Enumeration z = C.elements(); z.hasMoreElements();)
01650             try
01651             {
01652                 CircleObject c = (CircleObject)z.nextElement();
01653                 if(c.getName().equalsIgnoreCase(name))
01654                     try
01655                     {
01656                         double x = roundit(c.getX());
01657                         double y = roundit(c.getY());
01658                         double radius = roundit(c.getR());
01659                         result = "circle=" + name + ":" + "x=" + x + ":y=" + y + ":r=" + radius;
01660                         check++;
01661                     }
01662                     catch(Exception e)
01663                     {
01664                         result = "circle=" + name + " no value error";
01665                     }
01666             }
01667             catch(Exception exception) { }
01668 
01669         if(check == 0)
01670             result = "circle=" + name + " not present error";
01671         return result;
01672     }
01673 
01674     private String getthisfixedcircle(String name)
01675     {
01676         String result = "";
01677         int check = 0;
01678         Construction C = ZC.getConstruction();
01679         for(Enumeration z = C.elements(); z.hasMoreElements();)
01680             try
01681             {
01682                 FixedCircleObject c = (FixedCircleObject)z.nextElement();
01683                 if(c.getName().equalsIgnoreCase(name))
01684                     try
01685                     {
01686                         double x = roundit(c.getX());
01687                         double y = roundit(c.getY());
01688                         double radius = roundit(c.getR());
01689                         result = "fixedcircle=" + name + ":" + "x=" + x + ":y=" + y + ":r=" + radius;
01690                         check++;
01691                     }
01692                     catch(Exception e)
01693                     {
01694                         result = "fixedcircle=" + name + " no value error";
01695                     }
01696             }
01697             catch(Exception exception) { }
01698 
01699         if(check == 0)
01700             result = "fixedcircle=" + name + " not present error";
01701         return result;
01702     }
01703 
01704     private String getthisangle(String name)
01705     {
01706         String result = "";
01707         int check = 0;
01708         Construction C = ZC.getConstruction();
01709         for(Enumeration a = C.elements(); a.hasMoreElements();)
01710             try
01711             {
01712                 AngleObject c = (AngleObject)a.nextElement();
01713                 if(c.getName().equalsIgnoreCase(name))
01714                     try
01715                     {
01716                         result = "angle=" + name + ":value=" + c.getE();
01717                         check++;
01718                     }
01719                     catch(Exception e)
01720                     {
01721                         result = "angle=" + name + " no value error";
01722                     }
01723             }
01724             catch(Exception exception) { }
01725 
01726         if(check == 0)
01727             result = "angle=" + name + " not present error";
01728         return result;
01729     }
01730 
01731     private String getthisfunction(String name)
01732     {
01733         String result = "";
01734         int check = 0;
01735         Construction C = ZC.getConstruction();
01736         for(Enumeration ff = C.elements(); ff.hasMoreElements();)
01737             try
01738             {
01739                 FunctionObject c = (FunctionObject)ff.nextElement();
01740                 if(c.getName().equalsIgnoreCase(name))
01741                     try
01742                     {
01743                         check++;
01744                         result = c.getEquation();
01745                         result = "function=" + name + ":" + result;
01746                     }
01747                     catch(Exception e)
01748                     {
01749                         result = "function=" + name + " no value error";
01750                     }
01751             }
01752             catch(Exception exception) { }
01753 
01754         if(check == 0)
01755             result = "function=" + name + " not present error";
01756         return result;
01757     }
01758     
01759     private String getthisFreeDrawing(){
01760        Enumeration t=ZC.Drawings.elements();
01761        // is the drawing tool used? 
01762        // the resulting string will be all freehand drawings 
01763        // [they do not have names, e.g a collection of seperate points]
01764        String result = "";
01765        if(t.hasMoreElements()){
01766            while (t.hasMoreElements()){
01767               Drawing d=(Drawing)t.nextElement();
01768               Enumeration ec=d.elements();
01769               if (ec.hasMoreElements()){
01770                   CoordinatesXY xy=(CoordinatesXY)ec.nextElement();
01771                   while (ec.hasMoreElements()){
01772                      xy=(CoordinatesXY)ec.nextElement();                                                                
01773                      //System.out.println("X="+xy.X+"  Y="+xy.Y);
01774                      result=result+"freehand_point:noname:x="+xy.X+":y="+xy.Y+"\n,";  
01775                   }                                                                                                          
01776               }                                                                                                                  
01777            }                                                                                                                          
01778         }
01779        if(result.length()<1){
01780            result= "freehand_drawing not present error";
01781        }
01782        return result;
01783 
01784     }
01785 
01786     public String getDrawing(String type, String names)
01787     {
01788         String name[] = StringToArray(names);
01789         int i = name.length;
01790         String endresult = "";
01791        
01792        if(type.equalsIgnoreCase("freehand_drawing") ||type.equalsIgnoreCase("freehand_point"))
01793        {
01794            endresult = endresult + getthisFreeDrawing() + "\n";
01795        } else
01796        
01797         if(type.equalsIgnoreCase("line") || type.equalsIgnoreCase("lines"))
01798         {
01799             for(int p = 0; p < i; p++)
01800             {
01801                 String Name = name[p];
01802                 endresult = endresult + getthisline(Name) + "\n";
01803             }
01804 
01805         } else
01806 
01807         if(type.equalsIgnoreCase("function"))
01808         {
01809             for(int p = 0; p < i; p++)
01810             {
01811                 String Name = name[p];
01812               //System.out.println("...with name "+Name);
01813                 endresult = endresult + getthisfunction(Name) + "\n";
01814             }
01815 
01816         } else
01817         if(type.equalsIgnoreCase("area") || type.equalsIgnoreCase("poly") ||  type.equalsIgnoreCase("polygon"))
01818         {
01819             for(int p = 0; p < i; p++)
01820             {
01821                 String Name = name[p];
01822               //System.out.println("...with name "+Name);
01823                 endresult = endresult + getthisarea(Name) + "\n";
01824             }
01825 
01826         } else
01827         if(type.equalsIgnoreCase("ray") || type.equalsIgnoreCase("demiline"))
01828         {
01829             for(int p = 0; p < i; p++)
01830             {
01831                 String Name = name[p];
01832                 endresult = endresult + getthisray(Name) + "\n";
01833             }
01834 
01835         } else
01836         if(type.equalsIgnoreCase("circle") || type.equalsIgnoreCase("circles"))
01837         {
01838             for(int p = 0; p < i; p++)
01839             {
01840                 String Name = name[p];
01841                 endresult = endresult + getthiscircle(Name) + "\n";
01842             }
01843 
01844         } else
01845         if(type.equalsIgnoreCase("fixedcircle") || type.equalsIgnoreCase("fixedcircles"))
01846         {
01847             for(int p = 0; p < i; p++)
01848             {
01849                 String Name = name[p];
01850                 endresult = endresult + getthisfixedcircle(Name) + "\n";
01851             }
01852 
01853         } else
01854         if(type.equalsIgnoreCase("intersection")|| type.equalsIgnoreCase("intersectionpoint"))
01855         {
01856             for(int p = 0; p < i; p++)
01857             {
01858                 String Name = name[p];
01859                 endresult = endresult + getthisintersection(Name) + "\n";
01860             }
01861 
01862         } else
01863         if(type.equalsIgnoreCase("pointonobject") || type.equalsIgnoreCase("pointon"))
01864         {
01865             for(int p = 0; p < i; p++)
01866             {
01867                 String Name = name[p];
01868                 endresult = endresult + getthispoint(Name) + "\n";
01869             }
01870 
01871         } else
01872         if(type.equalsIgnoreCase("point") || type.equalsIgnoreCase("points"))
01873         {
01874             for(int p = 0; p < i; p++)
01875             {
01876                 String Name = name[p];
01877                 endresult = endresult + getthispoint(Name) + "\n";
01878             }
01879 
01880         } else
01881         if(type.equalsIgnoreCase("segment") || type.equalsIgnoreCase("segments"))
01882         {
01883             for(int p = 0; p < i; p++)
01884             {
01885                 String Name = name[p];
01886                 endresult = endresult + getthissegment(Name) + "\n";
01887             }
01888 
01889         } else
01890         if(type.equalsIgnoreCase("angle") || type.equalsIgnoreCase("angles"))
01891         {
01892             for(int p = 0; p < i; p++)
01893             {
01894                 String Name = name[p];
01895                 endresult = endresult + getthisangle(Name) + "\n";
01896             }
01897 
01898         }
01899         return endresult;
01900     }
01901 
01902 
01903 
01904 
01905        
01906        /*
01907        * end jm.evers test
01908        */
01909        
01916        public boolean putConstruction (String s)
01917        {
01918            System.out.println("trying:"+s);      
01919            try
01920               {      ByteArrayOutputStream bout=new ByteArrayOutputStream();
01921                      PrintWriter out=new PrintWriter(new OutputStreamWriter(bout,"utf-8"));
01922                      out.print(s);
01923                      out.close();
01924                      byte b[]=bout.toByteArray();
01925                      InputStream in=new ByteArrayInputStream(b);
01926                      ZC.load(in,true,true);
01927                      System.out.println("loaded "+in);
01928                      return true;
01929               }
01930               catch (Exception e)
01931               {      e.printStackTrace();
01932                      System.out.println("error"+e);
01933                      return false;
01934               }
01935        }
01936        
01937        public void track ()
01938        {      if (ZC.getCurrentTool() instanceof ObjectTracker &&
01939               ((ObjectTracker)ZC.getCurrentTool()).isComplete())
01940               {      ((ObjectTracker)ZC.getCurrentTool()).keep(ZC); 
01941               }
01942        }
01943        
01944 }