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 | |
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.
-rw-r--r-- | src/uk/org/ury/database/DatabaseDriver.java | 62 | ||||
-rw-r--r-- | src/uk/org/ury/database/exceptions/QueryFailureException.java | 44 | ||||
-rw-r--r-- | src/uk/org/ury/frontend/FrontendFrame.java | 3 | ||||
-rw-r--r-- | src/uk/org/ury/frontend/images/ury.jpg | bin | 30139 -> 0 bytes | |||
-rw-r--r-- | src/uk/org/ury/library/LibraryItem.java | 482 | ||||
-rw-r--r-- | src/uk/org/ury/library/LibraryTableModel.java | 111 | ||||
-rw-r--r-- | src/uk/org/ury/library/LibraryUtils.java | 119 | ||||
-rw-r--r-- | src/uk/org/ury/library/viewer/LibraryViewer.java | 101 | ||||
-rw-r--r-- | src/uk/org/ury/library/viewer/LibraryViewerPanel.java | 67 |
9 files changed, 502 insertions, 487 deletions
diff --git a/src/uk/org/ury/database/DatabaseDriver.java b/src/uk/org/ury/database/DatabaseDriver.java index 0f03267..1982215 100644 --- a/src/uk/org/ury/database/DatabaseDriver.java +++ b/src/uk/org/ury/database/DatabaseDriver.java @@ -2,6 +2,7 @@ package uk.org.ury.database; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -77,7 +78,15 @@ public class DatabaseDriver } - public void + /** + * Connect to the URY database. + * + * @param login The login tuple to use for the connection. + * + * @throws SQLException if the database connection failed. + */ + + private void connect (DatabaseLogin login) throws SQLException { if (login == null) @@ -89,6 +98,7 @@ public class DatabaseDriver if (login.getPassword () == null) throw new IllegalArgumentException ("Login has no associated password."); + conn = DriverManager.getConnection (DATABASE_PATH, login.getUsername (), login.getPassword ()); @@ -96,20 +106,21 @@ public class DatabaseDriver /** - * Execute a SQL statement. + * Execute an unprepared SQL statement with no arguments. * - * @param sql The SQL statement to execute. + * @param sql The SQL statement to execute. + * @param fetchSize The maximum number of query rows to return. * - * @return the JDBC results set. + * @return the JDBC results set. */ public ResultSet - executeQuery (String sql) + executeQuery (String sql, int fetchSize) { try { Statement st = conn.createStatement (); - st.setFetchSize (50); + st.setFetchSize (fetchSize); return st.executeQuery (sql); } @@ -119,4 +130,43 @@ public class DatabaseDriver return null; } } + + + /** + * Perform a SQL statement with arguments. + * + * This accepts an array of parameter objects, which must each + * either be String or Integer objects. The objects will be used + * sequentially to fill in '?' placeholders in the query text. + * + * @param sql The SQL statement to execute. + * @param params A list of parameter objects. + * @param fetchSize The maximum number of query rows to return. + * + * @return the set of results from the query. + * + * @throws IllegalArgumentException if any of the + * parameters is unsupported by the database as + * a statement parameter. + * + * @throws SQLException if a SQL error occurs. + */ + + public ResultSet + executeQuery (String sql, Object[] params, int fetchSize) throws SQLException + { + PreparedStatement st = conn.prepareStatement (sql); + + st.setFetchSize (50); + + for (int i = 0; i < params.length; i++) + if (params[i] instanceof String) + st.setString (i + 1, (String) params[i]); + else if (params[i] instanceof Integer) + st.setInt (i + 1, (Integer) params[i]); + else + throw new IllegalArgumentException ("Unsupported parameter #" + (i + 1)); + + return st.executeQuery (); + } } diff --git a/src/uk/org/ury/database/exceptions/QueryFailureException.java b/src/uk/org/ury/database/exceptions/QueryFailureException.java new file mode 100644 index 0000000..d7b3e5b --- /dev/null +++ b/src/uk/org/ury/database/exceptions/QueryFailureException.java @@ -0,0 +1,44 @@ +/** + * + */ +package uk.org.ury.database.exceptions; + +/** + * Exception thrown when the database backend fails to execute + * a query. + * + * @author Matt Windsor + */ + +public class QueryFailureException extends Exception +{ + /** + * + */ + private static final long serialVersionUID = -7353531873142099828L; + + +/** + * Construct a new QueryFailureException with a + * default reason. + */ + + public + QueryFailureException () + { + super ("Query failure."); + } + + + /** + * Construct a new QueryFailureException. + * + * @param reason The explanation for the exception. + */ + + public + QueryFailureException (String reason) + { + super (reason); + } +} diff --git a/src/uk/org/ury/frontend/FrontendFrame.java b/src/uk/org/ury/frontend/FrontendFrame.java index d27a85a..6324512 100644 --- a/src/uk/org/ury/frontend/FrontendFrame.java +++ b/src/uk/org/ury/frontend/FrontendFrame.java @@ -6,6 +6,7 @@ package uk.org.ury.frontend; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; +import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.BorderFactory; @@ -61,6 +62,8 @@ public class FrontendFrame extends JFrame cp.add (banner, BorderLayout.NORTH); cp.add (parent, BorderLayout.CENTER); + setPreferredSize (new Dimension (640, 480)); + pack (); setVisible (true); } diff --git a/src/uk/org/ury/frontend/images/ury.jpg b/src/uk/org/ury/frontend/images/ury.jpg Binary files differdeleted file mode 100644 index 96d2740..0000000 --- a/src/uk/org/ury/frontend/images/ury.jpg +++ /dev/null diff --git a/src/uk/org/ury/library/LibraryItem.java b/src/uk/org/ury/library/LibraryItem.java index 0e44be5..593d1a5 100644 --- a/src/uk/org/ury/library/LibraryItem.java +++ b/src/uk/org/ury/library/LibraryItem.java @@ -3,6 +3,10 @@ */ package uk.org.ury.library; + +import java.util.Map; + + /** * An item in the URY library. * @@ -11,436 +15,76 @@ package uk.org.ury.library; public class LibraryItem { - private String title; - private String artist; - private String label; - private String status; - private String medium; - private String format; - private String dateReleased; - private String dateAdded; - private String dateEdited; - private String shelfLetter; - private String shelfNumber; - private String addForename; - private String addSurname; - private String editForename; - private String editSurname; - private String cdID; - private int addMemberID; - private int editMemberID; - - public - LibraryItem () - { - } - - - /** - * @return the title - */ - - public String - getTitle () - { - return title; - } - - - /** - * @param title the title to set - */ - - public void - setTitle (String title) - { - this.title = title; - } - - - /** - * @return the artist - */ - - public String - getArtist () - { - return artist; - } - - - /** - * @param artist the artist to set - */ - - public void - setArtist (String artist) - { - this.artist = artist; - } - - - /** - * @return the label - */ - - public String - getLabel () - { - return label; - } - - - /** - * @param label the label to set - */ - - public void - setLabel (String label) - { - this.label = label; - } - - - /** - * @return the status - */ - - public String - getStatus () - { - return status; - } - - - /** - * @param status the status to set - */ - - public void - setStatus (String status) - { - this.status = status; - } - - - /** - * @return the medium - */ - - public String - getMedium () - { - return medium; - } - - - /** - * @param medium the medium to set - */ - - public void - setMedium (String medium) - { - this.medium = medium; - } - - - /** - * @return the format - */ - - public String - getFormat () - { - return format; - } - - - /** - * @param format the format to set - */ - - public void - setFormat (String format) - { - this.format = format; - } - - - /** - * @return the dateReleased - */ - - public String - getDateReleased () - { - return dateReleased; - } - - - /** - * @param dateReleased the dateReleased to set - */ - - public void - setDateReleased (String dateReleased) - { - this.dateReleased = dateReleased; - } - - - /** - * @return the dateAdded - */ - - public String - getDateAdded () - { - return dateAdded; - } - - - /** - * @param dateAdded the dateAdded to set - */ - - public void - setDateAdded (String dateAdded) - { - this.dateAdded = dateAdded; - } - - - /** - * @return the dateEdited - */ - - public String - getDateEdited () - { - return dateEdited; - } - - - /** - * @param dateEdited the dateEdited to set - */ - - public void - setDateEdited (String dateEdited) - { - this.dateEdited = dateEdited; - } - - - /** - * @return the shelfLetter - */ - - - public String - getShelfLetter () - { - return shelfLetter; - } - - - /** - * @param shelfLetter the shelfLetter to set - */ - - public void - setShelfLetter (String shelfLetter) - { - this.shelfLetter = shelfLetter; - } - - - /** - * @return the shelfNumber - */ - - public String - getShelfNumber () - { - return shelfNumber; - } - - - /** - * @param shelfNumber the shelfNumber to set - */ - - public void - setShelfNumber (String shelfNumber) - { - this.shelfNumber = shelfNumber; - } - - - /** - * @return the addForename - */ - - public String - getAddForename () - { - return addForename; - } - - - /** - * @param addForename the addForename to set - */ - - public void - setAddForename (String addForename) - { - this.addForename = addForename; - } - - - /** - * @return the addSurname - */ - - public String - getAddSurname () - { - return addSurname; - } - - - /** - * @param addSurname the addSurname to set - */ - - public void - setAddSurname (String addSurname) - { - this.addSurname = addSurname; - } - - - /** - * @return the editForename - */ - - public String - getEditForename () - { - return editForename; - } - - - /** - * @param editForename the editForename to set - */ - - public void - setEditForename (String editForename) - { - this.editForename = editForename; - } - - - /** - * @return the editSurname - */ - - public String - getEditSurname () - { - return editSurname; - } - - - /** - * @param editSurname the editSurname to set - */ - - public void - setEditSurname (String editSurname) - { - this.editSurname = editSurname; - } - - - /** - * @return the cdID - */ - - public String - getCdID () - { - return cdID; - } - - - /** - * @param cdID the cdID to set - */ - - public void - setCdID (String cdID) - { - this.cdID = cdID; - } - - - /** - * @return the addMemberID - */ - - public int - getAddMemberID () - { - return addMemberID; - } - - - /** - * @param addMemberID the addMemberID to set - */ - - public void - setAddMemberID (int addMemberID) - { - this.addMemberID = addMemberID; - } - - /** - * @return the editMemberID + * The parameters that are stored in the LibraryItem. + * + * @author Matt Windsor + */ + + public enum LibraryProperty + { + // Constant SQL identifier + TITLE ("title"), + ARTIST ("artist"), + LABEL ("label"), + STATUS ("status"), + MEDIUM ("medium"), + FORMAT ("format"), + DATE_RELEASED ("datereleased"), + DATE_ADDED ("dateadded"), + DATE_EDITED ("dateedited"), + SHELF_LETTER ("shelfletter"), + SHELF_NUMBER ("shelfnumber"), + CD_ID ("cdid"), + ADD_MEMBER_ID ("memberid_add"), + EDIT_MEMBER_ID ("memberid_lastedit"), + ADD_FORENAME ("fnameadd"), + ADD_SURNAME ("snameadd"), + EDIT_FORENAME ("fnameedit"), + EDIT_SURNAME ("snameedit"); + + + public final String sql; + + private + LibraryProperty (String sql) + { + this.sql = sql; + } + }; + + + private Map<LibraryProperty, String> properties; + + + /** + * Construct a new library item from an existing list of + * properties. + * + * @param properties The map of properties that the new item will + * inherit. */ - public int - getEditMemberID () - { - return editMemberID; - } - - - /** - * @param editMemberID the editMemberID to set - */ - - public void - setEditMemberID (int editMemberID) + public + LibraryItem (Map<LibraryProperty, String> properties) { - this.editMemberID = editMemberID; + this.properties = properties; } /** - * @return a human-readable string representation of the item. + * Query this item for a property. + * + * @param property The property to query. + * @return The property, if it exists, or "Unknown" otherwise. */ - @Override public String - toString () + get (LibraryProperty property) { - return getArtist () + " - " + getTitle () + " (" + getShelfLetter () + getShelfNumber () + ")"; + if (properties.containsKey (property)) + return properties.get (property); + else + return "Unknown"; } } 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"; + } + } +} diff --git a/src/uk/org/ury/library/LibraryUtils.java b/src/uk/org/ury/library/LibraryUtils.java new file mode 100644 index 0000000..87d3339 --- /dev/null +++ b/src/uk/org/ury/library/LibraryUtils.java @@ -0,0 +1,119 @@ +/** + * + */ +package uk.org.ury.library; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import uk.org.ury.database.DatabaseDriver; +import uk.org.ury.database.exceptions.QueryFailureException; + +import uk.org.ury.library.LibraryItem.LibraryProperty; + + +/** + * A set of common utility routines to facilitate the extraction of + * library items from the library areas of the URY database. + * + * @author Matt Windsor + * + */ + +public class LibraryUtils +{ + /** + * Perform a library search. + * + * Presently, the title and artist comparisons are logically ANDed. + * + * @param db The database to query. + * + * @param title The title fragment to include in the search. + * Can be empty or null. + * + * @param artist The artist fragment to include in the search. + * Can be empty or null. + * + * @throws IllegalArgumentException if db, title or artist + * are null. + * + * @throws QueryFailureException if the database backend + * yielded an error while executing the search + * query. + * + * @return a list of LibraryItems matching the search terms. + */ + + public static List<LibraryItem> + search (DatabaseDriver db, String title, String artist) + throws QueryFailureException + { + if (db == null) + throw new IllegalArgumentException ("Database handle is null."); + + if (title == null) + throw new IllegalArgumentException ("Title string is null."); + + if (artist == null) + throw new IllegalArgumentException ("Artist string is null."); + + + ResultSet rs = null; + List<LibraryItem> results = new ArrayList<LibraryItem> (); + Object[] params = {"%" + title + "%", "%" + artist + "%"}; + + try + { + rs = db.executeQuery ( + "SELECT title, artist, recordlabel AS label, status, media AS medium, format," + + " datereleased, EXTRACT(EPOCH FROM dateadded) as dateadded," + + " EXTRACT(EPOCH FROM datetime_lastedit) AS dateedited," + + " shelfletter, shelfnumber, cdid, memberid_add, memberid_lastedit," + + " a.fname AS fnameadd, a.sname AS snameadd, b.fname AS fnameedit, b.sname AS snameedit" + + " FROM rec_record AS r" + + " INNER JOIN member AS a ON (a.memberid = r.memberid_add)" + + " LEFT JOIN member AS b ON (b.memberid = r.memberid_lastedit)" + + " WHERE title ILIKE ?" + + " AND artist ILIKE ?;", params, 50); + } + catch (SQLException e) + { + throw new QueryFailureException (e.getMessage ()); + } + + try + { + while (rs.next ()) + { + // Translate SQL columns into a list of properties. + + HashMap<LibraryProperty, String> properties = new HashMap<LibraryProperty, String> (); + + for (LibraryProperty p : LibraryProperty.values ()) + { + try + { + properties.put (p, rs.getString (p.sql)); + } + catch (SQLException e) + { + // Ignore this, as it is almost certainly just a non-existent + // property. + } + } + + results.add (new LibraryItem (properties)); + } + } + catch (SQLException e) + { + throw new QueryFailureException (e.getMessage ()); + } + + return results; + } +}
\ No newline at end of file diff --git a/src/uk/org/ury/library/viewer/LibraryViewer.java b/src/uk/org/ury/library/viewer/LibraryViewer.java index 234e1eb..57ef117 100644 --- a/src/uk/org/ury/library/viewer/LibraryViewer.java +++ b/src/uk/org/ury/library/viewer/LibraryViewer.java @@ -1,8 +1,7 @@ package uk.org.ury.library.viewer; import java.lang.reflect.InvocationTargetException; -import java.sql.ResultSet; -import java.sql.SQLException; + import java.util.ArrayList; import java.util.List; @@ -11,18 +10,23 @@ import javax.swing.SwingUtilities; import uk.org.ury.database.DatabaseDriver; import uk.org.ury.database.UserClass; import uk.org.ury.database.exceptions.MissingCredentialsException; +import uk.org.ury.database.exceptions.QueryFailureException; import uk.org.ury.frontend.AbstractFrontendModule; import uk.org.ury.frontend.FrontendError; import uk.org.ury.frontend.FrontendFrame; -import uk.org.ury.frontend.FrontendModule; + import uk.org.ury.library.LibraryItem; +import uk.org.ury.library.LibraryUtils; + public class LibraryViewer extends AbstractFrontendModule { /** * */ + private static final long serialVersionUID = -2782366476480563739L; + private DatabaseDriver dd; private List<LibraryItem> libraryList; private LibraryViewerPanel panel; private FrontendFrame frame; @@ -51,6 +55,7 @@ public class LibraryViewer extends AbstractFrontendModule LibraryViewer () { frame = null; + libraryList = new ArrayList<LibraryItem> (); panel = new LibraryViewerPanel (this); } @@ -63,6 +68,7 @@ public class LibraryViewer extends AbstractFrontendModule init () { frame = null; + libraryList = new ArrayList<LibraryItem> (); panel = new LibraryViewerPanel (this); @@ -107,6 +113,7 @@ public class LibraryViewer extends AbstractFrontendModule add (panel); } + /** * Run the library viewer frontend in a FrontendFrame. */ @@ -128,7 +135,7 @@ public class LibraryViewer extends AbstractFrontendModule private void runFrontend () { - DatabaseDriver dd = null; + dd = null; try { @@ -143,55 +150,43 @@ public class LibraryViewer extends AbstractFrontendModule { FrontendError.reportFatal (f.getMessage (), frame); } + } - - System.out.println ("connection success"); - - ResultSet rs = dd.executeQuery ("SELECT title, artist, recordlabel AS label, status, media AS medium, format," - + " datereleased, EXTRACT(EPOCH FROM dateadded) as dateadded," - + " EXTRACT(EPOCH FROM datetime_lastedit) AS dateedited," - + " shelfletter, shelfnumber, cdid, memberid_add, memberid_lastedit," - + " a.fname AS fnameadd, a.sname AS snameadd, b.fname AS fnameedit, b.sname AS snameedit" - + " FROM rec_record AS r" - + " INNER JOIN member AS a ON (a.memberid = r.memberid_add)" - + " LEFT JOIN member AS b ON (b.memberid = r.memberid_lastedit)"); - - - libraryList = new ArrayList<LibraryItem> (); - - try - { - while (rs.next ()) - { - LibraryItem li = new LibraryItem (); - - li.setTitle (rs.getString ("title")); - li.setArtist (rs.getString ("artist")); - li.setLabel (rs.getString ("label")); - li.setStatus (rs.getString ("status")); - li.setMedium (rs.getString ("medium")); - li.setFormat (rs.getString ("format")); - li.setDateReleased (rs.getString ("datereleased")); - li.setDateEdited (rs.getString ("dateedited")); - li.setShelfLetter (rs.getString ("shelfletter")); - li.setShelfNumber (rs.getString ("shelfnumber")); - li.setCdID (rs.getString ("cdid")); - li.setAddMemberID (rs.getInt ("memberid_add")); - li.setEditMemberID (rs.getInt ("memberid_lastedit")); - li.setAddForename (rs.getString ("fnameadd")); - li.setAddSurname (rs.getString ("snameadd")); - li.setEditForename (rs.getString ("fnameedit")); - li.setEditSurname (rs.getString ("snameedit")); - - System.out.println (li); - - libraryList.add (li); - } - } - catch (SQLException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + /** + * Do a library search. + * + * This will update the library list to reflect the results of the + * search. + * + * @param title The title fragment to include in the search. + * Can be empty or null. + * + * @param artist The artist fragment to include in the search. + * Can be empty or null. + */ + + public void + doSearch (String title, String artist) + { + try + { + libraryList = LibraryUtils.search (dd, title, artist); + } + catch (QueryFailureException e) + { + FrontendError.reportFatal (e.getMessage (), frame); + } + } + + + /** + * @return the current library list. + */ + + public List<LibraryItem> + getLibraryList () + { + return libraryList; } } diff --git a/src/uk/org/ury/library/viewer/LibraryViewerPanel.java b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java index 6a100a6..37f36eb 100644 --- a/src/uk/org/ury/library/viewer/LibraryViewerPanel.java +++ b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java @@ -3,16 +3,24 @@ */ package uk.org.ury.library.viewer; +import java.awt.BorderLayout; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.BorderFactory; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; import uk.org.ury.frontend.FrontendPanel; +import uk.org.ury.library.LibraryTableModel; /** * @author Matt Windsor @@ -30,6 +38,11 @@ public class LibraryViewerPanel extends FrontendPanel private LibraryViewer master; /* Panel widgets. */ + + private LibraryTableModel resultsModel; + private JTable resultsTable; + private JScrollPane resultsPane; + private JLabel titleLabel; private JLabel artistLabel; @@ -42,19 +55,23 @@ public class LibraryViewerPanel extends FrontendPanel /** * Construct a new LibraryViewerPanel. * - * @param master The LibraryViewer controlling this LibraryViewerPanel. + * @param inMaster The LibraryViewer controlling this LibraryViewerPanel. */ public - LibraryViewerPanel (LibraryViewer master) + LibraryViewerPanel (LibraryViewer inMaster) { super (); - this.master = master; + master = inMaster; + + setLayout (new BorderLayout ()); - GroupLayout layout = new GroupLayout (this); + JPanel groupPanel = new JPanel (); - setLayout (layout); + GroupLayout layout = new GroupLayout (groupPanel); + + groupPanel.setLayout (layout); layout.setAutoCreateGaps (true); layout.setAutoCreateContainerGaps (true); @@ -62,11 +79,14 @@ public class LibraryViewerPanel extends FrontendPanel titleLabel = new JLabel ("By title: "); artistLabel = new JLabel ("By artist: "); - titleField = new JTextField ("Type part of the title here."); + titleField = new JTextField (); + + titleField.setPreferredSize (new Dimension (250, 15)); + titleLabel.setDisplayedMnemonic ('T'); titleLabel.setLabelFor (titleField); - artistField = new JTextField ("Type part of the artist name here."); + artistField = new JTextField (); artistLabel.setDisplayedMnemonic ('A'); artistLabel.setLabelFor (artistField); @@ -77,6 +97,8 @@ public class LibraryViewerPanel extends FrontendPanel public void actionPerformed (ActionEvent event) { + master.doSearch (titleField.getText (), artistField.getText ()); + resultsTable.setModel (new LibraryTableModel (master.getLibraryList ())); } }); @@ -109,8 +131,35 @@ public class LibraryViewerPanel extends FrontendPanel .addComponent (artistField)) ); - layout.linkSize(SwingConstants.HORIZONTAL, titleField, artistField); - layout.linkSize(SwingConstants.VERTICAL, titleField, artistField); + layout.linkSize (SwingConstants.HORIZONTAL, titleField, artistField); + layout.linkSize (SwingConstants.VERTICAL, titleField, artistField); + + add (groupPanel, BorderLayout.NORTH); + + + // Table + + resultsModel = new LibraryTableModel (master.getLibraryList ()); + resultsTable = new JTable (resultsModel); + + resultsPane = new JScrollPane (resultsTable); + + add (resultsPane, BorderLayout.CENTER); + + + // Explanation (TODO: Subclass?) + + JTextArea explanation = new JTextArea ("To narrow your search, type part or all of the record title or artist" + + " into the respective box above. If you leave a box blank, it will" + + " not be used in the search."); + + explanation.setLineWrap (true); + explanation.setWrapStyleWord (true); + explanation.setEditable (false); + explanation.setOpaque (false); + explanation.setBorder (BorderFactory.createEmptyBorder (5, 5, 5, 5)); + + add (explanation, BorderLayout.SOUTH); } |