001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: KQuestionDialog.java,v $ 023 Revision 1.13 2004/05/05 23:20:24 markl 024 comment block updates 025 026 Revision 1.12 2004/03/16 06:43:39 markl 027 LocaleManager method change 028 029 Revision 1.11 2004/01/23 00:06:28 markl 030 javadoc corrections 031 032 Revision 1.10 2003/01/19 09:38:51 markl 033 Added new constructors that take a parent dialog. 034 035 Revision 1.9 2001/09/26 07:05:36 markl 036 Version fixes, email address fixes. 037 038 Revision 1.8 2001/03/20 00:54:55 markl 039 Fixed deprecated calls. 040 041 Revision 1.7 2001/03/12 09:56:55 markl 042 KLabel/KLabelArea changes. 043 044 Revision 1.6 2001/03/12 05:19:59 markl 045 Source code cleanup. 046 047 Revision 1.5 1999/07/19 04:10:44 markl 048 Recoded to use KLabel to allow multi-line messages. 049 050 Revision 1.4 1999/06/21 06:55:57 markl 051 Added yes/no dialog support. 052 053 Revision 1.3 1999/04/19 06:06:16 markl 054 I18N changes, new constructor. 055 056 Revision 1.2 1999/01/10 03:22:17 markl 057 added GPL header & RCS tag 058 ---------------------------------------------------------------------------- 059*/ 060 061package kiwi.ui.dialog; 062 063import java.awt.*; 064import java.awt.event.*; 065import javax.swing.*; 066 067import kiwi.ui.*; 068import kiwi.util.*; 069 070/** This class represents a <i>Kiwi</i> question dialog. This dialog displays a 071 * message, and has <i>OK</i> and <i>Cancel</i> buttons, which correspond to 072 * "yes" and "no" responses. 073 * 074 * <p><center> 075 * <img src="snapshot/KQuestionDialog.gif"><br> 076 * <i>An example KQuestionDialog.</i> 077 * </center> 078 * 079 * @author Mark Lindner 080 */ 081 082public class KQuestionDialog extends ComponentDialog 083 { 084 private boolean status = false; 085 private KLabelArea l_text; 086 private String s_ok, s_cancel, s_yes, s_no; 087 /** Dialog type. Specifies an ok/cancel dialog. */ 088 public static final int OK_CANCEL_DIALOG = 0; 089 /** Dialog type. Specifies a yes/no dialog. */ 090 public static final int YES_NO_DIALOG = 1; 091 092 /** Construct a new <code>KQuestionDialog</code>. Constructs a new, modal 093 * <code>KQuestionDialog</code> with a default window title. 094 * 095 * @param parent The parent window for this dialog. 096 */ 097 098 public KQuestionDialog(Frame parent) 099 { 100 this(parent, "", true); 101 } 102 103 /** Construct a new <code>KQuestionDialog</code>. Constructs a new, modal 104 * <code>KQuestionDialog</code> with a default window title. 105 * 106 * @param parent The parent window for this dialog. 107 * 108 * @since Kiwi 1.4 109 */ 110 111 public KQuestionDialog(Dialog parent) 112 { 113 this(parent, "", true); 114 } 115 116 /** Construct a new <code>KQuestionDialog</code>. 117 * 118 * @param parent The parent window for the dialog. 119 * @param title The title for the dialog. 120 * @param modal A flag specifying whether this dialog will be modal. 121 */ 122 123 public KQuestionDialog(Frame parent, String title, boolean modal) 124 { 125 super(parent, title, modal); 126 setResizable(false); 127 } 128 129 /** Construct a new <code>KQuestionDialog</code>. 130 * 131 * @param parent The parent window for the dialog. 132 * @param title The title for the dialog. 133 * @param modal A flag specifying whether this dialog will be modal. 134 * 135 * @since Kiwi 1.4 136 */ 137 138 public KQuestionDialog(Dialog parent, String title, boolean modal) 139 { 140 super(parent, title, modal); 141 setResizable(false); 142 } 143 144 /** Set the dialog type. The dialog may either be an ok/cancel dialog or 145 * a yes/no dialog; this type merely reflects the labels on the accept and 146 * cancel buttons. 147 * 148 * @param type The new type; one of <code>OK_CANCEL_DIALOG</code> (the 149 * default), or <code>YES_NO_DIALOG</code>. 150 */ 151 152 public void setType(int type) 153 { 154 switch(type) 155 { 156 case YES_NO_DIALOG: 157 setAcceptButtonText(s_yes); 158 setCancelButtonText(s_no); 159 break; 160 161 case OK_CANCEL_DIALOG: 162 default: 163 setAcceptButtonText(s_ok); 164 setCancelButtonText(s_cancel); 165 } 166 } 167 168 /** Show or hide the dialog. */ 169 170 public void setVisible(boolean flag) 171 { 172 if(flag) 173 { 174 status = false; 175 b_cancel.requestFocus(); 176 } 177 super.setVisible(flag); 178 } 179 180 /** Build the dialog user interface. */ 181 182 protected Component buildDialogUI() 183 { 184 LocaleData loc = LocaleManager.getDefault().getLocaleData("KiwiDialogs"); 185 186 l_text = new KLabelArea(loc.getMessage("kiwi.dialog.prompt.question"), 3, 187 30); 188 l_text.setForeground(Color.black); 189 190 setIcon(KiwiUtils.getResourceManager().getIcon("question.gif")); 191 setComment(""); 192 if(getTitle().length() == 0) 193 setTitle(loc.getMessage("kiwi.dialog.title.message")); 194 195 s_ok = loc.getMessage("kiwi.button.ok"); 196 s_cancel = loc.getMessage("kiwi.button.cancel"); 197 s_yes = loc.getMessage("kiwi.button.yes"); 198 s_no = loc.getMessage("kiwi.button.no"); 199 200 return(l_text); 201 } 202 203 /** Set the prompt. Sets the dialog's message. 204 * 205 * @param message The text of the message. 206 */ 207 208 public void setMessage(String message) 209 { 210 l_text.setText(message); 211 pack(); 212 } 213 214 /** Accept the dialog. Always returns <code>true</code>. */ 215 216 protected boolean accept() 217 { 218 status = true; 219 return(true); 220 } 221 222 /** Get the status of the dialog. 223 * 224 * @return <code>true</code> if the dialog was dismissed via the <i>OK</i> 225 * button and <code>false</code> if it was cancelled. 226 */ 227 228 public boolean getStatus() 229 { 230 return(status); 231 } 232 233 } 234 235/* end of source file */