KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > key > passwd > swing > PromptingAesKeyProviderUI


1 /*
2  * Copyright 2006 Schlichtherle IT Services
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package de.schlichtherle.key.passwd.swing;
18
19 import de.schlichtherle.awt.*;
20 import de.schlichtherle.key.*;
21
22 import javax.swing.*;
23
24 /**
25  * Extends its base class to enable the user to select the key strength
26  * for the AES cipher.
27  * This class is thread safe.
28  *
29  * @author Christian Schlichtherle
30  * @since TrueZIP 6.0
31  * @version @version@
32  */

33 public class PromptingAesKeyProviderUI extends PromptingKeyProviderUI {
34
35     /**
36      * @deprecated This field is not used anymore and will be removed for the
37      * next major release number.
38      */

39     private AesKeyStrengthPanel aesKeyStrengthPanel;
40
41     /**
42      * @deprecated This method is not used anymore and will be removed for the
43      * next major release number.
44      * It's use may dead lock the GUI.
45      * Use {@link #createAesKeyStrengthPanel} instead.
46      */

47     protected AesKeyStrengthPanel getAesKeyStrengthPanel() {
48         if (aesKeyStrengthPanel == null)
49             aesKeyStrengthPanel = createAesKeyStrengthPanel();
50         return aesKeyStrengthPanel;
51     }
52
53     /**
54      * A factory method to create the AES Key Strength Panel.
55      */

56     protected AesKeyStrengthPanel createAesKeyStrengthPanel() {
57         return new AesKeyStrengthPanel();
58     }
59
60     protected void promptCreateKey(final PromptingKeyProvider provider, JComponent extraDataUI) {
61         assert null == extraDataUI;
62         assert EventQueue.isDispatchThread();
63
64         // We can safely cast the parameter to PromptingAesKeyProvider, because
65
// otherwise we would not have been called.
66
final PromptingAesKeyProvider aesKeyProvider = ((PromptingAesKeyProvider) provider);
67
68         final Object JavaDoc oldKey = aesKeyProvider.getKey();
69
70         // Init panel with current key strength and prompt user.
71
final AesKeyStrengthPanel aesKeyStrengthPanel = createAesKeyStrengthPanel();
72         aesKeyStrengthPanel.setKeyStrength(aesKeyProvider.getKeyStrength());
73         super.promptCreateKey(aesKeyProvider, aesKeyStrengthPanel);
74
75         // Update key strength only on valid input.
76
if (oldKey != aesKeyProvider.getKey())
77             aesKeyProvider.setKeyStrength(aesKeyStrengthPanel.getKeyStrength());
78     }
79 }
80
Popular Tags