001    /**
002     * planningtool - A Planning Tool with Critiquing Support.
003     * 
004     * Copyright (C) 2006 olale
005    
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU General Public License
008     * as published by the Free Software Foundation; either version 2
009     * of the License, or (at your option) any later version.
010    
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015    
016     * You should have received a copy of the GNU General Public License
017     * along with this program; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019    
020     * Contact information: 
021     * E-mail: olale@ida.liu.se
022     *         olale@lysator.liu.se
023     */
024    package se.liu.ida.critiquer.gui;
025    
026    import javax.swing.JPanel;
027    
028    import se.liu.ida.critiquer.constraints.ConstraintStatusListener;
029    import se.liu.ida.critiquer.constraints.GUIComponentCritic;
030    import se.liu.ida.critiquer.constraints.StandardConstraint;
031    
032    /**
033     * @author olale
034     *
035     */
036    public class ConstraintComponent implements ConstraintStatusListener {
037    
038            private GUIComponentCritic controllingCritic;
039            private JPanel panel = new JPanel();
040            
041            /**
042             * 
043             */
044            public ConstraintComponent() {
045                    StandardConstraint.addStatusListener(this);
046            }
047            
048            public JPanel getPanel() {
049                    return panel;
050            }
051            
052            /** 
053             * 
054             * Replace the controlling critic with this one if there is a new component critic active
055             * 
056             * @see se.liu.ida.critiquer.constraints.ConstraintStatusListener#activeStatusChanged(se.liu.ida.critiquer.constraints.StandardConstraint)
057             */
058            public void activeStatusChanged(StandardConstraint c) {
059                    if (c.isActive() && c instanceof GUIComponentCritic && c!=controllingCritic) {
060                            panel.removeAll();
061                            controllingCritic=(GUIComponentCritic) c;
062                            panel.add(controllingCritic.getComponent());
063                            
064                    }
065            }
066    
067            /** 
068             * Nothing to do, the critic should present all information necessary.
069             * 
070             * @see se.liu.ida.critiquer.constraints.ConstraintStatusListener#violationStatusChanged(se.liu.ida.critiquer.constraints.StandardConstraint)
071             */
072            public void violationStatusChanged(StandardConstraint c) {
073                    
074            }
075    }