Dialog.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* Dialog.java -- An AWT dialog box
  2. Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.awt;
  32. import java.awt.peer.DialogPeer;
  33. import java.awt.peer.WindowPeer;
  34. import java.awt.peer.ContainerPeer;
  35. import java.awt.peer.ComponentPeer;
  36. /**
  37. * A dialog box widget class.
  38. *
  39. * @author Aaron M. Renn (arenn@urbanophile.com)
  40. * @author Tom Tromey <tromey@redhat.com>
  41. */
  42. public class Dialog extends Window implements java.io.Serializable
  43. {
  44. /*
  45. * Static Variables
  46. */
  47. // Serialization constant
  48. private static final long serialVersionUID = 5920926903803293709L;
  49. /*************************************************************************/
  50. /*
  51. * Instance Variables
  52. */
  53. /**
  54. * @serial Indicates whether or not this dialog box is modal.
  55. */
  56. private boolean modal;
  57. /**
  58. * @serial Indicates whether or not this dialog box is resizable.
  59. */
  60. private boolean resizable;
  61. /**
  62. * @serial The title string for this dialog box, which can be
  63. * <code>null</code>.
  64. */
  65. private String title;
  66. /*************************************************************************/
  67. /*
  68. * Constructors
  69. */
  70. /**
  71. * Initializes a new instance of <code>Dialog</code> with the specified
  72. * parent, that is not resizable and not modal, and which has no title.
  73. *
  74. * @param parent The parent frame of this dialog box.
  75. */
  76. public
  77. Dialog(Frame parent)
  78. {
  79. this(parent, "", false);
  80. }
  81. /*************************************************************************/
  82. /**
  83. * Initializes a new instance of <code>Dialog</code> with the specified
  84. * parent and modality, that is not resizable and which has no title.
  85. *
  86. * @param parent The parent frame of this dialog box.
  87. * @param modal <true> if this dialog box is modal, <code>false</code>
  88. * otherwise.
  89. */
  90. public
  91. Dialog(Frame parent, boolean modal)
  92. {
  93. this(parent, "", modal);
  94. }
  95. /*************************************************************************/
  96. /**
  97. * Initializes a new instance of <code>Dialog</code> with the specified
  98. * parent, that is not resizable and not modal, and which has the specified
  99. * title.
  100. *
  101. * @param parent The parent frame of this dialog box.
  102. * @param title The title string for this dialog box.
  103. */
  104. public
  105. Dialog(Frame parent, String title)
  106. {
  107. this(parent, title, false);
  108. }
  109. /*************************************************************************/
  110. /**
  111. * Initializes a new instance of <code>Dialog</code> with the specified,
  112. * parent, title, and modality, that is not resizable.
  113. *
  114. * @param parent The parent frame of this dialog box.
  115. * @param title The title string for this dialog box.
  116. * @param modal <true> if this dialog box is modal, <code>false</code>
  117. * otherwise.
  118. */
  119. public
  120. Dialog(Frame parent, String title, boolean modal)
  121. {
  122. super(parent);
  123. this.title = title;
  124. this.modal = modal;
  125. resizable = false;
  126. setLayout(new BorderLayout());
  127. }
  128. public
  129. Dialog (Dialog owner)
  130. {
  131. this (owner, "", false);
  132. }
  133. public
  134. Dialog (Dialog owner, String title)
  135. {
  136. this (owner, title, false);
  137. }
  138. public
  139. Dialog (Dialog owner, String title, boolean modal)
  140. {
  141. super (owner);
  142. this.modal = modal;
  143. this.title = title;
  144. setLayout (new BorderLayout ());
  145. }
  146. /*************************************************************************/
  147. /*
  148. * Instance Variables
  149. */
  150. /**
  151. * Returns the title of this dialog box.
  152. *
  153. * @return The title of this dialog box.
  154. */
  155. public String
  156. getTitle()
  157. {
  158. return(title);
  159. }
  160. /*************************************************************************/
  161. /**
  162. * Sets the title of this dialog box to the specified string.
  163. *
  164. * @param title The new title.
  165. */
  166. public synchronized void
  167. setTitle(String title)
  168. {
  169. this.title = title;
  170. if (peer != null)
  171. {
  172. DialogPeer d = (DialogPeer) peer;
  173. d.setTitle (title);
  174. }
  175. }
  176. /*************************************************************************/
  177. /**
  178. * Tests whether or not this dialog box is modal.
  179. *
  180. * @return <code>true</code> if this dialog box is modal,
  181. * <code>false</code> otherwise.
  182. */
  183. public boolean
  184. isModal()
  185. {
  186. return(modal);
  187. }
  188. /*************************************************************************/
  189. /**
  190. * Changes the modality of this dialog box. This can only be done before
  191. * the peer is created.
  192. *
  193. * @param modal <code>true</code> to make this dialog box modal,
  194. * <code>false</code> to make it non-modal.
  195. */
  196. public void
  197. setModal(boolean modal)
  198. {
  199. this.modal = modal;
  200. }
  201. /*************************************************************************/
  202. /**
  203. * Tests whether or not this dialog box is resizable.
  204. *
  205. * @return <code>true</code> if this dialog is resizable, <code>false</code>,
  206. * otherwise.
  207. */
  208. public boolean
  209. isResizable()
  210. {
  211. return(resizable);
  212. }
  213. /*************************************************************************/
  214. /**
  215. * Changes the resizability of this dialog box.
  216. *
  217. * @param resizable <code>true</code> to make this dialog resizable,
  218. * <code>false</code> to make it non-resizable.
  219. */
  220. public synchronized void
  221. setResizable(boolean resizable)
  222. {
  223. this.resizable = resizable;
  224. if (peer != null)
  225. {
  226. DialogPeer d = (DialogPeer) peer;
  227. d.setResizable (resizable);
  228. }
  229. }
  230. /*************************************************************************/
  231. /**
  232. * Creates this object's native peer.
  233. */
  234. public synchronized void
  235. addNotify()
  236. {
  237. if (peer == null)
  238. peer = getToolkit ().createDialog (this);
  239. super.addNotify ();
  240. }
  241. /*************************************************************************/
  242. /**
  243. * Makes this dialog visible and brings it to the front.
  244. */
  245. public void
  246. show()
  247. {
  248. super.show();
  249. }
  250. /*************************************************************************/
  251. /**
  252. * Returns a debugging string for this component.
  253. *
  254. * @return A debugging string for this component.
  255. */
  256. protected String
  257. paramString()
  258. {
  259. return ("title+" + title + ",modal=" + modal +
  260. ",resizable=" + resizable + "," + super.paramString());
  261. }
  262. } // class Dialog