home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.3 KB | 146 lines |
- // NowEventPanel.java
- // 26.03.96
- //
- // one of the events on the NowPanel
-
- package cybcerone.main;
-
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Color;
-
- import cybcerone.utils.Date;
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.IdPanel;
- import cybcerone.utils.ScrollingPanel;
- import cybcerone.utils.Manif;
- import cybcerone.utils.Fonts;
-
- /**
- * The sub-subpanel for events that are happening now.
- */
- class NowEventPanel extends IdPanel {
- private Image ledsOn, ledsOff;
- private String time, faculte;
-
- private ScrollingPanel titlePanel;
- private boolean lightsOn;
-
- /* for double buffering */
- private Image offscreenImg;
- private Graphics offscreenG;
-
- private static Color gray = new Color (190, 190, 190);
-
- NowEventPanel (String id, String statusText, Image ledsOn, Image ledsOff,
- Appletlike app) {
- super (id, statusText, app);
-
- this.ledsOn = ledsOn;
- this.ledsOff = ledsOff;
-
- add (titlePanel = new ScrollingPanel (id, statusText, app));
- titlePanel.reshape (scale (246), 0, scale (522), scale (26));
- titlePanel.setFont (Fonts.smallFont);
- titlePanel.setColor (gray);
-
- hide ();
- }
-
- public boolean isValid () {
- return (faculte != null);
- }
-
- public void setTitleBg (String titleBgFile) {
- titlePanel.setBackground (titleBgFile, 2);
- }
-
- public void setManif (Manif theManif) {
- if (theManif != null) {
- titlePanel.setText (theManif.getTitle ());
- titlePanel.setNext (theManif);
-
- setTime (theManif);
- setFaculte (theManif);
-
- show ();
- repaint ();
- } else {
- hide ();
- faculte = null;
- }
- }
-
- /* makes this a copy of other */
- public void copyFrom (NowEventPanel other) {
- titlePanel.setText (other.titlePanel);
- time = other.time;
- faculte = other.faculte;
- }
-
- private void setTime (Manif theManif) {
- Date when = theManif.getDateAndTime ();
- if (when != null) {
- String minutes = String.valueOf (when.getMinutes ());
- if (minutes.length () < 2)
- minutes = "0" + minutes;
- String hours = String.valueOf (when.getHours ());
- if (hours.length () < 2)
- hours = " " + hours;
- time = hours + "H" + minutes;
- } else {
- time = "";
- }
- }
-
- private void setFaculte (Manif theManif) {
- faculte = theManif.getFaculte ();
- }
-
- public void stop () {
- super.stop ();
- if (isShowing ())
- turnLightsOff ();
- }
-
- public void turnLightsOn () {
- lightsOn = true;
- repaint ();
- }
-
- public void turnLightsOff () {
- lightsOn = false;
- repaint ();
- }
-
- public void paint (Graphics g) {
- if (lightsOn)
- g.drawImage (ledsOn, 0, 0, this);
- else
- g.drawImage (ledsOff, 0, 0, this);
-
- g.setFont (Fonts.smallFont);
-
- if (time != null && faculte != null) {
- g.setColor (gray);
- g.drawString (time, scale (86), scale (23));
-
- g.setColor (Color.white);
- g.drawString (faculte, scale (149), scale (23));
- }
- }
-
- public void update (Graphics g) {
- // for double buffering;
- if (offscreenG == null) {
- offscreenImg = createImage (size().width, size().height);
- offscreenG = offscreenImg.getGraphics ();
- }
-
- offscreenG.setColor (getBackground ());
- offscreenG.fillRect (0, 0, size().width, size().height);
- paint (offscreenG);
- g.drawImage (offscreenImg, 0, 0, this);
- }
- }
-