From 2efb758e7c2bd85801c76305161d9d8fa6d2be4b Mon Sep 17 00:00:00 2001 From: Matt Windsor Date: Sat, 19 Mar 2011 13:06:38 +0000 Subject: LibraryViewer: move to ResourceBundled text for localisation and decoupling purposes; warning cleanup; import of json_simple in preparation for JSON protocol implementation. --- .classpath | 1 + lib/json_simple-1.1.jar | Bin 0 -> 16046 bytes src/uk/org/ury/client/test/ClientTest.java | 3 +- src/uk/org/ury/database/DatabaseItem.java | 1 - src/uk/org/ury/frontend/FrontendFrame.java | 6 +- src/uk/org/ury/frontend/FrontendModulePanel.java | 2 +- src/uk/org/ury/library/LibraryUtils.java | 2 - .../ury/library/viewer/LibraryViewer.properties | 22 ++++++ .../org/ury/library/viewer/LibraryViewerPanel.java | 82 ++++++++++++++------- .../org/ury/library/viewer/library_viewer_gui.xml | 8 +- src/uk/org/ury/server/Server.java | 3 - src/uk/org/ury/show/viewer/ShowViewerPanel.java | 4 +- src/uk/org/ury/testrig/DemoMenuPanel.java | 2 +- 13 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 lib/json_simple-1.1.jar create mode 100644 src/uk/org/ury/library/viewer/LibraryViewer.properties diff --git a/.classpath b/.classpath index 2a83150..4b16e4c 100644 --- a/.classpath +++ b/.classpath @@ -11,6 +11,7 @@ + diff --git a/lib/json_simple-1.1.jar b/lib/json_simple-1.1.jar new file mode 100644 index 0000000..f395f41 Binary files /dev/null and b/lib/json_simple-1.1.jar differ diff --git a/src/uk/org/ury/client/test/ClientTest.java b/src/uk/org/ury/client/test/ClientTest.java index 085bebb..e83c28c 100644 --- a/src/uk/org/ury/client/test/ClientTest.java +++ b/src/uk/org/ury/client/test/ClientTest.java @@ -3,8 +3,6 @@ */ package uk.org.ury.client.test; -import static org.junit.Assert.*; - import java.util.List; import junit.framework.Assert; @@ -15,6 +13,7 @@ import org.junit.Test; import uk.org.ury.client.Client; + /** * JUnit test for the low-level client logic. * diff --git a/src/uk/org/ury/database/DatabaseItem.java b/src/uk/org/ury/database/DatabaseItem.java index f151dbf..b1482ce 100644 --- a/src/uk/org/ury/database/DatabaseItem.java +++ b/src/uk/org/ury/database/DatabaseItem.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import uk.org.ury.database.exceptions.MissingPropertyException; -import uk.org.ury.server.protocol.Directive; /** diff --git a/src/uk/org/ury/frontend/FrontendFrame.java b/src/uk/org/ury/frontend/FrontendFrame.java index 39cb89b..1683c9b 100644 --- a/src/uk/org/ury/frontend/FrontendFrame.java +++ b/src/uk/org/ury/frontend/FrontendFrame.java @@ -94,7 +94,7 @@ public class FrontendFrame extends JFrame implements FrontendMaster // Banner System.out.println (child); - banner = new FrontendBanner (child.getName ()); + banner = new FrontendBanner (child.getModuleName ()); // Composition @@ -171,7 +171,7 @@ public class FrontendFrame extends JFrame implements FrontendMaster child.setMaster (this); if (banner != null) - banner.setTitle (child.getName ()); + banner.setTitle (child.getModuleName ()); pack (); } @@ -303,7 +303,7 @@ public class FrontendFrame extends JFrame implements FrontendMaster child = mpanel; add (child); - banner.setTitle (child.getName ()); + banner.setTitle (child.getModuleName ()); if (cpanel != null) add (cpanel, BorderLayout.SOUTH); diff --git a/src/uk/org/ury/frontend/FrontendModulePanel.java b/src/uk/org/ury/frontend/FrontendModulePanel.java index f5009c4..312be8e 100644 --- a/src/uk/org/ury/frontend/FrontendModulePanel.java +++ b/src/uk/org/ury/frontend/FrontendModulePanel.java @@ -73,7 +73,7 @@ public abstract class FrontendModulePanel extends FrontendPanel */ public abstract String - getName (); + getModuleName (); /** diff --git a/src/uk/org/ury/library/LibraryUtils.java b/src/uk/org/ury/library/LibraryUtils.java index 8a71285..f1e41c8 100644 --- a/src/uk/org/ury/library/LibraryUtils.java +++ b/src/uk/org/ury/library/LibraryUtils.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map; import uk.org.ury.database.DatabaseDriver; import uk.org.ury.database.exceptions.QueryFailureException; @@ -25,7 +24,6 @@ import uk.org.ury.server.protocol.Directive; * library items from the library areas of the URY database. * * @author Matt Windsor - * */ public class LibraryUtils diff --git a/src/uk/org/ury/library/viewer/LibraryViewer.properties b/src/uk/org/ury/library/viewer/LibraryViewer.properties new file mode 100644 index 0000000..677cbc5 --- /dev/null +++ b/src/uk/org/ury/library/viewer/LibraryViewer.properties @@ -0,0 +1,22 @@ +// Module name +MODULE_NAME = Library Viewer Demo + +// Search errors +// 1st parameter: search term, 2nd parameter: failure reason etc. +ERR_UNKNOWN = Unknown error while searching for '%1$s'. +ERR_SEARCH_FAILED = Search for '%1$s' failed: %2$s +ERR_EMPTY_SEARCH = Please type in a search term. +ERR_NO_RESULTS = Sorry, but no results were found for '%1$s'. + +// Search messages +// 1st parameter: search term +MSG_SEARCHING = Searching for '%1$s', please wait... + +// Labels +LBL_SEARCHFOR = Search for: + +// Buttons +BTN_SEARCH = Start Search + +// Hint +HINT = To narrow your search, type part or all of the record title or artist into the box above. \ No newline at end of file diff --git a/src/uk/org/ury/library/viewer/LibraryViewerPanel.java b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java index e453095..79b5902 100644 --- a/src/uk/org/ury/library/viewer/LibraryViewerPanel.java +++ b/src/uk/org/ury/library/viewer/LibraryViewerPanel.java @@ -4,6 +4,7 @@ package uk.org.ury.library.viewer; +import java.util.ResourceBundle; import java.util.concurrent.ExecutionException; import javax.swing.JButton; @@ -17,6 +18,7 @@ import javax.swing.SwingWorker; import uk.org.ury.database.exceptions.QueryFailureException; import uk.org.ury.frontend.FrontendMaster; import uk.org.ury.frontend.FrontendModulePanel; +import uk.org.ury.frontend.HintField; import uk.org.ury.frontend.exceptions.UICreationFailureException; import uk.org.ury.library.exceptions.EmptySearchException; @@ -37,21 +39,32 @@ public class LibraryViewerPanel extends FrontendModulePanel /* Panel widgets exposed by the SwiXML user interface. */ - private JTable resultsTable; + private JTable resultsTable; private JScrollPane resultsPane; - private JPanel messagePanel; - private JLabel messageLabel; - private JPanel searchingPanel; - private JTextField searchField; - private JButton searchButton; + + private JPanel messagePanel; + private JLabel messageLabel; + + private JPanel searchingPanel; + private JLabel searchingLabel; + + private JTextField searchField; + private JButton searchButton; + private JLabel searchForLabel; + + private HintField hint; /* This contains the last search failure message, for use in * letting the user know what happened. */ - private String searchFailureMessage = "Unknown error."; + private String searchFailureMessage; + + + // Resource bundle. + private ResourceBundle rb; /** @@ -68,13 +81,24 @@ public class LibraryViewerPanel extends FrontendModulePanel LibraryViewerPanel (LibraryViewer viewer, FrontendMaster master) throws UICreationFailureException { - super (viewer, "library_viewer_gui.xml", master); - /* The UI implementation is contained in library_viewer_gui.xml. * * See this file for more details. */ - + + super (viewer, "library_viewer_gui.xml", master); + + + // Fill in locale-specific data. + + rb = ResourceBundle.getBundle ("uk.org.ury.library.viewer.LibraryViewer"); + + searchFailureMessage = rb.getString ("ERR_UNKNOWN"); + + searchingLabel.setText (rb.getString ("MSG_SEARCHING")); + searchForLabel.setText (rb.getString ("LBL_SEARCHFOR")); + searchButton.setText (rb.getString ("BTN_SEARCH")); + hint.setText (rb.getString ("HINT")); // Fine-tune table @@ -85,14 +109,14 @@ public class LibraryViewerPanel extends FrontendModulePanel /** * @return the name of the panel. * - * @see uk.org.ury.frontend.FrontendModulePanel#getName() + * @see uk.org.ury.frontend.FrontendModulePanel#getModuleName() */ @Override public String - getName () + getModuleName () { - return "Library Viewer Demo"; + return rb.getString ("MODULE_NAME"); } @@ -115,17 +139,22 @@ public class LibraryViewerPanel extends FrontendModulePanel * user-friendliness. */ - searchField.setEnabled (false); - searchButton.setEnabled (false); - resultsPane.setVisible (false); - messagePanel.setVisible (false); + searchField.setEnabled (false); + searchButton.setEnabled (false); + resultsPane.setVisible (false); + messagePanel.setVisible (false); searchingPanel.setVisible (true); + searchingLabel.setText (String.format (rb.getString ("MSG_SEARCHING"), + searchField.getText ())); final LibraryViewer master = (LibraryViewer) getModule (); SwingWorker worker = new SwingWorker () { + private String searchTerm = ""; + + /** * Perform a task in a separate thread from event-dispatch. * @@ -138,17 +167,20 @@ public class LibraryViewerPanel extends FrontendModulePanel public Boolean doInBackground () { + searchTerm = searchField.getText (); + try { - master.doSearch (searchField.getText ()); + master.doSearch (searchTerm); } catch (QueryFailureException e) { - searchFailureMessage = "Search failed: " + e.getMessage (); + searchFailureMessage = String.format (rb.getString ("ERR_SEARCH_FAILED"), + searchTerm, e.getMessage ()); } catch (EmptySearchException e) { - searchFailureMessage = "Please type in a search term."; + searchFailureMessage = rb.getString ("ERR_EMPTY_SEARCH"); return false; } @@ -186,8 +218,8 @@ public class LibraryViewerPanel extends FrontendModulePanel * or not results were found. */ - searchField.setEnabled (true); - searchButton.setEnabled (true); + searchField.setEnabled (true); + searchButton.setEnabled (true); searchingPanel.setVisible (false); if (hasSucceeded == false) @@ -197,8 +229,8 @@ public class LibraryViewerPanel extends FrontendModulePanel } else if (master.getLibraryList ().size () == 0) { - messageLabel.setText ("Sorry, but no results were " - + "found for that term."); + messageLabel.setText (String.format (rb.getString ("ERR_NO_RESULTS"), + searchTerm)); messagePanel.setVisible (true); } else @@ -208,7 +240,7 @@ public class LibraryViewerPanel extends FrontendModulePanel resultsTable.setModel (new LibraryTableModel (master.getLibraryList ())); messagePanel.setVisible (false); - resultsPane.setVisible (true); + resultsPane.setVisible (true); } } }; diff --git a/src/uk/org/ury/library/viewer/library_viewer_gui.xml b/src/uk/org/ury/library/viewer/library_viewer_gui.xml index 5177e3f..ce30a1d 100644 --- a/src/uk/org/ury/library/viewer/library_viewer_gui.xml +++ b/src/uk/org/ury/library/viewer/library_viewer_gui.xml @@ -1,11 +1,11 @@ -