AuthDialog.java
001 /*
002  * This class is part of DocWhatsUp, a bug profiling and -reporting lib.
003  
004  * Copyright (C)
005  
006  * This library is free software; you can redistribute it and/or modify it
007  * under the terms of the GNU General Public License as published by the
008  * Free Software Foundation; either version 2 of the License, or (at your
009  * option) any later version.
010  
011  * This program is distributed in the hope that it will be useful, but
012  * WITHOUT ANY WARRANTY; without even the implied warranty of
013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
014  * Public License for more details.
015  *  
016  * You should have received a copy of the GNU General Public License along
017  * with this program; if not, write to the Free Software Foundation, Inc.,
018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019  
020  * EXTENSION:
021  * Linking DocWhatsUp statically or dynamically with other modules is making a
022  * combined work based on DocWhatsUp.  Thus, the terms and conditions of the 
023  * GNU General Public License cover the whole combination.
024  *
025  * As a special exception, the copyright holder of DocWhatsUp give you
026  * permission to link DocWhatsUp with independent modules that communicate with
027  * DocWhatsUp solely through the DocWhatsUp.java interface, regardless of the 
028  * license terms of these independent modules, and to copy and distribute the
029  * resulting combined work under terms of your choice, provided that
030  * every copy of the combined work is accompanied by a complete copy of
031  * the source code of DocWhatsUp (the version of DocWhatsUp used to produce the
032  * combined work), being distributed under the terms of the GNU General
033  * Public License plus this exception.  An independent module is a module
034  * which is not derived from or based on DocWhatsUp.
035 
036  * Note that people who make modified versions of DocWhatsUp are not obligated
037  * to grant this special exception for their modified versions; it is
038  * their choice whether to do so.  The GNU General Public License gives
039  * permission to release a modified version without this exception; this
040  * exception also makes it possible to release a modified version which
041  * carries forward this exception.
042  
043  * Author: Philipp Bartsch; codeshaker@gmx.net
044  */
045 
046 package org.shaker.dwu;
047 
048 import java.awt.BorderLayout;
049 import java.awt.Dialog;
050 import java.awt.Frame;
051 import java.awt.event.ActionEvent;
052 import java.awt.event.ActionListener;
053 
054 import javax.swing.Box;
055 import javax.swing.JDialog;
056 import javax.swing.JPanel;
057 import javax.swing.JPasswordField;
058 
059 /**
060  * This class delivers an authentication dialog. It gets displayed, when the 
061  * user uses a pop-authentication smtp server.
062  
063  @author <A HREF="mailto:codeshaker@gmx.net">
064  *            Philipp Bartsch (codeshaker@gmx.net)</A>
065  *            <A HREF="../../../../gpl.txt">GPL License</A>
066  */
067 final class AuthDialog extends       JDialog 
068                        implements ActionListener{
069     
070     /**The password string*/
071     private        String            password;
072     /**The password textfield*/
073     private        JPasswordField     userPassField;
074     
075     /**
076      * Creates a authentication dialog
077      
078      @param parent    parental frame
079      */
080     AuthDialog (final Frame parent) {
081         super(parent,
082               ToolBox.localize("auth_dialog"),                   
083               true);  
084         initContentPane();          
085         pack();
086         ToolBox.setSmartSize(this,
087                              getWidth(),
088                              getHeight());                                                  
089     }
090     
091     /**
092      * Creates a authentication dialog
093      
094      @param parent parental dialog
095      */
096     AuthDialog (final Dialog parent) {
097         super(parent,
098               ToolBox.localize("auth_dialog"),                   
099               true);  
100         initContentPane();          
101         pack();
102         ToolBox.setSmartSize(this,
103                              getWidth(),
104                              getHeight());                                                  
105     }
106     /** 
107      * Returns the entered password 
108      
109      @return String    the password
110      */
111     public String getPassword () {
112         show();
113         return password;
114     }
115     
116     /**
117      * Inits the password pane and controling buttons.
118      */        
119     private void initContentPane () {
120         final JPanel masterPanel     = new JPanel (new BorderLayout(11));    
121         final JPanel passwordPanel    = new JPanel (new BorderLayout(00));
122          final JPanel controlPanel    = new JPanel (new BorderLayout(00));
123         
124         controlPanel.add(GUIFactory.button("cancel_btn",
125                                            this,
126                                            "CANCEL",
127                                            "cancel.png")
128                          BorderLayout.EAST);            
129         controlPanel.add(Box.createHorizontalStrut(5)
130                          BorderLayout.CENTER);
131         controlPanel.add(GUIFactory.button("ok_btn",
132                                            this,
133                                            "OK",
134                                            "close.png")
135                          BorderLayout.WEST);
136             
137         //
138         userPassField = new JPasswordField("");
139         userPassField.setFont(GUIFactory.ARIAL_10P);
140         userPassField.setEditable(true);
141         userPassField.requestFocus();
142         
143         passwordPanel.setBorder(GUIFactory.titledEBorder("brd_passwd"));
144         passwordPanel.add(userPassField, 
145                           BorderLayout.CENTER);
146         
147         masterPanel.add(passwordPanel, BorderLayout.CENTER);
148         masterPanel.add(controlPanel, BorderLayout.SOUTH);
149         setContentPane(masterPanel);
150     }
151     
152     /**
153      * Handles ok and cancel events. 
154      *
155      @param ae the event
156      @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
157      */
158     public void actionPerformed (final ActionEvent ae) {
159         if (ae.getActionCommand().equals("CANCEL")) {                
160             dispose();
161         else {    // must be "ok"
162             //if (userPassField.getPassword().length > 0)
163             password = new String(userPassField.getPassword());
164             dispose();
165         }
166     }
167 }