KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > bridge > AcceptCertificate


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.bridge;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.FlowLayout JavaDoc;
25 import java.awt.Frame JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29 import javax.swing.BorderFactory JavaDoc;
30 import javax.swing.JButton JavaDoc;
31 import javax.swing.JDialog JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33
34 import org.openide.util.NbBundle;
35 /**
36  * Displays CertificatePanel to user. User must accept Certificate to continue.
37  * if user does not accept false is return.
38  *
39  * @author Ludo
40  */

41
42 public final class AcceptCertificate {
43     
44     private static JDialog JavaDoc d;
45     private static String JavaDoc command;
46     
47     /** If Certificate was not accepted during installation user must accept it here.
48      */

49     public static boolean acceptCertificatePanel (String JavaDoc certificate) throws Exception JavaDoc {
50         CertificatePanel CertificatePanel = new CertificatePanel(certificate);
51         ResourceBundle JavaDoc bundle = NbBundle.getBundle(AcceptCertificate.class);
52         String JavaDoc yesLabel = bundle.getString("MSG_CertificateYesButton");
53         String JavaDoc noLabel = bundle.getString("MSG_CertificateNoButton");
54         JButton JavaDoc yesButton = new JButton JavaDoc(yesLabel);
55         JButton JavaDoc noButton = new JButton JavaDoc(noLabel);
56
57         ActionListener JavaDoc listener = new ActionListener JavaDoc () {
58             public void actionPerformed (ActionEvent JavaDoc e) {
59                 command = e.getActionCommand();
60                 d.setVisible(false);
61             }
62         };
63         yesButton.addActionListener(listener);
64         noButton.addActionListener(listener);
65         
66         yesButton.setActionCommand("yes"); // NOI18N
67
noButton.setActionCommand("no"); // NOI18N
68

69         yesButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_AcceptButton"));
70         yesButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSD_AcceptButton"));
71         
72         noButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_RejectButton"));
73         noButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSD_RejectButton"));
74         
75         int maxWidth = Math.max(yesButton.getPreferredSize().width, noButton.getPreferredSize().width);
76         int maxHeight = Math.max(yesButton.getPreferredSize().height, noButton.getPreferredSize().height);
77         yesButton.setPreferredSize(new Dimension JavaDoc(maxWidth, maxHeight));
78         noButton.setPreferredSize(new Dimension JavaDoc(maxWidth, maxHeight));
79         
80         d = new JDialog JavaDoc((Frame JavaDoc) null,bundle.getString("MSG_CertificateDlgTitle"),true);
81         
82         d.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CertificateDlg"));
83         d.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CertificateDlg"));
84         
85         d.getContentPane().add(CertificatePanel,BorderLayout.CENTER);
86         JPanel JavaDoc buttonPanel = new JPanel JavaDoc();
87         buttonPanel.setLayout(new FlowLayout JavaDoc(FlowLayout.RIGHT));
88         buttonPanel.setBorder(BorderFactory.createEmptyBorder(17,12,11,11));
89         buttonPanel.add(yesButton);
90         buttonPanel.add(noButton);
91         d.getContentPane().add(buttonPanel,BorderLayout.SOUTH);
92         d.setSize(new Dimension JavaDoc(600,600));
93         d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
94         d.setModal(true);
95         d.setResizable(true);
96         //Center on screen
97
d.setLocationRelativeTo(null);
98         d.setVisible(true);
99         
100         if ("yes".equals(command)) { // NOI18N
101
return true;
102         } else {
103             return false;
104         }
105     }
106     
107
108 }
109
Popular Tags