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: KInputDialog.java,v $ 023 Revision 1.9 2004/05/05 23:20:24 markl 024 comment block updates 025 026 Revision 1.8 2004/03/16 06:43:39 markl 027 LocaleManager method change 028 029 Revision 1.7 2003/01/19 09:38:51 markl 030 Added new constructors that take a parent dialog. 031 032 Revision 1.6 2001/03/20 00:54:55 markl 033 Fixed deprecated calls. 034 035 Revision 1.5 2001/03/12 09:56:55 markl 036 KLabel/KLabelArea changes. 037 038 Revision 1.4 2001/03/12 05:19:58 markl 039 Source code cleanup. 040 041 Revision 1.3 1999/04/19 06:05:57 markl 042 I18N changes, new constructor. 043 044 Revision 1.2 1999/01/10 03:22:17 markl 045 added GPL header & RCS tag 046 ---------------------------------------------------------------------------- 047*/ 048 049package kiwi.ui.dialog; 050 051import java.awt.*; 052import java.awt.event.*; 053import java.io.*; 054import javax.swing.*; 055 056import kiwi.ui.*; 057import kiwi.util.*; 058 059/** This class represents a <i>Kiwi</i> input dialog. This dialog allows input 060 * of a single line of text, and has <i>OK</i> and <i>Cancel</i> buttons. 061 * Pressing <i>Return</i> in the text field is equivalent to pressing the 062 * <i>OK</i> button. 063 * 064 * <p><center> 065 * <img src="snapshot/KInputDialog.gif"><br> 066 * <i>An example KInputDialog.</i> 067 * </center> 068 * 069 * @author Mark Lindner 070 */ 071 072public class KInputDialog extends ComponentDialog 073 { 074 private String input = null; 075 private JTextField t_input; 076 077 /** Construct a new <code>KInputDialog</code>. Constructs a new, modal 078 * <code>KInputDialog</code> with a default window title. 079 * 080 * @param parent The parent window for this dialog. 081 */ 082 083 public KInputDialog(Frame parent) 084 { 085 this(parent, "", true); 086 } 087 088 /** Construct a new <code>KInputDialog</code>. Constructs a new, modal 089 * <code>KInputDialog</code> with a default window title. 090 * 091 * @param parent The parent window for this dialog. 092 * 093 * @since Kiwi 1.4 094 */ 095 096 public KInputDialog(Dialog parent) 097 { 098 this(parent, "", true); 099 } 100 101 /** Construct a new <code>KInputDialog</code>. 102 * 103 * @param parent The parent window for the dialog. 104 * @param title The title for the dialog. 105 * @param modal A flag specifying whether this dialog will be modal. 106 */ 107 108 public KInputDialog(Frame parent, String title, boolean modal) 109 { 110 super(parent, title, true); 111 112 setResizable(false); 113 } 114 115 /** Construct a new <code>KInputDialog</code>. 116 * 117 * @param parent The parent window for the dialog. 118 * @param title The title for the dialog. 119 * @param modal A flag specifying whether this dialog will be modal. 120 * 121 * @since Kiwi 1.4 122 */ 123 124 public KInputDialog(Dialog parent, String title, boolean modal) 125 { 126 super(parent, title, true); 127 128 setResizable(false); 129 } 130 131 /** Show or hide the dialog. */ 132 133 public void setVisible(boolean flag) 134 { 135 if(flag) 136 t_input.requestFocus(); 137 super.setVisible(flag); 138 } 139 140 /** Build the dialog user interface. */ 141 142 protected Component buildDialogUI() 143 { 144 LocaleData loc = LocaleManager.getDefault().getLocaleData("KiwiDialogs"); 145 146 KPanel jp = new KPanel(); 147 GridBagLayout gb = new GridBagLayout(); 148 jp.setLayout(gb); 149 GridBagConstraints gbc = new GridBagConstraints(); 150 gbc.fill = gbc.HORIZONTAL; 151 gbc.weightx = 1; 152 gbc.anchor = gbc.WEST; 153 154 t_input = new JTextField(15); 155 registerTextInputComponent(t_input); 156 157 jp.add(t_input, gbc); 158 159 setIcon(KiwiUtils.getResourceManager().getIcon("question.gif")); 160 setComment(loc.getMessage("kiwi.dialog.prompt.input")); 161 162 if(getTitle().length() == 0) 163 setTitle(loc.getMessage("kiwi.dialog.title.input")); 164 165 return(jp); 166 } 167 168 /** Accept this dialog. Always returns <code>true</code>. */ 169 170 protected boolean accept() 171 { 172 input = t_input.getText(); 173 return(true); 174 } 175 176 /** Retrieve the text entered in the dialog. 177 * 178 * @return The contents of the dialog's text field, or <code>null</code> 179 * if the dialog was cancelled. 180 */ 181 182 public String getText() 183 { 184 return(input); 185 } 186 187 /** Set the text in the dialog's text field. 188 * 189 * @param text The text to place in the textfield. 190 */ 191 192 public void setText(String text) 193 { 194 t_input.setText(text); 195 } 196 197 /** Set the prompt. Sets the dialog's input prompt. 198 * 199 * @param text The text for the prompt. 200 */ 201 202 public void setPrompt(String text) 203 { 204 setComment(text); 205 pack(); 206 } 207 208 } 209 210/* end of source file */