home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / Dialog.java < prev    next >
Text File  |  1996-05-03  |  4KB  |  142 lines

  1. /*
  2.  * @(#)Dialog.java    1.15 96/04/22 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. import java.awt.peer.DialogPeer;
  22.  
  23. /**
  24.  * A class that produces a dialog - a window that takes input from the user.
  25.  * The default layout for a dialog is BorderLayout.
  26.  *
  27.  * @version     1.15, 22 Apr 1996
  28.  * @author     Sami Shaio
  29.  * @author     Arthur van Hoff
  30.  */
  31. public class Dialog extends Window {
  32.     boolean    resizable = true;
  33.  
  34.     /**
  35.      * Sets to true if the Dialog is modal.  A modal
  36.      * Dialog grabs all the input from the user.
  37.      */
  38.     boolean modal;
  39.  
  40.     /**
  41.      * The title of the Dialog.
  42.      */
  43.     String title;
  44.  
  45.     /**
  46.      * Constructs an initially invisible Dialog. A modal
  47.      * Dialog grabs all the input from the user.
  48.      * @param parent the owner of the dialog
  49.      * @param modal if true, dialog blocks input to other windows when shown
  50.      * @see Component#resize
  51.      * @see Component#show
  52.      */
  53.     public Dialog(Frame parent, boolean modal) {
  54.     super(parent);
  55.     this.modal = modal;
  56.     }
  57.  
  58.     /**
  59.      * Constructs an initially invisible Dialog with a title. 
  60.      * A modal Dialog grabs all the input from the user.
  61.      * @param parent the owner of the dialog
  62.      * @param title the title of the dialog
  63.      * @param modal if true, dialog blocks input to other windows when shown
  64.      * @see Component#resize
  65.      * @see Component#show
  66.      */
  67.     public Dialog(Frame parent, String title, boolean modal) {
  68.     this(parent, modal);
  69.     this.title = title;
  70.     }
  71.  
  72.     /**
  73.      * Creates the frame's peer.  The peer allows us to change the appearance
  74.      * of the frame without changing its functionality.
  75.      */
  76.     public synchronized void addNotify() {
  77.     if (peer == null) {
  78.         peer = getToolkit().createDialog(this);
  79.     }
  80.     super.addNotify();
  81.     }
  82.  
  83.     /**
  84.      * Returns true if the Dialog is modal.  A modal
  85.      * Dialog grabs all the input from the user.
  86.      */
  87.     public boolean isModal() {
  88.     return modal;
  89.     }
  90.  
  91.     /**
  92.      * Gets the title of the Dialog.
  93.      * @see #setTitle
  94.      */
  95.     public String getTitle() {
  96.     return title;
  97.     }
  98.  
  99.     /**
  100.      * Sets the title of the Dialog.
  101.      * @param title the new title being given to the Dialog
  102.      * @see #getTitle
  103.      */
  104.     public void setTitle(String title) {
  105.     this.title = title;
  106.     DialogPeer peer = (DialogPeer)this.peer;
  107.     if (peer != null) {
  108.         peer.setTitle(title);
  109.     }
  110.     }
  111.  
  112.     /**
  113.      * Returns true if the user can resize the frame.
  114.      */
  115.     public boolean isResizable() {
  116.     return resizable;
  117.     }
  118.  
  119.     /**
  120.      * Sets the resizable flag.
  121.      * @param resizable true if resizable; false otherwise
  122.      */
  123.     public void setResizable(boolean resizable) {
  124.     this.resizable = resizable;
  125.     DialogPeer peer = (DialogPeer)this.peer;
  126.     if (peer != null) {
  127.         peer.setResizable(resizable);
  128.     }
  129.     }
  130.  
  131.     /**
  132.      * Returns the parameter String of this Dialog.
  133.      */
  134.     protected String paramString() {
  135.     String str = super.paramString() + (modal ? ",modal" : ",modeless");
  136.     if (title != null) {
  137.         str += ",title=" + title;
  138.     }
  139.     return str;
  140.     }
  141. }
  142.