--- /dev/null 2018-01-03 13:55:22.000000000 -0800 +++ new/core/JemmyBrowser/src/org/jemmy/browser/ReflectionPanel.java 2018-01-03 13:55:21.000000000 -0800 @@ -0,0 +1,132 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007-2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at LICENSE.html or + * http://www.sun.com/cddl. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this License Header + * Notice in each file. + * + * If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): Alexandre (Shura) Iline. (shurymury@gmail.com) + * + * The Original Software is the Jemmy library. + * The Initial Developer of the Original Software is Alexandre Iline. + * All Rights Reserved. + * + */ + +/* + * ReflectionPanel.java + * + * Created on Nov 26, 2009, 7:14:24 PM + */ + +package org.jemmy.browser; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; + +/** + * + * @author shura + */ +public class ReflectionPanel extends javax.swing.JPanel { + + DefaultTreeModel model; + /** Creates new form ReflectionPanel */ + public ReflectionPanel() { + initComponents(); + DefaultMutableTreeNode root = new DefaultMutableTreeNode(""); + model = new DefaultTreeModel(root); + tree.setModel(model); + } + + public DefaultTreeModel getTreeModel() { + return model; + } + + public void setControl(Class controlClass) { + DefaultMutableTreeNode root = new DefaultMutableTreeNode(); + Class cls =controlClass; + do { + root.add(getClassNode(cls)); + } while((cls = cls.getSuperclass()) != null); + for(Class i : controlClass.getInterfaces()) { + root.add(getClassNode(i)); + } + model.setRoot(root); + tree.setModel(model); + revalidate(); + } + + private DefaultMutableTreeNode getClassNode(Class cls) { + DefaultMutableTreeNode classNode = new DefaultMutableTreeNode( + (cls.isInterface() ? "Interface " : "Class ") + + cls.getName()); + for(Method m : cls.getMethods()) { + StringBuffer signature = new StringBuffer(m.getReturnType().getName()); + signature.append(" " + m.getName() + "("); + for(int i = 0; i < m.getParameterTypes().length; i++) { + signature.append(m.getParameterTypes()[i].getName()); + if((i < m.getParameterTypes().length - 1)) { + signature.append(","); + } + } + signature.append(")"); + classNode.add(new DefaultMutableTreeNode(signature.toString())); + } + for(Field m : cls.getFields()) { + classNode.add(new DefaultMutableTreeNode(m.getType().getName() + " " + m.getName())); + } + return classNode; + } + + + /** 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + tree = new javax.swing.JTree(); + + jScrollPane1.setViewportView(tree); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTree tree; + // End of variables declaration//GEN-END:variables + +}