aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/library
diff options
context:
space:
mode:
authorNathan Lasseter <nathan.je.lasseter@googlemail.com>2011-02-20 13:43:01 +0000
committerNathan Lasseter <nathan.je.lasseter@googlemail.com>2011-02-20 13:43:01 +0000
commit904caa25f8de49cc20823a25ce8051dfdcae7c26 (patch)
tree65c174a386c7256e4ec784167bd23554e2c1217b /src/uk/org/ury/library
parentc8cb46d18ce2506e7da226b08c6521795b6e6173 (diff)
ConfigReader and some UI changes
Diffstat (limited to 'src/uk/org/ury/library')
-rw-r--r--src/uk/org/ury/library/LibraryUtils.java22
-rw-r--r--src/uk/org/ury/library/viewer/LibraryViewer.java6
-rw-r--r--src/uk/org/ury/library/viewer/LibraryViewerPanel.java56
3 files changed, 40 insertions, 44 deletions
diff --git a/src/uk/org/ury/library/LibraryUtils.java b/src/uk/org/ury/library/LibraryUtils.java
index 87d3339..0809d13 100644
--- a/src/uk/org/ury/library/LibraryUtils.java
+++ b/src/uk/org/ury/library/LibraryUtils.java
@@ -32,10 +32,7 @@ public class LibraryUtils
*
* @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.
+ * @param title The search fragment to include in the search.
* Can be empty or null.
*
* @throws IllegalArgumentException if db, title or artist
@@ -49,22 +46,23 @@ public class LibraryUtils
*/
public static List<LibraryItem>
- search (DatabaseDriver db, String title, String artist)
+ search (DatabaseDriver db, String search)
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.");
+ if (search == null)
+ throw new IllegalArgumentException ("Search string is null.");
+
+ if (search.equals(""))
+ //TODO: Be nicer about this
+ System.exit(1);
ResultSet rs = null;
List<LibraryItem> results = new ArrayList<LibraryItem> ();
- Object[] params = {"%" + title + "%", "%" + artist + "%"};
+ Object[] params = {"%" + search + "%", "%" + search + "%"};
try
{
@@ -78,7 +76,7 @@ public class LibraryUtils
+ " 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);
+ + " OR artist ILIKE ?;", params, 50);
}
catch (SQLException e)
{
diff --git a/src/uk/org/ury/library/viewer/LibraryViewer.java b/src/uk/org/ury/library/viewer/LibraryViewer.java
index 57ef117..970235a 100644
--- a/src/uk/org/ury/library/viewer/LibraryViewer.java
+++ b/src/uk/org/ury/library/viewer/LibraryViewer.java
@@ -7,6 +7,7 @@ import java.util.List;
import javax.swing.SwingUtilities;
+import uk.org.ury.config.ConfigReader;
import uk.org.ury.database.DatabaseDriver;
import uk.org.ury.database.UserClass;
import uk.org.ury.database.exceptions.MissingCredentialsException;
@@ -42,6 +43,7 @@ public class LibraryViewer extends AbstractFrontendModule
public static void
main (String[] args)
{
+ new ConfigReader();
LibraryViewer lv = new LibraryViewer ();
lv.runFrontendInFrame ();
}
@@ -167,11 +169,11 @@ public class LibraryViewer extends AbstractFrontendModule
*/
public void
- doSearch (String title, String artist)
+ doSearch (String search)
{
try
{
- libraryList = LibraryUtils.search (dd, title, artist);
+ libraryList = LibraryUtils.search (dd, search);
}
catch (QueryFailureException e)
{
diff --git a/src/uk/org/ury/library/viewer/LibraryViewerPanel.java b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java
index 37f36eb..cf2edfe 100644
--- a/src/uk/org/ury/library/viewer/LibraryViewerPanel.java
+++ b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java
@@ -5,6 +5,7 @@ package uk.org.ury.library.viewer;
import java.awt.BorderLayout;
import java.awt.Dimension;
+import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -43,11 +44,9 @@ public class LibraryViewerPanel extends FrontendPanel
private JTable resultsTable;
private JScrollPane resultsPane;
- private JLabel titleLabel;
- private JLabel artistLabel;
+ private JLabel searchLabel;
- private JTextField titleField;
- private JTextField artistField;
+ private JTextField searchField;
private JButton searchButton;
@@ -76,28 +75,32 @@ public class LibraryViewerPanel extends FrontendPanel
layout.setAutoCreateGaps (true);
layout.setAutoCreateContainerGaps (true);
- titleLabel = new JLabel ("By title: ");
- artistLabel = new JLabel ("By artist: ");
+ searchLabel = new JLabel ("Search");
+ searchLabel.setFont(new Font("Verdana", Font.BOLD, 14));
- titleField = new JTextField ();
+ searchField = new JTextField ();
- titleField.setPreferredSize (new Dimension (250, 15));
-
- titleLabel.setDisplayedMnemonic ('T');
- titleLabel.setLabelFor (titleField);
-
- artistField = new JTextField ();
- artistLabel.setDisplayedMnemonic ('A');
- artistLabel.setLabelFor (artistField);
+ searchField.setPreferredSize (new Dimension (250, 25));
+ searchField.setFont(new Font("Verdana", Font.BOLD, 14));
+ searchLabel.setDisplayedMnemonic ('T');
+ searchLabel.setLabelFor (searchField);
+
searchButton = new JButton ("Search");
+
+ searchField.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent event) {
+ master.doSearch (searchField.getText ());
+ resultsTable.setModel (new LibraryTableModel (master.getLibraryList ()));
+ }
+ });
searchButton.addActionListener (new ActionListener ()
{
public void
actionPerformed (ActionEvent event)
{
- master.doSearch (titleField.getText (), artistField.getText ());
+ master.doSearch (searchField.getText ());
resultsTable.setModel (new LibraryTableModel (master.getLibraryList ()));
}
});
@@ -110,11 +113,9 @@ public class LibraryViewerPanel extends FrontendPanel
(
layout.createSequentialGroup ()
.addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
- .addComponent (titleLabel)
- .addComponent (artistLabel))
+ .addComponent (searchLabel))
.addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
- .addComponent (titleField)
- .addComponent (artistField))
+ .addComponent (searchField))
.addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
.addComponent (searchButton))
);
@@ -123,16 +124,13 @@ public class LibraryViewerPanel extends FrontendPanel
(
layout.createSequentialGroup ()
.addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
- .addComponent (titleLabel)
- .addComponent (titleField)
+ .addComponent (searchLabel)
+ .addComponent (searchField)
.addComponent (searchButton))
- .addGroup (layout.createParallelGroup (GroupLayout.Alignment.LEADING)
- .addComponent (artistLabel)
- .addComponent (artistField))
);
- layout.linkSize (SwingConstants.HORIZONTAL, titleField, artistField);
- layout.linkSize (SwingConstants.VERTICAL, titleField, artistField);
+ layout.linkSize (SwingConstants.HORIZONTAL, searchField);
+ layout.linkSize (SwingConstants.VERTICAL, searchField);
add (groupPanel, BorderLayout.NORTH);
@@ -149,9 +147,7 @@ public class LibraryViewerPanel extends FrontendPanel
// 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.");
+ JTextArea explanation = new JTextArea ("To narrow your search, type part or all of the record title or artist into the box above.");
explanation.setLineWrap (true);
explanation.setWrapStyleWord (true);