Math2mat
|
00001 00015 package m2m.frontend.dynamicview.figure; 00016 00017 import m2m.frontend.dynamicview.model.*; 00018 00019 import org.eclipse.draw2d.ActionEvent; 00020 import org.eclipse.draw2d.ActionListener; 00021 import org.eclipse.draw2d.Button; 00022 import org.eclipse.draw2d.CheckBox; 00023 import org.eclipse.draw2d.ColorConstants; 00024 import org.eclipse.draw2d.Figure; 00025 import org.eclipse.draw2d.Label; 00026 import org.eclipse.draw2d.ToolbarLayout; 00027 import org.eclipse.draw2d.XYLayout; 00028 import org.eclipse.draw2d.geometry.Rectangle; 00029 00030 00031 public class ConnectionPropertyFigure extends Figure implements ActionListener 00032 { 00036 private XYLayout layout; 00040 private Connection conn; 00044 private Label labelSourceName = new Label(); 00048 private Label labelTargetName = new Label(); 00052 private Button btnDeleteBendPoints; 00056 private Button btnRoute; 00060 private CheckBox checkBoxAutoRoute = new CheckBox("Automatic route"); 00061 00062 00066 public ConnectionPropertyFigure() 00067 { 00068 /* Set the type of layout */ 00069 layout = new XYLayout(); 00070 setLayoutManager(layout); 00071 00072 /* Initialisation of the labelSourceName */ 00073 labelSourceName.setForegroundColor(ColorConstants.black); 00074 add(labelSourceName, ToolbarLayout.VERTICAL); 00075 setConstraint(labelSourceName, new Rectangle(0, 0, -1, -1)); 00076 labelSourceName.setText("Unknown"); 00077 00078 /* Initialisation of the labelTargetName */ 00079 labelTargetName.setForegroundColor(ColorConstants.black); 00080 add(labelTargetName, ToolbarLayout.VERTICAL); 00081 setConstraint(labelTargetName, new Rectangle(0, 15, -1, -1)); 00082 labelTargetName.setText("Unknown"); 00083 00084 /* Initialisation of the btnDeleteBendPoints */ 00085 btnDeleteBendPoints = new Button("Delete all bend points"); 00086 add(btnDeleteBendPoints); 00087 setConstraint(btnDeleteBendPoints, new Rectangle(0, 45, -1, -1)); 00088 btnDeleteBendPoints.addActionListener(this); 00089 00090 /* Initialisation of the btnRoute */ 00091 btnRoute = new Button("Route connections"); 00092 add(btnRoute); 00093 setConstraint(btnRoute, new Rectangle(0, 75, -1, -1)); 00094 btnRoute.addActionListener(this); 00095 00096 /* Initialisation of the checkBoxAutoRoute */ 00097 add(checkBoxAutoRoute); 00098 setConstraint(checkBoxAutoRoute, new Rectangle(0, 105, -1, -1)); 00099 checkBoxAutoRoute.addActionListener(this); 00100 00101 /* Initialisation of the figure */ 00102 setOpaque(true); 00103 setBackgroundColor(ColorConstants.menuBackground); 00104 setForegroundColor(ColorConstants.menuForeground); 00105 } 00106 00107 00112 public void setProperty(Connection conn) 00113 { 00114 this.conn = conn; 00115 00116 /* Get and show the name of source and target nodes of the connection */ 00117 labelSourceName.setText("Source : " + conn.getSource().getName()); 00118 labelTargetName.setText("Target : " + conn.getTarget().getName()); 00119 00120 /* Initialize the state of buttons and the checkBox */ 00121 btnDeleteBendPoints.setEnabled(!conn.getBendPoints().isEmpty()); 00122 checkBoxAutoRoute.setSelected(conn.getMustBeRoute()); 00123 } 00124 00125 00132 @Override 00133 public void actionPerformed(ActionEvent arg) 00134 { 00135 /* Remove all the bend points of the connection */ 00136 if(arg.getSource() == btnDeleteBendPoints) 00137 { 00138 conn.removeAllBendPoint(); 00139 btnDeleteBendPoints.setEnabled(false); 00140 } 00141 /* Route connections */ 00142 else if(arg.getSource() == btnRoute) 00143 { 00144 conn.route(); 00145 } 00146 /* Enable/Disable the atomatic routing of the connection */ 00147 else if(arg.getSource() == checkBoxAutoRoute) 00148 { 00149 conn.setMustBeRoute(checkBoxAutoRoute.isSelected()); 00150 } 00151 00152 } 00153 } 00154