Back to index

wims  3.65+svn20090927
FixedCircleObject.java
Go to the documentation of this file.
00001 package rene.zirkel.objects;
00002 
00003 // file: CircleObject.java
00004 
00005 import java.awt.*;
00006 import java.util.*;
00007 
00008 import rene.util.xml.*;
00009 import rene.zirkel.*;
00010 import rene.zirkel.construction.*;
00011 import rene.zirkel.dialogs.*;
00012 import rene.zirkel.expression.*;
00013 import rene.dialogs.*;
00014 
00015 public class FixedCircleObject extends PrimitiveCircleObject
00016        implements MoveableObject, SimulationObject
00017 {      Expression E;
00018        boolean EditAborted=false;
00019        boolean Dragable=false;
00020 
00021        public FixedCircleObject (Construction c, PointObject p1, double x, double y)
00022        {      super(c,p1);
00023               init(c,x,y);
00024        }
00025        
00026        public void init (Construction c, double x, double y)
00027        {      E=new Expression(""+
00028                      Math.sqrt((x-M.getX())*(x-M.getX())+(y-M.getY())*(y-M.getY())),
00029                      c,this);
00030               validate();
00031               updateText();
00032        }
00033        
00034        public String getTag () { return "Circle"; }
00035        
00036        public void updateText ()
00037        {      if (E==null || !E.isValid()) return;
00038               setText(text2(Zirkel.name("text.fixedcircle"),
00039                             M.getName(),""+E.toString()));
00040        }
00041 
00042        public void validate ()
00043        {      super.validate();
00044               if (!M.valid()) { Valid=false; return; }
00045               Valid=true;
00046               X=M.getX(); Y=M.getY();
00047               if (E!=null && !E.isValid())
00048               {      return;
00049               }
00050               try
00051               {      if (E!=null) R=E.getValue();
00052               }
00053               catch (Exception e)
00054               {      R=0; Valid=false;
00055               }
00056               if (R<-1e-10) { Valid=false; return; }
00057        }
00058 
00059        public void printArgs (XmlWriter xml)
00060        {      if (E.isValid()) xml.printArg("fixed",E.toString());
00061               else xml.printArg("fixed",""+R);
00062               if (Dragable) xml.printArg("dragable","true");
00063               super.printArgs(xml);
00064        }
00065        
00066        public boolean canFix ()
00067        {      return true;
00068        }
00069        
00070        public boolean fixed () { return true; }
00071        public void setFixed (String s)
00072        {      E=new Expression(s,getConstruction(),this);
00073        }
00074        
00075        public void round ()
00076        {      try
00077               {      setFixed(round(E.getValue(),ZirkelCanvas.LengthsFactor)+"");
00078                      validate();
00079               }
00080               catch (Exception e) {}
00081        }
00082 
00083        public void edit (ZirkelCanvas zc)
00084        {      ObjectEditDialog d;
00085               while (true)
00086               {      d=new CircleEditDialog(zc.getFrame(),this,zc);
00087                      d.setVisible(true);
00088                      EditAborted=false;
00089                      if (d.isAborted())
00090                      {      //E=new Expression(""+R,getConstruction(),this);
00091                             EditAborted=true;
00092                             break;
00093                      }
00094                      else if (!E.isValid())
00095                      {      Frame F=zc.getFrame();
00096                             Warning w=new Warning(F,E.getErrorText(),
00097                                    Zirkel.name("warning"),true);
00098                             w.center(F);
00099                             w.setVisible(true);
00100                      }
00101                      else break;
00102               }
00103               validate();
00104               updateText();
00105               zc.getConstruction().updateCircleDep();
00106               zc.repaint();
00107               if (d.wantsMore())
00108               {      new EditConditionals(zc.getFrame(),this);
00109                      validate();
00110               }
00111        }
00112        
00113        public boolean nearto (int c, int r, ZirkelCanvas zc)
00114        {      if (!Valid && M.valid()) return M.nearto(c,r,zc);
00115               return super.nearto(c,r,zc);
00116        }
00117        
00118        public boolean isValidFix ()
00119        {      return E.isValid();
00120        }
00121        
00122        public void translate ()
00123        {      super.translate();
00124               try
00125               {      setFixed(E.toString());
00126                      E.translate();
00127               }
00128               catch (Exception e) {}
00129        }
00130 
00131        public String getStringLength ()
00132        {      return E.toString();
00133        }
00134 
00135        public double getValue ()
00136               throws ConstructionException
00137        {      if (!Valid) throw new InvalidException("exception.invalid");
00138               else return R;
00139        }
00140 
00141        public Enumeration depending ()
00142        {      super.depending();
00143               Enumeration e=E.getDepList().elements();
00144               while (e.hasMoreElements())
00145               {      DL.add((ConstructionObject)e.nextElement());
00146               }
00147               return DL.elements();
00148        }
00149 
00150        public void move (double x, double y)
00151        {      init(getConstruction(),x,y);
00152        }
00153        
00154        public boolean moveable ()
00155        {      return Dragable || M.moveable();
00156        }
00157        
00158        public boolean isFixed ()
00159        {      return true;
00160        }
00161        
00162        public boolean isEditAborted ()
00163        {      return EditAborted;
00164        }
00165        
00166        public boolean isDragable ()
00167        {      return Dragable;
00168        }
00169        
00170        public void setDragable (boolean f)
00171        {      Dragable=f; 
00172        }
00173        
00174        public boolean fixedByNumber ()
00175        {      return (E!=null && E.isNumber());
00176        }
00177 
00178        // For the simulate function:
00179        
00183        public void setSimulationValue (double x) 
00184        {      R=x;
00185               Expression OldE=E; 
00186               E=null;
00187               validate();
00188               E=OldE;
00189        }
00190        
00194        public void resetSimulationValue () 
00195        {      validate();
00196        }
00197 
00198        double x1,y1,x2,y2;
00199        
00200        public void startDrag (double x, double y) 
00201        {      x1=M.getX(); y1=M.getY();
00202               x2=x; y2=y;
00203        }
00204 
00205        public void dragTo (double x, double y) 
00206        {      if (Dragable) move(x,y);
00207               else M.move(x1+(x-x2),y1+(y-y2));
00208        }
00209 
00210        public void snap (ZirkelCanvas zc)
00211        {      if (moveable() && !Dragable)
00212               {      M.snap(zc);
00213               }
00214        }
00215 }