d935b0191055b328212a2687dd6a0e19f2d064d2
[jkeytool.git] / src / net / pterodactylus / jkeytool / gui / ListKeyStorePanel.java
1 /*
2  * jkeytool - ListKeyStorePanel.java -
3  * Copyright © 2009 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package net.pterodactylus.jkeytool.gui;
21
22 import java.awt.BorderLayout;
23 import java.security.KeyStore;
24 import java.security.KeyStoreException;
25 import java.util.Collections;
26
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;
32
33 /**
34  * TODO
35  *
36  * @author David Roden <droden@gmail.com>
37  */
38 public class ListKeyStorePanel extends AbstractKeyStorePanel implements ListSelectionListener {
39
40         /** The list model containing all aliases. */
41         private final DefaultListModel listModel = new DefaultListModel();
42
43         /** The list. */
44         private final JList entryList = new JList(listModel);
45
46         /**
47          * Creates a new key store panel that displays all entry aliases in a list.
48          *
49          * @param keyStore
50          *            The key store to display
51          */
52         public ListKeyStorePanel(KeyStore keyStore) {
53                 super(keyStore);
54                 try {
55                         for (String alias : Collections.list(keyStore.aliases())) {
56                                 listModel.addElement(alias);
57                         }
58                 } catch (KeyStoreException kse1) {
59                         kse1.printStackTrace();
60                 }
61                 construct();
62                 entryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
63                 entryList.addListSelectionListener(this);
64         }
65
66         /**
67          * {@inheritDoc}
68          */
69         @Override
70         protected void createEntryPanel() {
71                 add(entryList, BorderLayout.WEST);
72         }
73
74         //
75         // INTERFACE ListSelectionListener
76         //
77
78         /**
79          * {@inheritDoc}
80          */
81         public void valueChanged(ListSelectionEvent listSelectionEvent) {
82                 if (listSelectionEvent.getValueIsAdjusting()) {
83                         return;
84                 }
85                 Object object = entryList.getSelectedValue();
86                 selectedEntry((String) object);
87         }
88
89 }