~gryle-devel/gryle/trunk-deleted

« back to all changes in this revision

Viewing changes to src/uk/org/wuglug/gryle/ui/m/SongModel.java

  • Committer: Richard Leo Marsh Warburton
  • Date: 2007-01-13 22:08:02 UTC
  • mto: (1.1.6 gryle)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: rlmw@viglab-28-20070113220802-6cjjur0hdk1rce47
added src files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * 
 
3
 */
 
4
package uk.org.wuglug.gryle.ui.m;
 
5
 
 
6
import java.io.File;
 
7
import java.io.Serializable;
 
8
import java.util.Collections;
 
9
import java.util.Comparator;
 
10
 
 
11
import javax.naming.Name;
 
12
 
 
13
/**
 
14
 * @author Richard Warburton
 
15
 * Data Class for one song
 
16
 */
 
17
public class SongModel implements Serializable {
 
18
        
 
19
        //  COMPARATORS ---------------------------------
 
20
        
 
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());
 
24
                }
 
25
        }
 
26
        
 
27
        public static class ArtistComparator implements Comparator<SongModel> {
 
28
                public int compare(SongModel o1, SongModel o2) {
 
29
                        return o1.getArtist().compareTo(o2.getArtist());
 
30
                }
 
31
        }
 
32
        
 
33
        public static class NameComparator implements Comparator<SongModel> {
 
34
                public int compare(SongModel o1, SongModel o2) {
 
35
                        return o1.getName().compareTo(o2.getName());
 
36
                }
 
37
        }
 
38
        
 
39
        public static class AlbumComparator implements Comparator<SongModel> {
 
40
                public int compare(SongModel o1, SongModel o2) {
 
41
                        return o1.getAlbum().compareTo(o2.getAlbum());
 
42
                }
 
43
        }
 
44
        
 
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());
 
48
                }
 
49
        }
 
50
        
 
51
        // COLUMN NAMES FOR SONGS -------------------------------
 
52
        
 
53
        public final static String[] Columns = {
 
54
                "Track",
 
55
                "Artist",
 
56
                "Name",
 
57
                "Album",
 
58
                "Time"
 
59
        };
 
60
        
 
61
        public final static Comparator[] comparators = {
 
62
                new TrackComparator(),
 
63
                new ArtistComparator(),
 
64
                new NameComparator(),
 
65
                new AlbumComparator(),
 
66
                new TimeComparator()
 
67
        };
 
68
        
 
69
        public static int[] indices = {
 
70
                0,
 
71
                1,
 
72
                2,
 
73
                3,
 
74
                4
 
75
        };
 
76
        
 
77
        //  MAIN CLASS BODY ---------------------------------
 
78
        
 
79
        private int track;
 
80
        private String artist;
 
81
        private String name;
 
82
        private String album;
 
83
        private float time;
 
84
        private File location;
 
85
        
 
86
        
 
87
        
 
88
        /**
 
89
         * @return the location
 
90
         */
 
91
        public File getLocation() {
 
92
                return location;
 
93
        }
 
94
 
 
95
        /**
 
96
         * @param track
 
97
         * @param artist
 
98
         * @param name
 
99
         * @param album
 
100
         * @param time
 
101
         */
 
102
        public SongModel(File location) {
 
103
                super();
 
104
                
 
105
                this.track = 0;
 
106
                this.artist = location.getParent();
 
107
                this.name = location.getName();
 
108
                this.album = location.getAbsolutePath();
 
109
                this.time = 2;
 
110
                this.location = location;
 
111
        }
 
112
        
 
113
        public Object getVal(int index) {
 
114
                switch(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;
 
121
                }
 
122
        }
 
123
        
 
124
        /**
 
125
         * Method used in filtering the list
 
126
         * @param input
 
127
         * @return
 
128
         */
 
129
        public boolean match(String input) {
 
130
                return (this.artist.indexOf(input) != -1) || (this.name.indexOf(input) != -1) || (this.album.indexOf(input) != -1);
 
131
        }
 
132
        
 
133
        /**
 
134
         * @return the album
 
135
         */
 
136
        public String getAlbum() {
 
137
                return album;
 
138
        }
 
139
        /**
 
140
         * @param album the album to set
 
141
         */
 
142
        public void setAlbum(String album) {
 
143
                this.album = album;
 
144
        }
 
145
        /**
 
146
         * @return the artist
 
147
         */
 
148
        public String getArtist() {
 
149
                return artist;
 
150
        }
 
151
        /**
 
152
         * @param artist the artist to set
 
153
         */
 
154
        public void setArtist(String artist) {
 
155
                this.artist = artist;
 
156
        }
 
157
        /**
 
158
         * @return the name
 
159
         */
 
160
        public String getName() {
 
161
                return name;
 
162
        }
 
163
        /**
 
164
         * @param name the name to set
 
165
         */
 
166
        public void setName(String name) {
 
167
                this.name = name;
 
168
        }
 
169
        /**
 
170
         * @return the time
 
171
         */
 
172
        public float getTime() {
 
173
                return time;
 
174
        }
 
175
        /**
 
176
         * @param time the time to set
 
177
         */
 
178
        public void setTime(float time) {
 
179
                this.time = time;
 
180
        }
 
181
        /**
 
182
         * @return the track
 
183
         */
 
184
        public int getTrack() {
 
185
                return track;
 
186
        }
 
187
        /**
 
188
         * @param track the track to set
 
189
         */
 
190
        public void setTrack(int track) {
 
191
                this.track = track;
 
192
        }
 
193
 
 
194
        /**
 
195
         * Delete the file for this song
 
196
         */
 
197
        public boolean delete() {
 
198
                return this.location.delete();
 
199
        }
 
200
 
 
201
}