HolonInfoPanel.java 3.9 KB

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