|
@@ -16,6 +16,13 @@ public class Controller {
|
|
|
*/
|
|
|
Model model;
|
|
|
|
|
|
+
|
|
|
+ * Create a new Controller, which controls the given model and allows
|
|
|
+ * manipulation of this model
|
|
|
+ *
|
|
|
+ * @param model
|
|
|
+ * model, that should be controlled
|
|
|
+ */
|
|
|
public Controller(Model model) {
|
|
|
this.model = model;
|
|
|
}
|
|
@@ -30,47 +37,45 @@ public class Controller {
|
|
|
* @param y
|
|
|
* new y position
|
|
|
* @param z
|
|
|
- * new z postiion
|
|
|
+ * new z position
|
|
|
*/
|
|
|
public void moveSmartDevice(SmartDevice device, int x, int y, int z) {
|
|
|
- for (SmartDevice d : model.getDevices()) {
|
|
|
- if (d == device) {
|
|
|
- d.setX(x);
|
|
|
- d.setY(y);
|
|
|
- d.setZ(z);
|
|
|
- }
|
|
|
- }
|
|
|
+ device.setX(x);
|
|
|
+ device.setY(y);
|
|
|
+ device.setZ(z);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Sets the Dimension of the model
|
|
|
+ * Changes the dimension of the model, without scaling the SmartDevice
|
|
|
+ * positions
|
|
|
*
|
|
|
* @param width
|
|
|
- * the width to set
|
|
|
+ * the new width to set
|
|
|
* @param height
|
|
|
- * the height to set
|
|
|
+ * the new height to set
|
|
|
* @param depth
|
|
|
- * the depth to set
|
|
|
+ * the new depth to set
|
|
|
*/
|
|
|
public void setDimension(int width, int height, int depth) {
|
|
|
setDimension(width, height, depth, false);
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Sets the Dimension of the model and moves SmartDevices to new relative
|
|
|
- * positions
|
|
|
+ * Changes the dimension of the model and moves SmartDevices to new relative
|
|
|
+ * positions if {@code stretchModel} is true
|
|
|
*
|
|
|
* @param width
|
|
|
- * the width to set
|
|
|
+ * the new width to set
|
|
|
* @param height
|
|
|
- * the height to set
|
|
|
+ * the new height to set
|
|
|
* @param depth
|
|
|
- * the depth to set
|
|
|
- * @param true
|
|
|
- * if smartDevice positions should be stretched
|
|
|
+ * the new depth to set
|
|
|
+ * @param stretchModel
|
|
|
+ * true, if smartDevice positions should be stretched
|
|
|
*/
|
|
|
public void setDimension(int width, int height, int depth, boolean stretchModel) {
|
|
|
-
|
|
|
+
|
|
|
if (width < 400)
|
|
|
width = 400;
|
|
|
if (height < 400)
|
|
@@ -108,84 +113,107 @@ public class Controller {
|
|
|
model.setHeight(height);
|
|
|
model.setDepth(depth);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- * Calculates the new scaled position, which should radius < newPost < upperBound - radius
|
|
|
- * @param oldPosition previous Position that should be scaled
|
|
|
- * @param factor how much it is stretched/shrunk
|
|
|
- * @param upperBound upper Bound of the frame, which should not be exceeded
|
|
|
- * @return newPosition that was calculated
|
|
|
+ * Calculates the new scaled position, which should be in Bounds:
|
|
|
+ * {@code radius < newPosition <
|
|
|
+ * (upperBound - radius)}
|
|
|
+ *
|
|
|
+ * @param oldPosition
|
|
|
+ * previous position that should be scaled
|
|
|
+ * @param factor
|
|
|
+ * how much it is stretched/shrunk
|
|
|
+ * @param upperBound
|
|
|
+ * upper bound of the frame, which should not be exceeded
|
|
|
+ * @return new position that was calculated
|
|
|
*/
|
|
|
- private int scalePos(int oldPosition, double factor, int upperBound){
|
|
|
+ private int scalePos(int oldPosition, double factor, int upperBound) {
|
|
|
|
|
|
* New Position that should be validated and returned
|
|
|
*/
|
|
|
int newPosition = (int) Math.round(factor * oldPosition);
|
|
|
-
|
|
|
- if(newPosition<model.getDevice_visualization_radius())
|
|
|
+
|
|
|
+ if (newPosition < model.getDevice_visualization_radius())
|
|
|
newPosition = model.getDevice_visualization_radius();
|
|
|
- if(newPosition>=upperBound-model.getDevice_visualization_radius())
|
|
|
- newPosition = upperBound-model.getDevice_visualization_radius();
|
|
|
-
|
|
|
+ if (newPosition >= upperBound - model.getDevice_visualization_radius())
|
|
|
+ newPosition = upperBound - model.getDevice_visualization_radius();
|
|
|
+
|
|
|
return newPosition;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- * Adds SmartDevice to the Model
|
|
|
+ * Adds SmartDevice to the Model and verifies that it is inside the model
|
|
|
+ * bounds
|
|
|
+ *
|
|
|
* @param sd
|
|
|
+ * SmartDevice which should be added to the model
|
|
|
*/
|
|
|
- public void addSmartDevice(SmartDevice sd){
|
|
|
+ public void addSmartDevice(SmartDevice sd) {
|
|
|
+ if (model.getDevices().contains(sd))
|
|
|
+ return;
|
|
|
model.addDevices(sd);
|
|
|
-
|
|
|
+
|
|
|
sd.setX(scalePos(sd.getX(), 1.0, model.getWidth()));
|
|
|
sd.setY(scalePos(sd.getY(), 1.0, model.getHeight()));
|
|
|
sd.setZ(scalePos(sd.getZ(), 1.0, model.getDepth()));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- * Creates a new SmartDevice at the given Position
|
|
|
- * @param name name of the smartDevice
|
|
|
- * @param x_pos position on the x-Axis
|
|
|
- * @param y_pos position on the y-Axis
|
|
|
- * @param z_pos position on the z-Axis
|
|
|
+ * Creates a new SmartDevice at the given Position. The Device is moved
|
|
|
+ * into the model bounds, if the position is outside the bounds
|
|
|
+ *
|
|
|
+ * @param name
|
|
|
+ * name of the smartDevice
|
|
|
+ * @param x_pos
|
|
|
+ * position on the x-Axis
|
|
|
+ * @param y_pos
|
|
|
+ * position on the y-Axis
|
|
|
+ * @param z_pos
|
|
|
+ * position on the z-Axis
|
|
|
*/
|
|
|
- public void createSmartDevice(String name, int x_pos, int y_pos, int z_pos){
|
|
|
+ public void createSmartDevice(String name, int x_pos, int y_pos, int z_pos) {
|
|
|
SmartDevice sd = new SmartDevice(name);
|
|
|
sd.setX(scalePos(x_pos, 1.0, model.getWidth()));
|
|
|
sd.setY(scalePos(y_pos, 1.0, model.getHeight()));
|
|
|
sd.setZ(scalePos(z_pos, 1.0, model.getDepth()));
|
|
|
model.addDevices(sd);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- * Deletes the given SmartDevice toDelete, removes it from its links and connections.
|
|
|
- * @param toDelete the SmartDevice to remove
|
|
|
+ * Deletes the given SmartDevice toDelete, removes it from its links and
|
|
|
+ * connections.
|
|
|
+ *
|
|
|
+ * @param toDelete
|
|
|
+ * the SmartDevice to delete
|
|
|
*/
|
|
|
- public void deleteSmartDevice(SmartDevice toDelete){
|
|
|
- if(toDelete == null) return;
|
|
|
-
|
|
|
- for(Link link:toDelete.getLinks())
|
|
|
+ public void deleteSmartDevice(SmartDevice toDelete) {
|
|
|
+ if (toDelete == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ for (Link link : toDelete.getLinks())
|
|
|
removeSmartDeviceFromLink(toDelete, link);
|
|
|
-
|
|
|
-
|
|
|
- for(Connection c: toDelete.getConnections()){
|
|
|
+
|
|
|
+
|
|
|
+ for (Connection c : toDelete.getConnections()) {
|
|
|
c.removeSmartDevice(toDelete);
|
|
|
- if(c.getSource()==null){
|
|
|
+ if (c.getSource() == null) {
|
|
|
model.addTerminatingConnections(c);
|
|
|
- for(SmartDevice sd:c.getParticipants()){
|
|
|
- if(sd!=null)sd.getConnections().remove(c);
|
|
|
+ for (SmartDevice sd : c.getParticipants()) {
|
|
|
+ if (sd != null)
|
|
|
+ sd.getConnections().remove(c);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
model.getDevices().remove(toDelete);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
* Removes the SmartDevice from the given Link
|
|
|
- * @param toRemove
|
|
|
- * @param link
|
|
|
+ *
|
|
|
+ * @param toRemove the Device that should be removed from the link
|
|
|
+ * @param link the Link, which contains the SmartDevice
|
|
|
*/
|
|
|
- public void removeSmartDeviceFromLink(SmartDevice toRemove, Link link){
|
|
|
+ public void removeSmartDeviceFromLink(SmartDevice toRemove, Link link) {
|
|
|
toRemove.removeLink(link);
|
|
|
}
|
|
|
}
|