Math2mat
|
00001 00015 package m2m.frontend.dynamicview.model; 00016 00017 import java.beans.PropertyChangeListener; 00018 import java.beans.PropertyChangeSupport; 00019 import java.util.Vector; 00020 00021 import org.eclipse.draw2d.Graphics; 00022 import org.eclipse.draw2d.geometry.Dimension; 00023 00024 public class Connection 00025 { 00029 public static final String VISIBLE_CONNECTION = "VisibleConnection"; 00033 public static final String BENDPOINT_POSITION = "BendPointPosition"; 00037 public static final String ROUTE_CONNECTION = "RouteConnection"; 00038 00039 00043 private PropertyChangeSupport listeners; 00047 private int lineStyle = Graphics.LINE_SOLID; 00051 private Node source; 00055 private Node target; 00059 private boolean visible = true; 00063 private boolean mustBeRoute = true; 00067 private Vector<BendPoint> bendPoints = new Vector<BendPoint>(); 00068 00069 00075 public Connection(Node source, Node target) 00076 { 00077 this.source = source; 00078 this.target = target; 00079 this.source.addConnection(this); 00080 this.target.addConnection(this); 00081 this.listeners = new PropertyChangeSupport(this); 00082 } 00083 00084 00089 public int getLineStyle() 00090 { 00091 return lineStyle; 00092 } 00093 00094 00099 public Node getSource() 00100 { 00101 return source; 00102 } 00103 00104 00109 public Node getTarget() 00110 { 00111 return target; 00112 } 00113 00114 00119 public boolean getVisible() 00120 { 00121 return this.visible; 00122 } 00123 00124 00129 public void setVisible(boolean visible) 00130 { 00131 boolean odlValue = this.visible; 00132 this.visible = visible; 00133 firePropertyChange(Connection.VISIBLE_CONNECTION, odlValue, visible); 00134 } 00135 00136 00141 public boolean getMustBeRoute() 00142 { 00143 return this.mustBeRoute; 00144 } 00145 00146 00151 public void setMustBeRoute(boolean val) 00152 { 00153 this.mustBeRoute = val; 00154 } 00155 00156 00161 public Vector<BendPoint> getBendPoints() 00162 { 00163 return bendPoints; 00164 } 00165 00166 00171 public void addBendPoint(BendPoint bp) 00172 { 00173 bendPoints.add(bp.getIndex(), bp); 00174 firePropertyChange(Connection.BENDPOINT_POSITION, null, bendPoints); 00175 firePropertyChange(Schema.PROPERTY, null, bendPoints); 00176 } 00177 00178 00183 public void removeBendPoint(int index) 00184 { 00185 bendPoints.remove(index); 00186 firePropertyChange(Connection.BENDPOINT_POSITION, null, bendPoints); 00187 firePropertyChange(Schema.PROPERTY, null, bendPoints); 00188 } 00189 00190 00194 public void removeAllBendPoint() 00195 { 00196 bendPoints.removeAll(bendPoints); 00197 firePropertyChange(Connection.BENDPOINT_POSITION, null, bendPoints); 00198 } 00199 00206 public void modifyBendPoint(int index, Dimension d1, Dimension d2) 00207 { 00208 BendPoint oldBp = bendPoints.get(index); 00209 BendPoint NewBp = oldBp; 00210 00211 NewBp.setHeight(d1.height, d2.height); 00212 NewBp.setWidth(d1.width, d2.width); 00213 00214 firePropertyChange(Connection.BENDPOINT_POSITION, null, NewBp); 00215 } 00216 00217 00221 public void route() 00222 { 00223 firePropertyChange(Connection.ROUTE_CONNECTION, null, this); 00224 } 00225 00226 00233 protected void firePropertyChange(String property, Object oldValue, Object newValue) 00234 { 00235 if (listeners.hasListeners(property)) 00236 listeners.firePropertyChange(property, oldValue, newValue); 00237 } 00238 00239 00244 public void addPropertyChangeListener(PropertyChangeListener listener) 00245 { 00246 listeners.addPropertyChangeListener(listener); 00247 } 00248 00249 00254 public void removePropertyChangeListener(PropertyChangeListener listener) 00255 { 00256 listeners.removePropertyChangeListener(listener); 00257 } 00258 00259 00263 public void refreshConnection() 00264 { 00265 firePropertyChange(Connection.BENDPOINT_POSITION, null, bendPoints); 00266 firePropertyChange(Schema.PROPERTY, null, bendPoints); 00267 } 00268 }