components/visual-panels/core/src/java/vpanels/client/com/oracle/solaris/vp/client/swing/LoginDialog.java
changeset 827 0944d8c0158b
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.client.swing;
       
    27 
       
    28 import java.awt.*;
       
    29 import java.awt.event.*;
       
    30 import java.beans.*;
       
    31 import javax.swing.WindowConstants;
       
    32 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    33 import com.oracle.solaris.vp.util.swing.ExtDialog;
       
    34 import com.oracle.solaris.vp.util.swing.glass.*;
       
    35 import com.oracle.solaris.vp.util.swing.layout.*;
       
    36 
       
    37 public class LoginDialog extends ExtDialog {
       
    38     //
       
    39     // Instance data
       
    40     //
       
    41 
       
    42     private WindowListener listener =
       
    43 	new WindowAdapter() {
       
    44 	    @Override
       
    45 	    public void windowClosing(WindowEvent e) {
       
    46 		loginPane.setClickedButton(
       
    47 		    loginPane.getButtonBar().getCancelButton());
       
    48 		certPane.setClickedButton(
       
    49 		    loginPane.getButtonBar().getCancelButton());
       
    50 	    }
       
    51 	};
       
    52 
       
    53     private LoginPane loginPane;
       
    54     private CertificatePane certPane;
       
    55     private BusyGlassPane busyPane;
       
    56 
       
    57     private PropertyChangeListener promptListener =
       
    58 	new PropertyChangeListener() {
       
    59 	    @Override
       
    60 	    public void propertyChange(final PropertyChangeEvent event) {
       
    61 		EventQueue.invokeLater(
       
    62 		    new Runnable() {
       
    63 			@Override
       
    64 			public void run() {
       
    65 			    if (event.getNewValue().equals(true)) {
       
    66 				Component comp = (Component)event.getSource();
       
    67 				if (comp == loginPane) {
       
    68 				    certPane.setVisible(false);
       
    69 				} else if (comp == certPane) {
       
    70 				    loginPane.setVisible(false);
       
    71 				}
       
    72 				comp.setVisible(true);
       
    73 				getGlassPane().setVisible(false);
       
    74 				setVisible(true);
       
    75 			    } else {
       
    76 				getGlassPane().setVisible(true);
       
    77 			    }
       
    78 			}
       
    79 		    });
       
    80 	    }
       
    81 	};
       
    82 
       
    83     //
       
    84     // Constructors
       
    85     //
       
    86 
       
    87     public LoginDialog(Window owner, LoginPane loginPane,
       
    88 	CertificatePane certPane, BusyGlassPane busyPane) {
       
    89 
       
    90 	super(owner, Finder.getString("login.title"),
       
    91 	    Dialog.DEFAULT_MODALITY_TYPE);
       
    92 
       
    93 	this.loginPane = loginPane;
       
    94 	this.certPane = certPane;
       
    95 	this.busyPane = busyPane;
       
    96 
       
    97 	LayeredGlassPane glass = new LayeredGlassPane();
       
    98 	glass.add(new BlockingGlassPane(false));
       
    99 	glass.add(busyPane);
       
   100 
       
   101 	setGlassPane(glass);
       
   102 
       
   103 	loginPane.addPropertyChangeListener(DialogPane.PROPERTY_PROMPTING,
       
   104 	    promptListener);
       
   105 
       
   106 	certPane.addPropertyChangeListener(DialogPane.PROPERTY_PROMPTING,
       
   107 	    promptListener);
       
   108 
       
   109 	addWindowListener(listener);
       
   110 
       
   111 	ColumnLayout layout = new ColumnLayout(VerticalAnchor.FILL);
       
   112 	ColumnLayoutConstraint c = new ColumnLayoutConstraint(
       
   113 	    HorizontalAnchor.FILL);
       
   114 
       
   115 	Container cont = getContentPane();
       
   116 	cont.setLayout(layout);
       
   117 	cont.add(loginPane, c);
       
   118 	cont.add(certPane, c);
       
   119 
       
   120 	setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
       
   121 	pack();
       
   122 	setAutoResizeEnabled(true);
       
   123     }
       
   124 
       
   125     //
       
   126     // Window methods
       
   127     //
       
   128 
       
   129     @Override
       
   130     public void dispose() {
       
   131 	loginPane.removePropertyChangeListener(
       
   132 	    DialogPane.PROPERTY_PROMPTING, promptListener);
       
   133 	certPane.removePropertyChangeListener(
       
   134 	    DialogPane.PROPERTY_PROMPTING, promptListener);
       
   135 	removeWindowListener(listener);
       
   136 	super.dispose();
       
   137     }
       
   138 
       
   139     //
       
   140     // LoginDialog methods
       
   141     //
       
   142 
       
   143     public CertificatePane getCertificatePane() {
       
   144 	return certPane;
       
   145     }
       
   146 
       
   147     public LoginPane getLoginPane() {
       
   148 	return loginPane;
       
   149     }
       
   150 }