1 /*
2  * aTunes
3  * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
4  *
5  * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
6  *
7  * http://www.atunes.org
8  * http://sourceforge.net/projects/atunes
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 package net.sourceforge.atunes.gui.views.controls;
22 
23 import javax.swing.JLabel;
24 
25 import net.sourceforge.atunes.model.IColorMutableImageIcon;
26 import net.sourceforge.atunes.model.ILookAndFeelChangeListener;
27 import net.sourceforge.atunes.model.ILookAndFeelManager;
28 
29 /**
30  * A JLabel that is repaint when look and feel changes
31  *
32  * @author fleax
33  *
34  */
35 public class LookAndFeelAwareLabel extends JLabel implements
36 		ILookAndFeelChangeListener {
37 
38 	/**
39 	 *
40 	 */
41 	private static final long serialVersionUID = 5017109922596290169L;
42 
43 	private final ILookAndFeelManager lookAndFeelManager;
44 
45 	private final IColorMutableImageIcon icon;
46 
47 	/**
48 	 * @param lookAndFeelManager
49 	 * @param icon
50 	 */
LookAndFeelAwareLabel(final ILookAndFeelManager lookAndFeelManager, final IColorMutableImageIcon icon)51 	public LookAndFeelAwareLabel(final ILookAndFeelManager lookAndFeelManager,
52 			final IColorMutableImageIcon icon) {
53 		super();
54 		this.lookAndFeelManager = lookAndFeelManager;
55 		this.icon = icon;
56 		lookAndFeelManager.addLookAndFeelChangeListener(this);
57 		paintIcon();
58 	}
59 
paintIcon()60 	private void paintIcon() {
61 		setIcon(this.icon.getIcon(this.lookAndFeelManager
62 				.getCurrentLookAndFeel().getPaintForSpecialControls()));
63 	}
64 
65 	@Override
lookAndFeelChanged()66 	public void lookAndFeelChanged() {
67 		paintIcon();
68 	}
69 }
70