
org.jemmy.browser.ReflectionPanel Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
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
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy