| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| IconListRenderer |
|
| 1.5;1.5 |
| 1 | package org.jtheque.core.managers.view.impl.components.renderers; | |
| 2 | ||
| 3 | import javax.swing.DefaultListCellRenderer; | |
| 4 | import javax.swing.Icon; | |
| 5 | import javax.swing.JList; | |
| 6 | import java.awt.Color; | |
| 7 | import java.awt.Component; | |
| 8 | import java.awt.Font; | |
| 9 | ||
| 10 | /* | |
| 11 | * This file is part of JTheque. | |
| 12 | * | |
| 13 | * JTheque is free software: you can redistribute it and/or modify | |
| 14 | * it under the terms of the GNU General Public License as published by | |
| 15 | * the Free Software Foundation, either version 3 of the License. | |
| 16 | * | |
| 17 | * JTheque is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 24 | */ | |
| 25 | ||
| 26 | /** | |
| 27 | * A list renderer with an icon for each item. | |
| 28 | * | |
| 29 | * @author Baptiste Wicht | |
| 30 | */ | |
| 31 | public final class IconListRenderer extends DefaultListCellRenderer { | |
| 32 | /** | |
| 33 | * Construct a new IconListRenderer. | |
| 34 | * | |
| 35 | * @param labelIcon The label icon. | |
| 36 | */ | |
| 37 | public IconListRenderer(Icon labelIcon){ | |
| 38 | 0 | super(); |
| 39 | ||
| 40 | 0 | setOpaque(false); |
| 41 | 0 | setIcon(labelIcon); |
| 42 | 0 | setForeground(Color.white); |
| 43 | 0 | } |
| 44 | ||
| 45 | @Override | |
| 46 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){ | |
| 47 | 0 | if (isSelected){ |
| 48 | 0 | setFont(getFont().deriveFont(Font.BOLD)); |
| 49 | } else { | |
| 50 | 0 | setFont(getFont().deriveFont(Font.PLAIN)); |
| 51 | } | |
| 52 | ||
| 53 | 0 | setText(value.toString()); |
| 54 | ||
| 55 | 0 | return this; |
| 56 | } | |
| 57 | } |