Browse Source

switch manualactive and autoactive

Kevin Trometer 7 years ago
parent
commit
bd9841e6fd
2 changed files with 63 additions and 26 deletions
  1. 61 24
      src/classes/HolonSwitch.java
  2. 2 2
      src/ui/view/MyCanvas.java

+ 61 - 24
src/classes/HolonSwitch.java

@@ -5,10 +5,17 @@ import java.util.LinkedList;
 
 public class HolonSwitch extends CpsObject {
 	/*
-	 * True, if this wire is working (capable of carrying electricity), else
-	 * false
+	 * manual state True, if this wire is working (capable of carrying
+	 * electricity), else false
 	 */
-	boolean active;
+	boolean manualActive;
+
+	/*
+	 * active state True, if this wire is working (capable of carrying
+	 * electricity), else false
+	 */
+	boolean autoActive;
+
 	/*
 	 * true if switch has to be used manually
 	 */
@@ -24,7 +31,8 @@ public class HolonSwitch extends CpsObject {
 
 	public HolonSwitch(String ObjName) {
 		super(ObjName);
-		setState(true);
+		setManualState(true);
+		setAutoState(true);
 		setActiveAt(true);
 		setManualMode(false);
 	}
@@ -32,7 +40,8 @@ public class HolonSwitch extends CpsObject {
 	public HolonSwitch(String ObjName, String obj) {
 		super(ObjName);
 		super.setName(obj);
-		setState(true);
+		setManualState(true);
+		setAutoState(true);
 		setActiveAt(true);
 		setManualMode(false);
 	}
@@ -40,30 +49,63 @@ public class HolonSwitch extends CpsObject {
 	public HolonSwitch(CpsObject obj) {
 		super(obj);
 		super.setName(obj.getName());
-		setState(true);
+		setManualState(true);
+		setAutoState(true);
 		setActiveAt(true);
 		setManualMode(false);
 	}
 
 	public void switchState() {
-		if (this.active == true) {
-			setImage("/Images/switch-off.png");
+		if (manualMode) {
+			if (this.manualActive == true) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
+			this.manualActive = !manualActive;
 		} else {
-			setImage("/Images/switch-on.png");
+			if (this.autoActive == true) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
+			this.autoActive = !autoActive;
 		}
-		this.active = !active;
+
 	}
 
 	public boolean getState() {
-		return this.active;
+		if (manualMode) {
+			return this.manualActive;
+		} else {
+			return this.autoActive;
+		}
+
+	}
+
+	public void setManualState(boolean state) {
+		this.manualActive = state;
+		setImage();
+	}
+
+	public void setAutoState(boolean state) {
+		this.autoActive = state;
+		setImage();
 	}
 
-	public void setState(boolean state) {
-		this.active = state;
-		if (this.active == true) {
-			setImage("/Images/switch-on.png");
+	private void setImage() {
+		if (manualMode) {
+			if (this.manualActive == false) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
 		} else {
-			setImage("/Images/switch-off.png");
+			if (this.autoActive == false) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
 		}
 	}
 
@@ -90,7 +132,7 @@ public class HolonSwitch extends CpsObject {
 	}
 
 	public boolean getActiveManual() {
-		return active;
+		return this.manualActive;
 	}
 
 	/**
@@ -98,13 +140,8 @@ public class HolonSwitch extends CpsObject {
 	 *            the default value
 	 */
 	public void setActiveAt(boolean active) {
-		if (getManualMode()) {
-			System.out.println("Activating...");
-			this.active = active;
-		} else {
-			for (int i = 0; i < activeAt.length; i++) {
-				this.activeAt[i] = active;
-			}
+		for (int i = 0; i < activeAt.length; i++) {
+			this.activeAt[i] = active;
 		}
 	}
 

+ 2 - 2
src/ui/view/MyCanvas.java

@@ -264,9 +264,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			} else {
 				if (cps instanceof HolonSwitch) {
 					if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
-						((HolonSwitch) cps).setState(true);
+						((HolonSwitch) cps).setAutoState(true);
 					} else {
-						((HolonSwitch) cps).setState(false);
+						((HolonSwitch) cps).setAutoState(false);
 					}
 				}
 				// Highlighting