123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package classes;
- import java.awt.Point;
- import java.util.LinkedList;
- public class HolonSwitch extends CpsObject {
- /*
- * manual state True, if this wire is working (capable of carrying
- * electricity), else false
- */
- 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
- */
- boolean manualMode;
- /*
- * Energy at each point of the graph with 50 predefined points. At the
- * beginning, it starts with all values at energy
- */
- boolean[] activeAt = new boolean[100];
- // Points on the UnitGraph
- LinkedList<Point> graphPoints = new LinkedList<>();
- public HolonSwitch(String ObjName) {
- super(ObjName);
- setManualState(true);
- setAutoState(true);
- setActiveAt(true);
- setManualMode(false);
- }
- public HolonSwitch(String ObjName, String obj) {
- super(ObjName);
- super.setName(obj);
- setManualState(true);
- setAutoState(true);
- setActiveAt(true);
- setManualMode(false);
- }
- public HolonSwitch(CpsObject obj) {
- super(obj);
- super.setName(obj.getName());
- setManualState(true);
- setAutoState(true);
- setActiveAt(true);
- setManualMode(false);
- }
- public void switchState() {
- if (manualMode) {
- if (this.manualActive == true) {
- setImage("/Images/switch-off.png");
- } else {
- setImage("/Images/switch-on.png");
- }
- this.manualActive = !manualActive;
- } else {
- if (this.autoActive == true) {
- setImage("/Images/switch-off.png");
- } else {
- setImage("/Images/switch-on.png");
- }
- this.autoActive = !autoActive;
- }
- }
- public boolean getState() {
- 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();
- }
- private void setImage() {
- if (manualMode) {
- if (this.manualActive == false) {
- setImage("/Images/switch-off.png");
- } else {
- setImage("/Images/switch-on.png");
- }
- } else {
- if (this.autoActive == false) {
- setImage("/Images/switch-off.png");
- } else {
- setImage("/Images/switch-on.png");
- }
- }
- }
- /**
- * @return the Graph Points
- */
- public LinkedList<Point> getGraphPoints() {
- return graphPoints;
- }
- /**
- * @param points,
- * the Graph points
- */
- public void setGraphPoints(LinkedList<Point> points) {
- this.graphPoints = points;
- }
- /**
- * get the activeAt Array
- */
- public boolean[] getActiveAt() {
- return activeAt;
- }
- public boolean getActiveManual() {
- return this.manualActive;
- }
- /**
- * @param active,
- * the default value
- */
- public void setActiveAt(boolean active) {
- for (int i = 0; i < activeAt.length; i++) {
- this.activeAt[i] = active;
- }
- }
- public void setManualMode(boolean mode) {
- manualMode = mode;
- }
- public boolean getManualMode() {
- return manualMode;
- }
- }
|