📄 certificatetreepanel.java
字号:
/*** $Id: CertificateTreePanel.java,v 1.3 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail.smime;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Image;import java.io.IOException;import java.util.Enumeration;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTree;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.TreePath;import javax.swing.event.TreeSelectionListener;import iaik.asn1.ObjectID;import iaik.asn1.structures.Name;import iaik.x509.X509Certificate;import org.icemail.util.AWTUtilities;public class CertificateTreePanel extends JPanel{ private JTree tree; private DefaultTreeModel model; private JScrollPane scroller; private X509Certificate[] chain; public CertificateTreePanel( X509Certificate[] chain, TreeSelectionListener listener ) { super(); setLayout( new BorderLayout() ); this.tree = new JTree(); this.tree.getSelectionModel().addTreeSelectionListener( listener ); DefaultTreeCellRenderer defRend = new DefaultTreeCellRenderer() { /** * Overrides return slightly taller preferred size value. */ public Dimension getPreferredSize() { Dimension result = super.getPreferredSize(); if ( result != null ) result.height += 2; return result; } }; try { Icon icon; Image img; img = AWTUtilities.getImageResource( "/org/icemail/mail/images/topcert.gif" ); if ( img != null ) { icon = new ImageIcon( img ); defRend.setLeafIcon( icon ); defRend.setOpenIcon( icon ); defRend.setClosedIcon( icon ); } } catch ( IOException ex ) { } this.tree.setCellRenderer( defRend ); this.tree.putClientProperty( "JTree.lineStyle", "Angled" ); this.tree.setShowsRootHandles( true ); setCertificateChain( chain ); this.scroller = new JScrollPane( this.tree ); add( BorderLayout.CENTER, this.scroller ); } public void setCertificateChain( X509Certificate[] chain ) { this.chain = chain; CertificateNode rootNode = null; CertificateNode parentNode = null; // CertificateNode[] nodes =// new CertificateNode[ chain.length ]; for ( int i = 0 ; i < chain.length ; ++i ) { CertificateNode node = new CertificateNode( chain[i] );// nodes[i] = node; if ( parentNode == null ) { rootNode = node; } else { parentNode.add( node ); } parentNode = node; } this.model = new DefaultTreeModel( rootNode ); this.tree.setModel( this.model ); } public void expandAllNodes() { Enumeration enum = ((CertificateNode) this.model.getRoot()).children(); expandAll( enum ); } public void expandAll( Enumeration enum ) { for ( ; enum.hasMoreElements() ; ) { CertificateNode node = (CertificateNode) enum.nextElement(); if ( ! node.isLeaf() ) { this.tree.expandPath( new TreePath( node.getPath() ) ); expandAll( node.children() ); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -