001 /** 002 * iFish - An iRiver iHP jukebox database creation tool 003 * 004 * Copyright (C) 2009 Richard "Shred" Körber 005 * http://ifish.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 019 */ 020 package net.shredzone.ifish.gui; 021 022 import java.awt.Component; 023 024 import javax.swing.DefaultListCellRenderer; 025 import javax.swing.Icon; 026 import javax.swing.JLabel; 027 import javax.swing.JList; 028 029 import net.shredzone.ifish.db.Playlist; 030 import net.shredzone.ifish.i18n.L; 031 import net.shredzone.ifish.pool.ImgPool; 032 033 /** 034 * A PlaylistCellRenderer rendering PlaylistDb entries. 035 * 036 * @author Richard Körber <dev@shredzone.de> 037 * @version $Id: PlaylistCellRenderer.java 291 2009-04-28 21:29:27Z shred $ 038 */ 039 public class PlaylistCellRenderer extends DefaultListCellRenderer { 040 private static final long serialVersionUID = 4049078241598124084L; 041 042 private final static Icon iconStatic = ImgPool.get( "pli_added.png" ); 043 private final static Icon iconDynamic = ImgPool.get( "pli_cmt.png" ); 044 private final static Icon iconCustomer = ImgPool.get( "tab_playlist.png" ); 045 046 private final static String ttStatic = L.tr( "plr.added.tt" ); 047 private final static String ttDynamic = L.tr( "plr.cmt.tt" ); 048 private final static String ttCustomer = L.tr( "plr.customer.tt" ); 049 050 /** 051 * Get the Component that renders one line. 052 * 053 * @param list JList that is used 054 * @param value Value to be shown in that row 055 * @param index Index of that value 056 * @param isSelected Is this entry selected? 057 * @param cellHasFocus Is this entry focussed? 058 * @return Component representing the row. 059 */ 060 @Override 061 public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { 062 JLabel jl = (JLabel) super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); 063 if( value instanceof Playlist ) { 064 Playlist pl = (Playlist) value; 065 if( pl.isStatic() ) { 066 if( pl.isCustomer() ) { 067 jl.setIcon( iconCustomer ); 068 jl.setToolTipText( ttCustomer ); 069 }else { 070 jl.setIcon( iconStatic ); 071 jl.setToolTipText( ttStatic ); 072 } 073 }else { 074 jl.setIcon( iconDynamic ); 075 jl.setToolTipText( ttDynamic ); 076 } 077 } 078 return jl; 079 } 080 081 }