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.kernel.modules.covernavigator;
22 
23 import java.awt.Cursor;
24 import java.util.List;
25 
26 import net.sourceforge.atunes.Constants;
27 import net.sourceforge.atunes.gui.views.dialogs.CoverNavigatorDialog;
28 import net.sourceforge.atunes.kernel.AbstractSimpleController;
29 import net.sourceforge.atunes.model.IArtist;
30 import net.sourceforge.atunes.model.IBeanFactory;
31 import net.sourceforge.atunes.model.IProcessFactory;
32 
33 /**
34  * Controller for cover navigator
35  *
36  * @author alex
37  *
38  */
39 public final class CoverNavigatorController extends
40 		AbstractSimpleController<CoverNavigatorDialog> {
41 
42 	static final int COVER_PANEL_WIDTH = Constants.COVER_NAVIGATOR_IMAGE_SIZE
43 			.getSize() + 20;
44 	static final int COVER_PANEL_HEIGHT = Constants.COVER_NAVIGATOR_IMAGE_SIZE
45 			.getSize() + 40;
46 
47 	private IProcessFactory processFactory;
48 
49 	private CoverNavigationListSelectionListener coverNavigationListSelectionListener;
50 
51 	private IBeanFactory beanFactory;
52 
53 	/**
54 	 * @param beanFactory
55 	 */
setBeanFactory(final IBeanFactory beanFactory)56 	public void setBeanFactory(final IBeanFactory beanFactory) {
57 		this.beanFactory = beanFactory;
58 	}
59 
60 	/**
61 	 * @param coverNavigationListSelectionListener
62 	 */
setCoverNavigationListSelectionListener( final CoverNavigationListSelectionListener coverNavigationListSelectionListener)63 	public void setCoverNavigationListSelectionListener(
64 			final CoverNavigationListSelectionListener coverNavigationListSelectionListener) {
65 		this.coverNavigationListSelectionListener = coverNavigationListSelectionListener;
66 	}
67 
68 	/**
69 	 * @param processFactory
70 	 */
setProcessFactory(final IProcessFactory processFactory)71 	public void setProcessFactory(final IProcessFactory processFactory) {
72 		this.processFactory = processFactory;
73 	}
74 
75 	/**
76 	 * Instantiates a new cover navigator controller.
77 	 *
78 	 * @param frame
79 	 */
CoverNavigatorController(final CoverNavigatorDialog frame)80 	public CoverNavigatorController(final CoverNavigatorDialog frame) {
81 		super(frame);
82 	}
83 
84 	/**
85 	 * Sets list of artists
86 	 *
87 	 * @param artists
88 	 */
setArtists(final List<IArtist> artists)89 	public void setArtists(final List<IArtist> artists) {
90 		getComponentControlled().setArtists(artists);
91 	}
92 
93 	/**
94 	 * @param visible
95 	 */
setVisible(final boolean visible)96 	public void setVisible(final boolean visible) {
97 		getComponentControlled().setVisible(visible);
98 	}
99 
100 	@Override
addBindings()101 	public void addBindings() {
102 		final CoverNavigatorDialog frame = getComponentControlled();
103 		frame.getList().addListSelectionListener(
104 				this.coverNavigationListSelectionListener);
105 		frame.getCoversButton().addActionListener(
106 				new GetCoversButtonActionListener(this, this.processFactory,
107 						frame));
108 	}
109 
110 	/**
111 	 * Update covers.
112 	 */
updateCovers()113 	void updateCovers() {
114 		final IArtist artistSelected = (IArtist) getComponentControlled()
115 				.getList().getSelectedValue();
116 		if (artistSelected == null) {
117 			return;
118 		}
119 
120 		this.getComponentControlled().getCoversPanel().removeAll();
121 
122 		this.getComponentControlled().getList().setEnabled(false);
123 		this.getComponentControlled().getCoversButton().setEnabled(false);
124 		this.getComponentControlled().setCursor(
125 				Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
126 
127 		this.beanFactory.getBean(
128 				GenerateAndShowAlbumPanelsBackgroundWorker.class).showCovers(
129 				getComponentControlled(), artistSelected);
130 	}
131 
132 }
133