Back to index

wims  3.65+svn20090927
ObjectConstructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: ObjectConstructor.java
00004 
00005 import java.awt.event.*;
00006 import java.util.*;
00007 
00008 import rene.util.xml.*;
00009 import rene.zirkel.*;
00010 import rene.zirkel.construction.*;
00011 import rene.zirkel.expression.*;
00012 import rene.zirkel.objects.*;
00013 
00014 public class ObjectConstructor
00015 {      protected boolean Dragging=false;
00016 
00017        public void mousePressed (MouseEvent e, ZirkelCanvas zc) {}
00018        public void mouseReleased (MouseEvent e, ZirkelCanvas zc) {}
00019        public void mouseDragged (MouseEvent e, ZirkelCanvas zc) {}
00020 
00021        public void mouseMoved (MouseEvent e, ZirkelCanvas zc, boolean simple)
00022        {      if (simple && (waitForPoint() || waitForLastPoint()))
00023               {      zc.indicateCreatePoint(e.getX(),e.getY(),false);
00024                      return;
00025               }
00026               if (waitForPoint())
00027                      zc.indicateCreatePoint(e.getX(),e.getY(),false);
00028               if (waitForLastPoint())
00029               {      if (zc.isPreview())
00030                      {      zc.movePreview(e);
00031                      }
00032                      else
00033                      {      zc.prepareForPreview(e);
00034                             finishConstruction(e,zc);
00035                             return;
00036                      }
00037               }
00038        }
00039 
00040        public void finishConstruction (MouseEvent e, ZirkelCanvas zc)
00041        {
00042        }
00043        
00044        public boolean waitForLastPoint ()
00045        {      return false;
00046        }
00047        
00048        public boolean waitForPoint ()
00049        {      return true;
00050        }
00051        
00052        public void reset (ZirkelCanvas zc)
00053        {      zc.validate();
00054               zc.clearSelected();
00055        }
00056        public void resetFirstTime (ZirkelCanvas zc)
00057        {      reset(zc);
00058        }
00059        public void invalidate (ZirkelCanvas zc) {}
00060        public void showStatus (ZirkelCanvas zc) {}
00061        public boolean construct (XmlTree tree, Construction c) 
00062               throws ConstructionException
00063        {      return false;
00064        }
00065        public boolean testTree (XmlTree t, String tag)
00066        {      return t.getTag().name().equals(tag);
00067        }
00068        public void setName (XmlTag tag, ConstructionObject o)
00069        {      if (tag.hasParam("name"))
00070               {      o.setName(tag.getValue("name"));
00071               }
00072               if (tag.hasParam("alias"))
00073               {      o.setAlias(tag.getValue("alias"));
00074               }
00075        }
00076        public void set (XmlTree tree, ConstructionObject o)
00077               throws ConstructionException
00078        {      XmlTag tag=tree.getTag();
00079               if (tag.hasParam("n"))
00080               {      try
00081                      {      o.setNCount(new Integer(tag.getValue("n")).intValue());
00082                             o.setGotNCount(true);
00083                      }
00084                      catch (Exception ex)
00085                      {      throw new ConstructionException("Illegal count!");
00086                      }
00087               }
00088               if (tag.hasParam("hidden"))
00089               {      if (tag.getValue("hidden").equals("super")) o.setSuperHidden(true);
00090                      else o.setHidden(true);
00091               }
00092               if (tag.hasTrueParam("showvalue"))
00093               {      o.setShowValue(true);
00094               }
00095               if (tag.hasTrueParam("showname"))
00096               {      o.setShowName(true);
00097               }
00098               if (tag.hasTrueParam("background"))
00099               {      o.setBack(true);
00100               }
00101               else o.setBack(false);
00102               if (tag.hasTrueParam("parameter"))
00103               {      o.setParameter();
00104               }
00105               if (tag.hasTrueParam("mainparameter"))
00106               {      o.setMainParameter();
00107               }
00108               if (tag.hasTrueParam("target"))
00109               {      o.setTarget(true);
00110               }
00111               if (tag.hasTrueParam("break"))
00112               {      o.setBreak(true);
00113               }
00114               if (tag.hasTrueParam("hidebreak"))
00115               {      o.setHideBreak(true);
00116               }
00117               if (tag.hasTrueParam("solid"))
00118               {      o.setSolid(true);
00119               }
00120               if (tag.hasTrueParam("bold"))
00121               {      o.setBold(true);
00122               }
00123               if (tag.hasTrueParam("large"))
00124               {      o.setLarge(true);
00125               }
00126               if (tag.hasParam("xoffset") || tag.hasParam("yoffset"))
00127               {      int x=0,y=0;
00128                      try
00129                      {      if (tag.hasParam("xoffset"))
00130                                    x=Integer.parseInt(tag.getValue("xoffset"));
00131                             if (tag.hasParam("yoffset"))
00132                                    y=Integer.parseInt(tag.getValue("yoffset"));
00133                             o.setOffset(x,y);
00134                      }
00135                      catch (Exception e)
00136                      {      throw new ConstructionException("Illegal offset value");
00137                      }
00138               }
00139               if (tag.hasTrueParam("keepclose"))
00140               {      o.setKeepClose(true);
00141               }
00142               if (tag.hasParam("xcoffset") || tag.hasParam("ycoffset"))
00143               {      double x=0,y=0;
00144                      try
00145                      {      if (tag.hasParam("xcoffset"))
00146                                    x=new Double(tag.getValue("xcoffset")).doubleValue();
00147                             if (tag.hasParam("ycoffset"))
00148                                    y=new Double(tag.getValue("ycoffset")).doubleValue();
00149                             o.setcOffset(x,y);
00150                      }
00151                      catch (Exception e)
00152                      {      throw new ConstructionException("Illegal offset value");
00153                      }
00154               }
00155               if (tag.hasParam("color"))
00156               {      try
00157                      {      String s=tag.getValue("color");
00158                             int n=-1;
00159                             for (int i=0; i<ZirkelFrame.ColorStrings.length; i++)
00160                             {      if (s.equals(ZirkelFrame.ColorStrings[i]))
00161                                    {      o.setColor(i); n=i; break;
00162                                    }
00163                             }
00164                             if (n<0)
00165                             {      n=Integer.parseInt(s);
00166                                    if (n<0 || n>=ZirkelFrame.Colors.length)
00167                                           throw new Exception("");
00168                                    o.setColor(n);
00169                             }
00170                      }
00171                      catch (Exception ex)
00172                      {      throw new ConstructionException("Illegal color index (1-"+
00173                                    (ZirkelFrame.Colors.length-1)+")");
00174                      }
00175               }
00176               if (tag.hasParam("type"))
00177               {      String type=tag.getValue("type");
00178                      if (type.equals("thick")) o.setColorType(ConstructionObject.THICK);
00179                      if (type.equals("thin")) o.setColorType(ConstructionObject.THIN);
00180                      if (type.equals("invisible")) o.setColorType(ConstructionObject.INVISIBLE);
00181               }
00182               if (tag.hasParam("unit"))
00183                      o.setUnit(tag.getValue("unit"));
00184               else
00185                      o.setUnit("");
00186               Enumeration e=tree.getContent();
00187               while (e.hasMoreElements())
00188               {      tree=(XmlTree)e.nextElement();
00189                      if (tree.getTag() instanceof XmlTagText)
00190                      {      o.setText(((XmlTagText)tree.getTag()).getContent(),true);
00191                      }
00192               }
00193        }
00194        public void setConditionals (XmlTree tree, Construction c, ConstructionObject o)
00195        {      o.clearConditionals();
00196               int i=0;
00197               XmlTag tag=tree.getTag();
00198               while (tag.hasParam("ctag"+i) && tag.hasParam("cexpr"+i))
00199               {      String t=tag.getValue("ctag"+i);
00200                      String e=tag.getValue("cexpr"+i);
00201                      Expression ex=new Expression(e,c,o);
00202                      o.addConditional(t,ex);
00203                      i++;
00204               }
00205        }
00206        public String getTag ()
00207        {      return "???";
00208        }
00209        public void construct (Construction c, 
00210               String name, String params[], int nparams)
00211               throws ConstructionException
00212        {      throw new ConstructionException("");
00213        }
00214        
00215        // for MetaMover :
00216        public void pause (boolean flag)
00217        {
00218        }
00219        
00220        public boolean useSmartBoard ()
00221        {      return true;
00222        }
00223 }
00224