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.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 import net.sourceforge.atunes.gui.views.dialogs.EditTitlesDialog;
29 import net.sourceforge.atunes.model.IAlbumInfo;
30 import net.sourceforge.atunes.model.ITrackInfo;
31 import net.sourceforge.atunes.model.IWebServicesHandler;
32 
33 /**
34  * The listener interface for receiving editTitlesDialogAction events.
35  */
36 public final class EditTitlesDialogActionListener implements ActionListener {
37 
38 	/** The dialog. */
39 	private final EditTitlesDialog dialog;
40 
41 	/** The controller. */
42 	private final EditTitlesDialogController controller;
43 
44 	private final IWebServicesHandler webServicesHandler;
45 
46 	/**
47 	 * Instantiates a new edits the titles dialog action listener.
48 	 *
49 	 * @param dialog
50 	 * @param controller
51 	 * @param webServicesHandler
52 	 */
EditTitlesDialogActionListener(EditTitlesDialog dialog, EditTitlesDialogController controller, IWebServicesHandler webServicesHandler)53 	public EditTitlesDialogActionListener(EditTitlesDialog dialog,
54 			EditTitlesDialogController controller,
55 			IWebServicesHandler webServicesHandler) {
56 		this.dialog = dialog;
57 		this.controller = controller;
58 		this.webServicesHandler = webServicesHandler;
59 	}
60 
61 	@Override
actionPerformed(ActionEvent e)62 	public void actionPerformed(ActionEvent e) {
63 		if (e.getSource() == dialog.getRetrieveTitles()) {
64 			IAlbumInfo albumInfo = webServicesHandler.getAlbum(controller
65 					.getAlbum().getArtist().toString(), controller.getAlbum()
66 					.getName());
67 			if (albumInfo != null) {
68 				List<String> tracks = new ArrayList<String>();
69 				for (ITrackInfo trackInfo : albumInfo.getTracks()) {
70 					tracks.add(trackInfo.getTitle());
71 				}
72 				controller.setTitles(tracks);
73 			}
74 		} else if (e.getSource() == dialog.getOkButton()) {
75 			controller.editFiles();
76 			dialog.setVisible(false);
77 		} else {
78 			dialog.setVisible(false);
79 		}
80 	}
81 }
82