CategoryControl.java 2.2 KB

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