home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 10.0 KB | 340 lines |
- // Cybcerone.java
- // 27.02.96
- //
- // the mother of all applets
-
- import java.applet.Applet;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Frame;
- import java.awt.Event;
-
- import cybcerone.utils.SuperPanel;
- import cybcerone.utils.Scaler;
- import cybcerone.utils.SuperPanels;
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.Literate;
- import cybcerone.utils.Mapable;
- import cybcerone.utils.DataLoader;
- import cybcerone.utils.Date;
-
- import cybcerone.init.InitPanel;
- import cybcerone.main.MainPanel;
- import cybcerone.credit.CreditPanel;
- import cybcerone.orient.PreorientPanel;
- import cybcerone.orient.OrientPanel;
- import cybcerone.person.PersonPanel;
- import cybcerone.faculte.FacultePanel;
- import cybcerone.manif.ManifPanel;
- import cybcerone.unite.UnitePanel;
- import cybcerone.control.ControlPanel;
- import cybcerone.control.UrgencesPanel;
-
- import cybcerone.main.NowPanel;
-
- /**
- * This is the class that implements Cybcerone, an interactive information
- * kiosk. The interface consists of a ControlPanel along the bottom and
- * one SuperPanel showing in the body of the screen. Each SuperPanel
- * provides some functionality, and switching between them can be accomplished
- * via the ControlPanel or often by selecting elements on the current
- * SuperPanel itself. This class merely starts all the SuperPanels and
- * provides a means for them to read images and data, as well as to switch
- * among themselves.
- */
- public class Cybcerone extends Applet implements Runnable, Appletlike {
- public static final String id = "cybcerone";
- public static String imagePath = "images/";
- public static final String dataPath = "data/";
- private static final int fullWidth = 1024;
- private static final int fullHeight = 768;
-
- private static final float scale = (float) (1 /Math.sqrt (2.0));
-
- private SuperPanels panels;
- private SuperPanel currentPanel;
-
- private MediaTracker tracker;
- private Thread imageLoader;
- private int maxPriority = 0;
- private boolean panelsLoaded;
-
- private DataLoader dataLoader;
- private OrientPanel theMapPanel;
- private ControlPanel theControlBar;
- private InitPanel theInitPanel;
-
- /**
- * Read available parameters, set up the SuperPanel's
- * and the control bar.
- */
- public void init () {
- setLayout (null);
- readParameters ();
- resize (Scaler.scale (fullWidth), Scaler.scale (fullHeight));
-
- tracker = new MediaTracker (this);
- dataLoader = new DataLoader (this, this);
-
- add (theControlBar = new ControlPanel (this));
- add (theInitPanel = new InitPanel (this));
- theInitPanel.show ();
- theControlBar.show ();
-
- panels = new SuperPanels ();
- panels.add (new MainPanel (this));
- panels.add (new CreditPanel (this));
- panels.add (new PreorientPanel (this));
- panels.add (new UnitePanel (this));
- panels.add (new PersonPanel (this));
- panels.add (theMapPanel = new OrientPanel (this));
- panels.add (new FacultePanel (this));
- panels.add (new ManifPanel (this));
- panels.add (new UrgencesPanel (this));
- panels.hide ();
- add (panels);
- }
-
- /**
- * Read the parameters from the web page.
- * date - specifies the current day: yyyy:mm:dd
- * preevent - how many minutes before an event is happening now
- * postevent - how many minutes after an event has started should it still
- * - be displayed as happening now
- * scale - all constants in these files are based on a 1024x768 screen
- - that can be reduced (or enlarged) by setting a scaling factor
- * imagepath - the directory to use for images
- */
- private void readParameters () {
- /* of the form yyyy:mm:dd */
- String currentDate = getParameter ("DATE");
- if (currentDate != null && currentDate.length () > 0)
- Date.setCurrent (Integer.parseInt (currentDate.substring (0, 4)),
- Integer.parseInt (currentDate.substring (5, 7)),
- Integer.parseInt (currentDate.substring (8, 10)));
-
- String preEvent = getParameter ("PREEVENT");
- if (preEvent != null && preEvent.length () > 0)
- NowPanel.setFutureOffset (Integer.parseInt (preEvent));
-
-
- String postEvent = getParameter ("POSTEVENT");
- if (postEvent != null && postEvent.length () > 0)
- NowPanel.setPastOffset (Integer.parseInt (postEvent));
-
- String scale = getParameter ("SCALE");
- if (scale != null && scale.length () > 0)
- Scaler.setScale ((Float.valueOf(scale)).floatValue ());
-
- String path = getParameter ("IMAGEPATH");
- if (path != null && path.length () > 0)
- imagePath = path;
- }
-
- /** Optional parameters. */
- public String[][] getParameterInfo() {
- String[][] info = {
- // Parameter Name Kind of Value Description
- {"date", "string", "Set the current date, yyyy:mm:dd"},
- {"preEvent", "int", "Number of minutes ahead for the now panel"},
- {"postEvent", "int", "Number of minutes behind for the now panel"},
- {"scale", "float", "Image (and font) scaling factor"},
- {"imagePath", "string", "Image directory, relative to the html file"},
- };
- return info;
- }
-
- /** Information about this applet. */
- public String getAppletInfo() {
- return ("Cybcerone, v1.0, 1995-1996, Singularis Communication & " +
- "The Computer Science Institute of the " +
- "University of Lausanne, Switzerland");
- }
-
- /**
- * Go to the initialization screen. Start a thread in the background
- * to load the image and data.
- */
- public void start () {
- theInitPanel.show ();
- theInitPanel.start ();
-
- if (imageLoader == null) {
- imageLoader = new Thread (this);
- imageLoader.start ();
- }
- theControlBar.start ();
- }
-
- /**
- * Stop anything going on in the current screen. If we're loading images
- * or data, stop those threads too.
- */
- public void stop () {
- if (currentPanel != null)
- currentPanel.stop ();
- if (imageLoader != null && imageLoader.isAlive ())
- imageLoader.stop ();
- imageLoader = null;
-
- theInitPanel.stop ();
- dataLoader.stop ();
- theControlBar.stop ();
- }
-
- /**
- * Load the images for the initialization screen, then load the images
- * for the rest of the screens. Wait until all the data is done loading
- * before going to the main screen.
- */
- public void run () {
- try {
- initMessage ("Loading image set " + 0 + " of " + maxPriority + "...");
- tracker.waitForID (0);
- dataLoader.start ();
-
- for (int i = 1; i <= maxPriority; i++) {
- initMessage ("Loading image set " + i + " of " + maxPriority + "...");
- tracker.waitForID (i);
- }
- } catch (InterruptedException e) {
- }
- initMessage ("Finished loading images.");
-
- while (!dataLoader.finished ()) {
- try {
- imageLoader.sleep (1000);
- } catch (InterruptedException e) {
- }
- }
-
- theInitPanel.stop ();
- theInitPanel.hide ();
- panels.show ();
- reset ();
- }
-
- /**
- * Handle this object according to its data type. This method is
- * implemented here to comply with the Appletlike interface.
- */
- public void update (Object updateVal) {
- if (updateVal instanceof String) {
- update ((String)updateVal);
- } else if (updateVal instanceof Mapable) {
- update ((Mapable)updateVal);
- } else {
- System.err.println ("Cybcerone: ERROR--updated with " + updateVal);
- }
- }
-
- /**
- * Updated with a String, use it as the ID of the panel to switch to.
- */
- private void update (String newPanelId) {
- theControlBar.update (newPanelId);
- switchTo (newPanelId);
- }
-
- /**
- * Updated with a Mapable object. Switch to the map panel, and display
- * the appropriate information.
- */
- private void update (Mapable selected) {
- theMapPanel.update (selected);
- theControlBar.update (selected);
- switchTo (OrientPanel.id);
- }
-
- /**
- * Switch to the panel with the given ID.
- */
- private void switchTo (String newPanelId) {
- if (currentPanel != null)
- currentPanel.stop ();
- currentPanel = panels.switchTo (newPanelId);
- currentPanel.start ();
- }
-
- /**
- * Load the image with this filename, at priority 0.
- */
- public Image getImage (String filename) {
- return getImage (filename, 0);
- }
-
- /**
- * Load the image with this filename at this priority.
- */
- public Image getImage (String filename, int priority) {
- Image theImage = getImage (getDocumentBase (), imagePath + filename);
-
- tracker.addImage (theImage, priority);
- if (priority > maxPriority) {
- maxPriority = priority;
- }
- return theImage;
- }
-
- /**
- * Load the specified file, use this Literate object to do the reading
- * and create a Vector of Objects, update the requester with that Vector
- * when you're done.
- */
- public void getData (String filename, Literate reader,
- Appletlike requester) {
- dataLoader.getData (dataPath + filename, reader, requester);
- }
-
- /**
- * Same as above, but since no reader has been provided, update
- * the requester with a Vector of Strings.
- */
- public void getData (String filename, Appletlike requester) {
- dataLoader.getData (dataPath + filename, requester);
- }
-
- /**
- * Returns the ID of this panel.
- */
- public String getId () { return id; }
-
- /**
- * If the browser supports it, change the cursor image. Note, this
- * does not work in the appletviewer.
- */
- public void setCursor (int cursorType) {
- if (getParent () instanceof Frame)
- ((Frame)getParent()).setCursor (cursorType);
- }
-
- /**
- * Go back to the main screen and reset all of the other screens.
- */
- public void reset () {
- update (MainPanel.id);
- panels.reset ();
- }
-
- /**
- * Used to send a message to the initialization log on the initialization
- * screen. Has no effect after initialization is complete.
- */
- public void initMessage (String message) {
- theInitPanel.update (message);
- }
-
- /**
- * The current panel receives mouse events but not keyboard events. Is this
- * a bug? In any case, this method ensures that all events are directed
- * to the current panel.
- */
- public boolean handleEvent (Event evt) {
- if (currentPanel != null)
- return currentPanel.handleEvent (evt);
- else
- return true;
- }
-
- }
-