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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // TextDialog.java       v 1.00 b2
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:           v 1.00b1 01-03-1996
  8. //                            v 1.00b2 07-03-1996 Untrusted windows reshape() bug fixed
  9. // Released in public domain: v 1.00b1 01-03-1996
  10. //
  11. // ---- Description ----
  12. // Java class containing methods for a Text Dialog.
  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.awt.*;
  30.  
  31. class TextDialog extends Dialog {
  32.     DigSimFrame frame;
  33.     String text;
  34.     protected Font TextDialogFont;
  35.     protected FontMetrics TextDialogFontMetrics;
  36.     TextField MyTextField = null;
  37.     Caption ActCaption = null;
  38.     Probe ActProbe = null;
  39.     int DialogID;
  40.  
  41. //----------------------------------------------------------------------------
  42. // The constructor of a new Text Dialog
  43. //----------------------------------------------------------------------------
  44.     TextDialog (DigSimFrame f, String Text, int MyID) {
  45.         super (f, "Enter new text", false);
  46.         frame = f;
  47.         DialogID = MyID;
  48.         text = Text;
  49.         TextDialogFont = new Font("TimesRoman",Font.PLAIN, 14);
  50.         TextDialogFontMetrics = getFontMetrics(TextDialogFont);
  51.         setFont(TextDialogFont);
  52.         setLayout(new BorderLayout());
  53.         add ("North", MyTextField = new TextField(Text)) ;
  54.         Panel control = new Panel () ;
  55.         control.setLayout (new FlowLayout ()) ;
  56.         add ("South", control) ;
  57.         control.add (new Button ("OK"));
  58.         control.add (new Button ("Cancel"));
  59.         reshape (200, 100, 200, 125);
  60.         show();
  61.         reshape (200, 100, 200, 125);
  62.         MyTextField.requestFocus();
  63.     }
  64.  
  65. //----------------------------------------------------------------------------
  66. // The constructor of a new Text Dialog used for changing a caption.
  67. //----------------------------------------------------------------------------
  68.     TextDialog (DigSimFrame f, Caption capt, int MyID) {
  69.         super (f, "Change text", false);
  70.         ActCaption = capt;
  71.         frame = f;
  72.         DialogID = MyID;
  73.         text = capt.Text;
  74.         TextDialogFont = new Font("TimesRoman",Font.PLAIN, 14);
  75.         TextDialogFontMetrics = getFontMetrics(TextDialogFont);
  76.         setFont(TextDialogFont);
  77.         setLayout(new BorderLayout());
  78.         add ("North", MyTextField = new TextField(capt.Text)) ;
  79.         Panel control = new Panel () ;
  80.         control.setLayout (new FlowLayout ()) ;
  81.         add ("South", control) ;
  82.         control.add (new Button ("OK"));
  83.         control.add (new Button ("Cancel"));
  84.         reshape (200, 100, 200, 125);
  85.         show();
  86.         reshape (200, 100, 200, 125);
  87.         MyTextField.requestFocus();
  88.     }
  89.  
  90. //----------------------------------------------------------------------------
  91. // The constructor of a new Text Dialog used for changing an analyzer probe
  92. //----------------------------------------------------------------------------
  93.     TextDialog (DigSimFrame f, Probe probe, int MyID) {
  94.         super (f, "Change probe name", false);
  95.         ActProbe = probe;
  96.         frame = f;
  97.         DialogID = MyID;
  98.         text = probe.IPin[0].getName();
  99.         TextDialogFont = new Font("TimesRoman",Font.PLAIN, 14);
  100.         TextDialogFontMetrics = getFontMetrics(TextDialogFont);
  101.         setFont(TextDialogFont);
  102.         setLayout(new BorderLayout());
  103.         add ("North", MyTextField = new TextField(text)) ;
  104.         Panel control = new Panel () ;
  105.         control.setLayout (new FlowLayout ()) ;
  106.         add ("South", control) ;
  107.         control.add (new Button ("OK"));
  108.         control.add (new Button ("Cancel"));
  109.         reshape (200, 100, 200, 125);
  110.         show();
  111.         reshape (200, 100, 200, 125);
  112.         MyTextField.requestFocus();
  113.     }
  114.  
  115. //----------------------------------------------------------------------------
  116. // Paint this dialog
  117. //----------------------------------------------------------------------------
  118.     public void paint(Graphics g) {
  119.     }
  120.  
  121. //----------------------------------------------------------------------------
  122. // Handle events of this text dialog
  123. //----------------------------------------------------------------------------
  124.     public boolean handleEvent(Event ev) {
  125.         if (ev.id == Event.WINDOW_DESTROY) {
  126.             hide();
  127.             return frame.action (ev, "TEXTDIALOG_Cancel_" + DialogID);
  128.         }
  129.         return super.handleEvent(ev);
  130.     }
  131.  
  132. //----------------------------------------------------------------------------
  133. // Handle actions of this text dialog
  134. //----------------------------------------------------------------------------
  135.     public boolean action(Event ev, Object arg) {
  136.         if (ev.target instanceof TextField) {
  137.                 hide();
  138.                 if (ActCaption != null) {
  139.                     // Change existing text
  140.                     ActCaption.Text = MyTextField.getText();
  141.                     return frame.action (ev, "TEXTDIALOG_Cancel_" + DialogID); // No new text
  142.                 } else if (ActProbe != null) {
  143.                     ActProbe.IPin[0].setName (MyTextField.getText());
  144.                     return frame.action (ev, "TEXTDIALOG_Cancel_" + DialogID); // No new text
  145.                 } else {
  146.                     return frame.action (ev, "TEXTDIALOG_OK_" + MyTextField.getText() + "_" + DialogID);
  147.                 }
  148.         } else if (ev.target instanceof Button) {
  149.             String label = (String)arg;
  150.             if (label.equals("OK")) {
  151.                  hide();
  152.                 if (ActCaption != null) {
  153.                     // Change existing text
  154.                     ActCaption.Text = MyTextField.getText();
  155.                     return frame.action (ev, "TEXTDIALOG_Cancel_" + DialogID); // No new text
  156.                 } else if (ActProbe != null) {
  157.                     ActProbe.IPin[0].setName (MyTextField.getText());
  158.                     return frame.action (ev, "TEXTDIALOG_Cancel_" + DialogID); // No new text
  159.                 } else {
  160.                     return frame.action (ev, "TEXTDIALOG_OK_" + MyTextField.getText() + "_" + DialogID);
  161.                 }
  162.             } else {
  163.                 hide();
  164.                 return frame.action (ev, "TEXTDIALOG_Cancel_" + DialogID);
  165.             }
  166.         }
  167.  
  168.         return false;
  169.     }
  170. }