HolonInfoPanel.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package ui.view.holarchy;
  2. import java.awt.Color;
  3. import java.util.ArrayList;
  4. import java.util.HashSet;
  5. import java.util.Set;
  6. import javax.swing.JLabel;
  7. import javax.swing.JPanel;
  8. import javax.swing.JScrollPane;
  9. import classes.Holon;
  10. import ui.controller.Control;
  11. public class HolonInfoPanel extends JPanel {
  12. Control control;
  13. int offset, offsetLabels = 110;
  14. HolarchyWindow parentFrame;
  15. Holon h = null;
  16. //name, state, parent, children, virtualNeihgbors, physicalNeighbors
  17. JPanel[] panels = { new JPanel(), new JPanel(), new JPanel()};
  18. JLabel[] labels1 = {new JLabel("Name: "), new JLabel("UUID"), new JLabel("State: "), new JLabel("Optimization Scheme: "), new JLabel("Parent: ")};
  19. String[] labels2 = {"Subholons", "Virtual neighbors", "Physical neighbors"};
  20. Set<JLabel> toRemove = new HashSet();
  21. public HolonInfoPanel(HolarchyWindow parentFrame, Control control) {
  22. this.control = control;
  23. this.parentFrame = parentFrame;
  24. this.setBounds(0, 0, parentFrame.getWidth()*1/5-1, parentFrame.getHeight());
  25. this.setBounds(0, 0, parentFrame.getWidth()*1/5-1, parentFrame.getHeight());
  26. this.offset = parentFrame.getWidth()*4/5+1;
  27. this.setLayout(null);
  28. this.setVisible(true);
  29. this.setBackground(Color.white);
  30. for(int i=0; i<this.labels1.length; i++) {
  31. this.labels1[i].setBounds(5, 5+i*21, this.getWidth(), 20);
  32. this.add(this.labels1[i]);
  33. }
  34. for(int i=0; i<this.panels.length; i++) {
  35. JPanel p = this.panels[i];
  36. p.setBounds(5, offsetLabels+21*i, this.getWidth(), 20);
  37. JLabel label = new JLabel(this.labels2[i]);
  38. label.setBounds(0, 0, p.getWidth(), p.getHeight());
  39. p.add(label);
  40. this.add(p);
  41. }
  42. }
  43. public void displayInfos(Holon h) {
  44. clearInfos();
  45. this.h = h;
  46. this.labels1[0].setText("Name: "+h.name);
  47. this.labels1[1].setText("UUID: "+h.getUniqueID());
  48. this.labels1[2].setText("State: "+h.holonControlUnit.getStateEstimator().getStateIndicator());
  49. this.labels1[3].setText("Optimization Scheme: "+h.holonControlUnit.getOptimizer().getOptimizationScheme());
  50. this.labels1[4].setText("Superholon: "+(h.getParent() != null ? h.getParent().name : ""));
  51. int offset = offsetLabels + 21;
  52. for(int i=0; i<h.childHolons.size(); i++) {
  53. Holon c = h.childHolons.get(i);
  54. JLabel l = new JLabel(c.name+" "+c.getUniqueID());
  55. l.setBounds(5, offset, this.getWidth(), 20);
  56. this.add(l);
  57. this.toRemove.add(l);
  58. offset += 21;
  59. }
  60. //display virtual neighbors
  61. this.panels[1].setLocation(5, offset);
  62. offset += 21;
  63. ArrayList<String> holons = h.holonControlUnit.getHierarchyController().getVirtualNeighbors();
  64. for(String s : holons) {
  65. // System.out.println("id: "+s);
  66. Holon c = this.control.getModel().getHolonsByID().get(s);
  67. JLabel l = new JLabel(c.name+" "+c.getUniqueID());
  68. l.setBounds(5, offset, this.getWidth(), 20);
  69. this.add(l);
  70. this.toRemove.add(l);
  71. offset += 21;
  72. }
  73. //display physical neighbors
  74. this.panels[2].setLocation(5, offset);
  75. offset += 21;
  76. holons = h.holonControlUnit.getHierarchyController().getPhysicalNeighbors();
  77. for(String s : holons) {
  78. JLabel l;
  79. if(s.contains("Switch")) {
  80. l = new JLabel(s);
  81. } else {
  82. Holon c = this.control.getModel().getHolonsByID().get(s);
  83. l = new JLabel(c.name+" "+c.getUniqueID());
  84. }
  85. l.setBounds(5, offset, this.getWidth(), 20);
  86. this.add(l);
  87. this.toRemove.add(l);
  88. offset += 21;
  89. }
  90. }
  91. public void clearInfos() {
  92. this.labels1[0].setText("Name: ");
  93. this.labels1[1].setText("State: ");
  94. this.labels1[2].setText("Superholon: ");
  95. for(JLabel l : this.toRemove) {
  96. this.remove(l);
  97. }
  98. for(int i=1; i<this.panels.length; i++) {
  99. this.panels[i].setLocation(5, 89+21*i);
  100. }
  101. this.repaint();
  102. }
  103. public void update() {
  104. if(this.h == null)
  105. return;
  106. displayInfos(this.h);
  107. }
  108. }