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.GridBagConstraints;
026    import java.awt.GridBagLayout;
027    import java.awt.Insets;
028    import java.math.BigDecimal;
029    
030    import javax.swing.JLabel;
031    import javax.swing.JList;
032    import javax.swing.JPanel;
033    import javax.swing.ListCellRenderer;
034    
035    import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg;
036    
037    /**
038     * List cell renderer for 2 columns.
039     * @author Lorenz Buehmann
040     *
041     */
042    public class ColumnListCellRenderer extends JPanel implements ListCellRenderer {
043    
044            private static final long serialVersionUID = 3024913291199515567L;
045            private ORE ore;
046            
047            
048            public ColumnListCellRenderer(ORE ore) {
049                    this.ore = ore;
050                    setOpaque(true);
051            }
052    
053            public Component getListCellRendererComponent(JList list, Object value,
054                            int index, boolean isSelected, boolean cellHasFocus) {
055    
056                    removeAll();
057    
058                    JLabel cor = new JLabel();
059                    JLabel desc = new JLabel();
060                    setLayout(new GridBagLayout());
061                    desc.setText(((EvaluatedDescriptionPosNeg) value).getDescription().toManchesterSyntaxString(ore.getBaseURI(), ore.getPrefixes()));
062                    //round accuracy to 2 digits
063                    double accuracy = ((EvaluatedDescriptionPosNeg) value).getAccuracy();
064                    
065                    BigDecimal roundedAccuracy = new BigDecimal(accuracy * 100);
066                    roundedAccuracy = roundedAccuracy.setScale(2, BigDecimal.ROUND_HALF_UP);
067                    cor.setText(roundedAccuracy.toString());
068                    add(cor, new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));//, BorderLayout.WEST);
069                    add(desc, new GridBagConstraints(1, 0, 1, 1, 0.8, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));//, BorderLayout.EAST);
070    
071                    Color background;
072                    Color foreground;
073                    
074                    if (index % 2 == 0 && !isSelected) {
075                            background = new Color(242, 242, 242);
076                            foreground = Color.BLACK;
077    
078                    } else if(isSelected){
079                     
080                 background = Color.LIGHT_GRAY;
081                 foreground = Color.WHITE;
082            }else{
083                    background = Color.WHITE;
084                foreground = Color.BLACK;
085            }
086                    
087                    setForeground(foreground);
088                    setBackground(background);
089    
090                    return this;
091            }
092    
093    }