01: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
02: // Released under the terms of the GNU General Public License version 2 or later.
03:
04: package eg.music;
05:
06: import java.util.*;
07: import java.text.*;
08:
09: public class Music {
10:
11: static String status = "ready";
12:
13: public String title;
14: public String artist;
15: public String album;
16: public String genre;
17: public long size;
18: public int seconds;
19: public int trackNumber;
20: public int trackCount;
21: public int year;
22: public Date date;
23: public transient boolean selected = false;
24:
25: // Accessors ////////////////////////////////
26:
27: public String track() {
28: return trackNumber + " of " + trackCount;
29: }
30:
31: public double time() {
32: return Math.round(seconds / 0.6) / 100.0;
33: }
34:
35: public String toString() {
36: if (title != null) {
37: return title;
38: } else {
39: return super .toString();
40: }
41: }
42:
43: // Factory //////////////////////////////////
44:
45: static DateFormat dateFormat = new SimpleDateFormat("M/d/yy h:mm a");
46:
47: static Music parse(String string) throws ParseException {
48: Music m = new Music();
49: StringTokenizer t = new StringTokenizer(string, "\t");
50: m.title = t.nextToken();
51: m.artist = t.nextToken();
52: m.album = t.nextToken();
53: m.genre = t.nextToken();
54: m.size = Long.parseLong(t.nextToken());
55: m.seconds = Integer.parseInt(t.nextToken());
56: m.trackNumber = Integer.parseInt(t.nextToken());
57: m.trackCount = Integer.parseInt(t.nextToken());
58: m.year = Integer.parseInt(t.nextToken());
59: m.date = dateFormat.parse(t.nextToken());
60: return m;
61: }
62:
63: }
|