1 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 ; 23 24 import javax.swing.ComboBoxModel ; 25 import javax.swing.DefaultComboBoxModel ; 26 27 34 public class AesKeyStrengthPanel extends EnhancedPanel { 35 36 private static final String CLASS_NAME 37 = "de/schlichtherle/key/passwd/swing/AesKeyStrengthPanel".replace('/', '.'); private static final ResourceBundle resources 39 = ResourceBundle.getBundle(CLASS_NAME); 40 41 static { 42 assert 0 == PromptingAesKeyProvider.KEY_STRENGTH_128; 44 assert 1 == PromptingAesKeyProvider.KEY_STRENGTH_192; 45 assert 2 == PromptingAesKeyProvider.KEY_STRENGTH_256; 46 } 47 48 51 public AesKeyStrengthPanel() { 52 initComponents(); 53 keyStrength.setSelectedIndex(PromptingAesKeyProvider.KEY_STRENGTH_256); 54 } 55 56 private ComboBoxModel createModel() { 57 return new DefaultComboBoxModel ( 58 new String [] { 59 resources.getString("medium"), 60 resources.getString("high"), 61 resources.getString("ultra"), 62 }); 63 } 64 65 70 private void initComponents() { 72 java.awt.GridBagConstraints gridBagConstraints; 73 javax.swing.JLabel keyStrengthLong; 74 75 keyStrengthLong = new javax.swing.JLabel (); 76 final javax.swing.JLabel keyStrengthShort = new javax.swing.JLabel (); 77 78 setLayout(new java.awt.GridBagLayout ()); 79 80 keyStrength.setModel(createModel()); 81 gridBagConstraints = new java.awt.GridBagConstraints (); 82 gridBagConstraints.gridx = 1; 83 gridBagConstraints.gridy = 1; 84 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 85 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 86 add(keyStrength, gridBagConstraints); 87 88 keyStrengthLong.setLabelFor(keyStrength); 89 keyStrengthLong.setText(resources.getString("prompt")); gridBagConstraints = new java.awt.GridBagConstraints (); 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")); gridBagConstraints = new java.awt.GridBagConstraints (); 101 gridBagConstraints.gridx = 0; 102 gridBagConstraints.gridy = 1; 103 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 104 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 5); 105 add(keyStrengthShort, gridBagConstraints); 106 107 } 109 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 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 (); 138 this.keyStrength.setSelectedIndex(keyStrength); 139 } 140 141 private final javax.swing.JComboBox keyStrength = new javax.swing.JComboBox (); 143 145 } 146 | Popular Tags |