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

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // SimpleDialog.java     v 1.00 b3
  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.00b3 26-03-1996 DialogPanel added
  9. // Released in public domain: v 1.00b1 01-03-1996
  10. //
  11. // ---- Description ----
  12. // Java class containing methods for Simple 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 SimpleDialog extends Frame {
  32.     DigSimFrame frame = null;
  33.     int DialogID;
  34.     String DefaultButton;
  35.     DialogPanel MyDialogPanel = null;
  36.     static final int IMAGE_NONE = 0x00;
  37.     static final int IMAGE_STOP = 0x01;
  38.     static final int IMAGE_WARNING = 0x02;
  39.  
  40. //----------------------------------------------------------------------------
  41. // The constructor of the SimpleDialog class.
  42. //----------------------------------------------------------------------------
  43.     public SimpleDialog(DigSimFrame f, String name, String capt,
  44.                         String DlgButtons[], int NumB, int DefB, int MyID, int ImageID) {
  45.         super (name);
  46.         int width = 0;
  47.  
  48.         DialogID = MyID;
  49.         frame = f;
  50.  
  51.         setLayout(new BorderLayout());
  52.         add("Center", MyDialogPanel = new DialogPanel(f, capt, ImageID));
  53.  
  54.         Panel control = new Panel () ;
  55.         control.setLayout (new FlowLayout ()) ;
  56.         add ("South", control) ;
  57.         for (int ix = 0; ix < NumB; ix++) {
  58.             control.add (new Button (DlgButtons[ix] )) ;
  59.         }
  60.  
  61.         if (MyDialogPanel != null) {
  62.             width = MyDialogPanel.HORIZONTAL_GAP + MyDialogPanel.CaptWidth;
  63.         }
  64.  
  65.         if (width < 200) width = 200;
  66.  
  67.         if (ImageID != 0) width += 50;
  68.         reshape (200, 100, width, 125);
  69.         show();
  70.         reshape (200, 100, width, 125);
  71.  
  72.         repaint();
  73.     }
  74.  
  75. //----------------------------------------------------------------------------
  76. // Paint the Simple Dialog
  77. //----------------------------------------------------------------------------
  78.     public void paint (Graphics g) {
  79.         if (MyDialogPanel != null) {
  80.             MyDialogPanel.repaint();
  81.         }
  82.     }
  83.  
  84. //-----------------------------------------------------------------------------
  85. // Calculate and return the preferred size of the Dialog
  86. //-----------------------------------------------------------------------------
  87.     public Dimension preferredSize() {
  88.        if (MyDialogPanel != null) {
  89.             return MyDialogPanel.preferredSize();
  90.        } else {
  91.            return new Dimension(200, 125);
  92.        }
  93.     }
  94.  
  95. //-----------------------------------------------------------------------------
  96. // handle events of this dialog and send the events to the frame.
  97. //-----------------------------------------------------------------------------
  98.     public boolean handleEvent(Event ev) {
  99.         if (ev.id == Event.WINDOW_DESTROY) {
  100.             hide();
  101.             if (frame != null) {
  102.                 return frame.action (ev, "SIMPLEDIALOG_"+ DefaultButton + "_" + DialogID);
  103.             }
  104.         }
  105.         return super.handleEvent(ev);
  106.     }
  107.  
  108. //-----------------------------------------------------------------------------
  109. // handle actions of this dialog and send the actions to the frame
  110. //-----------------------------------------------------------------------------
  111.     public boolean action(Event ev, Object arg) {
  112.         if (ev.target instanceof Button) {
  113.             String label = (String)arg;
  114.             hide();
  115.             if (frame != null) {
  116.                 return frame.action (ev, "SIMPLEDIALOG_"+ label + "_" + DialogID);
  117.             }
  118.         }
  119.  
  120.         return false;
  121.     }
  122. }