1 package net.suberic.pooka.gui.crypto; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.awt.event.ActionListener ; 6 import java.security.Key ; 7 import java.awt.event.ActionEvent ; 8 import java.awt.event.ActionListener ; 9 10 import net.suberic.util.VariableBundle; 11 import net.suberic.util.gui.IconManager; 12 import net.suberic.pooka.Pooka; 13 import net.suberic.crypto.EncryptionKey; 14 import net.suberic.pooka.gui.NewMessageProxy; 15 import net.suberic.pooka.gui.NewMessageCryptoInfo; 16 17 18 21 public class NewMessageCryptoDisplay extends JPanel implements CryptoStatusDisplay { 22 23 JButton mSignatureKeyButton = null; 24 JButton mEncryptionKeyButton = null; 25 26 JToggleButton mSignatureEnabledButton = null; 27 JToggleButton mEncryptionEnabledButton = null; 28 29 JList mAttachKeysList = null; 30 31 NewMessageProxy proxy = null; 32 33 36 public NewMessageCryptoDisplay(NewMessageProxy nmp) { 37 super(); 38 39 proxy = nmp; 40 41 this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 42 85 86 Box cryptoBox = new Box(BoxLayout.X_AXIS); 87 88 cryptoBox.add(new JLabel(Pooka.getProperty("NewMessageCryptoPanel.encryptionKey.label", "Encryption Key"))); 89 90 cryptoBox.add(Box.createHorizontalStrut(5)); 91 92 mEncryptionEnabledButton = createEncryptionEnabledButton(); 93 94 createEncryptionButton(); 95 96 cryptoBox.add(mEncryptionKeyButton); 97 98 cryptoBox.add(Box.createHorizontalGlue()); 99 100 cryptoBox.add(mEncryptionEnabledButton); 101 102 Box signatureBox = new Box(BoxLayout.X_AXIS); 103 104 signatureBox.add(new JLabel(Pooka.getProperty("NewMessageCryptoPanel.signatureKey.label", "Signature Key"))); 105 106 signatureBox.add(Box.createHorizontalStrut(5)); 107 108 mSignatureEnabledButton = createSignatureEnabledButton(); 109 110 createSignatureButton(); 111 112 signatureBox.add(mSignatureKeyButton); 113 114 signatureBox.add(Box.createHorizontalGlue()); 115 116 signatureBox.add(mSignatureEnabledButton); 117 118 this.add(cryptoBox); 119 this.add(signatureBox); 120 121 } 122 123 126 public void createEncryptionButton() { 127 mEncryptionKeyButton = new JButton(); 128 mEncryptionKeyButton.addActionListener(proxy.getAction("message-select-crypt-key")); 129 updateEncryptionButton(); 130 } 131 132 135 public void updateEncryptionButton() { 136 Runnable runMe = new Runnable () { 137 public void run() { 138 Key current = getEncryptionKey(); 139 if (current == null) 140 mEncryptionKeyButton.setText(Pooka.getProperty("NewMessageCryptoPanel.encryptionKey.none", "< Not Encrypted >")); 141 else 142 mEncryptionKeyButton.setText(current instanceof EncryptionKey ? ((EncryptionKey)current).getDisplayAlias() : current.toString()); 143 } 144 }; 145 146 if (SwingUtilities.isEventDispatchThread()) 147 runMe.run(); 148 else 149 SwingUtilities.invokeLater(runMe); 150 } 151 152 155 public JToggleButton createEncryptionEnabledButton() { 156 IconManager iconManager = Pooka.getUIFactory().getIconManager(); 157 158 ImageIcon keyIcon = iconManager.getIcon(Pooka.getProperty("NewMessageCryptoDisplay.keyIcon", "Key")); 159 ImageIcon noKeyIcon = iconManager.getIcon(Pooka.getProperty("NewMessageCryptoDisplay.noKeyIcon", "NoKey")); 160 if (keyIcon != null && noKeyIcon != null) { 161 JToggleButton returnValue = new JToggleButton(noKeyIcon, proxy.getCryptoInfo().getEncryptMessage() != NewMessageCryptoInfo.CRYPTO_NO); 162 163 returnValue.setSelectedIcon(keyIcon); 164 165 returnValue.addActionListener(new ActionListener () { 166 public void actionPerformed(ActionEvent e) { 167 boolean nowSelected = mEncryptionEnabledButton.isSelected(); 168 169 mEncryptionKeyButton.setEnabled(nowSelected); 170 if (nowSelected) 171 proxy.getCryptoInfo().setEncryptMessage(NewMessageCryptoInfo.CRYPTO_YES); 172 else 173 proxy.getCryptoInfo().setEncryptMessage(NewMessageCryptoInfo.CRYPTO_NO); 174 } 175 }); 176 177 returnValue.setSize(keyIcon.getIconHeight(), keyIcon.getIconWidth()); 178 returnValue.setPreferredSize(new java.awt.Dimension (keyIcon.getIconHeight(), keyIcon.getIconWidth())); 179 return returnValue; 180 } 181 182 return null; 183 } 184 185 188 public JButton createClearEncryptionButton() { 189 JButton returnValue = new JButton(Pooka.getProperty("NewMessageCryptoPanel.clearButton.label", "Clear Key")); 190 returnValue.addActionListener(proxy.getAction("message-clear-encrypt")); 191 return returnValue; 192 } 193 194 197 public Key getEncryptionKey() { 198 return proxy.getCryptoInfo().getEncryptionKey(); 199 } 200 201 204 public void setEncryptionKey(Key pEncryptionKey) { 205 proxy.getCryptoInfo().setEncryptionKey(pEncryptionKey); 206 updateEncryptionButton(); 207 } 208 209 212 public void createSignatureButton() { 213 mSignatureKeyButton = new JButton(); 214 mSignatureKeyButton.addActionListener(proxy.getAction("message-select-sig-key")); 215 updateSignatureButton(); 216 } 217 218 221 public JToggleButton createSignatureEnabledButton() { 222 IconManager iconManager = Pooka.getUIFactory().getIconManager(); 223 224 ImageIcon keyIcon = iconManager.getIcon(Pooka.getProperty("NewMessageCryptoDisplay.keyIcon", "Key")); 225 ImageIcon noKeyIcon = iconManager.getIcon(Pooka.getProperty("NewMessageCryptoDisplay.noKeyIcon", "NoKey")); 226 if (keyIcon != null && noKeyIcon != null) { 227 JToggleButton returnValue = new JToggleButton(noKeyIcon, proxy.getCryptoInfo().getSignMessage() != NewMessageCryptoInfo.CRYPTO_NO); 228 229 returnValue.setSelectedIcon(keyIcon); 230 231 returnValue.addActionListener(new ActionListener () { 232 public void actionPerformed(ActionEvent e) { 233 boolean nowSelected = mSignatureEnabledButton.isSelected(); 234 mSignatureKeyButton.setEnabled(nowSelected); 235 if (nowSelected) 236 proxy.getCryptoInfo().setSignMessage(NewMessageCryptoInfo.CRYPTO_YES); 237 else 238 proxy.getCryptoInfo().setSignMessage(NewMessageCryptoInfo.CRYPTO_NO); 239 } 240 }); 241 returnValue.setSize(new java.awt.Dimension (keyIcon.getIconHeight(), keyIcon.getIconWidth())); 242 returnValue.setPreferredSize(new java.awt.Dimension (keyIcon.getIconHeight(), keyIcon.getIconWidth())); 243 244 return returnValue; 245 } 246 247 return null; 248 } 249 250 253 public void updateSignatureButton() { 254 Runnable runMe = new Runnable () { 255 public void run() { 256 Key current = getSignatureKey(); 257 if (current == null) 258 mSignatureKeyButton.setText(Pooka.getProperty("NewMessageCryptoPanel.signatureKey.none", "< Not Signed >")); 259 else 260 mSignatureKeyButton.setText(current instanceof EncryptionKey ? ((EncryptionKey)current).getDisplayAlias() : current.toString()); } 261 }; 262 263 if (SwingUtilities.isEventDispatchThread()) 264 runMe.run(); 265 else 266 SwingUtilities.invokeLater(runMe); 267 } 268 269 272 public JButton createClearSignatureButton() { 273 JButton returnValue = new JButton(Pooka.getProperty("NewMessageCryptoPanel.clearButton.label", "Clear Key")); 274 returnValue.addActionListener(proxy.getAction("message-clear-signature")); 275 return returnValue; 276 } 277 278 281 public Key getSignatureKey() { 282 return proxy.getCryptoInfo().getSignatureKey(); 283 } 284 285 288 public void setSignatureKey(Key pSignatureKey) { 289 proxy.getCryptoInfo().setSignatureKey(pSignatureKey); 290 updateSignatureButton(); 291 } 292 293 296 public void setEncryptMessage(int encryptValue) { 297 proxy.getCryptoInfo().setEncryptMessage(encryptValue); 298 } 299 300 303 public void setSignMessage(int signValue) { 304 proxy.getCryptoInfo().setSignMessage(signValue); 305 } 306 307 310 public void attachEncryptionKey(Key cryptKey) { 311 proxy.getCryptoInfo().attachEncryptionKey(cryptKey); 312 } 313 314 317 public void removeEncryptionKey(Key cryptKey) { 318 proxy.getCryptoInfo().removeEncryptionKey(cryptKey); 319 } 320 321 324 public void cryptoUpdated(int newSignatureStatus, int newEncryptionStatus) { 325 326 } 327 328 331 public void cryptoUpdated(net.suberic.pooka.MessageCryptoInfo cryptoInfo) { 332 333 } 334 335 336 } 337 | Popular Tags |