001    /*
002     * SimuCS - Simulator to use with Classifier Systems 
003     * MSc project - Oxford University 
004     * by Benoit Isaac - Summer 2005
005     */
006    
007    package simuLCS.graphics;
008    import java.awt.Color;
009    import java.awt.Dimension;
010    import java.awt.Graphics;
011    import java.util.Set;
012    
013    import javax.swing.JLabel;
014    import javax.swing.SwingConstants;
015    
016    import simuLCS.Template;
017    
018    /**
019     * Component for the Tab "Behaviour"
020     * Show the corresponding GUI if an entity with a Template has been selected
021     * @author Benoit
022     * 
023     */
024    public class G_PanBehaviour extends G_Panel {
025    
026            private Set previousSelectedEntities;
027    
028            private boolean hasBeenRepainted = false;
029    
030            public G_PanBehaviour() {
031                    super();
032                    //              this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
033    
034            }
035    
036            public void createCustomBehaviours() {
037                    if (!getSetSelectedEntities().equals(previousSelectedEntities)) {
038                            removeAll();
039    
040                            if (getSetSelectedEntities().isEmpty()) {
041                                    JLabel j2 = new JLabel("Select at least one entity.");
042                                    j2.setOpaque(true);
043                                    this.setPreferredSize(new Dimension(this.getWidth(), 450));
044                                    add(j2);
045    
046                            } else {
047                                    //TODO if they don't share the same template, indicate it
048                                    Template t = getTemplateFromSelected();
049                                    if (t != null) {
050                                            JLabel j1 = new JLabel("Template:  " + t.getName());
051                                            j1.setBackground(Color.YELLOW);
052                                            j1.setOpaque(true);
053                                            JLabel j2 =
054                                                    new JLabel(
055                                                            "Classifiers in common:",
056                                                            SwingConstants.LEFT);
057                                            j2.setOpaque(true);
058                                            G_Panel listPanel = new G_ListPanel();
059                                            listPanel.setOpaque(true);
060                                            add(j1);
061                                            add(j2);
062                                            add(listPanel);
063                                    } else {
064                                            JLabel j =
065                                                    new JLabel("Entities selected don't share the same Template");
066                                            JLabel j2 = new JLabel(" or they don't have a Template.");
067                                            j.setOpaque(true);
068                                            j2.setOpaque(true);
069                                            add(j);
070                                            add(j2);
071                                    }
072                            }
073                            previousSelectedEntities = (Set) selectedEntities.clone();
074                            setOpaque(true);
075                            validate();
076                    }
077    
078            }
079    
080            public void paintComponent(Graphics g) {
081                    createCustomBehaviours();
082                    ////            this.validate();
083            }
084    
085    }