001    /**
002     * Copyright (C) 2007-2008, Jens Lehmann
003     *
004     * This file is part of DL-Learner.
005     * 
006     * DL-Learner is free software; you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation; either version 3 of the License, or
009     * (at your option) any later version.
010     *
011     * DL-Learner 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, see <http://www.gnu.org/licenses/>.
018     *
019     */
020    
021    package org.dllearner.tools.ore;
022    
023    import java.awt.Color;
024    import java.awt.Component;
025    import java.awt.event.ActionListener;
026    
027    import javax.swing.BorderFactory;
028    import javax.swing.JLabel;
029    import javax.swing.JPanel;
030    import javax.swing.SwingUtilities;
031    import javax.swing.border.BevelBorder;
032    
033    import org.dllearner.core.owl.Description;
034    import org.dllearner.core.owl.Individual;
035    
036    /**
037     * Panel where learned class description is shown, and parts that might occur errors are red colored.
038     * @author Lorenz Buehmann
039     *
040     */
041    public class DescriptionPanel extends JPanel{
042            
043            /**
044             * 
045             */
046            private static final long serialVersionUID = -3684937339236885595L;
047            
048            private ORE ore;
049            private Individual ind;
050            private ActionListener aL;
051            private String mode;
052            private boolean correct = false;
053            private Description newClassDescription;
054            
055            public DescriptionPanel(ORE ore, Individual ind, ActionListener aL, String mode){
056                    super();
057                    setBackground(Color.WHITE);
058                    setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
059                    this.ore = ore;
060                    this.newClassDescription = ore.getNewClassDescription().getDescription();
061                    this.ind = ind;
062                    this.aL = aL;
063                    this.mode = mode;
064                    if(mode.equals("neg")){
065                            for(JLabel jL : ore.descriptionToJLabelNeg(ind, newClassDescription)){
066                                    add(jL);
067                                    if(jL instanceof DescriptionLabel){
068                                            
069                                            ((DescriptionLabel) jL).setIndOre(ore, ind);
070                                            ((DescriptionLabel) jL).init();
071                                            ((DescriptionLabel) jL).addActionListeners(aL);
072                                            
073                                    }
074                                    
075                            }
076                    } else if(mode.equals("pos")){
077                            for(JLabel jL : ore.descriptionToJLabelPos(ind, newClassDescription)){
078                                    add(jL);
079                                    if(jL instanceof DescriptionLabel){
080                                            
081                                            ((DescriptionLabel) jL).setIndOre(ore, ind);
082                                            ((DescriptionLabel) jL).init();
083                                            ((DescriptionLabel) jL).addActionListeners(aL);
084                                            
085                                    }
086                                    
087                            }
088                    }
089            }
090            
091            /**
092             * Updates the panel.
093             */
094            public void updatePanel(){
095                    for(Component c : getComponents()){
096                            if(c instanceof JLabel){
097                                    remove(c);
098                            }
099                    }
100                    ore.updateReasoner();
101                    correct = true;
102                    if (mode.equals("neg")) {
103                            for (JLabel jL : ore.descriptionToJLabelNeg(ind, newClassDescription)) {
104                                    add(jL);
105                                    if (jL instanceof DescriptionLabel) {
106                                            ((DescriptionLabel) jL).setIndOre(ore, ind);
107                                            ((DescriptionLabel) jL).init();
108                                            ((DescriptionLabel) jL).addActionListeners(aL);
109                                            correct = false;
110    
111                                    }
112                            }
113                    } else if(mode.equals("pos")){
114                            for (JLabel jL : ore.descriptionToJLabelPos(ind, newClassDescription)) {
115                                    add(jL);
116                                    if (jL instanceof DescriptionLabel) {
117                                            ((DescriptionLabel) jL).setIndOre(ore, ind);
118                                            ((DescriptionLabel) jL).init();
119                                            ((DescriptionLabel) jL).addActionListeners(aL);
120                                            correct = false;
121    
122                                    }
123                            }
124                    }
125                    SwingUtilities.updateComponentTreeUI(this);
126                    
127    
128            }
129            /**
130             * Checks whether description is covered by positive example, or not covered by negative example.
131             * @return true if description is covered by positive example, or not covered by negative example, otherwise false is returned
132             */
133            public boolean isCorrect(){
134                    return correct;
135            }
136    }