Back to index

wims  3.65+svn20090927
ImageConstructor.java
Go to the documentation of this file.
00001 /*
00002  * Created on 19.11.2005
00003  *
00004  */
00005 package rene.zirkel.constructors;
00006 
00007 import java.awt.event.MouseEvent;
00008 import rene.util.xml.XmlTag;
00009 import rene.util.xml.XmlTree;
00010 import rene.zirkel.Zirkel;
00011 import rene.zirkel.ZirkelCanvas;
00012 import rene.zirkel.construction.Construction;
00013 import rene.zirkel.construction.ConstructionException;
00014 import rene.zirkel.objects.ConstructionObject;
00015 import rene.zirkel.objects.ImageObject;
00016 import rene.zirkel.objects.PointObject;
00017 
00018 public class ImageConstructor extends ObjectConstructor
00019 {      PointObject P[];
00020        int NPoints;
00021        
00022        public void mousePressed (MouseEvent e, ZirkelCanvas zc)
00023        {      if (!zc.Visual) return;
00024               PointObject p=zc.selectCreatePoint(e.getX(),e.getY());
00025               if (p!=null)
00026               {      P[NPoints++]=p;
00027                      p.setSelected(true);
00028                      zc.repaint();
00029               }
00030               showStatus(zc);
00031               if (NPoints==3)
00032               {      String filename=zc.loadImage();
00033                      if (filename.equals(""))
00034                      {      reset(zc);
00035                             return;
00036                      }
00037                      ImageObject o=new ImageObject(zc.getConstruction(),P,filename);
00038                      zc.addObject(o);
00039                      zc.clearSelected();
00040                      reset(zc);
00041                      zc.repaint();
00042               }
00043        }
00044 
00045        public void showStatus (ZirkelCanvas zc)
00046        {      if (NPoints<=1) zc.showStatus(ConstructionObject.text1(
00047                      Zirkel.name("message.image"),""+(NPoints+1)));
00048               else zc.showStatus(Zirkel.name("message.image.last"));
00049        }
00050        
00051        public void reset (ZirkelCanvas zc)
00052        {      super.reset(zc);
00053               if (zc.Visual)
00054               {      P=new PointObject[3]; NPoints=0;
00055                      showStatus(zc);
00056               }
00057               else
00058               {      zc.setPrompt(Zirkel.name("prompt.image"));
00059               }
00060        }
00061 
00062        public boolean construct (XmlTree tree, Construction c)
00063               throws ConstructionException
00064        {      if (!testTree(tree,"Image")) return false;
00065               XmlTag tag=tree.getTag();
00066               for (int i=0; i<3; i++)
00067                      if (!tag.hasParam("point"+(i+1)))
00068                             throw new ConstructionException("Image points missing!");
00069               if (!tag.hasParam("filename"))
00070                      throw new ConstructionException("Image filename missing!");
00071               try
00072               {      PointObject P[]=new PointObject[3];
00073                      for (int i=0; i<3; i++)
00074                             P[i]=(PointObject)c.find(tag.getValue("point"+(i+1))); 
00075                      String filename=tag.getValue("filename");
00076                      ImageObject p=new ImageObject(c,P,filename);
00077                      setName(tag,p);
00078                      set(tree,p);
00079                      c.add(p);
00080                      setConditionals(tree,c,p);
00081               }
00082               catch (ConstructionException e)
00083               {      throw e;
00084               }
00085               catch (Exception e)
00086               {      throw new ConstructionException("Image points illegal!");
00087               }
00088               return true;
00089        }
00090 
00091        public String getPrompt ()
00092        {      return Zirkel.name("prompt.image");
00093        }
00094 
00095        public String getTag () { return "Image"; }
00096 
00097        public void construct (Construction c, 
00098               String name, String params[], int nparams)
00099               throws ConstructionException
00100        {      
00101        }
00102 
00103 }
00104