blob: f3802745b42662edd2ba3403ea7c44f6c6544c78 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/**
*
*/
package uk.org.ury.library;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import uk.org.ury.database.exceptions.MissingPropertyException;
import uk.org.ury.library.LibraryItemProperty;
/**
* A table model for the library viewer.
*
* @author Matt Windsor
*/
public class LibraryTableModel extends AbstractTableModel
{
/**
*
*/
private static final long serialVersionUID = -1744980619128903509L;
private List<LibraryItem> data;
/**
* Construct a new table model.
*
* @param data The list of data on which the model will be based.
*/
public
LibraryTableModel (List<LibraryItem> data)
{
this.data = data;
}
/* (non-Javadoc)
* @see javax.swing.table.TableModel#getColumnCount()
*/
@Override
public int
getColumnCount ()
{
return 6;
}
/* (non-Javadoc)
* @see javax.swing.table.TableModel#getRowCount()
*/
@Override
public int
getRowCount ()
{
return data.size ();
}
/**
* @param c The column whose class should be investigated.
*
* @return the column class of column c.
*/
@Override
public Class<?>
getColumnClass (int c)
{
return getValueAt (0, c).getClass ();
}
/* (non-Javadoc)
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
@Override
public Object getValueAt (int rowIndex, int columnIndex)
{
LibraryItem li = data.get (rowIndex);
try
{
switch (columnIndex)
{
case 0: // Title
return li.get (LibraryItemProperty.TITLE);
case 1: // Artist
return li.get (LibraryItemProperty.ARTIST);
case 2: // Album
return li.get (LibraryItemProperty.ALBUM);
case 3: // Medium
// TODO: Make this less kludge-y
String mediumString = li.get (LibraryItemProperty.MEDIUM);
if (mediumString.equals ("c"))
return "Compact Disc";
else if (mediumString.equals ("7"))
return "7\" Vinyl";
else if (mediumString.equals ("2"))
return "12\" Vinyl";
else
return "Unrecognised";
case 4: // Clean?
// Return true if marked true, false if marked false or unknown etc.
String cleanString = li.get (LibraryItemProperty.IS_CLEAN);
// TODO: Nicer way of showing this
if (cleanString.equals ("y"))
return "Yes";
else if (cleanString.equals ("n"))
return "No";
else
return "???";
case 5: // isDigitised
// Return true if marked true, false if marked false or unknown etc.
String digitisedString = li.get (LibraryItemProperty.IS_DIGITISED);
if (digitisedString.equals ("t"))
return true;
else
return false;
default:
return "";
}
}
catch (MissingPropertyException e)
{
return "Unknown";
}
}
/* (non-Javadoc)
* @see javax.swing.table.TableModel#getColumnName(int, int)
*/
@Override
public String
getColumnName (int index)
{
switch (index)
{
case 0:
return "Title";
case 1:
return "Artist";
case 2:
return "Album";
case 3:
return "Medium";
case 4:
return "Clean?";
case 5:
return "On system?";
default:
return "ERROR";
}
}
}
|