Math2mat
|
00001 00016 package m2m.frontend.dynamicview.commands; 00017 00018 import m2m.frontend.dynamicview.ThreadRouteConnections; 00019 import m2m.frontend.dynamicview.model.GraphicFunction; 00020 import m2m.frontend.dynamicview.model.Node; 00021 import m2m.frontend.dynamicview.model.PointConnection; 00022 00023 import org.eclipse.draw2d.geometry.Rectangle; 00024 import org.eclipse.swt.widgets.Display; 00025 00026 00027 public class FunctionChangeLayoutCommand extends AbstractLayoutCommand 00028 { 00032 private GraphicFunction model; 00036 private Rectangle layoutOutPut = new Rectangle(); 00037 00038 00042 public void execute() 00043 { 00044 /* Set the layout of output connection points */ 00045 for(PointConnection pc : model.getOutputPointsConnection()) 00046 { 00047 layoutOutPut.x = getLayout().x - model.getLayout().x + pc.getLayout().x; 00048 layoutOutPut.y = getLayout().y - model.getLayout().y + pc.getLayout().y; 00049 layoutOutPut.height = pc.getLayout().height; 00050 layoutOutPut.width = pc.getLayout().width; 00051 pc.setLayout(new Rectangle(layoutOutPut)); 00052 } 00053 00054 // Set the layout of the model 00055 model.setLayout(getLayout()); 00056 00057 // Route connections 00058 Display.getCurrent().asyncExec(new ThreadRouteConnections()); 00059 } 00060 00061 00062 00067 public boolean canExecute() 00068 { 00069 /* Check if we can set the layout of the model */ 00070 if(model.CanSetLayout(getLayout())) 00071 { 00072 /* Check if we can set the layout of output connection points */ 00073 for(PointConnection pc : model.getOutputPointsConnection()) 00074 { 00075 layoutOutPut.x = getLayout().x - model.getLayout().x + pc.getLayout().x; 00076 layoutOutPut.y = getLayout().y - model.getLayout().y + pc.getLayout().y; 00077 layoutOutPut.height = pc.getLayout().height; 00078 layoutOutPut.width = pc.getLayout().width; 00079 if(!pc.CanSetLayout(layoutOutPut)) 00080 return false; 00081 } 00082 return true; 00083 } 00084 return false; 00085 } 00086 00087 00092 public void setModel(Node model) 00093 { 00094 this.model = (GraphicFunction)model; 00095 } 00096 }