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
026 import javax.swing.JLabel;
027 import javax.swing.JList;
028 import javax.swing.ListCellRenderer;
029
030 import org.dllearner.core.owl.Individual;
031 import org.dllearner.core.owl.NamedClass;
032
033 /**
034 * List cell renderer for colored lines to provide better view on list values.
035 * @author Lorenz Buehmann
036 *
037 */
038 public class ColorListCellRenderer extends JLabel implements ListCellRenderer {
039
040 private static final long serialVersionUID = -7592805113197759247L;
041 private ORE ore;
042
043 public ColorListCellRenderer(ORE ore) {
044 setOpaque(true);
045 this.ore = ore;
046 }
047
048 public Component getListCellRendererComponent(JList list, Object value,
049 int index, boolean isSelected, boolean cellHasFocus) {
050
051 if(value instanceof NamedClass){
052 setText(((NamedClass) value).toManchesterSyntaxString(ore.getBaseURI(), ore.getPrefixes()));
053 } else if(value instanceof Individual){
054 setText(((Individual) value).toManchesterSyntaxString(ore.getBaseURI(), ore.getPrefixes()));
055 }
056 Color background;
057 Color foreground;
058
059 if (index % 2 == 0 && !isSelected) {
060 background = new Color(242, 242, 242);
061 foreground = Color.BLACK;
062
063 } else if(isSelected){
064
065 background = Color.LIGHT_GRAY;
066 foreground = Color.BLACK;
067 }else{
068 background = Color.WHITE;
069 foreground = Color.BLACK;
070 }
071
072 setForeground(foreground);
073 setBackground(background);
074
075 return this;
076 }
077
078 }