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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // HelpDialog.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 a Help Dialog.
  12. //
  13. // This program and the Java source is in the public domain.
  14. // Permission to use, copy, modify, and distribute this software
  15. // and its documentation for NON-COMMERCIAL purposes and
  16. // without fee is hereby granted.
  17. //
  18. //    Copyright 1996
  19. //
  20. //    Iwan van Rienen
  21. //    Joan Maetsuyckerstr. 145
  22. //    2593 ZG  The Hague
  23. //    The Netherlands
  24. //
  25. // I am not responsible for any bugs in this program and
  26. // possible damage to hard- or software when using this program.
  27. //****************************************************************************
  28. import java.awt.*;
  29. import java.lang.InterruptedException;
  30. import java.io.StreamTokenizer;
  31. import java.io.InputStream;
  32. import java.io.PrintStream;
  33. import java.io.DataInputStream;
  34. import java.io.IOException;
  35. import java.net.URL;
  36.  
  37. class HelpDialog extends Dialog {
  38.     protected Font HelpDialogFont;
  39.     protected FontMetrics HelpDialogFontMetrics;
  40.     String Capt;
  41.     int CaptWidth;
  42.     DigSimFrame frame;
  43.     TextArea HelpTextArea;
  44.  
  45. //----------------------------------------------------------------------------
  46. // The constructor of the Help Dialog.
  47. //----------------------------------------------------------------------------
  48.     public HelpDialog(DigSimFrame f, String HelpFileName) {
  49.         super (f, "Help: " + HelpFileName, false);
  50.         String FileName;
  51.         frame = f;
  52.         f.applet.UserWantsPointer();
  53.         FileName = HelpFileName.replace(' ', '_');
  54.         FileName = FileName.replace('-', '_');
  55.         HelpDialogFont = new Font("TimesRoman",Font.PLAIN, 14);
  56.         HelpDialogFontMetrics = getFontMetrics(HelpDialogFont);
  57.         setFont(HelpDialogFont);
  58.         add ("North", (HelpTextArea = new TextArea ("Please wait, reading help file", 10, 40)));
  59.         HelpTextArea.setEditable (false);
  60.         Panel control = new Panel () ;
  61.         control.setLayout (new FlowLayout ()) ;
  62.         add ("South", control) ;
  63.         control.add (new Button ("OK")) ;
  64.         reshape (200, 100, 400, 250);
  65.  
  66.         while (frame.applet.TextFileRequested != null) {
  67.             // File loading in progress for another process.
  68.             // wait a while.
  69.             // System.out.println ("waiting on other process...");
  70.             try {
  71.                 Thread.currentThread().sleep (250);
  72.             } catch(Exception e) { }
  73.         }
  74.  
  75.         // System.out.println ("Request TextFile");
  76.         frame.applet.RequestedTextFileRead = false;
  77.         frame.applet.RequestedTextFileError = false;
  78.         frame.applet.TextFileRequested = "help/" + FileName + ".help";
  79.         show();
  80.         do {
  81.             // System.out.println ("waiting on data...");
  82.             try {
  83.                 Thread.currentThread().sleep (250);
  84.             } catch(Exception e) { }
  85.         } while (!frame.applet.RequestedTextFileRead && !frame.applet.RequestedTextFileError);
  86.  
  87.         HelpTextArea.setText (frame.applet.RequestedText);
  88.         frame.applet.TextFileRequested = null;
  89.     }
  90.  
  91. //----------------------------------------------------------------------------
  92. // paint the help dialog
  93. //----------------------------------------------------------------------------
  94.     public void paint(Graphics g) {
  95.     }
  96.  
  97. //----------------------------------------------------------------------------
  98. // handle the events of this dialog
  99. //----------------------------------------------------------------------------
  100.     public boolean handleEvent(Event ev) {
  101.         if (ev.id == Event.WINDOW_DESTROY) {
  102.             hide();
  103.             return true;
  104.         }
  105.         return super.handleEvent(ev);
  106.     }
  107.  
  108. //----------------------------------------------------------------------------
  109. // handle the actions of this dialog
  110. //----------------------------------------------------------------------------
  111.     public boolean action(Event ev, Object arg) {
  112.         if (ev.target instanceof Button) {
  113.             hide();
  114.             return true;
  115.         }
  116.  
  117.         return false;
  118.     }
  119.  
  120. }