home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Java++ / VJ / SAMPLES / JAVANOW / CHAP17 / DIALOGWINDOW / AUTODIALOG.JAVA < prev    next >
Encoding:
Java Source  |  1996-06-13  |  3.3 KB  |  110 lines

  1. //------------------------------------------------------------------------------
  2. // AutoDialog.java:
  3. //        Implementation for container control initialization class AutoDialog
  4. //
  5. //------------------------------------------------------------------------------
  6. import java.awt.*;
  7. import DialogLayout;
  8.  
  9. public class AutoDialog
  10. {
  11.     Container    m_Parent       = null;
  12.     boolean      m_fInitialized = false;
  13.     DialogLayout m_Layout;
  14.  
  15.     // Control definitions
  16.     //--------------------------------------------------------------------------
  17.     Button        IDOK;
  18.     Button        IDCANCEL;
  19.     TextField     IDC_EDIT1;
  20.     TextField     IDC_EDIT2;
  21.     Label         IDC_STATIC1;
  22.     Label         IDC_STATIC2;
  23.     Checkbox      IDC_CHECK1;
  24.  
  25.  
  26.     // Constructor
  27.     //--------------------------------------------------------------------------
  28.     public AutoDialog (Container parent)
  29.     {
  30.         m_Parent = parent;
  31.     }
  32.  
  33.     // Initialization.
  34.     //--------------------------------------------------------------------------
  35.     public boolean CreateControls()
  36.     {
  37.         // Can only init controls once
  38.         //----------------------------------------------------------------------
  39.         if (m_fInitialized || m_Parent == null)
  40.             return false;
  41.  
  42.         // Parent must be a derivation of the Container class
  43.         //----------------------------------------------------------------------
  44.         if (!(m_Parent instanceof Container))
  45.             return false;
  46.  
  47.         // Since there is no way to know if a given font is supported from
  48.         // platform to platform, we only change the size of the font, and not
  49.         // type face name.  And, we only change the font if the dialog resource
  50.         // specified a font.
  51.         //----------------------------------------------------------------------
  52.         if (true)
  53.         {
  54.             Font OldFnt = m_Parent.getFont();
  55.             if (OldFnt != null)
  56.             {
  57.                 Font NewFnt = new Font(OldFnt.getName(), OldFnt.getStyle(), 14);
  58.  
  59.                 m_Parent.setFont(NewFnt);
  60.             }
  61.         }
  62.  
  63.         // All position and sizes are in Dialog Units, so, we use the 
  64.         // DialogLayout manager.
  65.         //----------------------------------------------------------------------
  66.         m_Layout = new DialogLayout(m_Parent, 186, 79);
  67.         m_Parent.setLayout(m_Layout);
  68.         m_Parent.addNotify();
  69.  
  70.         Dimension size   = m_Layout.getDialogSize();
  71.         Insets    insets = m_Parent.insets();
  72.         
  73.         m_Parent.resize(insets.left + size.width  + insets.right,
  74.                         insets.top  + size.height + insets.bottom);
  75.  
  76.         // Control creation
  77.         //----------------------------------------------------------------------
  78.         IDOK = new Button ("OK");
  79.         m_Parent.add(IDOK);
  80.         m_Layout.setShape(IDOK, 129, 7, 50, 14);
  81.  
  82.         IDCANCEL = new Button ("Cancel");
  83.         m_Parent.add(IDCANCEL);
  84.         m_Layout.setShape(IDCANCEL, 129, 24, 50, 14);
  85.  
  86.         IDC_EDIT1 = new TextField ("");
  87.         m_Parent.add(IDC_EDIT1);
  88.         m_Layout.setShape(IDC_EDIT1, 58, 13, 62, 14);
  89.  
  90.         IDC_EDIT2 = new TextField ("");
  91.         m_Parent.add(IDC_EDIT2);
  92.         m_Layout.setShape(IDC_EDIT2, 58, 35, 62, 14);
  93.  
  94.         IDC_STATIC1 = new Label ("First Name:", Label.LEFT);
  95.         m_Parent.add(IDC_STATIC1);
  96.         m_Layout.setShape(IDC_STATIC1, 13, 13, 41, 8);
  97.  
  98.         IDC_STATIC2 = new Label ("Last Name:", Label.LEFT);
  99.         m_Parent.add(IDC_STATIC2);
  100.         m_Layout.setShape(IDC_STATIC2, 13, 37, 40, 8);
  101.  
  102.         IDC_CHECK1 = new Checkbox ("Married");
  103.         m_Parent.add(IDC_CHECK1);
  104.         m_Layout.setShape(IDC_CHECK1, 59, 55, 39, 10);
  105.  
  106.         m_fInitialized = true;
  107.         return true;
  108.     }
  109. }
  110.