Back to index

wims  3.65+svn20090927
ImageObject.java
Go to the documentation of this file.
00001 /*
00002  * Created on 19.11.2005
00003  *
00004  */
00005 package rene.zirkel.objects;
00006 
00007 import java.awt.Image;
00008 import java.util.Enumeration;
00009 
00010 import rene.util.FileName;
00011 import rene.util.xml.XmlWriter;
00012 import rene.zirkel.Zirkel;
00013 import rene.zirkel.ZirkelCanvas;
00014 import rene.zirkel.construction.Construction;
00015 import rene.zirkel.construction.Count;
00016 import rene.zirkel.dialogs.ObjectEditDialog;
00017 import rene.zirkel.graphics.MyGraphics;
00018 
00019 public class ImageObject extends ConstructionObject
00020 {      PointObject P[];
00021        static Count N=new Count();
00022        String Filename;
00023        Image I;
00024        
00025        public ImageObject (Construction c, PointObject p[], String filename)
00026        {      super(c);
00027               P=p;
00028               Filename=FileName.filename(filename);
00029               updateText();
00030        }
00031 
00032        public String getTag () { return "Image"; }
00033        public int getN () { return N.next(); }
00034        
00035        public void updateText ()
00036        {      try
00037               {      String Names[]=new String[P.length];
00038                      for (int i=0; i<P.length; i++) Names[i]=P[i].getName();
00039                      setText(textAny(Zirkel.name("text.image"),Names));
00040               } 
00041               catch (Exception e) {}
00042        }
00043        
00044        public void validate ()
00045        {
00046        }
00047        
00048        public void paint (MyGraphics g, ZirkelCanvas zc)
00049        {      if (!Valid || mustHide(zc)) return;
00050               if (I==null)
00051               {      I=zc.doLoadImage(Filename);
00052                      if (I==null || I.getWidth(zc)==0 || I.getHeight(zc)==0)
00053                      {      Valid=false; return;
00054                      }
00055                      else Valid=true;
00056               }
00057               if (P[1]==P[2] || P[0]==P[2])
00058               {      int w=I.getWidth(zc),h=I.getWidth(zc);
00059                      double dx=P[1].getX()-P[0].getX(),dy=P[1].getY()-P[0].getY();
00060                      g.drawImage(I,
00061                             zc.col(P[0].getX()),zc.row(P[0].getY()),
00062                             zc.col(P[1].getX()),zc.row(P[1].getY()),
00063                             zc.col(P[0].getX()+dy),zc.row(P[0].getY()-dx),
00064                             zc);
00065               }
00066               g.drawImage(I,
00067                      zc.col(P[0].getX()),zc.row(P[0].getY()),
00068                      zc.col(P[1].getX()),zc.row(P[1].getY()),
00069                      zc.col(P[2].getX()),zc.row(P[2].getY()),
00070                      zc);
00071        }
00072        
00073        public boolean nearto (int cc, int rr, ZirkelCanvas zc)
00074        {      if (!displays(zc)) return false;
00075               return P[0].nearto(cc,rr,zc) || P[1].nearto(cc,rr,zc) || P[2].nearto(cc,rr,zc);
00076        }
00077               
00078        public void edit (ZirkelCanvas zc)
00079        {      new ObjectEditDialog(zc.getFrame(),"",this).setVisible(true);
00080               zc.repaint();
00081        }
00082 
00083        public void printArgs (XmlWriter xml)
00084        {      for (int i=0; i<P.length; i++)
00085                      xml.printArg("point"+(i+1),P[i].getName());
00086               xml.printArg("filename",FileName.filename(Filename));
00087        }
00088 
00089        public Enumeration depending ()
00090        {      DL.reset();
00091               for (int i=0; i<P.length; i++) DL.add(P[i]);
00092               return DL.elements();
00093        }
00094 
00095        public void translate ()
00096        {      for (int i=0; i<P.length; i++)
00097                      P[i]=(PointObject)P[i].getTranslation();
00098        }
00099 
00100        public ConstructionObject copy ()
00101        {      try
00102               {      QuadricObject o=(QuadricObject)clone();
00103                      setTranslation(o);
00104                      o.P=new PointObject[P.length];
00105                      for (int i=0; i<P.length; i++) o.P[i]=P[i];
00106                      o.translateConditionals();
00107                      o.translate();
00108                      o.setName();
00109                      o.updateText();
00110                      o.setBreak(false);
00111                      o.setTarget(false);
00112                      return o;
00113               }
00114               catch (Exception e)
00115               {      return null; 
00116               }
00117        }
00118        
00119        public boolean onlynearto (int x, int y, ZirkelCanvas zc)
00120        {      return nearto(x,y,zc);
00121        }
00122 
00123        public boolean hasUnit ()
00124        {      return false;
00125        }
00126 }