2 * jkeytool - ListKeyStorePanel.java -
3 * Copyright © 2009 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.jkeytool.gui;
22 import java.awt.BorderLayout;
23 import java.security.KeyStore;
24 import java.security.KeyStoreException;
25 import java.util.Collections;
27 import javax.swing.DefaultListModel;
28 import javax.swing.JList;
29 import javax.swing.ListSelectionModel;
30 import javax.swing.event.ListSelectionEvent;
31 import javax.swing.event.ListSelectionListener;
36 * @author David Roden <droden@gmail.com>
38 public class ListKeyStorePanel extends AbstractKeyStorePanel implements ListSelectionListener {
40 /** The list model containing all aliases. */
41 private final DefaultListModel listModel = new DefaultListModel();
44 private final JList entryList = new JList(listModel);
47 * Creates a new key store panel that displays all entry aliases in a list.
50 * The key store to display
52 public ListKeyStorePanel(KeyStore keyStore) {
55 for (String alias : Collections.list(keyStore.aliases())) {
56 listModel.addElement(alias);
58 } catch (KeyStoreException kse1) {
59 kse1.printStackTrace();
62 entryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
63 entryList.addListSelectionListener(this);
70 protected void createEntryPanel() {
71 add(entryList, BorderLayout.WEST);
75 // INTERFACE ListSelectionListener
81 public void valueChanged(ListSelectionEvent listSelectionEvent) {
82 if (listSelectionEvent.getValueIsAdjusting()) {
85 Object object = entryList.getSelectedValue();
86 selectedEntry((String) object);