From 9b4647f1ae8c3f41163d0d4053504dab861d0c94 Mon Sep 17 00:00:00 2001 From: Matt Windsor Date: Mon, 7 Mar 2011 13:50:24 +0000 Subject: Emergency impending hard drive failure dump - lots of changes on the frontend, but they're all potentially controversial so I'm not pushing to master yet. Beginnings of show viewer. Application now run through demo menu, which allows for the links between modules to be tested. --- src/uk/org/ury/frontend/FrontendFrame.java | 205 ++++++++++++++++++++++++++--- 1 file changed, 184 insertions(+), 21 deletions(-) (limited to 'src/uk/org/ury/frontend/FrontendFrame.java') diff --git a/src/uk/org/ury/frontend/FrontendFrame.java b/src/uk/org/ury/frontend/FrontendFrame.java index 6324512..ef2a31a 100644 --- a/src/uk/org/ury/frontend/FrontendFrame.java +++ b/src/uk/org/ury/frontend/FrontendFrame.java @@ -4,26 +4,20 @@ 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; -import javax.swing.ImageIcon; import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; /** - * A frame that hosts a FrontendPanel, used for serving frontend + * A frame that hosts a FrontendModulePanel, used for serving frontend * panels in a window (application mode). * * @author Matt Windsor * */ -public class FrontendFrame extends JFrame +public class FrontendFrame extends JFrame implements FrontendMaster { /** * @@ -31,31 +25,24 @@ public class FrontendFrame extends JFrame private static final long serialVersionUID = 740928181256928433L; - private FrontendPanel parent; + private FrontendBanner banner; + private FrontendModulePanel child; + private FrontendControlPanel cpanel; public - FrontendFrame (FrontendPanel parent) + FrontendFrame (FrontendModulePanel parent) { super (parent.getName ()); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); - this.parent = parent; + this.child = parent; Container cp = getContentPane (); // Banner - JPanel banner = new JPanel (); - JLabel bannerLabel = new JLabel ("

" - + parent.getName () + "

"); - - bannerLabel.setBorder (BorderFactory.createEmptyBorder (5, 15, 5, 5)); - - banner.setLayout (new FlowLayout (FlowLayout.LEFT)); - banner.setBackground (new Color (0, 0, 0)); - banner.add (new JLabel (new ImageIcon (getClass ().getResource ("images/ury.png")))); - banner.add (bannerLabel); + banner = new FrontendBanner (parent.getName ()); // Composition @@ -67,4 +54,180 @@ public class FrontendFrame extends JFrame 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. + */ + + @Override + public void + loadModule (String moduleName) + { + Class moduleClass = null; + + try + { + moduleClass = Class.forName ("uk.org.ury." + moduleName); + } + catch (ClassNotFoundException e) + { + FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this); + } + + + if (FrontendModule.class.isAssignableFrom (moduleClass)) + { + FrontendModulePanel temp = child; + + try + { + child = ((FrontendModule) moduleClass.newInstance ()).runFrontend (this); + } + catch (InstantiationException e) + { + FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this); + } + catch (IllegalAccessException e) + { + FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this); + } + + remove (temp); + add (child); + + banner.setTitle (child.getName ()); + 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. + */ + + @Override + public void + loadModule (String moduleName, String cPanelName) + { + 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. + */ + + private void + loadControlPanel (String cPanelName, FrontendModulePanel parent, + FrontendModulePanel child) + { + Class cPanelClass = null; + + try + { + cPanelClass = Class.forName ("uk.org.ury." + cPanelName); + } + catch (ClassNotFoundException e) + { + FrontendError.reportFatal ("Could not load control panel: " + e.getMessage (), this); + } + + + if (FrontendControlPanel.class.isAssignableFrom (cPanelClass)) + { + FrontendControlPanel temp = cpanel; + + try + { + cpanel = ((FrontendControlPanel) cPanelClass.newInstance ()); + } + catch (InstantiationException e) + { + FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this); + } + catch (IllegalAccessException e) + { + FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this); + } + + 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.getName ()); + + if (cpanel != null) + add (cpanel, BorderLayout.SOUTH); + + this.cpanel = cpanel; + + pack (); + repaint (); + } } -- cgit v1.2.3