Back to index

wims  3.65+svn20090927
ExpressionConstructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: PointConstructor.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.expression.*;
00011 import rene.zirkel.objects.*;
00012 
00013 public class ExpressionConstructor extends ObjectConstructor
00014 {      ExpressionObject O;
00015        public void mousePressed (MouseEvent e, ZirkelCanvas zc)
00016        {      double x=zc.x(e.getX()),y=zc.y(e.getY());
00017               ExpressionObject o=new ExpressionObject(zc.getConstruction(),x,y);
00018               zc.addObject(o);
00019               o.setShowName(false);
00020               o.setDefaults();
00021               zc.repaint();
00022               Dragging=true;
00023               O=o;
00024        }
00025        public void mouseDragged (MouseEvent e, ZirkelCanvas zc)
00026        {      if (!Dragging) return;
00027               O.move(zc.x(e.getX()),zc.y(e.getY()));
00028               zc.repaint();
00029        }
00030        public void mouseReleased (MouseEvent e, ZirkelCanvas zc)
00031        {      if (!Dragging) return;
00032               Dragging=false;
00033               O.edit(zc);
00034        }
00035        public boolean waitForPoint ()
00036        {      return false;
00037        }
00038        public void showStatus (ZirkelCanvas zc)
00039        {      zc.showStatus(
00040                      Zirkel.name("message.expression","Expression: Choose a place!"));
00041        }
00042        public boolean construct (XmlTree tree, Construction c)
00043               throws ConstructionException
00044        {      if (!testTree(tree,"Expression")) return false;
00045               XmlTag tag=tree.getTag();
00046               if (!tag.hasParam("x") || !tag.hasParam("y"))
00047                      throw new ConstructionException("Expression coordinates missing!");
00048               if (!tag.hasParam("value"))
00049                      throw new ConstructionException(
00050                             Zirkel.name("exception.expression"));
00051               ExpressionObject p=new ExpressionObject(c,0,0);
00052               double x,y;
00053               try
00054               {      x=new Expression(tag.getValue("x"),c,p).getValue();
00055                      y=new Expression(tag.getValue("y"),c,p).getValue();
00056                      p.move(x,y);
00057               }
00058               catch (Exception e) {}
00059               p.setDefaults();
00060               if (tag.hasParam("prompt")) p.setPrompt(tag.getValue("prompt"));
00061               if (tag.hasParam("fixed"))
00062               {      p.setFixed(tag.getValue("x"),tag.getValue("y"));
00063               }
00064               p.setShowValue(tag.hasParam("showvalue"));
00065               setName(tag,p);
00066               set(tree,p);
00067               c.add(p);
00068               try
00069               {      p.setExpression(tag.getValue("value"),c);
00070               }
00071               catch (Exception e)
00072               {      throw new ConstructionException(
00073                             Zirkel.name("exception.expression"));
00074               }
00075               setConditionals(tree,c,p);
00076               if (tag.hasTrueParam("slider"))
00077               {      try
00078                      {      p.setSlider(tag.getValue("min"),
00079                                    tag.getValue("max"));
00080                      }
00081                      catch (Exception e)
00082                      {      throw new ConstructionException(
00083                                    Zirkel.name("exception.expression"));
00084                      }
00085               }
00086               return true;
00087        }
00088 
00089        public String getTag () { return "Expression"; }
00090        public void construct (Construction c, 
00091               String name, String params[], int nparams)
00092               throws ConstructionException
00093        {      if (nparams==1)
00094               {      ExpressionObject o=new ExpressionObject(c,
00095                             c.getX()+(Math.random()-0.5)*c.getW(),
00096                             c.getY()+(Math.random()-0.5)*c.getW());
00097                      if (!name.equals("")) o.setNameCheck(name);
00098                      c.add(o);
00099                      o.setDefaults();
00100                      try
00101                      {      o.setExpression(params[0],c);
00102                      }
00103                      catch (Exception e)
00104                      {      throw new ConstructionException(
00105                                    Zirkel.name("exception.expression"));
00106                      }
00107               }
00108               else
00109                      throw new ConstructionException(Zirkel.name("exception.nparams"));
00110        }
00111 
00112        public boolean useSmartBoard ()
00113        {      return false;
00114        }
00115 
00116 }