aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Windsor <mattwindsor@btinternet.com>2011-03-19 13:06:38 +0000
committerMatt Windsor <mattwindsor@btinternet.com>2011-03-19 13:06:38 +0000
commit2efb758e7c2bd85801c76305161d9d8fa6d2be4b (patch)
tree8072dcfb2ed1dd34c17d05488c64b245be74cf28
parentdfde3f3d62ee5de17d09195513711fd006cbf270 (diff)
LibraryViewer: move to ResourceBundled text for localisation and decoupling purposes; warning cleanup; import of json_simple in preparation for JSON protocol implementation.
-rw-r--r--.classpath1
-rw-r--r--lib/json_simple-1.1.jarbin0 -> 16046 bytes
-rw-r--r--src/uk/org/ury/client/test/ClientTest.java3
-rw-r--r--src/uk/org/ury/database/DatabaseItem.java1
-rw-r--r--src/uk/org/ury/frontend/FrontendFrame.java6
-rw-r--r--src/uk/org/ury/frontend/FrontendModulePanel.java2
-rw-r--r--src/uk/org/ury/library/LibraryUtils.java2
-rw-r--r--src/uk/org/ury/library/viewer/LibraryViewer.properties22
-rw-r--r--src/uk/org/ury/library/viewer/LibraryViewerPanel.java82
-rw-r--r--src/uk/org/ury/library/viewer/library_viewer_gui.xml8
-rw-r--r--src/uk/org/ury/server/Server.java3
-rw-r--r--src/uk/org/ury/show/viewer/ShowViewerPanel.java4
-rw-r--r--src/uk/org/ury/testrig/DemoMenuPanel.java2
13 files changed, 92 insertions, 44 deletions
diff --git a/.classpath b/.classpath
index 2a83150..4b16e4c 100644
--- a/.classpath
+++ b/.classpath
@@ -11,6 +11,7 @@
<classpathentry kind="lib" path="lib/httpclient-cache-4.1.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.1.jar"/>
<classpathentry kind="lib" path="lib/httpmime-4.1.jar"/>
+ <classpathentry kind="lib" path="lib/json_simple-1.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/lib/json_simple-1.1.jar b/lib/json_simple-1.1.jar
new file mode 100644
index 0000000..f395f41
--- /dev/null
+++ b/lib/json_simple-1.1.jar
Binary files 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<Boolean, Void> worker = new SwingWorker<Boolean, Void> ()
{
+ 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 @@
<?xml version="1.0" encoding="UTF-8"?>
<panel layout="BorderLayout">
<hbox constraints="BorderLayout.NORTH" border="EmptyBorder(5,5,5,5)">
- <label text="Search for:" labelfor="searchField" displayedmnemonic="VK_F" />
+ <label id="searchForLabel" labelfor="searchField" displayedmnemonic="VK_F" />
<hbox border="EmptyBorder(0,5,0,5)">
<textfield id="searchField" mnemonic="VK_F" action="search" />
</hbox>
- <button id="searchButton" text="Search" mnemonic="VK_S" action="search" />
+ <button id="searchButton" mnemonic="VK_S" action="search" />
</hbox>
<hbox constraints="BorderLayout.CENTER" border="EmptyBorder(0,5,0,5)">
@@ -14,7 +14,7 @@
</scrollpane>
<panel id="searchingPanel" constraints="BorderLayout.CENTER" visible="false"
layout="BorderLayout">
- <label id="searchingLabel" text="Searching..."
+ <label id="searchingLabel"
constraints="BorderLayout.CENTER" horizontalalignment="CENTER" />
<progressbar id="searchingProgressBar" indeterminate="true"
constraints="BorderLayout.SOUTH" />
@@ -27,6 +27,6 @@
</hbox>
<hbox constraints="BorderLayout.SOUTH" border="EmptyBorder(5,5,5,5)">
- <hint text="To narrow your search, type part or all of the record title or artist into the box above." />
+ <hint id="hint" />
</hbox>
</panel>
diff --git a/src/uk/org/ury/server/Server.java b/src/uk/org/ury/server/Server.java
index 6ac192c..5273362 100644
--- a/src/uk/org/ury/server/Server.java
+++ b/src/uk/org/ury/server/Server.java
@@ -21,12 +21,10 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.http.Header;
-import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.ParseException;
-import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.protocol.HTTP;
@@ -55,7 +53,6 @@ public class Server
private ServerSocket serverSocket;
- private static final String HTTP_VERSION = "HTTP/1.1";
private static final String SERVER_VERSION = "SLUT 0.0";
private static final String DOCTYPE =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
diff --git a/src/uk/org/ury/show/viewer/ShowViewerPanel.java b/src/uk/org/ury/show/viewer/ShowViewerPanel.java
index ce1b794..0bc5cd2 100644
--- a/src/uk/org/ury/show/viewer/ShowViewerPanel.java
+++ b/src/uk/org/ury/show/viewer/ShowViewerPanel.java
@@ -101,12 +101,12 @@ public class ShowViewerPanel 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 "Show Viewer Demo";
}
diff --git a/src/uk/org/ury/testrig/DemoMenuPanel.java b/src/uk/org/ury/testrig/DemoMenuPanel.java
index 69cf982..f38a3a0 100644
--- a/src/uk/org/ury/testrig/DemoMenuPanel.java
+++ b/src/uk/org/ury/testrig/DemoMenuPanel.java
@@ -83,7 +83,7 @@ public class DemoMenuPanel extends FrontendModulePanel
@Override
public String
- getName ()
+ getModuleName ()
{
return "Demo Menu";
}