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.context.album;
22 
23 import javax.swing.table.DefaultTableModel;
24 
25 import net.sourceforge.atunes.kernel.modules.context.ITrackTableModel;
26 import net.sourceforge.atunes.model.IAlbumInfo;
27 import net.sourceforge.atunes.model.ITrackInfo;
28 import net.sourceforge.atunes.utils.I18nUtils;
29 import net.sourceforge.atunes.utils.StringUtils;
30 
31 /**
32  * Table model to show album tracks
33  * @author alex
34  *
35  */
36 class ContextTracksTableModel extends DefaultTableModel implements ITrackTableModel {
37 
38 	/**
39 	 *
40 	 */
41 	private static final long serialVersionUID = 7703905638405573814L;
42 
43 	private IAlbumInfo album;
44 
45 	/**
46 	 * @param album
47 	 */
setAlbum(final IAlbumInfo album)48 	public void setAlbum(final IAlbumInfo album) {
49 		this.album = album;
50 		fireTableDataChanged();
51 	}
52 
53 	@Override
getColumnClass(final int columnIndex)54 	public Class<?> getColumnClass(final int columnIndex) {
55 		return columnIndex == 0 ? Integer.class : ITrackInfo.class;
56 	}
57 
58 	@Override
getColumnCount()59 	public int getColumnCount() {
60 		return 2;
61 	}
62 
63 	@Override
getColumnName(final int columnIndex)64 	public String getColumnName(final int columnIndex) {
65 		return columnIndex != 0 ? I18nUtils.getString("SONGS") : "";
66 	}
67 
68 	@Override
getRowCount()69 	public int getRowCount() {
70 		return album != null ? album.getTracks().size() : 0;
71 	}
72 
73 	/**
74 	 * Gets the track.
75 	 *
76 	 * @param index
77 	 *            the index
78 	 *
79 	 * @return the track
80 	 */
81 	@Override
getTrack(final int index)82 	public ITrackInfo getTrack(final int index) {
83 		return album != null ? album.getTracks().get(index) : null;
84 	}
85 
86 	@Override
getValueAt(final int rowIndex, final int columnIndex)87 	public Object getValueAt(final int rowIndex, final int columnIndex) {
88 		if (columnIndex == 0) {
89 			return StringUtils.getString(rowIndex + 1, ".");
90 		}
91 		return getTrack(rowIndex);
92 	}
93 
94 	@Override
isCellEditable(final int rowIndex, final int columnIndex)95 	public boolean isCellEditable(final int rowIndex, final int columnIndex) {
96 		return false;
97 	}
98 }
99