Back to index

wims  3.65+svn20090927
MidpointConstructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: MidpointConstructor.java
00004 
00005 import rene.util.xml.XmlTag;
00006 import rene.util.xml.XmlTree;
00007 import rene.zirkel.Zirkel;
00008 import rene.zirkel.ZirkelCanvas;
00009 import rene.zirkel.construction.Construction;
00010 import rene.zirkel.construction.ConstructionException;
00011 import rene.zirkel.objects.ConstructionObject;
00012 import rene.zirkel.objects.MidpointObject;
00013 import rene.zirkel.objects.PointObject;
00014 
00015 public class MidpointConstructor extends LineConstructor
00016 {      public ConstructionObject create (Construction c, PointObject p1, PointObject p2)
00017        {      return new MidpointObject(c,p1,p2);
00018        }
00019        public void showStatus (ZirkelCanvas zc)
00020        {      if (P1==null) zc.showStatus(
00021                      Zirkel.name("message.midpoint.first","Midpoint: Set the first point!"));
00022               else zc.showStatus(
00023                      Zirkel.name("message.midpoint.second","Midpoint: Set the second point!"));
00024        }
00025        
00026        public boolean construct (XmlTree tree, Construction c)
00027               throws ConstructionException
00028        {      if (!testTree(tree,"Midpoint")) return false;
00029               XmlTag tag=tree.getTag();
00030               if (!tag.hasParam("first") || !tag.hasParam("second"))
00031                      throw new ConstructionException("Line points missing!");
00032               try
00033               {      PointObject p1=(PointObject)c.find(tag.getValue("first")); 
00034                      PointObject p2=(PointObject)c.find(tag.getValue("second"));
00035                      MidpointObject p=new MidpointObject(c,p1,p2);
00036                      PointConstructor.setType(tag,p);
00037                      setName(tag,p);
00038                      set(tree,p);
00039                      c.add(p);
00040                      setConditionals(tree,c,p);
00041               }
00042               catch (ConstructionException e)
00043               {      throw e;
00044               }
00045               catch (Exception e)
00046               {      throw new ConstructionException("Midpoint points illegal!");
00047               }
00048               return true;
00049        }
00050 
00051        public String getPrompt ()
00052        {      return Zirkel.name("prompt.midpoint");
00053        }
00054 
00055        public String getTag () { return "Midpoint"; }
00056        public void construct (Construction c, 
00057               String name, String params[], int nparams)
00058               throws ConstructionException
00059        {      if (nparams!=2)
00060                      throw new ConstructionException(Zirkel.name("exception.nparams"));
00061               ConstructionObject
00062                      P1=c.find(params[0]);
00063               if (P1==null)
00064                      throw new ConstructionException(Zirkel.name("exception.notfound")+" "+
00065                             params[0]);
00066               if (!(P1 instanceof PointObject))
00067                      throw new ConstructionException(Zirkel.name("exception.type")+" "+
00068                             params[0]);
00069               ConstructionObject
00070                      P2=c.find(params[1]);
00071               if (P2==null)
00072                      throw new ConstructionException(Zirkel.name("exception.notfound")+" "+
00073                             params[1]);
00074               if (!(P2 instanceof PointObject))
00075                      throw new ConstructionException(Zirkel.name("exception.type")+" "+
00076                             params[1]);
00077               MidpointObject s=new MidpointObject(c,(PointObject)P1,(PointObject)P2);
00078               if (!name.equals("")) s.setNameCheck(name);
00079               c.add(s);
00080               s.setDefaults();
00081        }
00082 
00083 }