--- /dev/null 2018-01-03 13:55:19.000000000 -0800 +++ new/core/JemmyBrowser/src/org/jemmy/browser/InterfacesPanel.java 2018-01-03 13:55:19.000000000 -0800 @@ -0,0 +1,145 @@ +/* + * 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. + * + */ + +/* + * InterfacesPanel.java + * + * Created on Dec 2, 2009, 11:30:18 AM + */ +package org.jemmy.browser; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import javax.swing.table.DefaultTableModel; +import org.jemmy.control.ControlInterfaces; +import org.jemmy.control.Property; +import org.jemmy.control.Wrap; +import org.jemmy.interfaces.ControlInterface; +import org.jemmy.interfaces.InterfaceException; + +/** + * + * @author shura + */ +public class InterfacesPanel extends javax.swing.JPanel { + + private static final String OFFSET = " "; + Wrap wrap; + DefaultTableModel tableModel; + + /** Creates new form InterfacesPanel */ + public InterfacesPanel() { + tableModel = new DefaultTableModel(); + tableModel.addColumn("Interface/Property"); + tableModel.addColumn("Class/Value"); + initComponents(); + } + + public void setWrap(Wrap wrap) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + this.wrap = wrap; + buildModel(); + revalidate(); + } + + /** 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(); + interfacesTable = new javax.swing.JTable(); + + interfacesTable.setModel(getTableModel()); + jScrollPane1.setViewportView(interfacesTable); + + 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, 481, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTable interfacesTable; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables + + public DefaultTableModel getTableModel() { + return tableModel; + } + + private void buildModel() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + while (getTableModel().getRowCount() > 0) { + getTableModel().removeRow(0); + } + Class cls = wrap.getClass(); + ArrayList interfaces = + new ArrayList(); + do { + ControlInterfaces cis = ((Class) cls).getAnnotation(ControlInterfaces.class); + for (Class c : cis.value()) { + if (!interfaces.contains(c)) { + interfaces.add(c); + } + } + } while (Wrap.class.isAssignableFrom((cls = cls.getSuperclass()))); + Collections.sort(interfaces, new Comparator() { + public int compare(Object t, Object t1) { + return t.toString().compareTo(t1.toString()); + } + }); + for (Class c : interfaces) { + String iName = c.getName(); + try { + Object iInstance = wrap.as(c); + getTableModel().addRow(new Object[]{iName, iInstance.getClass().getName()}); + for (Method m : c.getMethods()) { + if (m.isAnnotationPresent(Property.class)) { + String name = m.getAnnotation(Property.class).value(); + getTableModel().addRow(new Object[]{OFFSET + name, wrap.getProperty(name, c)}); + } + } + } catch (InterfaceException e) { + //do nothing + } + } + } +}