From df7d7981b56a4560c95ea7e9b194080e93398ecf Mon Sep 17 00:00:00 2001 From: Matt Windsor Date: Mon, 21 Mar 2011 21:54:31 +0000 Subject: GREAT PACKAGE RESHUFFLE: Everything is now organised into frontend, backend and common (to frontend and backend) packages. Things may have been broken. Doc refresh. --- src/uk/org/ury/frontend/FrontendApplet.java | 2 +- src/uk/org/ury/frontend/FrontendFrame.java | 584 +++++++++------------ src/uk/org/ury/frontend/FrontendModule.java | 42 +- src/uk/org/ury/frontend/client/Client.java | 60 +++ .../org/ury/frontend/client/test/ClientTest.java | 57 ++ .../frontend/cpanels/menu/DemoControlPanel.java | 47 ++ .../frontend/cpanels/menu/demo_control_panel.xml | 7 + .../frontend/cpanels/show/LibraryControlPanel.java | 48 ++ .../cpanels/show/library_control_panel.xml | 9 + .../modules/library/LibraryTableModel.java | 184 +++++++ .../frontend/modules/library/LibraryViewer.java | 159 ++++++ .../modules/library/LibraryViewer.properties | 22 + .../modules/library/LibraryViewerPanel.java | 219 ++++++++ .../modules/library/library_viewer_gui.xml | 32 ++ src/uk/org/ury/frontend/modules/menu/DemoMenu.java | 64 +++ .../ury/frontend/modules/menu/DemoMenuPanel.java | 68 +++ .../ury/frontend/modules/show/ChannelPanel.java | 84 +++ .../org/ury/frontend/modules/show/ShowViewer.java | 118 +++++ .../ury/frontend/modules/show/ShowViewerPanel.java | 133 +++++ src/uk/org/ury/frontend/modules/show/TrackBin.java | 56 ++ .../ury/frontend/modules/show/channel_panel.xml | 36 ++ .../ury/frontend/modules/show/show_viewer_gui.xml | 43 ++ .../frontend/modules/show/show_viewer_gui_old.xml | 46 ++ .../modules/show/show_viewer_gui_panels.xml | 43 ++ src/uk/org/ury/frontend/modules/show/track_bin.xml | 10 + .../ury/frontend/testrig/ApplicationLauncher.java | 27 + src/uk/org/ury/frontend/testrig/Launcher.java | 17 + 27 files changed, 1870 insertions(+), 347 deletions(-) create mode 100644 src/uk/org/ury/frontend/client/Client.java create mode 100644 src/uk/org/ury/frontend/client/test/ClientTest.java create mode 100644 src/uk/org/ury/frontend/cpanels/menu/DemoControlPanel.java create mode 100644 src/uk/org/ury/frontend/cpanels/menu/demo_control_panel.xml create mode 100644 src/uk/org/ury/frontend/cpanels/show/LibraryControlPanel.java create mode 100644 src/uk/org/ury/frontend/cpanels/show/library_control_panel.xml create mode 100644 src/uk/org/ury/frontend/modules/library/LibraryTableModel.java create mode 100644 src/uk/org/ury/frontend/modules/library/LibraryViewer.java create mode 100644 src/uk/org/ury/frontend/modules/library/LibraryViewer.properties create mode 100644 src/uk/org/ury/frontend/modules/library/LibraryViewerPanel.java create mode 100644 src/uk/org/ury/frontend/modules/library/library_viewer_gui.xml create mode 100644 src/uk/org/ury/frontend/modules/menu/DemoMenu.java create mode 100644 src/uk/org/ury/frontend/modules/menu/DemoMenuPanel.java create mode 100644 src/uk/org/ury/frontend/modules/show/ChannelPanel.java create mode 100644 src/uk/org/ury/frontend/modules/show/ShowViewer.java create mode 100644 src/uk/org/ury/frontend/modules/show/ShowViewerPanel.java create mode 100644 src/uk/org/ury/frontend/modules/show/TrackBin.java create mode 100644 src/uk/org/ury/frontend/modules/show/channel_panel.xml create mode 100644 src/uk/org/ury/frontend/modules/show/show_viewer_gui.xml create mode 100644 src/uk/org/ury/frontend/modules/show/show_viewer_gui_old.xml create mode 100644 src/uk/org/ury/frontend/modules/show/show_viewer_gui_panels.xml create mode 100644 src/uk/org/ury/frontend/modules/show/track_bin.xml create mode 100644 src/uk/org/ury/frontend/testrig/ApplicationLauncher.java create mode 100644 src/uk/org/ury/frontend/testrig/Launcher.java (limited to 'src/uk/org/ury/frontend') diff --git a/src/uk/org/ury/frontend/FrontendApplet.java b/src/uk/org/ury/frontend/FrontendApplet.java index 8e0e229..375a260 100644 --- a/src/uk/org/ury/frontend/FrontendApplet.java +++ b/src/uk/org/ury/frontend/FrontendApplet.java @@ -11,7 +11,7 @@ import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import uk.org.ury.frontend.exceptions.LoadFailureException; -import uk.org.ury.testrig.Launcher; +import uk.org.ury.frontend.testrig.Launcher; /** * A frame that hosts a FrontendModulePanel, used for serving frontend panels in diff --git a/src/uk/org/ury/frontend/FrontendFrame.java b/src/uk/org/ury/frontend/FrontendFrame.java index 1683c9b..24a12cb 100644 --- a/src/uk/org/ury/frontend/FrontendFrame.java +++ b/src/uk/org/ury/frontend/FrontendFrame.java @@ -14,330 +14,270 @@ import javax.swing.UnsupportedLookAndFeelException; import uk.org.ury.frontend.exceptions.LoadFailureException; /** - * A frame that hosts a FrontendModulePanel, used for serving frontend - * panels in a window (application mode). + * A frame that hosts a FrontendModulePanel, used for serving frontend panels in + * a window (application mode). * * @author Matt Windsor - * + * */ -public class FrontendFrame extends JFrame implements FrontendMaster -{ - /** - * - */ - - private static final long serialVersionUID = 740928181256928433L; - - private FrontendBanner banner; - private FrontendModulePanel child; - private FrontendControlPanel cpanel; - - - /** - * Construct a new FrontendFrame given an initial frontend module. - * - * Loading will fail with a fatal error if the class is not found, - * or is not an implementor of FrontendModule. - * - * @param moduleName The fully qualified class-name of the module, - * minus the leading "uk.org.ury." domain. - */ - - public - FrontendFrame (String moduleName) - { - super ("URY newBAPS"); - try - { - loadModule (moduleName); - } - catch (LoadFailureException e) - { - fatalError (e.getMessage ()); - } - } - - - /** - * Set up the user interface of the frame. - */ - - public void - setupUI () - { - try - { - // Set System L&F - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName ()); - } - catch (UnsupportedLookAndFeelException e) - { - // handle exception - } - catch (ClassNotFoundException e) - { - // handle exception - } - catch (InstantiationException e) - { - // handle exception - } - catch (IllegalAccessException e) - { - // handle exception - } - - setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); - - Container cp = getContentPane (); - - // Banner - System.out.println (child); - banner = new FrontendBanner (child.getModuleName ()); - - // Composition - - cp.add (banner, BorderLayout.NORTH); - cp.add (child, BorderLayout.CENTER); - - setPreferredSize (new Dimension (800, 600)); - setMinimumSize (new Dimension (800, 600)); - - pack (); - setVisible (true); - } - - - /** - * Load a module into the frontend frame. - * - * Loading will fail with a fatal error if the class is not found, - * or is not an implementor of FrontendModule. - * - * @param moduleName The fully qualified class-name of the module, - * minus the leading "uk.org.ury." domain. - * - * @throws LoadFailureException if the class is - * not found, or is not an implementor of - * FrontendModule. - */ - - @Override - public void - loadModule (String moduleName) - throws LoadFailureException - { - Class moduleClass = null; - - try - { - moduleClass = Class.forName ("uk.org.ury." + moduleName); - } - catch (ClassNotFoundException e) - { - throw new LoadFailureException ("Could not load module: " - + e.getMessage ()); - } - - - if (FrontendModule.class.isAssignableFrom (moduleClass) == false) - { - throw new LoadFailureException ("Could not load module: Not a FrontendModule"); - } - else - { - FrontendModulePanel temp = child; - - try - { - child = ((FrontendModule) moduleClass.newInstance ()).runFrontend (this); - } - catch (InstantiationException e) - { - throw new LoadFailureException ("Could not load module: " - + e.getMessage ()); - } - catch (IllegalAccessException e) - { - throw new LoadFailureException ("Could not load module: " - + e.getMessage ()); - } - - if (temp != null) - remove (temp); - - add (child); - child.setMaster (this); - - if (banner != null) - banner.setTitle (child.getModuleName ()); - - pack (); - } - } - - - /** - * Load a module into the frontend frame, additionally installing - * a control panel to communicate with the previous module. - * - * Loading will fail with a fatal error if the class is not found, - * or is not an implementor of FrontendModule. - * - * @param moduleName The fully qualified class-name of the module, - * minus the leading "uk.org.ury." domain. - * - * @param cPanelName The fully qualified class-name of the control - * panel to install, minus the leading - * "uk.org.ury." domain. - * - * @throws LoadFailureException if the class is - * not found, or is not an implementor of - * FrontendModule. - */ - - @Override - public void - loadModule (String moduleName, String cPanelName) - throws LoadFailureException - { - FrontendModulePanel newParent = child; - loadModule (moduleName); - FrontendModulePanel newChild = child; - - loadControlPanel (cPanelName, newParent, newChild); - } - - - /** - * Load and install a control panel class given the class name. - * - * @param cPanelName The fully qualified class-name of the control - * panel to load, minus the leading - * "uk.org.ury." domain. - * - * @param parent The parent panel in the relationship modelled - * by the control panel interface. - * - * @param child The child panel in the relationship modelled - * by the control panel interface. - * - * @throws LoadFailureException if the class is - * not found, or is not an implementor of - * FrontendControlPanel. - */ - - private void - loadControlPanel (String cPanelName, FrontendModulePanel parent, - FrontendModulePanel child) - throws LoadFailureException - { - Class cPanelClass = null; - - try - { - cPanelClass = Class.forName ("uk.org.ury." + cPanelName); - } - catch (ClassNotFoundException e) - { - throw new LoadFailureException ("Could not load control panel: " - + e.getMessage ()); - } - - - if (FrontendControlPanel.class.isAssignableFrom (cPanelClass)) - { - FrontendControlPanel temp = cpanel; - - try - { - cpanel = ((FrontendControlPanel) cPanelClass.newInstance ()); - } - catch (InstantiationException e) - { - throw new LoadFailureException ("Could not load control panel: " - + e.getMessage ()); - } - catch (IllegalAccessException e) - { - throw new LoadFailureException ("Could not load control panel: " - + e.getMessage ()); - } - - if (temp != null) - remove (temp); - - cpanel.setPanels (parent, child); - cpanel.setMaster (this); - cpanel.setPreviousCPanel (temp); - - add (cpanel, BorderLayout.SOUTH); - pack (); - } - } - - - /** - * Restore an existing module and control panel into the frontend - * frame. - * - * @param mpanel The module panel to restore. - * - * @param cpanel The control panel to restore, if any. A null - * value signifies a lack of control panel. - * - * @throws IllegalArgumentException if the mpanel is null. - */ - - @Override - public void - restoreModule (FrontendModulePanel mpanel, - FrontendControlPanel cpanel) - { - if (mpanel == null) - throw new IllegalArgumentException ("mpanel is null."); - - remove (child); - remove (this.cpanel); - - child = mpanel; - add (child); - banner.setTitle (child.getModuleName ()); - - if (cpanel != null) - add (cpanel, BorderLayout.SOUTH); - - this.cpanel = cpanel; - - pack (); - repaint (); - } - - - /** - * Report a fatal error, - * - * @param message The message, eg the exception message, to report - * to the user. - */ - - @Override - public void - fatalError (String message) - { - FrontendError.reportFatal (message, this); - } - - - /** - * @return the resource directory. - */ - - @Override - public String - getResourceDirectory () - { - return "res/"; - } +public class FrontendFrame extends JFrame implements FrontendMaster { + /** + * + */ + private static final long serialVersionUID = 740928181256928433L; + + private FrontendBanner banner; + private FrontendModulePanel child; + private FrontendControlPanel cpanel; + + /** + * Construct a new FrontendFrame given an initial frontend module. + * + * Loading will fail with a fatal error if the class is not found, or is not + * an implementor of FrontendModule. + * + * @param moduleName + * The fully qualified class-name of the module, minus the + * leading "uk.org.ury." domain. + */ + public FrontendFrame(String moduleName) { + super("URY newBAPS"); + try { + loadModule(moduleName); + } catch (LoadFailureException e) { + fatalError(e.getMessage()); + } + } + + /** + * Set up the user interface of the frame. + */ + public void setupUI() { + try { + // Set System L&F + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (UnsupportedLookAndFeelException e) { + // handle exception + } catch (ClassNotFoundException e) { + // handle exception + } catch (InstantiationException e) { + // handle exception + } catch (IllegalAccessException e) { + // handle exception + } + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + Container cp = getContentPane(); + + // Banner + System.out.println(child); + banner = new FrontendBanner(child.getModuleName()); + + // Composition + cp.add(banner, BorderLayout.NORTH); + cp.add(child, BorderLayout.CENTER); + + setPreferredSize(new Dimension(800, 600)); + setMinimumSize(new Dimension(800, 600)); + + pack(); + setVisible(true); + } + + /** + * Load a module into the frontend frame. + * + * Loading will fail with a fatal error if the class is not found, or is not + * an implementor of FrontendModule. + * + * @param moduleName + * The fully qualified class-name of the module, minus the + * leading "uk.org.ury." domain. + * + * @throws LoadFailureException + * if the class is not found, or is not an implementor of + * FrontendModule. + */ + @Override + public void loadModule(String moduleName) throws LoadFailureException { + Class moduleClass = null; + + try { + moduleClass = Class.forName("uk.org.ury.frontend.modules." + + moduleName); + } catch (ClassNotFoundException e) { + throw new LoadFailureException("Could not load module: " + + e.getMessage()); + } + + if (FrontendModule.class.isAssignableFrom(moduleClass) == false) { + throw new LoadFailureException( + "Could not load module: Not a FrontendModule"); + } else { + FrontendModulePanel temp = child; + + try { + child = ((FrontendModule) moduleClass.newInstance()) + .runFrontend(this); + } catch (InstantiationException e) { + throw new LoadFailureException("Could not load module: " + + e.getMessage()); + } catch (IllegalAccessException e) { + throw new LoadFailureException("Could not load module: " + + e.getMessage()); + } + + if (temp != null) + remove(temp); + + add(child); + child.setMaster(this); + + if (banner != null) + banner.setTitle(child.getModuleName()); + + pack(); + } + } + + /** + * Load a module into the frontend frame, additionally installing a control + * panel to communicate with the previous module. + * + * Loading will fail with a fatal error if the class is not found, or is not + * an implementor of FrontendModule. + * + * @param moduleName + * The fully qualified class-name of the module, minus the + * leading "uk.org.ury." domain. + * + * @param cPanelName + * The fully qualified class-name of the control panel to + * install, minus the leading "uk.org.ury." domain. + * + * @throws LoadFailureException + * if the class is not found, or is not an implementor of + * FrontendModule. + */ + @Override + public void loadModule(String moduleName, String cPanelName) + throws LoadFailureException { + FrontendModulePanel newParent = child; + loadModule(moduleName); + FrontendModulePanel newChild = child; + + loadControlPanel(cPanelName, newParent, newChild); + } + + /** + * Load and install a control panel class given the class name. + * + * @param cPanelName + * The fully qualified class-name of the control panel to load, + * minus the leading "uk.org.ury." domain. + * + * @param parent + * The parent panel in the relationship modelled by the control + * panel interface. + * + * @param child + * The child panel in the relationship modelled by the control + * panel interface. + * + * @throws LoadFailureException + * if the class is not found, or is not an implementor of + * FrontendControlPanel. + */ + private void loadControlPanel(String cPanelName, + FrontendModulePanel parent, FrontendModulePanel child) + throws LoadFailureException { + Class cPanelClass = null; + + try { + cPanelClass = Class.forName("uk.org.ury.frontend.cpanels." + cPanelName); + } catch (ClassNotFoundException e) { + throw new LoadFailureException("Could not load control panel: " + + e.getMessage()); + } + + if (FrontendControlPanel.class.isAssignableFrom(cPanelClass)) { + FrontendControlPanel temp = cpanel; + + try { + cpanel = ((FrontendControlPanel) cPanelClass.newInstance()); + } catch (InstantiationException e) { + throw new LoadFailureException("Could not load control panel: " + + e.getMessage()); + } catch (IllegalAccessException e) { + throw new LoadFailureException("Could not load control panel: " + + e.getMessage()); + } + + if (temp != null) + remove(temp); + + cpanel.setPanels(parent, child); + cpanel.setMaster(this); + cpanel.setPreviousCPanel(temp); + + add(cpanel, BorderLayout.SOUTH); + pack(); + } + } + + /** + * Restore an existing module and control panel into the frontend frame. + * + * @param mpanel + * The module panel to restore. + * + * @param cpanel + * The control panel to restore, if any. A null value signifies a + * lack of control panel. + * + * @throws IllegalArgumentException + * if the mpanel is null. + */ + @Override + public void restoreModule(FrontendModulePanel mpanel, + FrontendControlPanel cpanel) { + if (mpanel == null) + throw new IllegalArgumentException("mpanel is null."); + + remove(child); + remove(this.cpanel); + + child = mpanel; + add(child); + banner.setTitle(child.getModuleName()); + + if (cpanel != null) + add(cpanel, BorderLayout.SOUTH); + + this.cpanel = cpanel; + + pack(); + repaint(); + } + + /** + * Report a fatal error, + * + * @param message + * The message, eg the exception message, to report to the user. + */ + @Override + public void fatalError(String message) { + FrontendError.reportFatal(message, this); + } + + /** + * @return the resource directory. + */ + @Override + public String getResourceDirectory() { + return "res/"; + } } diff --git a/src/uk/org/ury/frontend/FrontendModule.java b/src/uk/org/ury/frontend/FrontendModule.java index 4d1e3bf..8298ac5 100644 --- a/src/uk/org/ury/frontend/FrontendModule.java +++ b/src/uk/org/ury/frontend/FrontendModule.java @@ -4,38 +4,32 @@ package uk.org.ury.frontend; /** - * Interface for all system modules that are to be reachable from - * the frontend array. + * Interface for all system modules that are to be reachable from the frontend + * array. * * Frontend-exposed modules must: * * - be runnable standalone, as either an application or an applet; * - * - contain their user interface in a subclass of FrontendModulePanel - * which can be embedded either in a FrontendFrame, a web page - * or another module; - * + * - contain their user interface in a subclass of FrontendModulePanel which can + * be embedded either in a FrontendFrame, a web page or another module; + * * - use the frontend error reporting systems. * - * An abstract implementation of this interface, - * AbstractFrontendModule, is provided to simplify the creation of - * frontend modules. + * An abstract implementation of this interface, AbstractFrontendModule, is + * provided to simplify the creation of frontend modules. * * @author Matt Windsor - * + * */ - -public interface FrontendModule -{ - /** - * Begin execution of the frontend module. - * - * @param master The FrontendMaster driving the frontend. - * - * @return the frontend panel to insert into the - * FrontendMaster. - */ - - public FrontendModulePanel - runFrontend (FrontendMaster master); +public interface FrontendModule { + /** + * Begin execution of the frontend module. + * + * @param master + * The FrontendMaster driving the frontend. + * + * @return the frontend panel to insert into the FrontendMaster. + */ + public FrontendModulePanel runFrontend(FrontendMaster master); } diff --git a/src/uk/org/ury/frontend/client/Client.java b/src/uk/org/ury/frontend/client/Client.java new file mode 100644 index 0000000..9606d89 --- /dev/null +++ b/src/uk/org/ury/frontend/client/Client.java @@ -0,0 +1,60 @@ +package uk.org.ury.frontend.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + +import java.util.Map; + +import uk.org.ury.common.protocol.ProtocolUtils; +import uk.org.ury.common.protocol.exceptions.DecodeFailureException; + +public class Client { + /** + * Get a raw response from the server. + * + * @param file + * The "file", including path and query string, to fetch from the + * server. + * + * @return The response from the server, as a key-value map. + * + * @throws DecodeFailureException + * if the decode failed. + */ + public Map get(String file) throws DecodeFailureException { + URL url = null; + URLConnection uc = null; + String result = ""; + + try { + url = new URL("http://localhost:8000" + file); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + try { + uc = url.openConnection(); + + BufferedReader in = new BufferedReader(new InputStreamReader( + uc.getInputStream())); + + String inputLine; + + for (inputLine = in.readLine(); inputLine != null; inputLine = in + .readLine()) { + result += inputLine; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return ProtocolUtils.decode(result); + } +} diff --git a/src/uk/org/ury/frontend/client/test/ClientTest.java b/src/uk/org/ury/frontend/client/test/ClientTest.java new file mode 100644 index 0000000..d75a0ac --- /dev/null +++ b/src/uk/org/ury/frontend/client/test/ClientTest.java @@ -0,0 +1,57 @@ +/** + * + */ +package uk.org.ury.frontend.client.test; + +import java.util.Map; + +import junit.framework.Assert; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import uk.org.ury.common.protocol.Directive; +import uk.org.ury.common.protocol.exceptions.DecodeFailureException; +import uk.org.ury.frontend.client.Client; + +/** + * JUnit test for the low-level client logic. + * + * @author Matt Windsor + */ +public class ClientTest { + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link uk.org.ury.frontend.client.Client#get(java.lang.String)}. + */ + @Test + public void testGet() { + Client client = new Client(); + + Map response = null; + + try { + response = client.get("/server/ServerRequestHandler?function=test"); + } catch (DecodeFailureException e) { + e.printStackTrace(); + } + + Assert.assertEquals("Test succeeded.", + response.get(Directive.INFO.toString())); + } +} diff --git a/src/uk/org/ury/frontend/cpanels/menu/DemoControlPanel.java b/src/uk/org/ury/frontend/cpanels/menu/DemoControlPanel.java new file mode 100644 index 0000000..7ef0907 --- /dev/null +++ b/src/uk/org/ury/frontend/cpanels/menu/DemoControlPanel.java @@ -0,0 +1,47 @@ +package uk.org.ury.frontend.cpanels.menu; + + +import uk.org.ury.frontend.FrontendControlPanel; +import uk.org.ury.frontend.exceptions.UICreationFailureException; + + +/** + * Control panel for the demo system. + * + * @author Matt Windsor + * + */ + +public class DemoControlPanel extends FrontendControlPanel +{ + + /** + * + */ + private static final long serialVersionUID = 7558888612002013312L; + + + /** + * Constructs a new DemoControlPanel. + * + * @throws UICreationFailureException if the UI creation fails. + */ + + public + DemoControlPanel () + throws UICreationFailureException + { + super ("demo_control_panel.xml"); + } + + + /** + * Go back to the previous module. + */ + + public void + back () + { + master.restoreModule (parent, prevCPanel); + } +} diff --git a/src/uk/org/ury/frontend/cpanels/menu/demo_control_panel.xml b/src/uk/org/ury/frontend/cpanels/menu/demo_control_panel.xml new file mode 100644 index 0000000..a9b5329 --- /dev/null +++ b/src/uk/org/ury/frontend/cpanels/menu/demo_control_panel.xml @@ -0,0 +1,7 @@ + + + +