View Javadoc
1 package org.neuclear.commons.crypto.passphraseagents.swing; 2 3 /* 4 * The NeuClear Project and it's libraries are 5 * (c) 2002-2004 Antilles Software Ventures SA 6 * For more information see: http://neuclear.org 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 import com.jgoodies.plaf.HeaderStyle; 24 import com.jgoodies.plaf.Options; 25 import org.neuclear.commons.crypto.passphraseagents.icons.IconTools; 26 import org.neuclear.commons.crypto.passphraseagents.swing.actions.NewPersonalityAction; 27 import org.neuclear.commons.crypto.passphraseagents.swing.actions.OpenKeyStoreAction; 28 import org.neuclear.commons.crypto.passphraseagents.swing.actions.SaveKeyStoreAction; 29 import org.neuclear.commons.crypto.signers.*; 30 import org.neuclear.commons.swing.Messages; 31 32 import javax.swing.*; 33 import javax.swing.event.ListSelectionListener; 34 import java.awt.*; 35 import java.security.KeyStoreException; 36 import java.util.ArrayList; 37 import java.util.Iterator; 38 import java.util.Vector; 39 import java.util.prefs.Preferences; 40 41 /*** 42 * User: pelleb 43 * Date: Apr 7, 2004 44 * Time: 9:55:37 AM 45 */ 46 public class KeyStorePanel extends JPanel { 47 public KeyStorePanel(BrowsableSigner signer) { 48 // SwingTools.setLAF(); 49 this.signer = signer; 50 prefs = Preferences.userNodeForPackage(DefaultSigner.class); 51 52 53 setLayout(new BorderLayout()); 54 toolbar = new JToolBar(); 55 toolbar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.SINGLE); 56 toolbar.setFloatable(true); 57 toolbar.setRollover(true); 58 actions = new ArrayList(3); 59 addAction(new OpenKeyStoreAction(signer), true); 60 addAction(new SaveKeyStoreAction(signer), true); 61 toolbar.addSeparator(); 62 addAction(new NewPersonalityAction(this), false); 63 add(toolbar, BorderLayout.NORTH); 64 65 list = new JList(); 66 if (signer instanceof PersonalSigner) 67 list.setModel((ListModel) signer); 68 // list.setBorder(BorderFactory.createLoweredBevelBorder()); 69 list.setCellRenderer(new KeyStoreListCellRenderer()); 70 add(new JScrollPane(list), BorderLayout.CENTER); 71 // nad = new NewAliasDialog(this); 72 fillAliasList(); 73 74 } 75 76 public JButton addAction(Action action, boolean tiny) { 77 JButton button = new JButton(action); 78 if (tiny) { 79 button.setText(null); 80 button.putClientProperty(Options.IS_NARROW_KEY, Boolean.TRUE); 81 } 82 toolbar.add(button); 83 actions.add(action); 84 return button; 85 } 86 87 88 void updateList(String alias) { 89 if (alias != null) { 90 fillAliasList(); 91 list.setSelectedValue(alias, true); 92 // message.info(alias + " added"); 93 // SaveKeyStore.save(signer, message); 94 95 } 96 } 97 98 public Action[] getFileActions() { 99 return getActions(); 100 } 101 102 public Action[] getActions() { 103 Action array[] = new Action[actions.size()]; 104 for (int i = 0; i < actions.size(); i++) { 105 array[i] = (Action) actions.get(i); 106 107 } 108 return array; 109 } 110 111 public JLabel getLabel() { 112 JLabel idlabel = new JLabel(Messages.getText("identities")); 113 idlabel.setIcon(IconTools.getPersonalities()); 114 idlabel.setLabelFor(list); 115 return idlabel; 116 } 117 118 private void fillAliasList() { 119 try { 120 if (signer == null || signer instanceof PersonalSigner) 121 return; 122 Iterator iter = signer.iterator(); 123 Vector vector = new Vector(); 124 while (iter.hasNext()) { 125 Object o = iter.next(); 126 vector.add(o); 127 } 128 list.setListData(vector); 129 } catch (KeyStoreException e) { 130 e.printStackTrace(); 131 } 132 } 133 134 public void addListSelectionListener(ListSelectionListener listener) { 135 list.addListSelectionListener(listener); 136 } 137 138 public BrowsableSigner getSigner() { 139 return signer; 140 } 141 142 public String getSelectedValue() { 143 return (String) list.getSelectedValue(); 144 } 145 146 public JList getList() { 147 return list; 148 } 149 150 final private BrowsableSigner signer; 151 private String lastSelected; 152 private final JList list; 153 private final JToolBar toolbar; 154 private final ArrayList actions; 155 // private final NewAliasDialog nad; 156 private final Preferences prefs; 157 158 159 private static final String DEFAULT_ALIAS = "DEFAULT_ALIAS"; 160 161 162 public static void main(String args[]) { 163 JFrame frame = new JFrame(); 164 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 165 try { 166 final KeyStorePanel panel = new KeyStorePanel(new TestCaseSigner()); 167 frame.getContentPane().add(panel); 168 } catch (InvalidPassphraseException e) { 169 e.printStackTrace(); 170 System.exit(1); 171 } 172 frame.pack(); 173 frame.show(); 174 } 175 176 public int getSelectedIndex() { 177 return list.getSelectedIndex(); 178 } 179 180 public void setSelectedIndex(int i) { 181 list.setSelectedIndex(i); 182 183 } 184 185 public void setSelectedValue(String s, boolean b) { 186 list.setSelectedValue(s, b); 187 188 } 189 190 public ListModel getModel() { 191 return list.getModel(); 192 } 193 194 }

This page was automatically generated by Maven