File Source: CertificateChainPanel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.sslcertificate.CertificateChainPanel__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.ui_swing.dialogs.sslcertificate;
24
25 import com.dmdirc.ui.IconManager;
26 import com.dmdirc.ui.core.dialogs.sslcertificate.CertificateChainEntry;
27 import com.dmdirc.addons.ui_swing.components.ListScroller;
28 import com.dmdirc.addons.ui_swing.components.renderers.CertificateChainEntryCellRenderer;
29
30 import java.util.List;
31
32 import javax.swing.BorderFactory;
33 import javax.swing.DefaultListModel;
34 import javax.swing.JLabel;
35 import javax.swing.JList;
36 import javax.swing.JPanel;
37 import javax.swing.JScrollPane;
38 import javax.swing.ListSelectionModel;
39 import javax.swing.event.ListSelectionListener;
40
41 import net.miginfocom.swing.MigLayout;
42
43 /**
44 * Displays the certificate chain.
45 */
46 public class CertificateChainPanel extends JPanel {
47
48 /**
49 * A version number for this class. It should be changed whenever the class
50 * structure is changed (or anything else that would prevent serialized
51 * objects being unserialized with the new class).
52 */
53 private static final long serialVersionUID = 1;
54 /** Certificate chain list. */
55 private List<CertificateChainEntry> certificateChain;
56 /** Chain list. */
57 private JList list;
58 /** List model. */
59 private DefaultListModel model;
60
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.sslcertificate.CertificateChainPanel()
*
* Postconditions:
* this.list == &new JList(initComponents#2)
* this.model == &new DefaultListModel(initComponents#1)
* new DefaultListModel(initComponents#1) num objects == 1
* new JList(initComponents#2) num objects == 1
*/
61 public CertificateChainPanel() {
62 initComponents();
63 layoutComponents();
64 }
65
66 private void initComponents() {
/*
P/P * Method: void initComponents()
*
* Postconditions:
* this.list == &new JList(initComponents#2)
* this.model == &new DefaultListModel(initComponents#1)
* new DefaultListModel(initComponents#1) num objects == 1
* new JList(initComponents#2) num objects == 1
*/
67 model = new DefaultListModel();
68 list = new JList(model);
69 list.setCellRenderer(new CertificateChainEntryCellRenderer());
70 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
71 new ListScroller(list);
72 }
73
74 private void layoutComponents() {
/*
P/P * Method: void layoutComponents()
*
* Preconditions:
* init'ed(this.list)
*
* Presumptions:
* com.dmdirc.ui.IconManager:getIconManager(...)@79 != null
* com.dmdirc.ui.IconManager:getIconManager(...)@81 != null
*/
75 setBorder(BorderFactory.createTitledBorder("Certificate Chain"));
76 setLayout(new MigLayout("fillx, wrap 1"));
77
78 add(new JScrollPane(list), "grow, pushy");
79 add(new JLabel("Certificate is trusted", IconManager.getIconManager().
80 getIcon("tick"), JLabel.LEFT), "growx");
81 add(new JLabel("Problem with certificate", IconManager.getIconManager().
82 getIcon("cross"), JLabel.LEFT), "growx");
83 }
84
85 public void setChain(final List<CertificateChainEntry> certificateChain) {
/*
P/P * Method: void setChain(List)
*
* Preconditions:
* (soft) this.model != null
*
* Postconditions:
* this.certificateChain == certificateChain
* init'ed(this.certificateChain)
*
* Test Vectors:
* certificateChain: Inverse{null}, Addr_Set{null}
* java.util.Iterator:hasNext(...)@91: {0}, {1}
*/
86 this.certificateChain = certificateChain;
87
88 if (certificateChain == null) {
89 model.clear();
90 } else {
91 for (CertificateChainEntry entry : certificateChain) {
92 model.addElement(entry);
93 }
94 }
95 }
96
97 public String getName(final int index) {
/*
P/P * Method: String getName(int)
*
* Preconditions:
* this.model != null
*
* Presumptions:
* javax.swing.DefaultListModel:get(...)@98 != null
*
* Postconditions:
* init'ed(return_value)
*/
98 return ((CertificateChainEntry) model.get(index)).getName();
99 }
100
101 public int getSelectedIndex() {
/*
P/P * Method: int getSelectedIndex()
*
* Preconditions:
* this.list != null
*
* Postconditions:
* init'ed(return_value)
*/
102 return list.getSelectedIndex();
103 }
104
105 public void setSelectedIndex(final int index) {
/*
P/P * Method: void setSelectedIndex(int)
*
* Preconditions:
* this.list != null
*/
106 list.setSelectedIndex(index);
107 }
108
109 public void addListSelectionListener(final ListSelectionListener listener) {
/*
P/P * Method: void addListSelectionListener(ListSelectionListener)
*
* Preconditions:
* this.list != null
*/
110 list.addListSelectionListener(listener);
111 }
112 }
SofCheck Inspector Build Version : 2.17854
| CertificateChainPanel.java |
2009-Jun-25 01:54:24 |
| CertificateChainPanel.class |
2009-Sep-02 17:04:16 |