Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/dynamicview/model/GraphicIf.java

Go to the documentation of this file.
00001 
00015 package m2m.frontend.dynamicview.model;
00016 
00017 import java.util.Vector;
00018 
00019 import m2m.backend.structure.IfThenElse;
00020 import m2m.backend.structure.Multiplexer;
00021 import m2m.backend.structure.Operation;
00022 import m2m.backend.structure.StructTreatment;
00023 import m2m.frontend.dynamicview.figure.IfFigure;
00024 import m2m.frontend.dynamicview.figure.InternPointConnectionFigure;
00025 import m2m.frontend.view.Editor;
00026 
00027 import org.eclipse.draw2d.geometry.Rectangle;
00028 import org.eclipse.ui.PlatformUI;
00029 
00030 
00031 
00032 public class GraphicIf extends Node
00033 {
00037         private String condition;
00041         private InternPointConnection truePoint = new InternPointConnection();
00045         private InternPointConnection falsePoint = new InternPointConnection();
00049         private InternPointConnection outPoint = new InternPointConnection();
00053         private PointConnection outputPointConnection = null;
00057         private Vector<Node> conditionNodes = new Vector<Node>();
00058         
00059         
00063         public GraphicIf()
00064         {
00065                 super();
00066                 
00067                 /* Initialisation of the true intern connection point */
00068         truePoint.setName("true");
00069         truePoint.setParent(this);
00070         truePoint.setLayout(new Rectangle (IfFigure.TRUE_POINT_X_POSITION,IfFigure.TRUE_POINT_Y_POSITION,
00071                                                    InternPointConnectionFigure.WIDTH, InternPointConnectionFigure.HEIGHT));    
00072         
00073         /* Initialisation of the false intern connection point */
00074         falsePoint.setName("false");
00075         falsePoint.setParent(this);
00076         falsePoint.setLayout(new Rectangle (IfFigure.FALSE_POINT_X_POSITION,IfFigure.FALSE_POINT_Y_POSITION,
00077                                                     InternPointConnectionFigure.WIDTH, InternPointConnectionFigure.HEIGHT));       
00078         
00079         /* Initialisation of the out intern connection point */
00080         outPoint.setName("out");
00081         outPoint.setParent(this);
00082         outPoint.setLayout(new Rectangle (IfFigure.OUT_POINT_X_POSITION,IfFigure.OUT_POINT_Y_POSITION,
00083                                                   InternPointConnectionFigure.WIDTH, InternPointConnectionFigure.HEIGHT));      
00084         }
00085         
00086         
00091         public PointConnection getOutputPointConnection()
00092         {
00093                 return outputPointConnection;
00094         }
00095         
00096         
00101         public void setOutputPointConnexion(PointConnection pc)
00102         {
00103                 outputPointConnection = pc;
00104                 pc.setOutputResult(this);
00105         }
00106         
00107         
00112         public boolean getMonitor()
00113         {
00114                 if(getElement() instanceof Multiplexer)
00115                         return ((Multiplexer)getElement()).getSel().getMonitor();
00116                 else
00117                         return ((Operation)((IfThenElse)getElement()).getCond().firstElement()).getInputAt(0).getMonitor();
00118         }
00119         
00120         
00125         public void setMonitor(boolean monitor)
00126         {
00127                 Editor editor = (Editor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
00128                 StructTreatment treatment = editor.getM2MProject().getStructTreatment();
00129                 
00130                 if(getElement() instanceof Multiplexer)
00131                         ((Multiplexer)getElement()).getSel().setMonitor(monitor,treatment);
00132                 else
00133                         ((Operation)((IfThenElse)getElement()).getCond().firstElement()).getInputAt(0).setMonitor(monitor,treatment);
00134         }
00135         
00136         
00141         public String getCondition()
00142         {
00143                 return condition;
00144         }
00145         
00146         
00151         public void setCondition(String cond)
00152         {
00153                 condition = cond;
00154         }
00155         
00156         
00161         public InternPointConnection getTruePoint()
00162         {
00163                 return truePoint;
00164                 
00165         }
00166         
00167         
00172         public InternPointConnection getFalsePoint()
00173         {
00174                 return falsePoint;
00175         }
00176         
00177         
00182         public InternPointConnection getOutPoint()
00183         {
00184                 return outPoint;
00185         }
00186         
00187         
00192     public void addConditionNodes(Node node) 
00193         {
00194         if (node == null)
00195             throw new IllegalArgumentException();
00196         else 
00197                 conditionNodes.add(node);     
00198     }
00199         
00200     
00205     public void removeConditionNodes(Node node) 
00206         {
00207         if (node == null)
00208             throw new IllegalArgumentException();
00209         else 
00210                 conditionNodes.remove(node);     
00211     }
00212         
00213         
00218         public Vector<Node> getConditionNodes() 
00219         {
00220         return conditionNodes;
00221         }
00222         
00223         
00228     public Vector<Node> getChildrenArray() 
00229     {
00230         Vector<Node> children = new Vector<Node>();
00231         children.add(truePoint);
00232         children.add(falsePoint);
00233         children.add(outPoint);
00234         return children;
00235     }
00236     
00237     
00242     public void setVisible(boolean visible) 
00243     {
00244                 super.setVisible(visible);
00245                 truePoint.setVisible(visible);
00246                 falsePoint.setVisible(visible);
00247                 outPoint.setVisible(visible);
00248     }     
00249     
00250     
00255         public boolean CanSetLayout(Rectangle layoutTest)
00256         {
00257                 /* Check if the new layout is inside its parent */
00258                 if(!isInParent(layoutTest))
00259                         return false;
00260                 
00261                 /* Check if the new layout is under connection points */
00262                 for(Node node : getParent().getChildrenArray())
00263                 {
00264                         if(node != this && node != outputPointConnection)
00265                                 if(nodeUnderNode(layoutTest, node.getLayout()))
00266                                         return false;
00267                 }               
00268                 return true;
00269         }
00270 }
 All Classes Namespaces Files Functions Variables Enumerations