4
package uk.org.wuglug.gryle.ui.m;
7
import java.io.Serializable;
8
import java.util.Collections;
9
import java.util.Comparator;
11
import javax.naming.Name;
14
* @author Richard Warburton
15
* Data Class for one song
17
public class SongModel implements Serializable {
19
// COMPARATORS ---------------------------------
21
public static class TrackComparator implements Comparator<SongModel> {
22
public int compare(SongModel o1, SongModel o2) {
23
return new Integer(o1.getTrack()).compareTo(o2.getTrack());
27
public static class ArtistComparator implements Comparator<SongModel> {
28
public int compare(SongModel o1, SongModel o2) {
29
return o1.getArtist().compareTo(o2.getArtist());
33
public static class NameComparator implements Comparator<SongModel> {
34
public int compare(SongModel o1, SongModel o2) {
35
return o1.getName().compareTo(o2.getName());
39
public static class AlbumComparator implements Comparator<SongModel> {
40
public int compare(SongModel o1, SongModel o2) {
41
return o1.getAlbum().compareTo(o2.getAlbum());
45
public static class TimeComparator implements Comparator<SongModel> {
46
public int compare(SongModel o1, SongModel o2) {
47
return new Float(o1.getTime()).compareTo(o2.getTime());
51
// COLUMN NAMES FOR SONGS -------------------------------
53
public final static String[] Columns = {
61
public final static Comparator[] comparators = {
62
new TrackComparator(),
63
new ArtistComparator(),
65
new AlbumComparator(),
69
public static int[] indices = {
77
// MAIN CLASS BODY ---------------------------------
80
private String artist;
84
private File location;
89
* @return the location
91
public File getLocation() {
102
public SongModel(File location) {
106
this.artist = location.getParent();
107
this.name = location.getName();
108
this.album = location.getAbsolutePath();
110
this.location = location;
113
public Object getVal(int index) {
115
case 0: return this.track;
116
case 1: return this.artist;
117
case 2: return this.name;
118
case 3: return this.album;
119
case 4: return this.time;
120
default: return null;
125
* Method used in filtering the list
129
public boolean match(String input) {
130
return (this.artist.indexOf(input) != -1) || (this.name.indexOf(input) != -1) || (this.album.indexOf(input) != -1);
136
public String getAlbum() {
140
* @param album the album to set
142
public void setAlbum(String album) {
148
public String getArtist() {
152
* @param artist the artist to set
154
public void setArtist(String artist) {
155
this.artist = artist;
160
public String getName() {
164
* @param name the name to set
166
public void setName(String name) {
172
public float getTime() {
176
* @param time the time to set
178
public void setTime(float time) {
184
public int getTrack() {
188
* @param track the track to set
190
public void setTrack(int track) {
195
* Delete the file for this song
197
public boolean delete() {
198
return this.location.delete();