Back to index

wims  3.65+svn20090927
ParallelConstructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: ParallelConstructor.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 ParallelConstructor extends ObjectConstructor
00013 {      PointObject P=null;
00014        PrimitiveLineObject L=null;
00015        public void mousePressed (MouseEvent e, ZirkelCanvas zc)
00016        {      if (!zc.Visual) return;
00017               if (L==null)
00018               {      L=selectline(e.getX(),e.getY(),zc);
00019                      if (L!=null)
00020                      {      L.setSelected(true);
00021                             zc.repaint();
00022                      }
00023                      showStatus(zc);
00024               }
00025               else
00026               {      P=select(e.getX(),e.getY(),zc);
00027                      if (P!=null)
00028                      {      ConstructionObject o=create(zc.getConstruction(),L,P);
00029                             zc.addObject(o);
00030                             o.setDefaults();
00031                             P=null; L=null;
00032                             zc.clearSelected();
00033                             showStatus(zc);
00034                      }
00035               }
00036        }
00037        public boolean waitForLastPoint ()
00038        {      return L!=null;
00039        }
00040        public void finishConstruction (MouseEvent e, ZirkelCanvas zc)
00041        {      P=select(e.getX(),e.getY(),zc);
00042               if (P!=null)
00043               {      ConstructionObject o=create(zc.getConstruction(),L,P);
00044                      zc.addObject(o);
00045                      o.setDefaults();
00046                      zc.validate();
00047                      zc.repaint();
00048                      P=null;
00049               }      
00050        }
00051        public void mouseMoved (MouseEvent e, ZirkelCanvas zc, boolean simple)
00052        {      if (!simple && waitForLastPoint())
00053               {      if (zc.isPreview())
00054                      {      zc.movePreview(e);
00055                      }
00056                      else
00057                      {      zc.prepareForPreview(e);
00058                             finishConstruction(e,zc);
00059                      }
00060               }
00061               if (L==null) zc.indicateLineObjects(e.getX(),e.getY());
00062               else if (P==null) zc.indicateCreatePoint(e.getX(),e.getY(),false);
00063        }
00064        public PointObject select (int x, int y, ZirkelCanvas zc)
00065        {      return zc.selectCreatePoint(x,y);
00066        }
00067        public PrimitiveLineObject selectline (int x, int y, ZirkelCanvas zc)
00068        {      return zc.selectLine(x,y);
00069        }
00070        public PrimitiveLineObject create (Construction c, PrimitiveLineObject l, PointObject p)
00071        {      return new ParallelObject(c,l,p);
00072        }
00073        public void reset (ZirkelCanvas zc)
00074        {      super.reset(zc);
00075               if (zc.Visual)
00076               {      P=null; L=null;
00077                      showStatus(zc);
00078               }
00079               else
00080               {      zc.setPrompt(getPrompt());
00081               }
00082        }
00083        public String getPrompt ()
00084        {      return Zirkel.name("prompt.parallel");
00085        }
00086        public void showStatus (ZirkelCanvas zc)
00087        {      if (L==null) zc.showStatus(
00088                      Zirkel.name("message.parallel.first","Parallel: Choose a line!"));
00089               else zc.showStatus(
00090                      Zirkel.name("message.parallel.second","Parallel: Choose a Point!"));
00091        }
00092        public boolean construct (XmlTree tree, Construction c)
00093               throws ConstructionException
00094        {      if (!testTree(tree,"Parallel")) return false;
00095               XmlTag tag=tree.getTag();
00096               if (!tag.hasParam("point") || !tag.hasParam("line"))
00097                      throw new ConstructionException("Parallel parameters missing!");
00098               try
00099               {      PointObject p1=(PointObject)c.find(tag.getValue("point"));
00100                      PrimitiveLineObject p2=(PrimitiveLineObject)c.find(tag.getValue("line"));
00101                      ParallelObject o=new ParallelObject(c,p2,p1);
00102                      setName(tag,o);
00103                      set(tree,o);
00104                      if (tag.hasParam("partial")) o.setPartial(true);
00105                      c.add(o);
00106                      setConditionals(tree,c,o);
00107               }
00108               catch (ConstructionException e)
00109               {      throw e;
00110               }
00111               catch (Exception e)
00112               {      throw new ConstructionException("Parallel parameters illegal!");
00113               }
00114               return true;
00115        }
00116 
00117        public String getTag () { return "Parallel"; }
00118        public void construct (Construction c, 
00119               String name, String params[], int nparams)
00120               throws ConstructionException
00121        {      if (nparams!=2)
00122                      throw new ConstructionException(Zirkel.name("exception.nparams"));
00123               ConstructionObject
00124                      P1=c.find(params[0]);
00125               if (P1==null)
00126                      throw new ConstructionException(Zirkel.name("exception.notfound")+" "+
00127                             params[0]);
00128               ConstructionObject
00129                      P2=c.find(params[1]);
00130               if (P2==null)
00131                      throw new ConstructionException(Zirkel.name("exception.notfound")+" "+
00132                             params[1]);
00133               if (!(P1 instanceof PrimitiveLineObject))
00134                      throw new ConstructionException(Zirkel.name("exception.type")+" "+
00135                             params[0]);
00136               if (!(P2 instanceof PointObject))
00137                      throw new ConstructionException(Zirkel.name("exception.type")+" "+
00138                             params[1]);
00139               ParallelObject s=new ParallelObject(c,
00140                      (PrimitiveLineObject)P1,(PointObject)P2);
00141               if (!name.equals("")) s.setNameCheck(name);
00142               c.add(s);
00143               s.setDefaults();
00144        }
00145 
00146 }