📄 swingui.java
字号:
/* * Copyright (c) 2001-2005 Sun Microsystems, Inc. All rights reserved. * * The Sun Project JXTA(TM) Software License * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by Sun Microsystems, Inc. for JXTA(TM) technology." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must * not be used to endorse or promote products derived from this software * without prior written permission. For written permission, please contact * Project JXTA at http://www.jxta.org. * * 5. Products derived from this software may not be called "JXTA", nor may * "JXTA" appear in their name, without prior written permission of Sun. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN * MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * JXTA is a registered trademark of Sun Microsystems, Inc. in the United * States and other countries. * * Please see the license information page at : * <http://www.jxta.org/project/www/license.html> for instructions on use of * the license in source files. * * ==================================================================== * * This software consists of voluntary contributions made by many individuals * on behalf of Project JXTA. For more information on Project JXTA, please see * http://www.jxta.org. * * This license is based on the BSD license adopted by the Apache Foundation. */package tutorial.psesample;import net.jxta.credential.AuthenticationCredential;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredDocumentFactory;import net.jxta.document.XMLDocument;import net.jxta.exception.PeerGroupException;import net.jxta.exception.ProtocolNotSupportedException;import net.jxta.id.ID;import net.jxta.id.IDFactory;import net.jxta.impl.membership.pse.PSECredential;import net.jxta.impl.membership.pse.PSEMembershipService;import net.jxta.impl.membership.pse.PSEUtils;import net.jxta.impl.membership.pse.StringAuthenticator;import net.jxta.impl.protocol.Certificate;import net.jxta.peergroup.PeerGroup;import net.jxta.protocol.ModuleImplAdvertisement;import net.jxta.protocol.PeerGroupAdvertisement;import org.bouncycastle.asn1.DERSet;import org.bouncycastle.jce.PKCS10CertificationRequest;import org.bouncycastle.jce.X509Principal;import org.bouncycastle.jce.X509V3CertificateGenerator;import javax.crypto.EncryptedPrivateKeyInfo;import javax.swing.*;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.ByteArrayInputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.lang.reflect.UndeclaredThrowableException;import java.math.BigInteger;import java.security.*;import java.security.cert.CertificateEncodingException;import java.security.cert.X509Certificate;import java.util.*;/** * Main User Interface for the PSE Sample Peer Group application. * <p/> * <p/>Provides access to a wide variety of fun and interesting PSE operations. * <p/> * <p/>This user interface is appropriate for this sample application but is * not appropriate for real applications. The major difference is the strategy * used for dynamically updating buttons and panels. After some experimentation * and feedback it was decided that this application would not dynamically * enable and disable most buttons. By leaving all buttons enabled, but * including status messages when unavailable options are attempted developers * can better experiment and understand why the application behaves as it does. * <p/> * <p/>Real applications should not present users with unavailable options. */public class SwingUI extends javax.swing.JFrame { /** * The peer group which is the parent for our PSE peer group. Normally this * will be the Net Peer Group, but it is a bad idea to assume that it * always will be the Net Peer Group. * <p/> * <p/>The PSE peer group is instantiated into the parent peer group. The * parent peer group is also used for publishing our peer group * advertisement and the module implementation advertisement for the PSE * peer group. */ final PeerGroup parentgroup; /** * Our peer group object, the PSE Peer Group. */ final PeerGroup group; /** * The Membership service of the PSE Peer Group. */ final PSEMembershipService membership; /** * Credential which is created when the user successfully authenticates * for the invitation certificate. This requires that they know the * password used to encrypt the private key. */ PSECredential invitationCredential = null; /** * Authenticator which is used for generating the invitation credential. */ StringAuthenticator invitationAuthenticator = null; /** * Credential which is created when the user successfully authenticates * for the member certificate. This requires that they know the password * used to encrypt the private key. */ PSECredential memberCredential = null; /** * Authenticator which is used for generating the invitation credential. */ StringAuthenticator memberAuthenticator = null; /** * Credential which is created when the user successfully authenticates * for the owner certificate. This requires that they know the password * used to encrypt the private key. */ PSECredential ownerCredential = null; /** * Authenticator which is used for generating the invitation credential. */ StringAuthenticator ownerAuthenticator = null; /** * Creates new form SwingUI */ public SwingUI(PeerGroup parent, PeerGroupAdvertisement pse_pga) { parentgroup = parent; try { group = parentgroup.newGroup(pse_pga); } catch (PeerGroupException failed) { JOptionPane.showMessageDialog(null, failed.getMessage(), "Couldn't create PSE Peer Group", JOptionPane.ERROR_MESSAGE); throw new IllegalStateException("Can't continue without being able to create a peergroup."); } membership = (PSEMembershipService) group.getMembershipService(); initComponents(); membership.addPropertyChangeListener("defaultCredential", new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() {// FIXME 20050624 bondolo how do I tell the swing UI???? } }); } }); } /** * This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; javax.swing.JLabel invitationDescriptionText; javax.swing.JLabel invitationPasswordLabel; javax.swing.JLabel memberPasswordLabel; memberTab = new javax.swing.JPanel(); memberPasswordLabel = new javax.swing.JLabel(); memberPasswordField = new javax.swing.JPasswordField(); generateMemberCertButton = new javax.swing.JButton(); memberAuthenticateButton = new javax.swing.JButton(); memberGenerateCSRButton = new javax.swing.JButton(); memberImportCertButton = new javax.swing.JButton(); memberResignButton = new javax.swing.JButton(); adminTab = new javax.swing.JPanel(); adminSignCSRButton = new javax.swing.JButton(); adminInviteButton = new javax.swing.JButton(); adminInvitationPasswordLabel = new javax.swing.JLabel(); adminInvitationPasswordField = new javax.swing.JPasswordField(); ownerTab = new javax.swing.JPanel(); ownerSignCSRButton = new javax.swing.JButton(); ownerPasswordLabel = new javax.swing.JLabel(); ownerPasswordField = new javax.swing.JPasswordField(); ownerAuthenticateButton = new javax.swing.JButton(); ownerResignButton = new javax.swing.JButton(); invitationTab = new javax.swing.JPanel(); invitationDescriptionText = new javax.swing.JLabel(); invitationPasswordLabel = new javax.swing.JLabel(); invitationPasswordField = new javax.swing.JPasswordField(); invitationConfirmButton = new javax.swing.JButton(); keyStorePasswordLabel = new javax.swing.JLabel(); keyStorePasswordField = new javax.swing.JPasswordField(); tabs = new javax.swing.JTabbedPane(); authenticationStatus = new javax.swing.JTextField(); memberTab.setLayout(new java.awt.GridBagLayout()); memberTab.setToolTipText("Actions for Peer Group Members"); memberTab.setName("Member"); memberTab.setNextFocusableComponent(adminTab); if (membership.getPSEConfig().isInitialized()) { tabs.add(memberTab); } memberPasswordLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); memberPasswordLabel.setLabelFor(memberPasswordField); memberPasswordLabel.setText("Member Password"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 3); memberTab.add(memberPasswordLabel, gridBagConstraints); memberPasswordField.setColumns(16); memberPasswordField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { memberPasswordFieldActionPerformed(evt); } }); memberPasswordField.addKeyListener(new java.awt.event.KeyAdapter() { @Override public void keyReleased(java.awt.event.KeyEvent evt) { memberPasswordFieldKeyReleasedHandler(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.insets = new java.awt.Insets(4, 2, 2, 4); memberTab.add(memberPasswordField, gridBagConstraints); generateMemberCertButton.setText("Generate Certificate "); generateMemberCertButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { generateMemberCertButtonActionPerformed(evt); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -