001 /* 002 * $Id: JXLoginDialog.java,v 1.8 2006/05/14 08:12:16 dmouse Exp $ 003 * 004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 */ 007 008 package org.jdesktop.swingx; 009 010 import java.awt.Dialog; 011 import java.awt.Frame; 012 import java.awt.GraphicsConfiguration; 013 import java.awt.HeadlessException; 014 import javax.swing.JDialog; 015 import javax.swing.UIManager; 016 import org.jdesktop.swingx.auth.LoginService; 017 import org.jdesktop.swingx.auth.PasswordStore; 018 import org.jdesktop.swingx.auth.UserNameStore; 019 020 /** 021 * A standard login dialog that provides a reasonable amount of flexibility 022 * while also providing ease of use and a professional look. 023 * 024 * @author rbair 025 */ 026 public class JXLoginDialog extends JDialog { 027 /** 028 * The login panel containing the username & password fields, and handling 029 * the login procedures. 030 */ 031 private JXLoginPanel panel; 032 033 /** 034 * Creates a non-modal dialog without a title and without a specified 035 * <code>Frame</code> owner. A shared, hidden frame will be 036 * set as the owner of the dialog. 037 * <p> 038 * This constructor sets the component's locale property to the value 039 * returned by <code>JComponent.getDefaultLocale</code>. 040 * 041 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 042 * returns true. 043 * @see java.awt.GraphicsEnvironment#isHeadless 044 * @see javax.swing.JComponent#getDefaultLocale 045 */ 046 public JXLoginDialog() throws HeadlessException { 047 super(); 048 init(); 049 } 050 051 /** 052 * Creates a non-modal dialog without a title with the 053 * specified <code>Frame</code> as its owner. If <code>owner</code> 054 * is <code>null</code>, a shared, hidden frame will be set as the 055 * owner of the dialog. 056 * <p> 057 * This constructor sets the component's locale property to the value 058 * returned by <code>JComponent.getDefaultLocale</code>. 059 * 060 * @param owner the <code>Frame</code> from which the dialog is displayed 061 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 062 * returns true. 063 * @see java.awt.GraphicsEnvironment#isHeadless 064 * @see javax.swing.JComponent#getDefaultLocale 065 */ 066 public JXLoginDialog(Frame owner) throws HeadlessException { 067 super(owner); 068 init(); 069 } 070 071 /** 072 * Creates a modal or non-modal dialog without a title and 073 * with the specified owner <code>Frame</code>. If <code>owner</code> 074 * is <code>null</code>, a shared, hidden frame will be set as the 075 * owner of the dialog. 076 * <p> 077 * This constructor sets the component's locale property to the value 078 * returned by <code>JComponent.getDefaultLocale</code>. 079 * 080 * @param owner the <code>Frame</code> from which the dialog is displayed 081 * @param modal true for a modal dialog, false for one that allows 082 * others windows to be active at the same time 083 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 084 * returns true. 085 * @see java.awt.GraphicsEnvironment#isHeadless 086 * @see javax.swing.JComponent#getDefaultLocale 087 */ 088 public JXLoginDialog(Frame owner, boolean modal) throws HeadlessException { 089 super(owner, modal); 090 init(); 091 } 092 093 /** 094 * Creates a non-modal dialog with the specified title and 095 * with the specified owner frame. If <code>owner</code> 096 * is <code>null</code>, a shared, hidden frame will be set as the 097 * owner of the dialog. 098 * <p> 099 * This constructor sets the component's locale property to the value 100 * returned by <code>JComponent.getDefaultLocale</code>. 101 * 102 * @param owner the <code>Frame</code> from which the dialog is displayed 103 * @param title the <code>String</code> to display in the dialog's 104 * title bar 105 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 106 * returns true. 107 * @see java.awt.GraphicsEnvironment#isHeadless 108 * @see javax.swing.JComponent#getDefaultLocale 109 */ 110 public JXLoginDialog(Frame owner, String title) throws HeadlessException { 111 super(owner, title); 112 init(); 113 } 114 115 /** 116 * Creates a modal or non-modal dialog with the specified title 117 * and the specified owner <code>Frame</code>. If <code>owner</code> 118 * is <code>null</code>, a shared, hidden frame will be set as the 119 * owner of this dialog. All constructors defer to this one. 120 * <p> 121 * NOTE: Any popup components (<code>JComboBox</code>, 122 * <code>JPopupMenu</code>, <code>JMenuBar</code>) 123 * created within a modal dialog will be forced to be lightweight. 124 * <p> 125 * This constructor sets the component's locale property to the value 126 * returned by <code>JComponent.getDefaultLocale</code>. 127 * 128 * @param owner the <code>Frame</code> from which the dialog is displayed 129 * @param title the <code>String</code> to display in the dialog's 130 * title bar 131 * @param modal true for a modal dialog, false for one that allows 132 * other windows to be active at the same time 133 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 134 * returns true. 135 * @see java.awt.GraphicsEnvironment#isHeadless 136 * @see javax.swing.JComponent#getDefaultLocale 137 */ 138 public JXLoginDialog(Frame owner, String title, boolean modal) 139 throws HeadlessException { 140 super(owner, title, modal); 141 init(); 142 } 143 144 /** 145 * Creates a modal or non-modal dialog with the specified title, 146 * owner <code>Frame</code>, and <code>GraphicsConfiguration</code>. 147 * 148 * <p> 149 * NOTE: Any popup components (<code>JComboBox</code>, 150 * <code>JPopupMenu</code>, <code>JMenuBar</code>) 151 * created within a modal dialog will be forced to be lightweight. 152 * <p> 153 * This constructor sets the component's locale property to the value 154 * returned by <code>JComponent.getDefaultLocale</code>. 155 * 156 * @param owner the <code>Frame</code> from which the dialog is displayed 157 * @param title the <code>String</code> to display in the dialog's 158 * title bar 159 * @param modal true for a modal dialog, false for one that allows 160 * other windows to be active at the same time 161 * @param gc the <code>GraphicsConfiguration</code> 162 * of the target screen device. If <code>gc</code> is 163 * <code>null</code>, the same 164 * <code>GraphicsConfiguration</code> as the owning Frame is used. 165 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 166 * returns true. 167 * @see java.awt.GraphicsEnvironment#isHeadless 168 * @see javax.swing.JComponent#getDefaultLocale 169 * @since 1.4 170 */ 171 public JXLoginDialog(Frame owner, String title, boolean modal, 172 GraphicsConfiguration gc) { 173 super(owner, title, modal, gc); 174 init(); 175 } 176 177 /** 178 * Creates a non-modal dialog without a title with the 179 * specified <code>Dialog</code> as its owner. 180 * <p> 181 * This constructor sets the component's locale property to the value 182 * returned by <code>JComponent.getDefaultLocale</code>. 183 * 184 * @param owner the non-null <code>Dialog</code> from which the dialog is displayed 185 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 186 * returns true. 187 * @see java.awt.GraphicsEnvironment#isHeadless 188 * @see javax.swing.JComponent#getDefaultLocale 189 */ 190 public JXLoginDialog(Dialog owner) throws HeadlessException { 191 super(owner); 192 init(); 193 } 194 195 /** 196 * Creates a modal or non-modal dialog without a title and 197 * with the specified owner dialog. 198 * <p> 199 * This constructor sets the component's locale property to the value 200 * returned by <code>JComponent.getDefaultLocale</code>. 201 * 202 * @param owner the non-null <code>Dialog</code> from which the dialog is displayed 203 * @param modal true for a modal dialog, false for one that allows 204 * other windows to be active at the same time 205 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 206 * returns true. 207 * @see java.awt.GraphicsEnvironment#isHeadless 208 * @see javax.swing.JComponent#getDefaultLocale 209 */ 210 public JXLoginDialog(Dialog owner, boolean modal) throws HeadlessException { 211 super(owner, modal); 212 init(); 213 } 214 215 /** 216 * Creates a non-modal dialog with the specified title and 217 * with the specified owner dialog. 218 * <p> 219 * This constructor sets the component's locale property to the value 220 * returned by <code>JComponent.getDefaultLocale</code>. 221 * 222 * @param owner the non-null <code>Dialog</code> from which the dialog is displayed 223 * @param title the <code>String</code> to display in the dialog's 224 * title bar 225 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 226 * returns true. 227 * @see java.awt.GraphicsEnvironment#isHeadless 228 * @see javax.swing.JComponent#getDefaultLocale 229 */ 230 public JXLoginDialog(Dialog owner, String title) throws HeadlessException { 231 super(owner, title); 232 init(); 233 } 234 235 /** 236 * Creates a modal or non-modal dialog with the specified title 237 * and the specified owner frame. 238 * <p> 239 * This constructor sets the component's locale property to the value 240 * returned by <code>JComponent.getDefaultLocale</code>. 241 * 242 * @param owner the non-null <code>Dialog</code> from which the dialog is displayed 243 * @param title the <code>String</code> to display in the dialog's 244 * title bar 245 * @param modal true for a modal dialog, false for one that allows 246 * other windows to be active at the same time 247 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 248 * returns true. 249 * @see java.awt.GraphicsEnvironment#isHeadless 250 * @see javax.swing.JComponent#getDefaultLocale 251 */ 252 public JXLoginDialog(Dialog owner, String title, boolean modal) 253 throws HeadlessException { 254 super(owner, title, modal); 255 init(); 256 } 257 258 /** 259 * Creates a modal or non-modal dialog with the specified title, 260 * owner <code>Dialog</code>, and <code>GraphicsConfiguration</code>. 261 * 262 * <p> 263 * NOTE: Any popup components (<code>JComboBox</code>, 264 * <code>JPopupMenu</code>, <code>JMenuBar</code>) 265 * created within a modal dialog will be forced to be lightweight. 266 * <p> 267 * This constructor sets the component's locale property to the value 268 * returned by <code>JComponent.getDefaultLocale</code>. 269 * 270 * @param owner the <code>Dialog</code> from which the dialog is displayed 271 * @param title the <code>String</code> to display in the dialog's 272 * title bar 273 * @param modal true for a modal dialog, false for one that allows 274 * other windows to be active at the same time 275 * @param gc the <code>GraphicsConfiguration</code> 276 * of the target screen device. If <code>gc</code> is 277 * <code>null</code>, the same 278 * <code>GraphicsConfiguration</code> as the owning Dialog is used. 279 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 280 * @see java.awt.GraphicsEnvironment#isHeadless 281 * @see javax.swing.JComponent#getDefaultLocale 282 * returns true. 283 * @since 1.4 284 */ 285 public JXLoginDialog(Dialog owner, String title, boolean modal, 286 GraphicsConfiguration gc) throws HeadlessException { 287 288 super(owner, title, modal, gc); 289 init(); 290 } 291 292 /** 293 */ 294 public JXLoginDialog(LoginService service, PasswordStore ps, UserNameStore us) { 295 super(); 296 setTitle(UIManager.getString(JXLoginPanel.class.getCanonicalName() + ".loginString")); 297 setPanel(new JXLoginPanel(service, ps, us)); 298 JXLoginPanel.initWindow(this, getPanel()); 299 } 300 301 protected void init() { 302 setPanel(new JXLoginPanel()); 303 JXLoginPanel.initWindow(this, getPanel()); 304 } 305 306 /** 307 * @return the status of the login dialog 308 */ 309 public JXLoginPanel.Status getStatus() { 310 return getPanel().getStatus(); 311 } 312 313 public JXLoginPanel getPanel() { 314 return panel; 315 } 316 317 public void setPanel(JXLoginPanel panel) { 318 this.panel = panel; 319 } 320 }