001 /**
002 * Copyright (C) 2007-2009, 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 package org.dllearner.tools.protege;
021
022 import java.awt.Color;
023 import java.awt.Component;
024
025 import javax.swing.BorderFactory;
026 import javax.swing.JLabel;
027 import javax.swing.JList;
028 import javax.swing.ListCellRenderer;
029 /**
030 * This is the class that is responsible for the rendering of the
031 * concepts that are shown in the SuggestPanel.
032 * @author Christian Koetteritzsch
033 *
034 */
035 public class SuggestListCellRenderer extends JLabel implements ListCellRenderer {
036
037 private static final long serialVersionUID = 8040385703448641356L;
038 /**
039 * Constructor for the Cell Renderer for the Suggest List.
040 */
041 public SuggestListCellRenderer() {
042 setOpaque(true);
043 }
044
045 /**
046 * Renderer for the entries of the SuggestPanel.
047 * @param list JList
048 * @param value Object
049 * @param arg2 int
050 * @param arg4 boolean
051 * @param iss boolean boolean if current element is selected.
052 * @return Component Returns the currently rendered component of the suggest list
053 */
054 public Component getListCellRendererComponent(JList list, Object value,
055 int arg2, boolean iss, boolean arg4) {
056 // Set the text and
057 // background color for rendering
058 setText(((SuggestListItem) value).getValue() + " " + "Accuracy: " + Math.round(((SuggestListItem) value).getAccuracy())+"%");
059 setBackground(Color.WHITE);
060 setForeground(((SuggestListItem) value).getColor());
061 // Set a border if the list
062 // item is selected
063 if (iss) {
064 setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
065 } else {
066 setBorder(BorderFactory.createLineBorder(list.getBackground(), 2));
067 }
068 setEnabled(list.isEnabled());
069
070 return this;
071 }
072
073 }