HolonInfoPanel.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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;
  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("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, 89+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: ");
  49. this.labels1[3].setText("Superholon: "+(h.getParent() != null ? h.getParent().name : ""));
  50. int offset = 110;
  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. // System.out.println("Holon: "+h.name+" virtual neighbors: "+holons.toString());
  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. Holon c = this.control.getModel().getHolonsByID().get(s);
  79. JLabel l = new JLabel(c.name+" "+c.getUniqueID());
  80. l.setBounds(5, offset, this.getWidth(), 20);
  81. this.add(l);
  82. this.toRemove.add(l);
  83. offset += 21;
  84. }
  85. }
  86. public void clearInfos() {
  87. this.labels1[0].setText("Name: ");
  88. this.labels1[1].setText("State: ");
  89. this.labels1[2].setText("Superholon: ");
  90. for(JLabel l : this.toRemove) {
  91. this.remove(l);
  92. }
  93. for(int i=1; i<this.panels.length; i++) {
  94. this.panels[i].setLocation(5, 89+21*i);
  95. }
  96. this.repaint();
  97. }
  98. }