1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
|
/**
* Classe d' équipment du schéma
*/
public class SlipEquipment implements Equipment{
private static final long serialVersionUID = 1L;
/**
* les propriétés de chaques equipement peuvent être trié
*/
public enum SortableProperty {NAME, STATION, DEPARTURE, NUMBER,
ACTION,MANOEUVRABLE, X, Y, ANGLE, WIDTH, HEIGHT,VISIBLE};
private String name;
private Content icon;
private String model;
private String station;
private String departure;
private String action;
private boolean manoeuvrable;
private int number;
private float x;
private float y;
private float angle;
private float width;
private float height;
private boolean visible;
private GraphicEquipment graphicEquipment;
private Equipment equipment;
private transient Shape shapeCache;
public SlipEquipment(Equipment equipment) {
this.equipment= equipment;
this.name = equipment.getName();
this.icon = equipment.getIcon();
this.model = equipment.getModel();
this.station = equipment.getStation();
this.departure = equipment.getDeparture();
this.action = equipment.getAction();
this.manoeuvrable = equipment.isManoeuvrable();
this.number = equipment.getNumber();
this.width = equipment.getWidth();
this.height = equipment.getHeight();
if (equipment instanceof SlipEquipment) {
SlipEquipment slipPiece =
(SlipEquipment)equipment;
this.graphicEquipment = slipPiece.getGraphicEquipment();
this.visible = slipPiece.isVisible();
this.angle = slipPiece.getAngle();
this.x = slipPiece.getX();
this.y = slipPiece.getY();
} else {
this.visible = true;
this.x = this.width / 2;
this.y = this.height / 2;
}
}
/**
* Renvoie le nom de l'équipement
*/
public String getName() {
return this.name;
}
/**
* Sets the name of this equipment.
*/
void setName(String name) {
this.name = name;
}
/**
* Renvoie l'icone de l'équipement
*/
public Content getIcon() {
return this.icon;
}
/**
* Renvoie le model de l'équipment
*/
public String getModel() {
return this.model;
}
/**
* Renvoie si l'équipement est manoeuvrable
*/
public boolean isManoeuvrable() {
return this.manoeuvrable;
}
/**
* Sets the manoeuvrabilty of this equipment
*/
void setManoeuvrable(boolean manoeuvrable) {
this.manoeuvrable = manoeuvrable;
}
/**
* Returns <code>true</code> if this piece of furniture is visible.
*/
public boolean isVisible() {
return this.visible;
}
/**
* Sets whether this equipment is visible or not.
* This method should be called from {@link Slip}, which
* controls notifications when a piece changed.
*/
void setVisible(boolean visible) {
this.visible = visible;
}
/**
* Renvoie le poste d'appartenance de l'équipement
*/
public String getStation() {
return this.station;
}
/**
* Sets the station of this equipment.
*/
void setStation(String station) {
this.station = station;
}
/**
* Renvoie le départ de l'équipement
*/
public String getDeparture() {
return this.departure;
}
/**
* Sets the departure of this equipment.
*/
void setDeparture(String departure) {
this.departure = departure;
}
/**
* Renvoie l'action réaliser par l'équipement
*/
public String getAction() {
return this.action;
}
/**
* Sets the action of this equipment.
*/
void setAction(String action) {
this.action = action;
}
/**
* Renvoie le numéro chronologique de l'action
*/
public int getNumber() {
return this.number;
}
/**
* Sets the number of this equipment.
*/
void setNumber(int number) {
this.number = number;
}
/**
* Returns the width of this equipment.
*/
public float getWidth() {
this.width = getGraphicEquipment().getWidth();
return this.width;
}
/**
* Sets the width of this equipment.
* This method should be called from {@link Slip}, which
* controls notifications when a equipment changed.
*/
void setWidth(float width) {
this.width = width;
getGraphicEquipment().setWidth(width);
}
/**
* Returns the height of this piece of furniture.
*/
public float getHeight() {
this.height = getGraphicEquipment().getHeight();
return this.height;
}
/**
* Sets the height of this equipment.
* This method should be called from {@link Slip}, which
* controls notifications when a piece changed.
*/
void setHeight(float height) {
this.height = height;
getGraphicEquipment().setHeight(height);
}
/**
* Renvoie l'abscisse de l'équipement
*/
public float getX() {
this.x = getGraphicEquipment().getX();
return this.x;
}
/**
*
* Modifie l'abscisse de l'équipement
*/
void setX(float x) {
this.x = x;
System.out.println("SlipEquipment setX "+this.x);
getGraphicEquipment().setX(x);
}
/**
* Renvoie l'ordonnée de l'équipement
*/
public float getY() {
this.y = getGraphicEquipment().getY();
return this.y;
}
/**
* Modifie l'ordonnée de l'équipement
*/
void setY(float y) {
this.y = y;
System.out.println("SlipEquipment setY "+this.y);
getGraphicEquipment().setY(y);
}
/**
* Renvoie l'angle en radian de l'équipement
*/
public float getAngle() {
this.angle = getGraphicEquipment().getAngle();
return this.angle;
}
/**
* Modifie l'angle de l'équipement
*/
void setAngle(float angle) {
this.angle = angle;
getGraphicEquipment().setAngle(angle);
}
/**
* Renvoie l'equipment graphique
*/
public GraphicEquipment getGraphicEquipment() {
this.graphicEquipment = GraphicEquipmentManager.getInstance().readGraphicsEquipment(this.equipment.getModel());
return this.graphicEquipment;
}
/**
* Revoie les points de contour d'un équipement
* @return une liste de 4 points de coordonnées(x,y) d'un équipement
*/
/* public float [][] getPoints() {
float [][] piecePoints = new float[4][2];
PathIterator it = getShape().getPathIterator(null);
for (int i = 0; i < piecePoints.length; i++) {
it.currentSegment(piecePoints [i]);
it.next();
}
return piecePoints;
}*/
/**
* Renvoie <code>true</code> si l'équipement est détecté
* Returns <code>true</code> if this piece intersects
* with the horizontal rectangle which opposite corners are at points
* (<code>x0</code>, <code>y0</code>) and (<code>x1</code>, <code>y1</code>).
*/
public boolean intersectsRectangle(float x0, float y0,
float x1, float y1) {
Rectangle2D rectangle = new Rectangle2D.Float(x0, y0, 0, 0);
rectangle.add(x1, y1);
return getGraphicEquipment().getShape().intersects(rectangle);
}
/**
* Renvoie <code>true</code> si l'équipement contient
* les points (<code>x</code>, <code>y</code>) avec
* une marge donnée
*/
public boolean containsPoint(float x, float y, float margin) {
return getGraphicEquipment().getShape().intersects(x - margin, y - margin, 2 * margin, 2 * margin);
}
/**
* Renvoie <code>true</code> si un des sommets du
* contour d'un équipement est à une certaine position
* de la souris
*/
public boolean isVertexAt(float x, float y, float margin) {
for (float [] point : getGraphicEquipment().getPoints()) {
if (Math.abs(x - point[0]) <= margin && Math.abs(y - point[1]) <= margin) {
return true;
}
}
return false;
}
/**
* Returns <code>true</code> if the top left vertex of this piece is
* the point at (<code>x</code>, <code>y</code>)
* with a given <code>margin</code>.
*/
public boolean isTopLeftVertexAt(float x, float y, float margin) {
float [][] points = getGraphicEquipment().getPoints();
return (Math.abs(x - points[0][0]) <= margin && Math.abs(y - points[0][1]) <= margin);
}
/**
* Returns <code>true</code> if the top right vertex of this piece is
* the point at (<code>x</code>, <code>y</code>)
* with a given <code>margin</code>.
*/
public boolean isTopRightVertexAt(float x, float y, float margin) {
float [][] points = getGraphicEquipment().getPoints();
return Math.abs(x - points[1][0]) <= margin && Math.abs(y - points[1][1]) <= margin;
}
/**
* Returns <code>true</code> if the bottom left vertex of this piece is
* the point at (<code>x</code>, <code>y</code>)
* with a given <code>margin</code>.
*/
public boolean isBottomLeftVertexAt(float x, float y, float margin) {
float [][] points = getGraphicEquipment().getPoints();
return Math.abs(x - points[3][0]) <= margin && Math.abs(y - points[3][1]) <= margin;
}
/**
* Returns <code>true</code> if the bottom right vertex of this piece is
* the point at (<code>x</code>, <code>y</code>)
* with a given <code>margin</code>.
*/
public boolean isBottomRightVertexAt(float x, float y, float margin) {
float [][] points = getGraphicEquipment().getPoints();
return (Math.abs(x - points[2][0]) <= margin && Math.abs(y - points[2][1]) <= margin);
} |
Partager