Back to index

wims  3.65+svn20090927
BoundedPointConstructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: PointConstructor.java
00004 
00005 import java.awt.event.*;
00006 
00007 import rene.util.xml.*;
00008 import rene.zirkel.*;
00009 import rene.zirkel.construction.*;
00010 import rene.zirkel.objects.*;
00011 
00012 public class BoundedPointConstructor extends ObjectConstructor
00013        implements Selector
00014 {      boolean Control;
00015 
00016        public void mousePressed (MouseEvent e, ZirkelCanvas zc)
00017        {      if (!zc.Visual) return;
00018               Control=e.isControlDown();
00019               ConstructionObject o=zc.selectWithSelector(e.getX(),e.getY(),this);
00020               if (o==null) return;
00021               PointObject p=
00022                      new PointObject(zc.getConstruction(),zc.x(e.getX()),zc.y(e.getY()),o);
00023               if (!e.isShiftDown()) p.setUseAlpha(true);
00024               if (Control && o instanceof InsideObject) p.setInside(true);
00025               zc.addObject(p);
00026               p.validate();
00027               p.setDefaults();
00028        }
00029 
00030        public void mouseMoved (MouseEvent e, ZirkelCanvas zc, boolean simple)
00031        {      Control=e.isControlDown();
00032               zc.indicateWithSelector(e.getX(),e.getY(),this);
00033        }
00034        
00035        public void showStatus (ZirkelCanvas zc)
00036        {      zc.showStatus(
00037                      Zirkel.name("message.boundedpoint",
00038                             "Bounded Point: Choose a circle or line!"));
00039        }
00040        
00041        public boolean isAdmissible (ZirkelCanvas zc, ConstructionObject o) 
00042        {      if (Control && o instanceof InsideObject) return true;
00043               else if (!Control && o instanceof PointonObject) return true;
00044               return false;
00045        }      
00046        
00047        public boolean construct (XmlTree tree, Construction c)
00048               throws ConstructionException
00049        {      if (!testTree(tree,"PointOn")) return false;
00050               XmlTag tag=tree.getTag();
00051               if (!tag.hasParam("on"))
00052                      throw new ConstructionException("Point bound missing!");
00053               try
00054               {      ConstructionObject o=
00055                             (ConstructionObject)c.find(tag.getValue("on"));
00056                      if (o!=null && !(o instanceof PointonObject) && !(o instanceof InsideObject))
00057                                    throw new ConstructionException("");
00058                      double x=0,y=0;
00059                      try
00060                      {      x=new Double(tag.getValue("x")).doubleValue();
00061                             y=new Double(tag.getValue("y")).doubleValue();
00062                      }
00063                      catch (Exception e) {}
00064                      PointObject p;
00065                      if (o!=null) p=new PointObject(c,x,y,o);
00066                      else
00067                      {      p=new PointObject(c,x,y);
00068                             p.setLaterBind(tag.getValue("on"));
00069                      }
00070                      p.setInside(tag.hasTrueParam("inside"));
00071                      try
00072                      {      double alpha=new Double(tag.getValue("alpha")).doubleValue();
00073                             p.setAlpha(alpha);
00074                             p.setUseAlpha(true);
00075                             if (tag.hasParam("on"))
00076                             {      ConstructionObject on=c.find(tag.getValue("on"));
00077                                    if (on!=null) p.project(on,alpha);
00078                             }
00079                      }
00080                      catch (Exception e) {}
00081                      if (tag.hasParam("shape"))
00082                      {      String s=tag.getValue("shape");
00083                             if (s.equals("square")) p.setType(0);
00084                             if (s.equals("diamond")) p.setType(1);
00085                             if (s.equals("circle")) p.setType(2);
00086                             if (s.equals("dot")) p.setType(3);
00087                             if (s.equals("cross")) p.setType(4);
00088                             if (s.equals("dcross")) p.setType(5);
00089                      }
00090                      setName(tag,p);
00091                      set(tree,p);                
00092                      c.add(p);
00093                      setConditionals(tree,c,p);
00094                      if (tag.hasParam("fixed"))
00095                      {      p.setFixed(tag.getValue("x"),tag.getValue("y"));
00096                      }
00097                      if (tag.hasParam("increment"))
00098                      {      try
00099                             {      p.setIncrement(new Double(tag.getValue("increment")).doubleValue());
00100                             }
00101                             catch (Exception e) {}
00102                      }
00103               }
00104               catch (Exception e)
00105               {      e.printStackTrace();
00106                      throw new ConstructionException("Illegal point bound!");
00107               }
00108               return true;
00109        }
00110 
00111        public void reset (ZirkelCanvas zc)
00112        {      super.reset(zc);
00113               zc.setPrompt(Zirkel.name("prompt.pointon"));
00114        }
00115 }