home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 4.3 KB | 184 lines |
- // NowPanel.java
- // 20.03.96
- //
- // events that are happening now
-
- package cybcerone.main;
-
- import java.awt.Rectangle;
- import java.awt.Image;
- import java.util.Enumeration;
-
- import cybcerone.utils.Date;
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.Manif;
-
- /**
- * Events that are happening now, up to 3 at a time. If there's
- * more than that, they scroll.
- */
- public class NowPanel extends HappeningPanel implements Runnable {
- private static final Rectangle placement = new Rectangle (0, 433, 768, 150);
-
- private static final String id = "NowPanel";
- private static String statusText = "Events happening now";
-
- private static final String bgFile = imagePath + "nowBg.gif";
- private static final String panelsBgBase = imagePath + "nowBg";
- private static final int totalPanels = 3;
-
- private NowEventPanel panels[];
-
- private Thread scroller;
- private NowBlinkThread blinker;
- private NowUpdateThread updater;
-
- private Enumeration eventList;
- private int activePanels;
-
- private static int pastOffset = 11;
- private static int futureOffset = 21;
-
- NowPanel (Image ledsOn, Image ledsOff, Appletlike app) {
- super (id, statusText, app);
- reshape (placement);
-
- if (!Date.realDate ()) {
- statusText += " (demonstration)";
- setStatusText (statusText);
- }
-
- setBackground (bgFile, 0);
- panels = new NowEventPanel[totalPanels];
-
- for (int i = 0; i < totalPanels; i++) {
- add (panels[i] = new NowEventPanel (id, statusText, ledsOn,
- ledsOff, app));
- panels[i].reshape (0, scale (37 + (35 * i)), scale (768), scale (26));
- panels[i].setTitleBg (panelsBgBase + (i + 1) + ".gif");
- }
-
- activePanels = 0;
- hide ();
- }
-
- int getActivePanels () { return activePanels; }
- NowEventPanel[] getPanels () { return panels; }
-
- /** Remove the topmost event */
- void popEvent () {
- int i;
-
- if (activePanels > 0) {
- for (i = 0; i < activePanels - 1; i++)
- panels[i].copyFrom (panels[i+1]);
- panels[i].setManif (null);
- if (--activePanels == 0)
- hide ();
- }
- }
-
- public static void setPastOffset (int offset) {
- pastOffset = offset;
- }
-
- public static void setFutureOffset (int offset) {
- futureOffset = offset;
- }
-
- /** Add an event to the bottom */
- void pushEvent () {
- if (getTheEvents () != null && getTheEvents().size () > 0) {
- if (eventList == null || !eventList.hasMoreElements ())
- eventList = getTheEvents().elements ();
-
- panels[activePanels++].setManif ((Manif)eventList.nextElement ());
- show ();
- }
- }
-
- /** Take an event off the top and add a new one to the bottom */
- void cycle () {
- int i;
-
- if (activePanels > 0) {
- for (i = 0; i < activePanels - 1; i++)
- panels[i].copyFrom (panels[i+1]);
-
- if (!eventList.hasMoreElements ())
- eventList = getTheEvents().elements ();
-
- panels[i].setManif ((Manif) eventList.nextElement ());
- }
- }
-
- protected Date pastDate (Date now) {
- return (new Date (now.getYear (), now.getMonth (), now.getDate (),
- now.getHours (), now.getMinutes () - pastOffset));
- }
-
- protected Date futureDate (Date now) {
- return (new Date (now.getYear (), now.getMonth (), now.getDate (),
- now.getHours (), now.getMinutes () + futureOffset));
- }
-
- public void update () {
- super.update ();
- updatePanels ();
- }
-
- public void updatePanels () {
- int size = getTheEvents().size ();
-
- while (activePanels > size)
- popEvent ();
- while (activePanels < size && activePanels < totalPanels)
- pushEvent ();
- }
-
- public void start () {
- super.start ();
- if (getTheEvents () != null && getTheEvents().size () > 0) {
- if (scroller == null) {
- scroller = new Thread (this);
- scroller.start ();
- }
- if (blinker == null) {
- blinker = new NowBlinkThread (this);
- blinker.start ();
- }
- if (updater == null) {
- updater = new NowUpdateThread (this);
- updater.start ();
- }
- }
- }
-
- public void stop () {
- super.stop ();
- if (scroller != null)
- scroller.stop ();
- scroller = null;
- if (blinker != null)
- blinker.stop ();
- blinker = null;
- if (updater != null)
- updater.stop ();
- updater = null;
- }
-
- public void run () {
- while (scroller != null) {
- repaint ();
-
- try {
- scroller.sleep (25000);
- } catch (InterruptedException e) {
- }
-
- cycle ();
-
- }
- }
- }
-