Add list display for a key store.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 20 Jan 2009 06:30:23 +0000 (07:30 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 20 Jan 2009 06:30:23 +0000 (07:30 +0100)
src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java [new file with mode: 0644]

diff --git a/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java b/src/net/pterodactylus/jkeytool/gui/ListKeyStorePanel.java
new file mode 100644 (file)
index 0000000..d935b01
--- /dev/null
@@ -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 &lt;droden@gmail.com&gt;
+ */
+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);
+       }
+
+}