CategoryControl.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package ui.controller;
  2. import java.util.ArrayList;
  3. import ui.model.*;
  4. import ui.view.*;
  5. public class CategoryControl{
  6. private IdCounter ID;
  7. private Model M;
  8. public CategoryControl(Model model, IdCounter id){
  9. this.ID = id;
  10. this.M = model;
  11. initCategories();
  12. }
  13. /**
  14. * init default category and objects
  15. */
  16. public void initCategories(){
  17. Category energy = new Category("Energy");
  18. Category building = new Category("Building");
  19. Category component = new Category("Component");
  20. HolonObject powerp = new HolonObject("Power Plant");
  21. HolonObject house = new HolonObject("House");
  22. HolonTransformer transformer = new HolonTransformer("Transformer");
  23. HolonSwitch sw = new HolonSwitch("Switch");
  24. addObject(energy, powerp);
  25. addObject(building, house);
  26. addObject(component, transformer);
  27. addObject(component, sw);
  28. addCategory(energy);
  29. addCategory(building);
  30. addCategory(component);
  31. }
  32. /**
  33. * Adds Category into Model
  34. * @param toAdd neue Kategorie
  35. */
  36. public void addCategory(Category toAdd){
  37. M.addCategory(toAdd);
  38. }
  39. /**
  40. * Adds New Category into Model
  41. * @param name Bezeichnung der neuen Kategorie
  42. */
  43. public void addNewCategory(String name){
  44. M.addCategory(new Category(name));
  45. }
  46. /**
  47. * Add Object into a Category
  48. * @param cat Category
  49. * @param obj Object
  50. */
  51. public void addObject(Category cat,CpsObject obj){
  52. cat.getObjects().add(obj);
  53. }
  54. /**
  55. * Add new Holon Object
  56. * @param cat Category
  57. * @param obj New Object Name
  58. */
  59. public void addNewHolonObject(Category cat, String obj){
  60. addObject(cat, new HolonObject(obj));
  61. }
  62. /**
  63. * Add new Holon Transformer
  64. * @param cat Category
  65. * @param obj New Object Name
  66. */
  67. public void addNewHolonTransformer(Category cat, String obj){
  68. addObject(cat, new HolonTransformer(obj));
  69. }
  70. /**
  71. * Add new Holon Switch
  72. * @param cat Category
  73. * @param obj New Object Name
  74. */
  75. public void addNewHolonSwitch(Category cat, String obj){
  76. addObject(cat, new HolonSwitch(obj));
  77. }
  78. public void deleteCategory(int idx){
  79. M.getCategories().remove(idx);
  80. }
  81. }