aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/frontend/FrontendFrame.java
diff options
context:
space:
mode:
authorMatt Windsor <matt@deling.(none)>2011-03-18 08:28:09 +0000
committerMatt Windsor <matt@deling.(none)>2011-03-18 08:28:09 +0000
commitd547f87da5f68c12dede7c9d45618cae11ff5699 (patch)
tree613aa95d94b363c72ba9a7be639c74f76edf81f8 /src/uk/org/ury/frontend/FrontendFrame.java
parentc8bb324e757587e742df0824304144e1eb881cee (diff)
Mega-commit to the rescue! Added Javadoc snapshot (admittedly old); show UI now fixed-layout; UI uses system selection colours for accents; now uses bapsserver password and can thus talk to show database relations; removed member relation dependencies until further notice; attempted to get application and applet launchers working but having issues with the latter; started working on a server communicating via a minimal implementation of HTTP 1.1 (standardisation required eventually).
Diffstat (limited to 'src/uk/org/ury/frontend/FrontendFrame.java')
-rw-r--r--src/uk/org/ury/frontend/FrontendFrame.java125
1 files changed, 105 insertions, 20 deletions
diff --git a/src/uk/org/ury/frontend/FrontendFrame.java b/src/uk/org/ury/frontend/FrontendFrame.java
index aabdfbd..39cb89b 100644
--- a/src/uk/org/ury/frontend/FrontendFrame.java
+++ b/src/uk/org/ury/frontend/FrontendFrame.java
@@ -11,6 +11,8 @@ import javax.swing.JFrame;
import javax.swing.UIManager;
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).
@@ -31,11 +33,39 @@ public class FrontendFrame extends JFrame implements FrontendMaster
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 (FrontendModulePanel parent)
+ 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 ()
{
- super (parent.getName ());
-
try
{
// Set System L&F
@@ -43,7 +73,7 @@ public class FrontendFrame extends JFrame implements FrontendMaster
}
catch (UnsupportedLookAndFeelException e)
{
- // handle exception
+ // handle exception
}
catch (ClassNotFoundException e)
{
@@ -60,21 +90,19 @@ public class FrontendFrame extends JFrame implements FrontendMaster
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
- this.child = parent;
-
Container cp = getContentPane ();
// Banner
-
- banner = new FrontendBanner (parent.getName ());
+ System.out.println (child);
+ banner = new FrontendBanner (child.getName ());
// Composition
cp.add (banner, BorderLayout.NORTH);
- cp.add (parent, BorderLayout.CENTER);
+ cp.add (child, BorderLayout.CENTER);
setPreferredSize (new Dimension (800, 600));
- setMinimumSize (new Dimension (800, 600));
+ setMinimumSize (new Dimension (800, 600));
pack ();
setVisible (true);
@@ -89,11 +117,16 @@ public class FrontendFrame extends JFrame implements FrontendMaster
*
* @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;
@@ -103,11 +136,16 @@ public class FrontendFrame extends JFrame implements FrontendMaster
}
catch (ClassNotFoundException e)
{
- FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this);
+ throw new LoadFailureException ("Could not load module: "
+ + e.getMessage ());
}
- if (FrontendModule.class.isAssignableFrom (moduleClass))
+ if (FrontendModule.class.isAssignableFrom (moduleClass) == false)
+ {
+ throw new LoadFailureException ("Could not load module: Not a FrontendModule");
+ }
+ else
{
FrontendModulePanel temp = child;
@@ -117,17 +155,24 @@ public class FrontendFrame extends JFrame implements FrontendMaster
}
catch (InstantiationException e)
{
- FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this);
+ throw new LoadFailureException ("Could not load module: "
+ + e.getMessage ());
}
catch (IllegalAccessException e)
{
- FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this);
+ throw new LoadFailureException ("Could not load module: "
+ + e.getMessage ());
}
- remove (temp);
+ if (temp != null)
+ remove (temp);
+
add (child);
+ child.setMaster (this);
+
+ if (banner != null)
+ banner.setTitle (child.getName ());
- banner.setTitle (child.getName ());
pack ();
}
}
@@ -146,11 +191,16 @@ public class FrontendFrame extends JFrame implements FrontendMaster
* @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);
@@ -172,11 +222,16 @@ public class FrontendFrame extends JFrame implements FrontendMaster
*
* @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;
@@ -186,7 +241,8 @@ public class FrontendFrame extends JFrame implements FrontendMaster
}
catch (ClassNotFoundException e)
{
- FrontendError.reportFatal ("Could not load control panel: " + e.getMessage (), this);
+ throw new LoadFailureException ("Could not load control panel: "
+ + e.getMessage ());
}
@@ -200,11 +256,13 @@ public class FrontendFrame extends JFrame implements FrontendMaster
}
catch (InstantiationException e)
{
- FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this);
+ throw new LoadFailureException ("Could not load control panel: "
+ + e.getMessage ());
}
catch (IllegalAccessException e)
{
- FrontendError.reportFatal ("Could not load module: " + e.getMessage (), this);
+ throw new LoadFailureException ("Could not load control panel: "
+ + e.getMessage ());
}
if (temp != null)
@@ -255,4 +313,31 @@ public class FrontendFrame extends JFrame implements FrontendMaster
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/";
+ }
}