| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic.ui; |
| 17 | |
| 18 | import java.awt.Component; |
| 19 | |
| 20 | import javax.swing.JLabel; |
| 21 | import javax.swing.JList; |
| 22 | import javax.swing.ListCellRenderer; |
| 23 | |
| 24 | import net.sf.jomic.tools.FileTools; |
| 25 | |
| 26 | import org.apache.commons.logging.Log; |
| 27 | import org.apache.commons.logging.LogFactory; |
| 28 | |
| 29 | /** |
| 30 | * ListCellRenderer to show non-comics as disabled. |
| 31 | * |
| 32 | * @author Thomas Aglassinger |
| 33 | */ |
| 34 | public class FileArchiveListCellRenderer extends JLabel implements ListCellRenderer |
| 35 | { |
| 36 | private FileTools fileTools; |
| 37 | private Log logger; |
| 38 | |
| 39 | public FileArchiveListCellRenderer() { |
| 40 | logger = LogFactory.getLog(FileArchiveListCellRenderer.class); |
| 41 | fileTools = FileTools.instance(); |
| 42 | |
| 43 | setOpaque(true); |
| 44 | setHorizontalAlignment(LEFT); |
| 45 | setVerticalAlignment(CENTER); |
| 46 | } |
| 47 | |
| 48 | public Component getListCellRendererComponent( |
| 49 | JList list, |
| 50 | Object value, |
| 51 | int index, |
| 52 | boolean isSelected, |
| 53 | boolean cellHasFocus) { |
| 54 | assert list != null; |
| 55 | assert value != null; |
| 56 | |
| 57 | if (isSelected) { |
| 58 | setBackground(list.getSelectionBackground()); |
| 59 | setForeground(list.getSelectionForeground()); |
| 60 | } else { |
| 61 | setBackground(list.getBackground()); |
| 62 | setForeground(list.getForeground()); |
| 63 | } |
| 64 | |
| 65 | String fileName = value.toString(); |
| 66 | |
| 67 | setText(fileName); |
| 68 | |
| 69 | boolean enabled = fileTools.isComic(fileName); |
| 70 | |
| 71 | if (logger.isDebugEnabled()) { |
| 72 | logger.debug("enabled = " + enabled + " <- " + fileName); |
| 73 | } |
| 74 | setEnabled(enabled); |
| 75 | |
| 76 | return this; |
| 77 | } |
| 78 | } |