KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > security > cert > CertGeneralViewPanel


1
2 package com.ca.commons.security.cert;
3
4 import java.awt.*;
5 import java.awt.event.*;
6 import javax.swing.*;
7 import java.util.StringTokenizer JavaDoc;
8 import java.text.SimpleDateFormat JavaDoc;
9
10 import java.security.cert.*;
11
12 import com.ca.commons.cbutil.CBToolBarButton;
13
14 /**
15  * First tab: Display general information about the certificate.
16  * Intended for, Issued to, Issued by, Valid from .. to ..,
17  * &Install Certificate... button, Issuer &Statement... button disabled.
18  *
19  * @author vbui
20  */

21 public class CertGeneralViewPanel extends JPanel
22 {
23     private X509Certificate cert = null;
24
25     // visual elements
26
private CBToolBarButton installCertificateButton = new CBToolBarButton("&Install Certificate...", null);
27     private CBToolBarButton issuerStatementButton = new CBToolBarButton("Issuer &Statement...", null);
28
29     private JLabel topLabel = new JLabel("Certificate Information",
30             CertViewer.certLargeIcon, SwingConstants.LEFT);
31
32     private JLabel intendLabel = new JLabel("This certificate:");
33     private JTextArea intend = new JTextArea(7, 20);
34     private JLabel subjectLabel = new JLabel("Issued to:");
35     private JLabel subject = new JLabel("subject");
36     private JLabel issuerLabel = new JLabel("Issued by:");
37     private JLabel issuer = new JLabel("issuer");
38     private JLabel fromLabel = new JLabel("Valid from");
39     private JLabel from = new JLabel("from");
40     private JLabel toLabel = new JLabel("to");
41     private JLabel to = new JLabel("to");
42
43     /**
44      * Constructor.
45      */

46     public CertGeneralViewPanel(X509Certificate cert)
47     {
48         this.cert = cert;
49
50         // prepare visual elements
51
installCertificateButton.setWidthHeight(110, 23);
52         issuerStatementButton.setWidthHeight(110, 23);
53
54         installCertificateButton.setEnabled(false);
55         issuerStatementButton.setEnabled(false);
56
57         intend.setPreferredSize(new Dimension(200, 150));
58         intend.setMinimumSize(new Dimension(200, 150));
59         intend.setMaximumSize(new Dimension(200, 150));
60 /*
61 XXX - I believe formal use of the line separator class is unnecessary - I
62 believe java seamlessly translates between unicode character '\n' and the
63 system dependant line separator... (leaving code here in case I'm wrong :-) ) - CB
64
65         intend.setText(" Performs Windows System Component Verification" +
66                 Constants.ls +
67                 " Performs Windows Hardware Driver Verification" +
68                 Constants.ls +
69                 " Allows data on disk to be encrypted" +
70                 Constants.ls +
71                 " Allows secured communication on Internet" +
72                 Constants.ls +
73                 " ...");
74 */

75         intend.setText(" Performs Windows System Component Verification" +
76                 "\n Performs Windows Hardware Driver Verification" +
77                 "\n Allows data on disk to be encrypted" +
78                 "\n Allows secured communication on Internet" +
79                 "\n ...");
80
81         intend.setEditable(false);
82
83         // copied from com ca pki util Constants to decouple from the pki packages
84
Font courierBoldFont = new Font("SansSerif", Font.BOLD, 11);
85
86         topLabel.setFont(courierBoldFont);
87         intendLabel.setFont(courierBoldFont);
88         subjectLabel.setFont(courierBoldFont);
89         issuerLabel.setFont(courierBoldFont);
90         fromLabel.setFont(courierBoldFont);
91         toLabel.setFont(courierBoldFont);
92
93         JPanel generalPanel = new JPanel();
94         generalPanel.setBackground(Color.white);
95
96         JScrollPane intendScroll = new JScrollPane(intend);
97         intendScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
98
99         if (cert != null)
100         {
101             SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc("EEE, MMM d, yyyy");
102             from.setText(df.format(cert.getNotBefore()));
103             to.setText(df.format(cert.getNotAfter()));
104
105             subject.setText(CertViewer.getMostSignificantName(cert.getSubjectX500Principal().getName()));
106             issuer.setText(CertViewer.getMostSignificantName(cert.getIssuerX500Principal().getName()));
107         }
108
109         // layout
110
JPanel bottomPanel = new JPanel();
111         bottomPanel.setBackground(Color.white);
112         bottomPanel.setLayout(new GridBagLayout());
113         bottomPanel.add(subjectLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0,
114                 GridBagConstraints.CENTER, GridBagConstraints.NONE,
115                 new Insets(0, 30, 6, 0), 0, 0));
116         bottomPanel.add(subject, new GridBagConstraints(1, 0, 3, 1, 1.0, 1.0,
117                 GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL,
118                 new Insets(1, 5, 6, 0), 0, 0));
119         bottomPanel.add(issuerLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0,
120                 GridBagConstraints.CENTER, GridBagConstraints.NONE,
121                 new Insets(0, 30, 6, 0), 0, 0));
122         bottomPanel.add(issuer, new GridBagConstraints(1, 1, 3, 1, 1.0, 1.0,
123                 GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL,
124                 new Insets(1, 5, 6, 0), 0, 0));
125         bottomPanel.add(fromLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 1.0,
126                 GridBagConstraints.CENTER, GridBagConstraints.NONE,
127                 new Insets(0, 30, 6, 0), 0, 0));
128         bottomPanel.add(from, new GridBagConstraints(1, 2, 1, 1, 0.0, 1.0,
129                 GridBagConstraints.EAST, GridBagConstraints.NONE,
130                 new Insets(1, 5, 6, 0), 0, 0));
131         bottomPanel.add(toLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 1.0,
132                 GridBagConstraints.CENTER, GridBagConstraints.NONE,
133                 new Insets(0, 5, 6, 0), 0, 0));
134         bottomPanel.add(to, new GridBagConstraints(3, 2, 1, 1, 1.0, 1.0,
135                 GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL,
136                 new Insets(1, 5, 6, 0), 0, 0));
137
138         generalPanel.setLayout(new GridBagLayout());
139         generalPanel.add(topLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
140                 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
141                 new Insets(10, 10, 6, 10), 0, 0));
142         generalPanel.add(new JSeparator(), new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0,
143                 GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
144                 new Insets(0, 10, 6, 10), 0, 0));
145         generalPanel.add(intendLabel, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
146                 GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
147                 new Insets(0, 10, 6, 10), 0, 0));
148         generalPanel.add(intendScroll, new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0,
149                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
150                 new Insets(0, 40, 6, 10), 0, 0));
151         generalPanel.add(new JSeparator(), new GridBagConstraints(0, 4, 1, 1, 1.0, 0.0,
152                 GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
153                 new Insets(6, 10, 6, 10), 0, 0));
154         generalPanel.add(bottomPanel, new GridBagConstraints(0, 5, 1, 1, 1.0, 1.0,
155                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
156                 new Insets(0, 10, 6, 10), 0, 0));
157
158         JPanel buttonsPanel = new JPanel();
159         buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
160
161         //buttonsPanel.add(installCertificateButton);
162
//buttonsPanel.add(issuerStatementButton);
163

164         setLayout(new GridBagLayout());
165         add(new JScrollPane(generalPanel), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
166                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
167                 new Insets(10, 10, 6, 10), 0, 0));
168         add(buttonsPanel, new GridBagConstraints(0, 3, 3, 1, 1.0, 0.0,
169                 GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL,
170                 new Insets(0, 10, 6, 5), 0, 0));
171
172         // add listeners
173
installCertificateButton.addActionListener(new ActionListener()
174         {
175             public void actionPerformed(ActionEvent e)
176             {
177                 installCertificateButton_actionPerformed(e);
178             }
179         });
180
181         issuerStatementButton.addActionListener(new ActionListener()
182         {
183             public void actionPerformed(ActionEvent e)
184             {
185                 issuerStatementButton_actionPerformed(e);
186             }
187         });
188     }
189
190     /**
191      * Install certificate action.
192      */

193     private void installCertificateButton_actionPerformed(ActionEvent e)
194     {
195         System.out.println("Install the certificate to this machine");
196     }
197
198     /**
199      * Issuer statement action.
200      */

201     private void issuerStatementButton_actionPerformed(ActionEvent e)
202     {
203         System.out.println("View issuer statement");
204     }
205 }
206
Popular Tags