Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / swing / JPasswordDlg.java @ 40561

History | View | Annotate | Download (6.58 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils.swing;
25

    
26
import java.awt.event.KeyEvent;
27
import java.awt.event.WindowAdapter;
28
import java.awt.event.WindowEvent;
29

    
30
import javax.swing.JButton;
31
import javax.swing.JDialog;
32
import javax.swing.JEditorPane;
33
import javax.swing.JPanel;
34
import javax.swing.JPasswordField;
35
import javax.swing.JTextArea;
36

    
37
public class JPasswordDlg extends JDialog {
38

    
39
    private JPanel jContentPane = null;
40

    
41
    private JButton jButtonOK = null;
42

    
43
    private JButton jButton1 = null;
44

    
45
    private JPasswordField jPasswordField = null;
46

    
47
    private String password = null;
48

    
49
    private JEditorPane jEditorPane = null;
50

    
51
    private JTextArea jLblMensaje = null;
52
    
53
    private WindowEventsHandler windowHandler = new WindowEventsHandler();
54

    
55
    /**
56
     * This is the default constructor
57
     */
58
    public JPasswordDlg() {
59
        super();
60
        initialize();
61
    }
62

    
63
    class WindowEventsHandler extends WindowAdapter
64
    {
65

    
66
        /* (non-Javadoc)
67
         * @see java.awt.event.WindowAdapter#windowActivated(java.awt.event.WindowEvent)
68
         */
69
        public void windowActivated(WindowEvent e) {
70
            // TODO Auto-generated method stub
71
            super.windowActivated(e);
72
            jPasswordField.requestFocus();
73
        }
74
        
75
    }
76
    /**
77
     * This method initializes this
78
     * 
79
     * @return void
80
     */
81
private void initialize() {
82
        this.setSize(287, 172);
83
        this.setModal(true);
84
        this.setResizable(false);
85
        this.setTitle("Enter Password");
86
        this.setContentPane(getJContentPane());
87
        
88
        addWindowListener(windowHandler);
89
    }
90
    /**
91
     * This method initializes jContentPane
92
     * 
93
     * @return javax.swing.JPanel
94
     */
95
    private JPanel getJContentPane() {
96
        if (jContentPane == null) {
97
            jContentPane = new JPanel();
98
            jContentPane.setLayout(null);
99
            jContentPane.add(getJButton1(), null);
100
            jContentPane.add(getJButtonOK(), null);
101
            jContentPane.add(getJPasswordField(), null);
102
            jContentPane.add(getJLblMensaje(), null);
103

    
104
        }
105
        return jContentPane;
106
    }
107

    
108
    /**
109
     * This method initializes jButton
110
     * 
111
     * @return javax.swing.JButton
112
     */
113
    private JButton getJButtonOK() {
114
        if (jButtonOK == null) {
115
            jButtonOK = new JButton();
116
            jButtonOK.setText("OK");
117
            jButtonOK.setPreferredSize(new java.awt.Dimension(65, 23));
118
            jButtonOK.setBounds(35, 110, 101, 22);
119
            jButtonOK.addActionListener(new java.awt.event.ActionListener() {
120
                public void actionPerformed(java.awt.event.ActionEvent e) {
121
                    System.out.println("actionPerformed()"); // TODO
122
                    // Auto-generated
123
                    // Event stub
124
                    // actionPerformed()
125
                    password = String.copyValueOf(getJPasswordField()
126
                            .getPassword());
127
                    dispose();
128
                }
129
            });
130
        }
131
        return jButtonOK;
132
    }
133

    
134
    /**
135
     * This method initializes jButton1
136
     * 
137
     * @return javax.swing.JButton
138
     */
139
    private JButton getJButton1() {
140
        if (jButton1 == null) {
141
            jButton1 = new JButton();
142
            jButton1.setText("Cancel");
143
            jButton1.setBounds(136, 110, 99, 22);
144
            jButton1.addActionListener(new java.awt.event.ActionListener() {
145
                public void actionPerformed(java.awt.event.ActionEvent e) {
146
                    password = null;
147
                    dispose();
148
                }
149
            });
150
        }
151
        return jButton1;
152
    }
153

    
154
    /**
155
     * This method initializes jPasswordField
156
     * 
157
     * @return javax.swing.JPasswordField
158
     */
159
    private JPasswordField getJPasswordField() {
160
        if (jPasswordField == null) {
161
            jPasswordField = new JPasswordField();
162
            jPasswordField.setPreferredSize(new java.awt.Dimension(60, 22));
163
            jPasswordField.setBounds(65, 78, 145, 21);
164
            jPasswordField.addKeyListener(new java.awt.event.KeyAdapter() {
165
                public void keyTyped(java.awt.event.KeyEvent e) {
166
                    if (e.getKeyChar() == KeyEvent.VK_ENTER) {
167
                        // System.out.println("INTRO");
168
                        getJButtonOK().doClick();
169
                    }
170
                }
171
            });
172
        }
173
        return jPasswordField;
174
    }
175

    
176
    /**
177
     * @return Returns the password.
178
     */
179
    public String getPassword() {
180
        return password;
181
    }
182

    
183
    public void setMessage(String str) {
184
        getJLblMensaje().setText(str);
185
    }
186

    
187
    /**
188
     * This method initializes jEditorPane
189
     * 
190
     * @return javax.swing.JEditorPane
191
     */
192
    private JEditorPane getJEditorPane() {
193
        if (jEditorPane == null) {
194
            jEditorPane = new JEditorPane();
195
        }
196
        return jEditorPane;
197
    }
198

    
199
    /**
200
     * This method initializes jTextArea
201
     * 
202
     * @return javax.swing.JTextArea
203
     */
204
    private JTextArea getJLblMensaje() {
205
        if (jLblMensaje == null) {
206
            jLblMensaje = new JTextArea();
207
            jLblMensaje.setEditable(false);
208
            jLblMensaje.setForeground(java.awt.Color.black);
209
            jLblMensaje.setBackground(java.awt.SystemColor.control);
210
            jLblMensaje.setText("Mensaje");
211
            jLblMensaje.setLineWrap(true);
212
            jLblMensaje.setFont(new java.awt.Font("SansSerif",
213
                    java.awt.Font.PLAIN, 12));
214
            jLblMensaje.setPreferredSize(new java.awt.Dimension(270, 50));
215
            jLblMensaje.setBounds(9, 6, 266, 68);
216
            jLblMensaje.setWrapStyleWord(true);
217
        }
218
        return jLblMensaje;
219
    }
220
} // @jve:decl-index=0:visual-constraint="10,10"