Back to index

wims  3.65+svn20090927
Circle3Constructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: Cicle3Constructor.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 Circle3Constructor extends ObjectConstructor
00013 {      PointObject P1=null,P2=null,P3=null;
00014        public void mousePressed (MouseEvent e, ZirkelCanvas zc)
00015        {      if (!zc.Visual) return;
00016               if (P1==null)
00017               {      P1=select(e.getX(),e.getY(),zc);
00018                      if (P1!=null)
00019                      {      P1.setSelected(true);
00020                             zc.repaint();
00021                      }
00022                      showStatus(zc);
00023               }
00024               else if (P2==null)
00025               {      P2=select(e.getX(),e.getY(),zc);
00026                      if (P2!=null && P2!=P1)
00027                      {      P2.setSelected(true);
00028                             zc.repaint();
00029                      }
00030                      showStatus(zc);
00031               }
00032               else
00033               {      P3=select(e.getX(),e.getY(),zc);
00034                      if (P3!=null)
00035                      {      Circle3Object c=new Circle3Object(zc.getConstruction(),P1,P2,P3);
00036                             zc.addObject(c);
00037                             c.setDefaults();
00038                             c.updateCircleDep();
00039                             P1=P2=P3=null;
00040                             zc.clearSelected();
00041                             showStatus(zc);
00042                      }
00043               }
00044        }
00045        public boolean waitForLastPoint ()
00046        {      return P1!=null && P2!=null;
00047        }
00048        public void finishConstruction (MouseEvent e, ZirkelCanvas zc)
00049        {      P3=select(e.getX(),e.getY(),zc);
00050               if (P3!=null)
00051               {      Circle3Object c=new Circle3Object(zc.getConstruction(),P1,P2,P3);
00052                      zc.addObject(c);
00053                      c.setDefaults();
00054                      zc.validate();
00055                      zc.repaint();
00056                      P3=null;
00057               }      
00058        }
00059        public PointObject select (int x, int y, ZirkelCanvas zc)
00060        {      return zc.selectCreatePoint(x,y);
00061        }
00062        public void reset (ZirkelCanvas zc)
00063        {      super.reset(zc);
00064               if (zc.Visual)
00065               {      P1=P2=P3=null;
00066                      showStatus(zc);
00067               }
00068               else
00069               {      zc.setPrompt(Zirkel.name("prompt.circle3"));
00070               }
00071        }
00072        public void showStatus (ZirkelCanvas zc)
00073        {      if (P1==null) zc.showStatus(
00074                      Zirkel.name("message.circle3.first","Circle: Choose the first radius point!"));
00075               else if (P2==null) zc.showStatus(
00076                      Zirkel.name("message.circle3.second","Circle: Choose the second radius point!"));
00077               else zc.showStatus(
00078                      Zirkel.name("message.circle3.midpoint","Circle: Choose the midpoint!"));
00079        }
00080 
00081        public boolean construct (XmlTree tree, Construction c)
00082               throws ConstructionException
00083        {      if (!testTree(tree,"Circle3")) return false;
00084               XmlTag tag=tree.getTag();
00085               if (!tag.hasParam("midpoint") || !tag.hasParam("from") ||
00086                             !tag.hasParam("to"))
00087                      throw new ConstructionException("Circle3 parameters missing!");
00088               try
00089               {      PointObject p1=(PointObject)c.find(tag.getValue("midpoint")); 
00090                      PointObject p2=(PointObject)c.find(tag.getValue("from"));
00091                      PointObject p3=(PointObject)c.find(tag.getValue("to"));
00092                      Circle3Object o=new Circle3Object(c,p2,p3,p1);
00093                      if (tag.hasParam("partial")) o.setPartial(true);
00094                      if (tag.hasParam("start") && tag.hasParam("end"))
00095                             o.setRange(tag.getValue("start"),tag.getValue("end"));
00096                      setName(tag,o);
00097                      set(tree,o);
00098                      c.add(o);
00099                      setConditionals(tree,c,o);
00100               }
00101               catch (ConstructionException e)
00102               {      throw e;
00103               }
00104               catch (Exception e)
00105               {      throw new ConstructionException("Circle3 parameters illegal!");
00106               }
00107               return true;
00108        }
00109 }