home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ed8n1t2i / statuspanel.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  4.4 KB  |  114 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // StatusPanel.java      v 1.00 b1
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:
  8. // Released in public domain:
  9. //
  10. // ---- Description ----
  11. // Java class containing methods for creating and maintaining a
  12. // Status panel.
  13. //
  14. // This program and the Java source is in the public domain.
  15. // Permission to use, copy, modify, and distribute this software
  16. // and its documentation for NON-COMMERCIAL purposes and
  17. // without fee is hereby granted.
  18. //
  19. //    Copyright 1996
  20. //
  21. //    Iwan van Rienen
  22. //    Joan Maetsuyckerstr. 145
  23. //    2593 ZG  The Hague
  24. //    The Netherlands
  25. //
  26. // I am not responsible for any bugs in this program and
  27. // possible damage to hard- or software when using this program.
  28. //****************************************************************************
  29. import java.applet.Applet;
  30. import java.awt.*;
  31. import java.util.Vector;
  32.  
  33. class StatusPanel extends Panel {
  34.     DigSim applet;
  35.     public static final int STATUSPANEL_HEIGHT = 20;
  36.     protected Font StatusFont;
  37.     protected FontMetrics StatusFontMetrics;
  38.     protected static final Color BackGroundColor = Color.green;
  39.     protected static final Color TextColor = Color.black;
  40.     protected String ActMessage = "Please wait";
  41.     protected static final int STATUSLEDS_WIDTH = 20;
  42.     boolean SimulationInitializeInProgress = false;
  43.     boolean SimulationRunning = false;
  44.     boolean StatusLedOn = false;
  45.  
  46. //----------------------------------------------------------------------------
  47. // The constructor of the status panel
  48. //----------------------------------------------------------------------------
  49.     public StatusPanel(DigSim app) {
  50.         applet = app;
  51.         setLayout( new BorderLayout());
  52.         StatusFont = new Font("TimesRoman",Font.PLAIN,12);
  53.         setFont(StatusFont);
  54.         StatusFontMetrics = getFontMetrics(StatusFont);
  55.         repaint();
  56.     }
  57.  
  58. //----------------------------------------------------------------------------
  59. // Check if the simulation is running
  60. //----------------------------------------------------------------------------
  61.     public boolean SimulateRunning() {
  62.         return (SimulationRunning | SimulationInitializeInProgress);
  63.     }
  64.  
  65. //----------------------------------------------------------------------------
  66. // Calculate the preferred size of this panel
  67. //----------------------------------------------------------------------------
  68.     public Dimension preferredSize() {
  69.         // System.out.println ("StatusPanel preferredSize()");
  70.         int w = applet.size().width;
  71.         int h = STATUSPANEL_HEIGHT;
  72.         return new Dimension(w, h);
  73.     }
  74.  
  75. //----------------------------------------------------------------------------
  76. // Draw the status LED
  77. //----------------------------------------------------------------------------
  78.     public void DrawStatusLED(Graphics g) {
  79.         StatusLedOn = !StatusLedOn;
  80.        int LedX = size().width - STATUSLEDS_WIDTH;
  81.         if (SimulationRunning && StatusLedOn) {
  82.             g.setColor (Color.green);
  83.         } else if (SimulationInitializeInProgress && StatusLedOn) {
  84.             g.setColor (Color.red);
  85.         } else {
  86.             g.setColor (Color.gray);
  87.         }
  88.         g.fillOval (LedX + 3, 3, 15, 15);
  89.     }
  90.  
  91. //----------------------------------------------------------------------------
  92. // Draw the status panel
  93. //----------------------------------------------------------------------------
  94.     public void paint(Graphics g) {
  95.         g.setColor(BackGroundColor);
  96.         g.fillRect(0, 0, size().width - STATUSLEDS_WIDTH, 20);
  97.         g.setColor(TextColor);
  98.         g.drawString(ActMessage, 2, StatusFontMetrics.getHeight() - 2);
  99.         g.setColor(Color.black);
  100.         g.fillRect (size().width - STATUSLEDS_WIDTH, 0, STATUSLEDS_WIDTH, 20);
  101.         g.setColor(BackGroundColor);
  102.         g.drawRect (size().width - STATUSLEDS_WIDTH, 0, STATUSLEDS_WIDTH, 20);
  103.         DrawStatusLED(g);
  104.     }
  105.  
  106. //----------------------------------------------------------------------------
  107. // Display the message
  108. //----------------------------------------------------------------------------
  109.     public void StatusMessage(String msg) {
  110.         ActMessage = msg;
  111.         repaint();
  112.     }
  113.  
  114. }