Math2mat
|
00001 00017 package m2m.frontend.dynamicview.model; 00018 00019 import java.util.Iterator; 00020 import java.util.LinkedList; 00021 import java.util.Vector; 00022 00023 import m2m.backend.buildingblocks.BuildingBlock.NumType; 00024 import m2m.backend.project.M2MProject; 00025 import m2m.backend.structure.Element; 00026 import m2m.frontend.dynamicview.model.GraphicLoopIterator; 00027 00028 public class Schema extends Node 00029 { 00033 public static final String PROPERTY = "Property"; 00034 00035 00039 private GraphicIf lastIfSelected = null; 00043 private GraphicLoopIterator lastLoopIteratorSelected = null; 00047 private Node selectedNode; 00051 private Connection selectedConnection; 00055 private boolean propertyLock = false; 00059 public int maxDepth = 0; 00063 private M2MProject project; 00064 00065 00070 public Node getSelectedNode() 00071 { 00072 return selectedNode; 00073 } 00074 00075 00080 public void setSelectedNode(Node newNode) 00081 { 00082 Node oldNode = selectedNode; 00083 selectedNode = newNode; 00084 selectedConnection = null; 00085 firePropertyChange(Schema.PROPERTY, oldNode, newNode); 00086 } 00087 00088 00093 public Connection getSelectedConnection() 00094 { 00095 return selectedConnection; 00096 } 00097 00098 00103 public void setSelectedConnection(Connection newConn) 00104 { 00105 selectedConnection = newConn; 00106 selectedNode = null; 00107 firePropertyChange(Schema.PROPERTY, null, newConn); 00108 } 00109 00110 00115 public void setLastIfSelected(GraphicIf ifSelected) 00116 { 00117 lastIfSelected = ifSelected; 00118 } 00119 00120 00125 public GraphicIf getLastIfSelected() 00126 { 00127 return lastIfSelected; 00128 } 00129 00130 00135 public void setLastLoopIteratorSelected(GraphicLoopIterator iteratorSelected) 00136 { 00137 lastLoopIteratorSelected = iteratorSelected; 00138 } 00139 00140 00145 public GraphicLoopIterator getLastloopIteratorSelected() 00146 { 00147 return lastLoopIteratorSelected; 00148 } 00149 00150 00155 public void setPropertyLock(boolean val) 00156 { 00157 propertyLock = val; 00158 } 00159 00160 00165 public boolean getPropertyLock() 00166 { 00167 return propertyLock; 00168 } 00169 00170 00175 public Vector<Node> getAllNodes() 00176 { 00177 /* Use to get all nodes */ 00178 Node node; 00179 LinkedList<Node> tempNodeList = new LinkedList<Node>(); 00180 Iterator<Node> iterNode; 00181 Vector<Node> nodeList = new Vector<Node>(); 00182 00183 /* Initialize the nodes list and the node iterator */ 00184 tempNodeList.addAll(getChildrenArray()); 00185 nodeList.addAll(tempNodeList); 00186 iterNode = tempNodeList.iterator(); 00187 00188 /* Get all the node and connection inside the schema */ 00189 while (iterNode.hasNext()) 00190 { 00191 node = iterNode.next(); 00192 00193 /* Check if the node has children */ 00194 if(node.getChildrenArray().size() != 0) 00195 { 00196 tempNodeList.addAll(node.getChildrenArray()); 00197 nodeList.addAll(node.getChildrenArray()); 00198 } 00199 00200 tempNodeList.remove(tempNodeList.indexOf(node)); 00201 iterNode = tempNodeList.iterator(); 00202 } 00203 00204 return nodeList; 00205 } 00206 00207 00212 public Vector<Element> getInternalElements() 00213 { 00214 Vector<Element> internalElements = new Vector<Element>(); 00215 Vector<Node> nodes = new Vector<Node>(); 00216 00217 // Get all nodes of the graphic schema 00218 nodes = getAllNodes(); 00219 00220 /* Select internal pointConnection and get its internal element */ 00221 for(Node node : nodes) 00222 if(node instanceof PointConnection && node.getParent() != this && !internalElements.contains(node.getElement())) 00223 internalElements.add(node.getElement()); 00224 00225 return internalElements; 00226 } 00227 00228 00233 public void setMaxDepth(Vector<Node> nodes) 00234 { 00235 for(Node node : nodes) 00236 { 00237 node.setDepthLevel(); 00238 if(maxDepth < node.getDepthLevel()) 00239 maxDepth = node.getDepthLevel(); 00240 } 00241 } 00242 00243 00248 public void setproject(M2MProject project) { 00249 this.project = project; 00250 } 00251 00252 00257 public NumType getDataType() { 00258 return project.getOptimisationProperties().getOptimisationDataType(); 00259 } 00260 00261 00266 public boolean getFifoComp() { 00267 return project.getProperties().getOptimisationProperties().getFifoCompensation(); 00268 } 00269 00274 public void setFifoComp(boolean val) { 00275 project.getProperties().getOptimisationProperties().setFifoCompensation(val); 00276 } 00277 00282 public void setDataType(NumType num) { 00283 if (num!=project.getOptimisationProperties().getOptimisationDataType()) { 00284 project.getOptimisationProperties().setOptimisationDataType(num); 00285 project.getStructTreatment().modifyNumType(num); 00286 } 00287 } 00288 }