123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package ui.view.holarchy;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.Set;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import classes.Holon;
- import ui.controller.Control;
- public class HolonInfoPanel extends JPanel {
- Control control;
- int offset, offsetLabels = 110;
- HolarchyWindow parentFrame;
- Holon h = null;
- JPanel[] panels = { new JPanel(), new JPanel(), new JPanel()};
- JLabel[] labels1 = {new JLabel("Name: "), new JLabel("UUID: "), new JLabel("State: "), new JLabel("Optimization Scheme: "), new JLabel("Parent: ")};
- String[] labels2 = {"Subholons", "Virtual neighbors", "Physical neighbors"};
- Set<JLabel> toRemove = new HashSet<JLabel>();
-
- public HolonInfoPanel(HolarchyWindow parentFrame, Control control) {
- this.control = control;
- this.parentFrame = parentFrame;
- this.setBounds(0, 0, parentFrame.getWidth()*1/5-21, (parentFrame.getHeight()-100)/2);
- this.setPreferredSize(new Dimension(parentFrame.getWidth()*1/5-21, parentFrame.getHeight()/2-20));
- this.offset = parentFrame.getWidth()*4/5+1;
- this.setLayout(null);
- this.setVisible(true);
- this.setBackground(Color.white);
-
- for(int i=0; i<this.labels1.length; i++) {
- this.labels1[i].setBounds(5, 5+i*21, this.getWidth(), 20);
- this.add(this.labels1[i]);
- }
- for(int i=0; i<this.panels.length; i++) {
- JPanel p = this.panels[i];
- p.setBounds(5, offsetLabels+21*i, this.getWidth(), 20);
- JLabel label = new JLabel(this.labels2[i]);
- label.setBounds(0, 0, p.getWidth(), p.getHeight());
- p.add(label);
- this.add(p);
- }
- }
-
- public void displayInfos(Holon h) {
- clearInfos();
- this.h = h;
- this.labels1[0].setText("Name: "+h.name);
- this.labels1[1].setText("UUID: "+h.getUniqueID());
- this.labels1[2].setText("State: "+h.holonControlUnit.getStateEstimator().getStateIndicator());
- this.labels1[3].setText("Optimization Scheme: "+h.holonControlUnit.getOptimizer().getOptimizationScheme());
- this.labels1[4].setText("Superholon: "+(h.getParent() != null ? h.getParent().name : ""));
-
- int offset = offsetLabels + 21;
- for(int i=0; i<h.childHolons.size(); i++) {
- Holon c = h.childHolons.get(i);
- JLabel l = new JLabel(c.name+" "+c.getUniqueID());
- l.setBounds(5, offset, this.getWidth(), 20);
- this.add(l);
- this.toRemove.add(l);
- offset += 21;
- }
-
- //display virtual neighbors
- this.panels[1].setLocation(5, offset);
- offset += 21;
- ArrayList<String> holons = h.holonControlUnit.getHierarchyController().getVirtualNeighbors();
- for(String s : holons) {
- Holon c = this.control.getModel().getHolonsByID().get(s);
- JLabel l = new JLabel(c.name+" "+c.getUniqueID());
- l.setBounds(5, offset, this.getWidth(), 20);
- this.add(l);
- this.toRemove.add(l);
- offset += 21;
- }
-
- //display physical neighbors
- this.panels[2].setLocation(5, offset);
- offset += 21;
- holons = h.holonControlUnit.getHierarchyController().getPhysicalNeighbors();
- for(String s : holons) {
- JLabel l;
- if(s.contains("Switch") || s.contains("Node")) {
- l = new JLabel(s);
- } else {
- Holon c = this.control.getModel().getHolonsByID().get(s);
- l = new JLabel(c.name+" "+c.getUniqueID());
- }
- l.setBounds(5, offset, this.getWidth(), 20);
- this.add(l);
- this.toRemove.add(l);
- offset += 21;
- }
- this.setPreferredSize(new Dimension(this.getWidth()*1/5-1, offset+21));
- }
-
- public void clearInfos() {
- this.labels1[0].setText("Name: ");
- this.labels1[1].setText("UUID: ");
- this.labels1[2].setText("State: ");
- this.labels1[3].setText("Optimization scheme: ");
- this.labels1[4].setText("Parent holon: ");
- for(JLabel l : this.toRemove) {
- this.remove(l);
- }
- for(int i=0; i<this.panels.length; i++) {
- this.panels[i].setLocation(5, 89+21*i);
- }
- this.setPreferredSize(new Dimension(parentFrame.getWidth()*1/5-21, parentFrame.getHeight()/2-20));
- this.repaint();
- }
-
- public void update() {
- if(this.h == null)
- return;
- displayInfos(this.h);
- }
-
- }
|