CpsObject.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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> connectedTo;
  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. this.objName = objName;
  26. this.name = objName;
  27. connectedTo = new ArrayList<CpsObject>();
  28. position = new Position();
  29. id = iDCounter.nextId();
  30. image = "/Images/Dummy_House.png";
  31. // System.out.println("ID: " + id + " of " + objName);
  32. }
  33. public CpsObject(CpsObject obj) {
  34. this.objName = obj.getObjName();
  35. connectedTo = new ArrayList<CpsObject>();
  36. position = new Position();
  37. id = iDCounter.nextId();
  38. this.name = obj.getName();
  39. this.energyIn = obj.getEnergyIn();
  40. this.energyOut = obj.getEnergyOut();
  41. this.image = obj.getImage();
  42. }
  43. /* Obj type */
  44. public String getObjName() {
  45. return objName;
  46. }
  47. public void setObjName(String objName) {
  48. this.objName = objName;
  49. }
  50. /* User defined Name */
  51. public String getName() {
  52. return name;
  53. }
  54. public void setName(String name) {
  55. this.name = name;
  56. }
  57. /* Unique ID number */
  58. public int getID() {
  59. return id;
  60. }
  61. /* Image path */
  62. public String getImage() {
  63. return image;
  64. }
  65. public void setImage(String image) {
  66. this.image = image;
  67. }
  68. /* Neighbors array */
  69. public ArrayList<CpsObject> getConnectedTo() {
  70. return connectedTo;
  71. }
  72. public void AddConnection(CpsObject toConnect) {
  73. connectedTo.add(toConnect);
  74. }
  75. /* Position (x and Y) */
  76. public void setPos(int x, int y) {
  77. position.x = x;
  78. position.y = y;
  79. }
  80. public Position getPos() {
  81. return position;
  82. }
  83. /* Getter and Setters for the energy input and output */
  84. public float getEnergyIn() {
  85. return energyIn;
  86. }
  87. public void setEnergyIn(float energyIn) {
  88. this.energyIn = energyIn;
  89. }
  90. public float getEnergyOut() {
  91. return energyOut;
  92. }
  93. public void setEnergyOut(float energyOut) {
  94. this.energyOut = energyOut;
  95. }
  96. @Override
  97. public String getCompareName() {
  98. return objName;
  99. }
  100. }