aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/frontend/FrontendFrame.java
diff options
context:
space:
mode:
authorMatt Windsor <mattwindsor@btinternet.com>2011-03-21 21:54:31 +0000
committerMatt Windsor <mattwindsor@btinternet.com>2011-03-21 21:54:31 +0000
commitdf7d7981b56a4560c95ea7e9b194080e93398ecf (patch)
treeb3ae4f02d23ae1f7f4951c776ee8d91b0047dd6f /src/uk/org/ury/frontend/FrontendFrame.java
parent2d073129857a42ab4195cd433c8be152e357033f (diff)
GREAT PACKAGE RESHUFFLE: Everything is now organised into frontend, backend and common (to frontend and backend) packages. Things may have been broken. Doc refresh.
Diffstat (limited to 'src/uk/org/ury/frontend/FrontendFrame.java')
-rw-r--r--src/uk/org/ury/frontend/FrontendFrame.java584
1 files changed, 262 insertions, 322 deletions
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/";
+ }
}