123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- package classes;
- import java.awt.Point;
- import java.util.LinkedList;
- import com.google.gson.annotations.Expose;
- public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
-
-
- @Expose
- boolean manualActive;
-
- @Expose
- boolean autoActive;
-
- @Expose
- boolean manualMode;
-
- @Expose
- int localPeriod;
-
- boolean[] activeAt;
-
- LinkedList<Point> graphPoints = new LinkedList<>();
-
- public HolonSwitch(String objName) {
- super(objName);
- activeAt=new boolean[100];
- setManualState(true);
- setAutoState(true);
- setActiveAt(true);
- setManualMode(false);
- setGraphPoints(new LinkedList<Point>());
- }
-
- public HolonSwitch(AbstractCpsObject obj) {
- super(obj);
- super.setName(obj.getName());
- setManualState(((HolonSwitch) obj).getActiveManual());
- setAutoState(true);
- setLocalPeriod(((IGraphedElement)obj).getLocalPeriod());
- setActiveAt(true);
- for (int i = 0; i < activeAt.length; i++) {
- activeAt[i] = ((HolonSwitch) obj).getActiveAt()[i];
- }
- setGraphPoints(new LinkedList<Point>());
- for (Point p : ((HolonSwitch) obj).getGraphPoints()) {
- this.graphPoints.add(new Point((int) p.getX(), (int) p.getY()));
- }
- setManualMode(((HolonSwitch) obj).getManualMode());
- }
-
- public void switchState() {
- if (!manualMode) {
- setManualMode(true);
- }
- if (this.manualActive == true) {
- setImage("/Images/switch-off.png");
- } else {
- setImage("/Images/switch-on.png");
- }
- this.manualActive = !manualActive;
- }
-
- public boolean getState(int timeStep) {
- if (manualMode) {
- return this.manualActive;
- } else {
- return getActiveAt()[timeStep];
- }
- }
-
- 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");
- }
- }
- }
-
- public LinkedList<Point> getGraphPoints() {
- return graphPoints;
- }
-
- public void setGraphPoints(LinkedList<Point> points) {
- this.graphPoints = points;
- }
-
- public boolean[] getActiveAt() {
- return activeAt;
- }
-
- public boolean getActiveManual() {
- return this.manualActive;
- }
-
- public void setActiveAt(boolean active) {
- activeAt = new boolean[100];
- for (int i = 0; i < activeAt.length; i++) {
- this.activeAt[i] = active;
- }
- }
-
- public void setManualMode(boolean mode) {
- manualMode = mode;
- }
-
- public boolean getManualMode() {
- return manualMode;
- }
- @Override
- public void setLocalPeriod(int period) {
- localPeriod=period;
- activeAt=new boolean[localPeriod];
- }
- @Override
- public int getLocalPeriod() {
- return localPeriod;
- }
- }
|