KickJava   Java API By Example, From Geeks To Geeks.

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


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.key.PromptingAesKeyProvider;
20 import de.schlichtherle.swing.EnhancedPanel;
21
22 import java.util.ResourceBundle JavaDoc;
23
24 import javax.swing.ComboBoxModel JavaDoc;
25 import javax.swing.DefaultComboBoxModel JavaDoc;
26
27 /**
28  * A panel which allows the user to select the key strength for the AES cipher.
29  *
30  * @author Christian Schlichtherle
31  * @since TrueZIP 6.0 (refactored from package de.schlichtherle.crypto.io.swing)
32  * @version @version@
33  */

34 public class AesKeyStrengthPanel extends EnhancedPanel {
35     
36     private static final String JavaDoc CLASS_NAME
37             = "de/schlichtherle/key/passwd/swing/AesKeyStrengthPanel".replace('/', '.'); // support code obfuscation!
38
private static final ResourceBundle JavaDoc resources
39             = ResourceBundle.getBundle(CLASS_NAME);
40
41     static {
42         // This check avoids a mapping function.
43
assert 0 == PromptingAesKeyProvider.KEY_STRENGTH_128;
44         assert 1 == PromptingAesKeyProvider.KEY_STRENGTH_192;
45         assert 2 == PromptingAesKeyProvider.KEY_STRENGTH_256;
46     }
47
48     /**
49      * Creates new form AesKeyStrengthPanel
50      */

51     public AesKeyStrengthPanel() {
52         initComponents();
53         keyStrength.setSelectedIndex(PromptingAesKeyProvider.KEY_STRENGTH_256);
54     }
55
56     private ComboBoxModel JavaDoc createModel() {
57         return new DefaultComboBoxModel JavaDoc(
58             new String JavaDoc[] {
59                 resources.getString("medium"),
60                 resources.getString("high"),
61                 resources.getString("ultra"),
62             });
63     }
64
65     /** This method is called from within the constructor to
66      * initialize the form.
67      * WARNING: Do NOT modify this code. The content of this method is
68      * always regenerated by the Form Editor.
69      */

70     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
71
private void initComponents() {
72         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
73         javax.swing.JLabel JavaDoc keyStrengthLong;
74
75         keyStrengthLong = new javax.swing.JLabel JavaDoc();
76         final javax.swing.JLabel JavaDoc keyStrengthShort = new javax.swing.JLabel JavaDoc();
77
78         setLayout(new java.awt.GridBagLayout JavaDoc());
79
80         keyStrength.setModel(createModel());
81         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
82         gridBagConstraints.gridx = 1;
83         gridBagConstraints.gridy = 1;
84         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
85         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
86         add(keyStrength, gridBagConstraints);
87
88         keyStrengthLong.setLabelFor(keyStrength);
89         keyStrengthLong.setText(resources.getString("prompt")); // NOI18N
90
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
91         gridBagConstraints.gridx = 0;
92         gridBagConstraints.gridy = 0;
93         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
94         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
95         gridBagConstraints.weightx = 1.0;
96         add(keyStrengthLong, gridBagConstraints);
97
98         keyStrengthShort.setLabelFor(keyStrength);
99         keyStrengthShort.setText(resources.getString("keyStrength")); // NOI18N
100
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.gridx = 0;
102         gridBagConstraints.gridy = 1;
103         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
104         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 5);
105         add(keyStrengthShort, gridBagConstraints);
106
107     }// </editor-fold>//GEN-END:initComponents
108

109     /**
110      * Getter for the metaData property .
111      *
112      * @return Value of property keyStrength.
113      */

114     public int getKeyStrength() {
115         final int ks = keyStrength.getSelectedIndex();
116         assert ks == PromptingAesKeyProvider.KEY_STRENGTH_128
117                 || ks == PromptingAesKeyProvider.KEY_STRENGTH_192
118                 || ks == PromptingAesKeyProvider.KEY_STRENGTH_256;
119         return ks;
120     }
121     
122     /**
123      * Setter for property keyStrength.
124      *
125      * @param keyStrength One of
126      * <code>PromptingAesKeyProvider.KEY_STRENGTH_128</code>,
127      * <code>PromptingAesKeyProvider.KEY_STRENGTH_192</code> or
128      * <code>PromptingAesKeyProvider.KEY_STRENGTH_256</code>.
129      *
130      * @throws IllegalArgumentException If the preconditions for the parameter
131      * do not hold.
132      */

133     public void setKeyStrength(int keyStrength) {
134         if (keyStrength != PromptingAesKeyProvider.KEY_STRENGTH_128
135                 && keyStrength != PromptingAesKeyProvider.KEY_STRENGTH_192
136                 && keyStrength != PromptingAesKeyProvider.KEY_STRENGTH_256)
137             throw new IllegalArgumentException JavaDoc();
138         this.keyStrength.setSelectedIndex(keyStrength);
139     }
140     
141     // Variables declaration - do not modify//GEN-BEGIN:variables
142
private final javax.swing.JComboBox JavaDoc keyStrength = new javax.swing.JComboBox JavaDoc();
143     // End of variables declaration//GEN-END:variables
144

145 }
146
Popular Tags