Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/backend/structure/VectorVariable.java

Go to the documentation of this file.
00001 
00007 package m2m.backend.structure;
00008 
00009 import m2m.backend.utils.XMLUtils;
00010 
00011 import org.w3c.dom.Document;
00012 import org.w3c.dom.Node;
00013 
00014 public class VectorVariable extends Variable {
00015         
00016 
00017         private Variable var;
00018         private int indice;
00019 
00020         public boolean insideFromXml(org.w3c.dom.Element el,Function newFunc) {
00021                 super.insideFromXml(el,newFunc);
00022                 indice=XMLUtils.getIntValue(el,"Indice",0);
00023                 
00024 
00025                 Node node = el.getFirstChild();
00026                 while(node!=null) {
00027                         if (node.getNodeName().equalsIgnoreCase("InntVar")) {
00028                                 org.w3c.dom.Element inputEl=(org.w3c.dom.Element)node;
00029                                 Node nodeIn = inputEl.getFirstChild().getNextSibling();
00030                                 while(nodeIn!=null) {
00031                                         if (nodeIn.getNodeType()==org.w3c.dom.Node.ELEMENT_NODE) {
00032                                                 Element element=getElement((org.w3c.dom.Element)nodeIn,newFunc);
00033                                                 if (element!=null)
00034                                                         var=(Variable)element;
00035                                         }
00036                                         nodeIn=nodeIn.getNextSibling();
00037                                 }
00038                         }
00039                 }
00040                 if (name.isEmpty())
00041                         return false;
00042                 return true;
00043         }
00044         
00045         public String getXmlTagName() {
00046                 return "VectorVariable";
00047         }
00048         
00049         public void insideToXml(org.w3c.dom.Element el,Document dom,boolean shortRef) {
00050                 if (shortRef)
00051                         el.appendChild(XMLUtils.createTextElement(dom,"Name",name));
00052                 else {
00053                         super.insideToXml(el,dom,shortRef);
00054                         el.appendChild(XMLUtils.createIntElement(dom,"Indice",indice));
00055                         org.w3c.dom.Element v=dom.createElement("IntVar");
00056                         v.appendChild(var.toXml(dom,shortRef));
00057                         el.appendChild(v);
00058                 }
00059         }
00060         
00061         @Override
00062         public Element copy(Function newFunc) {
00063                 VectorVariable newVect=new VectorVariable();
00064                 newVect.var = (Variable)var.copy(newFunc);
00065                 newVect.indice = this.indice;
00066                 return newVect;
00067         }
00068 
00069 
00070         public VectorVariable() {
00071                 this.var = null;
00072                 this.indice = 0;
00073         }
00074 
00075         public VectorVariable(Variable var, int i) {
00076                 this.var = var;
00077                 this.indice = i;
00078         }
00079 
00080         public void setVar(Variable var) {
00081                 this.var = var;
00082         }
00083 
00084         public Variable getVar() {
00085                 return this.var;
00086         }
00087 
00088         public void setInd(int i) {
00089                 this.indice = i;
00090         }
00091 
00092         public int getInd() {
00093                 return this.indice;
00094         }
00095 
00096         public void setVal(double val) {
00097                 this.var.setVal(val);
00098         }
00099 
00100         public double getVal() {
00101                 return this.var.getVal();
00102         }
00103 
00104         public void setType(String t) {
00105                 this.var.setType(t);
00106         }
00107 
00108         public String getType() {
00109                 return this.var.getType();
00110         }
00111 
00112         public int getSize() {
00113                 return 1;
00114         }
00115 
00116         @Override
00117         public String getName() {
00118                 return this.var.getName();
00119         }
00120 
00121         @Override
00122         public void setName(String name) {
00123                 this.var.setName(name);
00124         }
00125 
00126         @Override
00127         public String toString(int level) {
00128                 String s = new String();
00129                 s += this.tab(level) + "[VectorVariable]\tIndice: " + this.indice + "\n";
00130                 s += this.var.toString(level + 1);
00131                 return s;
00132         }
00133 
00134         @Override
00135         public String toSchematic(int level, String prefix, String boxFormat, String color) {
00136                 String s = new String();
00137                 if (prefix.isEmpty()) {
00138                         prefix = "var";
00139                 }
00140                 if (this.getName().isEmpty()) {
00141                         s += "\n" + tab(level) + prefix + "[shape=\"" + boxFormat + "\" label = \"" + this.getVal() + "\" color=\"" + color + "\" style=\"filled\"]";
00142                 } else {
00143                         s += "\n" + tab(level) + prefix + "[shape=\"" + boxFormat + "\" label = \"" + this.getName() + "[" + this.indice + "]" + "\" color=\"" + color + "\" style=\"filled\"]";
00144                 }
00145                 return s;
00146         }
00147 }
 All Classes Namespaces Files Functions Variables Enumerations