File Source: SSLCertificateDialog.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.sslcertificate.SSLCertificateDialog__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.SSLCertificateDialogModel;
26 import com.dmdirc.addons.ui_swing.components.StandardDialog;
27 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
28
29 import java.awt.Window;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32
33 import javax.swing.JButton;
34 import javax.swing.event.ListSelectionEvent;
35 import javax.swing.event.ListSelectionListener;
36
37 import net.miginfocom.swing.MigLayout;
38
39 /**
40 * SSL Certificate information dialog. Also provides the ability to accept and
41 * reject certificates whilst connecting to an SSL server.
42 */
43 public class SSLCertificateDialog extends StandardDialog implements ActionListener,
44 ListSelectionListener {
45
46 /**
47 * A version number for this class. It should be changed whenever the class
48 * structure is changed (or anything else that would prevent serialized
49 * objects being unserialized with the new class).
50 */
51 private static final long serialVersionUID = 1;
52 /** SSL Certificate dialog model. */
53 private SSLCertificateDialogModel model;
54 /** Panel listing actions that can be taken on a certificate. */
55 private ActionsPanel actions;
56 /** Panel showing the certificate chain of a certificate. */
57 private CertificateChainPanel chain;
58 /** Panel showing the information available for a certificate. */
59 private CertificateInfoPanel info;
60 /** Panel showing a summary of the certificate information. */
61 private SummaryPanel summary;
62 /** Informational blurb. */
63 private TextLabel blurb;
64 /** Parent window. */
65 private Window parent;
66 /** Selected index. */
67 private int selectedIndex;
68
69 /**
70 * Creates a new instance of ActionsManagerDialog.
71 *
72 * @param parent Parent window for the dialog
73 * @param model dialog model
74 */
75 public SSLCertificateDialog(final Window parent,
76 final SSLCertificateDialogModel model) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.sslcertificate.SSLCertificateDialog(Window, SSLCertificateDialogModel)
*
* Preconditions:
* model != null
*
* Presumptions:
* init'ed(java.awt.Dialog$ModalityType.MODELESS)
*
* Postconditions:
* this.actions == &new ActionsPanel(initComponents#3)
* this.blurb == &new TextLabel(initComponents#7)
* this.chain == &new CertificateChainPanel(initComponents#4)
* this.info == &new CertificateInfoPanel(initComponents#5)
* this.model == model
* this.model != null
* this.parent == parent
* init'ed(this.parent)
* init'ed(this.selectedIndex)
* this.summary == &new SummaryPanel(initComponents#6)
* ...
*/
77 super(parent, ModalityType.MODELESS);
78
79 this.parent = parent;
80 this.model = model;
81 this.selectedIndex = 0;
82
83 initComponents();
84 addListeners();
85 layoutComponents();
86
87 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
88 setTitle("DMDirc: Certificate Information");
89 setResizable(false);
90 pack();
91 setLocationRelativeTo(parent);
92 chain.setSelectedIndex(0);
93 }
94
95 private void addListeners() {
/*
P/P * Method: void addListeners()
*
* Preconditions:
* this.chain != null
* this.chain.list != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.dialogs.sslcertificate.SSLCertificateDialog:getCancelButton(...)@97 != null
* com.dmdirc.addons.ui_swing.dialogs.sslcertificate.SSLCertificateDialog:getOkButton(...)@96 != null
*/
96 getOkButton().addActionListener(this);
97 getCancelButton().addActionListener(this);
98 chain.addListSelectionListener(this);
99 }
100
101 private void initComponents() {
/*
P/P * Method: void initComponents()
*
* Preconditions:
* this.model != null
*
* Presumptions:
* com.dmdirc.ui.core.dialogs.sslcertificate.SSLCertificateDialogModel:getSummary(...)@110 != null
*
* Postconditions:
* this.actions == &new ActionsPanel(initComponents#3)
* this.blurb == &new TextLabel(initComponents#7)
* this.chain == &new CertificateChainPanel(initComponents#4)
* init'ed(this.chain.certificateChain)
* this.info == &new CertificateInfoPanel(initComponents#5)
* this.summary == &new SummaryPanel(initComponents#6)
* init'ed(this.summary.summary)
* new ActionsPanel(initComponents#3) num objects == 1
* new ArrayList(SummaryPanel#1) num objects == 1
* new ArrayList(initComponents#2) num objects == 1
* ...
*
* Test Vectors:
* com.dmdirc.ui.core.dialogs.sslcertificate.SSLCertificateDialogModel:needsResponse(...)@113: {0}, {1}
*/
102 orderButtons(new JButton(), new JButton());
103 actions = new ActionsPanel();
104 chain = new CertificateChainPanel();
105 info = new CertificateInfoPanel();
106 summary = new SummaryPanel();
107 blurb = new TextLabel();
108
109 chain.setChain(model.getCertificateChain());
110 summary.setSummary(model.getSummary());
111
112 actions.setVisible(model.needsResponse());
113 if (model.needsResponse()) {
114 blurb.setText("Theres is a problem with the certificate used by " +
115 model.getServerName());
116 } else {
117 blurb.setText("Your connection to " + model.getServerName() +
118 " is encrypted using SSL.");
119 }
120 }
121
122 private void layoutComponents() {
/*
P/P * Method: void layoutComponents()
*
* Preconditions:
* init'ed(this.actions)
* init'ed(this.blurb)
* init'ed(this.chain)
* init'ed(this.info)
* init'ed(this.summary)
*/
123 setLayout(new MigLayout("fill, wrap 2, wmin 600, wmax 600, hmax 600, hidemode 3, pack"));
124
125 add(blurb, "span 2");
126 add(chain, "wmax 250, grow");
127 add(info, "growx, pushx");
128 add(summary, "span 2, growx");
129 add(actions, "span 2, growx");
130 add(getOkButton(), "span, right");
131 }
132
133 /**
134 * {@inheritDoc}.
135 *
136 * @param e Action event
137 */
138 @Override
139 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* e != null
* (soft) this.actions != null
* (soft) this.actions.group != null
* (soft) this.actions.permAccept != null
* (soft) this.actions.tempAccept != null
* (soft) this.model != null
*
* Presumptions:
* java.awt.event.ActionEvent:getSource(...)@140 != null
*
* Test Vectors:
* java.lang.Object:equals(...)@140: {1}, {0}
*/
140 if (!e.getSource().equals(getCancelButton())) {
141 model.performAction(actions.getAction());
142 dispose();
143 }
144 }
145
146 @Override
147 public void valueChanged(final ListSelectionEvent e) {
/*
P/P * Method: void valueChanged(ListSelectionEvent)
*
* Preconditions:
* e != null
* (soft) init'ed(this.selectedIndex)
* (soft) this.chain != null
* (soft) this.chain.list != null
* (soft) this.chain.model != null
* (soft) this.info != null
* (soft) this.info.content != null
* (soft) this.model != null
*
* Postconditions:
* possibly_updated(this.info.certificateInfo)
* possibly_updated(this.info.certificateName)
* init'ed(this.selectedIndex)
* new ArrayList(setInfo#1) num objects <= 1
*
* Test Vectors:
* javax.swing.JList:getSelectedIndex(...)@102: {-231..-2, 0..232-1}, {-1}
* javax.swing.event.ListSelectionEvent:getValueIsAdjusting(...)@148: {1}, {0}
*/
148 if (!e.getValueIsAdjusting()) {
149 final int index = chain.getSelectedIndex();
150 if (index == -1) {
151 chain.setSelectedIndex(selectedIndex);
152 } else {
153 info.setInfo(chain.getName(index),
154 model.getCertificateInfo(index));
155 selectedIndex = index;
156 }
157 }
158 }
159 }
SofCheck Inspector Build Version : 2.17854
| SSLCertificateDialog.java |
2009-Jun-25 01:54:24 |
| SSLCertificateDialog.class |
2009-Sep-02 17:04:16 |