diff options
author | Matt Windsor <mbw500@student.cs.york.ac.uk> | 2011-02-20 01:30:54 +0000 |
---|---|---|
committer | Matt Windsor <mbw500@student.cs.york.ac.uk> | 2011-02-20 01:30:54 +0000 |
commit | c8cb46d18ce2506e7da226b08c6521795b6e6173 (patch) | |
tree | 15a0cbc679cfb99d4f0ccd73a7c288838dac2b99 /src/uk/org/ury/library/LibraryTableModel.java | |
parent | a0030a5314fe29960b82bc38a96728ee222a3be5 (diff) |
Search now works; database and library viewer now separated by LibraryUtils static class (staticness will probably change later). LibraryItem now uses a hash-map to store semi-arbitrary data on tracks.
Diffstat (limited to 'src/uk/org/ury/library/LibraryTableModel.java')
-rw-r--r-- | src/uk/org/ury/library/LibraryTableModel.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/uk/org/ury/library/LibraryTableModel.java b/src/uk/org/ury/library/LibraryTableModel.java new file mode 100644 index 0000000..6f55243 --- /dev/null +++ b/src/uk/org/ury/library/LibraryTableModel.java @@ -0,0 +1,111 @@ +/** + * + */ +package uk.org.ury.library; + +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +import uk.org.ury.library.LibraryItem.LibraryProperty; + + +/** + * 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 3; + } + + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getRowCount() + */ + + @Override + public int + getRowCount () + { + return data.size (); + } + + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + + @Override + public Object getValueAt (int rowIndex, int columnIndex) + { + LibraryItem li = data.get (rowIndex); + + switch (columnIndex) + { + case 0: // Title + return li.get (LibraryProperty.TITLE); + case 1: // Artist + return li.get (LibraryProperty.ARTIST); + case 2: // Medium + return li.get (LibraryProperty.MEDIUM); + default: + return ""; + } + } + + + /* (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 "Medium"; + default: + return "ERROR"; + } + } +} |