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.tags;
22 
23 import java.util.List;
24 
25 import javax.swing.ImageIcon;
26 
27 import net.sourceforge.atunes.Constants;
28 import net.sourceforge.atunes.kernel.BackgroundWorker;
29 import net.sourceforge.atunes.model.ILocalAudioObject;
30 import net.sourceforge.atunes.model.ILocalAudioObjectImageHandler;
31 
32 /**
33  * Gets internal picture of audio object
34  *
35  * @author alex
36  *
37  */
38 public final class GetInsidePictureBackgroundWorker extends
39 		BackgroundWorker<ImageIcon, Void> {
40 
41 	private List<ILocalAudioObject> audioFiles;
42 
43 	private EditTagDialogController controller;
44 
45 	private ILocalAudioObjectImageHandler localAudioObjectImageHandler;
46 
47 	/**
48 	 * @param localAudioObjectImageHandler
49 	 */
setLocalAudioObjectImageHandler( final ILocalAudioObjectImageHandler localAudioObjectImageHandler)50 	public void setLocalAudioObjectImageHandler(
51 			final ILocalAudioObjectImageHandler localAudioObjectImageHandler) {
52 		this.localAudioObjectImageHandler = localAudioObjectImageHandler;
53 	}
54 
55 	/**
56 	 * @param controller
57 	 */
setController(final EditTagDialogController controller)58 	public void setController(final EditTagDialogController controller) {
59 		this.controller = controller;
60 	}
61 
62 	/**
63 	 * @param audioFiles
64 	 */
setAudioFiles(final List<ILocalAudioObject> audioFiles)65 	public void setAudioFiles(final List<ILocalAudioObject> audioFiles) {
66 		this.audioFiles = audioFiles;
67 	}
68 
69 	@Override
before()70 	protected void before() {
71 	}
72 
73 	@Override
whileWorking(List<Void> chunks)74 	protected void whileWorking(List<Void> chunks) {
75 	}
76 
77 	@Override
doInBackground()78 	protected ImageIcon doInBackground() {
79 		return this.localAudioObjectImageHandler.getInsidePicture(
80 				this.audioFiles.get(0), Constants.DIALOG_LARGE_IMAGE_WIDTH,
81 				Constants.DIALOG_LARGE_IMAGE_HEIGHT);
82 	}
83 
84 	@Override
done(final ImageIcon cover)85 	protected void done(final ImageIcon cover) {
86 		// Check if it's the right dialog
87 		if (this.controller.audioFilesEditing.equals(this.audioFiles)) {
88 			this.controller.getEditTagDialog().getCover().setIcon(cover);
89 			this.controller.getEditTagDialog().getCoverButton()
90 					.setEnabled(true);
91 			this.controller.getEditTagDialog().getRemoveCoverButton()
92 					.setEnabled(true);
93 			this.controller.getEditTagDialog().getOkButton().setEnabled(true);
94 		}
95 	}
96 }