From 5d458cc1c35d036632abee42e884bb583ab1a4e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 20 Jan 2009 07:30:23 +0100 Subject: [PATCH] Add list display for a key store. --- .../jkeytool/gui/ListKeyStorePanel.java | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java diff --git a/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java b/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java new file mode 100644 index 0000000..d935b01 --- /dev/null +++ b/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java @@ -0,0 +1,89 @@ +/* + * jkeytool - ListKeyStorePanel.java - + * Copyright © 2009 David Roden + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.pterodactylus.jkeytool.gui; + +import java.awt.BorderLayout; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.util.Collections; + +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * TODO + * + * @author David Roden <droden@gmail.com> + */ +public class ListKeyStorePanel extends AbstractKeyStorePanel implements ListSelectionListener { + + /** The list model containing all aliases. */ + private final DefaultListModel listModel = new DefaultListModel(); + + /** The list. */ + private final JList entryList = new JList(listModel); + + /** + * Creates a new key store panel that displays all entry aliases in a list. + * + * @param keyStore + * The key store to display + */ + public ListKeyStorePanel(KeyStore keyStore) { + super(keyStore); + try { + for (String alias : Collections.list(keyStore.aliases())) { + listModel.addElement(alias); + } + } catch (KeyStoreException kse1) { + kse1.printStackTrace(); + } + construct(); + entryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + entryList.addListSelectionListener(this); + } + + /** + * {@inheritDoc} + */ + @Override + protected void createEntryPanel() { + add(entryList, BorderLayout.WEST); + } + + // + // INTERFACE ListSelectionListener + // + + /** + * {@inheritDoc} + */ + public void valueChanged(ListSelectionEvent listSelectionEvent) { + if (listSelectionEvent.getValueIsAdjusting()) { + return; + } + Object object = entryList.getSelectedValue(); + selectedEntry((String) object); + } + +} -- 2.7.4