1 package net.suberic.pooka.gui.propedit; 2 import net.suberic.util.gui.propedit.*; 3 import net.suberic.util.VariableBundle; 4 import net.suberic.pooka.gui.filechooser.*; 5 import net.suberic.pooka.*; 6 7 import javax.swing.*; 8 import java.awt.event.ActionEvent ; 9 10 import java.util.Set ; 11 import java.util.Vector ; 12 13 16 17 public class KeySelectorPane extends LabelValuePropertyEditor { 18 19 JLabel label; 20 JComboBox valueDisplay; 21 22 29 public void configureEditor(String propertyName, String template, String propertyBaseName, PropertyEditorManager newManager) { 30 configureBasic(propertyName, template, propertyBaseName, newManager); 31 32 if (debug) { 33 System.out.println("property is " + property + "; editorTemplate is " + editorTemplate); 34 } 35 36 label = createLabel(); 37 38 valueDisplay = createKeyList(originalValue); 39 40 42 this.add(label); 43 labelComponent = label; 44 JPanel tmpPanel = new JPanel(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT, 0,0)); 45 tmpPanel.add(valueDisplay); 46 tmpPanel.setPreferredSize(new java.awt.Dimension (Math.max(150, tmpPanel.getMinimumSize().width), valueDisplay.getMinimumSize().height)); 47 valueComponent = tmpPanel; 48 this.add(tmpPanel); 49 50 updateEditorEnabled(); 51 52 } 53 54 57 public JComboBox createKeyList(String defaultValue) { 58 if (Pooka.isDebug()) 59 System.out.println("creating keylist."); 60 61 String encryptionType = manager.getProperty(editorTemplate + ".encryptionType", "All"); 62 63 if (encryptionType.equalsIgnoreCase("All")) 64 encryptionType = null; 65 66 String keyType = manager.getProperty(editorTemplate + ".keyType", "private"); 67 68 Set keySet = null; 69 70 try { 71 if (keyType.equalsIgnoreCase("private")) 72 keySet = Pooka.getCryptoManager().privateKeyAliases(encryptionType); 73 else 74 keySet = Pooka.getCryptoManager().publicKeyAliases(encryptionType); 75 } catch (java.security.KeyStoreException kse) { 76 keySet = null; 77 } 78 79 Vector listModel = null; 80 81 if (keySet != null) { 82 listModel = new Vector (keySet); 83 } else { 84 listModel = new Vector (); 85 } 86 87 if (originalValue != null && originalValue != "") { 88 if (! listModel.contains(originalValue)) 89 listModel.add(originalValue); 90 JComboBox returnValue = new JComboBox(listModel); 91 returnValue.setSelectedItem(originalValue); 92 93 return returnValue; 94 } else { 95 JComboBox returnValue = new JComboBox(listModel); 96 97 return returnValue; 98 } 99 } 100 101 103 public void setValue() throws PropertyValueVetoException { 104 validateProperty(); 105 if (Pooka.isDebug()) 106 System.out.println("calling ksp.setValue. isEditorEnabled() = " + isEditorEnabled() + "; isChanged() = " + isChanged()); 107 108 String newValue = (String ) valueDisplay.getSelectedItem(); 109 if (newValue == null) 110 newValue = ""; 111 112 if (isEditorEnabled() && isChanged()) { 113 manager.setProperty(property, newValue); 114 } 115 } 116 117 public void validateProperty() throws PropertyValueVetoException { 118 String newValue = (String ) valueDisplay.getSelectedItem(); 119 if (newValue == null) 120 newValue = ""; 121 122 if (isEditorEnabled()) { 123 firePropertyCommittingEvent(newValue); 124 } 125 } 126 127 public java.util.Properties getValue() { 128 java.util.Properties retProps = new java.util.Properties (); 129 130 String newValue = (String ) valueDisplay.getSelectedItem(); 131 if (newValue == null) 132 newValue = ""; 133 134 retProps.setProperty(property, newValue); 135 136 return retProps; 137 } 138 139 public void resetDefaultValue() { 140 valueDisplay.setSelectedItem(originalValue); 141 } 142 143 public boolean isChanged() { 144 return (!(originalValue.equals(valueDisplay.getSelectedItem()))); 145 } 146 147 150 protected void updateEditorEnabled() { 151 if (Pooka.isDebug()) 152 System.out.println("calling ksp.updateEditorEnabled(). isEditorEnabled() = " + isEditorEnabled()); 153 154 if (valueDisplay != null) { 155 valueDisplay.setEnabled(isEditorEnabled()); 156 } 157 } 158 159 } 160 | Popular Tags |