File Source: CertificateInfoPanel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.sslcertificate.CertificateInfoPanel__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.core.dialogs.sslcertificate.CertificateInformationEntry;
26 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
28 import java.awt.Color;
29 import java.util.ArrayList;
30
31 import java.util.List;
32 import javax.swing.BorderFactory;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JScrollPane;
36 import javax.swing.text.SimpleAttributeSet;
37 import javax.swing.text.StyleConstants;
38
39 import net.miginfocom.swing.MigLayout;
40
41 /**
42 * Displays the certificate info panel. Listing various informational
43 * snippets about a certificate.
44 */
45 public class CertificateInfoPanel extends JScrollPane {
46
47 /**
48 * A version number for this class. It should be changed whenever the class
49 * structure is changed (or anything else that would prevent serialized
50 * objects being unserialized with the new class).
51 */
52 private static final long serialVersionUID = 1;
53 /** Certificate info list. */
54 private List<List<CertificateInformationEntry>> certificateInfo;
55 /** Certificate name. */
56 private String certificateName;
57 /** Content panel. */
58 private JPanel content;
59
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.sslcertificate.CertificateInfoPanel()
*
* Postconditions:
* this.certificateInfo == &new ArrayList(initComponents#2)
* init'ed(this.certificateName)
* this.content == &new JPanel(initComponents#1)
* new ArrayList(initComponents#2) num objects == 1
* new JPanel(initComponents#1) num objects == 1
*/
60 public CertificateInfoPanel() {
61 initComponents();
62 layoutComponents();
63 setViewportView(content);
64 }
65
66 private void initComponents() {
/*
P/P * Method: void initComponents()
*
* Postconditions:
* this.certificateInfo == &new ArrayList(initComponents#2)
* this.content == &new JPanel(initComponents#1)
* new ArrayList(initComponents#2) num objects == 1
* new JPanel(initComponents#1) num objects == 1
*/
67 content = new JPanel();
68 certificateInfo = new ArrayList<List<CertificateInformationEntry>>();
69 }
70
71 private void layoutComponents() {
/*
P/P * Method: void layoutComponents()
*
* Preconditions:
* this.certificateInfo != null
* init'ed(this.certificateName)
* this.content != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.text.TextLabel:getDocument(...)@86 != null
* com.dmdirc.addons.ui_swing.components.text.TextLabel:getDocument(...)@92 != null
* com.dmdirc.ui.core.dialogs.sslcertificate.CertificateInformationEntry:getValue(...)@86 != null
* com.dmdirc.ui.core.dialogs.sslcertificate.CertificateInformationEntry:getValue(...)@92 != null
* init'ed(java.awt.Color.RED)
* ...
*
* Test Vectors:
* com.dmdirc.ui.core.dialogs.sslcertificate.CertificateInformationEntry:isInvalid(...)@83: {0}, {1}
* com.dmdirc.ui.core.dialogs.sslcertificate.CertificateInformationEntry:isMissing(...)@89: {0}, {1}
* java.util.Iterator:hasNext(...)@79: {0}, {1}
* java.util.Iterator:hasNext(...)@80: {0}, {1}
*/
72 setBorder(BorderFactory.createTitledBorder("Information for " +
73 certificateName));
74 content.setVisible(false);
75 content.removeAll();
76 content.setLayout(new MigLayout("fillx, wmax 100%, wrap 2, pack"));
77
78 int i = 1;
79 for (List<CertificateInformationEntry> entry : certificateInfo) {
80 for (CertificateInformationEntry info : entry) {
81 content.add(new TextLabel(info.getTitle() + ": "), "alignx right");
82 final TextLabel text = new TextLabel(info.getValue(), false);
83 if (info.isInvalid()) {
84 SimpleAttributeSet sas = new SimpleAttributeSet();
85 StyleConstants.setForeground(sas, Color.RED);
86 text.getDocument().setParagraphAttributes(0, info.getValue().
87 length(), sas, true);
88 }
89 if (info.isMissing()) {
90 SimpleAttributeSet sas = new SimpleAttributeSet();
91 StyleConstants.setItalic(sas, true);
92 text.getDocument().setParagraphAttributes(0, info.getValue().
93 length(), sas, true);
94 }
95 content.add(text, "growx, pushx");
96 }
97 if (i < certificateInfo.size()) {
98 content.add(new JLabel(), "spanx, gaptop 2*unrel");
99 }
100 i++;
101 }
102 content.setVisible(true);
103 }
104
105 public void setInfo(final String certificateName,
106 final List<List<CertificateInformationEntry>> certificateInfo) {
/*
P/P * Method: void setInfo(String, List)
*
* Preconditions:
* this.content != null
*
* Postconditions:
* this.certificateInfo == One-of{certificateInfo, &new ArrayList(setInfo#1)}
* this.certificateInfo != null
* this.certificateName == certificateName
* init'ed(this.certificateName)
* new ArrayList(setInfo#1) num objects <= 1
*
* Test Vectors:
* certificateInfo: Inverse{null}, Addr_Set{null}
*/
107 this.certificateInfo = certificateInfo;
108 this.certificateName = certificateName;
109
110 if (certificateInfo == null) {
111 this.certificateInfo =
112 new ArrayList<List<CertificateInformationEntry>>();
113 }
114 layoutComponents();
115 }
116 }
SofCheck Inspector Build Version : 2.17854
| CertificateInfoPanel.java |
2009-Jun-25 01:54:24 |
| CertificateInfoPanel.class |
2009-Sep-02 17:04:16 |