CpsObject.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package classes;
  2. import java.util.ArrayList;
  3. import Interfaces.ComparableObject;
  4. import ui.model.idCounter;
  5. public abstract class CpsObject implements ComparableObject {
  6. /* Type of the Object */
  7. String objName;
  8. /* Name given by the user */
  9. String name;
  10. /* ID of the Obj. */
  11. int ID;
  12. /* Path of the image for the Obj. */
  13. String image;
  14. /* Array of neighbors */
  15. ArrayList<CpsObject> connections;
  16. /* Position with a X and Y value */
  17. Position position;
  18. /* Energy input and output of each object in the grid */
  19. float energyIn;
  20. float energyOut;
  21. /**
  22. * Constructor for an CpsObejct with an unique ID
  23. */
  24. public CpsObject(String objName) {
  25. setObjName(objName);
  26. setName(objName);
  27. setConnections(new ArrayList<CpsObject>());
  28. setPosition(new Position());
  29. setImage("/Images/Dummy_House.png");
  30. System.out.println("ID: " + ID + " of " + objName);
  31. }
  32. public CpsObject(CpsObject obj) {
  33. setObjName(obj.getObjName());
  34. setName(obj.getObjName());
  35. setConnections(new ArrayList<CpsObject>());
  36. setPosition(new Position());
  37. setID(idCounter.nextId());
  38. setEnergyIn(obj.getEnergyIn());
  39. setEnergyOut(obj.getEnergyOut());
  40. setImage(obj.getImage());
  41. }
  42. /* Obj type */
  43. public String getObjName() {
  44. return objName;
  45. }
  46. public void setObjName(String objName) {
  47. this.objName = objName;
  48. }
  49. /* User defined Name */
  50. public String getName() {
  51. return name;
  52. }
  53. public void setName(String name) {
  54. this.name = name;
  55. }
  56. /* Unique ID number */
  57. public int getID() {
  58. return ID;
  59. }
  60. /**
  61. * @param iD
  62. * the iD to set
  63. */
  64. public void setID(int ID) {
  65. this.ID = ID;
  66. }
  67. /* Image path */
  68. public String getImage() {
  69. return image;
  70. }
  71. public void setImage(String image) {
  72. this.image = image;
  73. }
  74. /**
  75. * @return the connections
  76. */
  77. public ArrayList<CpsObject> getConnections() {
  78. return connections;
  79. }
  80. /**
  81. * @param connections
  82. * the connections to set
  83. */
  84. public void setConnections(ArrayList<CpsObject> connections) {
  85. this.connections = connections;
  86. }
  87. /* Neighbors array */
  88. public ArrayList<CpsObject> getConnectedTo() {
  89. return connections;
  90. }
  91. public void AddConnection(CpsObject toConnect) {
  92. connections.add(toConnect);
  93. }
  94. public void setPosition(Position pos) {
  95. this.position = pos;
  96. }
  97. /* Position (x and Y) */
  98. public void setPosition(int x, int y) {
  99. setPosition(new Position(x, y));
  100. }
  101. public Position getPosition() {
  102. return position;
  103. }
  104. /* Getter and Setters for the energy input and output */
  105. public float getEnergyIn() {
  106. return energyIn;
  107. }
  108. public void setEnergyIn(float energyIn) {
  109. this.energyIn = energyIn;
  110. }
  111. public float getEnergyOut() {
  112. return energyOut;
  113. }
  114. public void setEnergyOut(float energyOut) {
  115. this.energyOut = energyOut;
  116. }
  117. @Override
  118. public String getCompareName() {
  119. return objName;
  120. }
  121. }