1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package org.jemmy.browser;
  25 
  26 import java.util.ArrayList;
  27 import java.util.Collection;
  28 import java.util.Collections;
  29 import java.util.HashMap;
  30 import javax.swing.table.DefaultTableModel;
  31 import org.jemmy.control.Wrap;
  32 
  33 /**
  34  *
  35  * @author shura
  36  */
  37 public class PropertiesPanel extends javax.swing.JPanel {
  38 
  39     DefaultTableModel model;
  40 
  41     /** Creates new form PropertiesPanel */
  42     public PropertiesPanel() {
  43         model = new DefaultTableModel();
  44         model.addColumn("Property");
  45         model.addColumn("Class");
  46         model.addColumn("Value");
  47         initComponents();
  48     }
  49 
  50     public DefaultTableModel getTableModel() {
  51         return model;
  52     }
  53 
  54     public void setWrap(Wrap<?> control) {
  55         while (getTableModel().getRowCount() > 0) {
  56             getTableModel().removeRow(0);
  57         }
  58         if (control != null) {
  59             HashMap<String, Object> props = control.getPropertiesQiuet();
  60             Object val;
  61             ArrayList<String> propNames = new ArrayList<String>(props.keySet());
  62             Collections.sort(propNames);
  63             for (String pk : propNames) {
  64                 val = props.get(pk);
  65                 if(val != null) {
  66                     model.addRow(new Object[]{pk, val.getClass().getName(), val.toString()});
  67                 } else {
  68                     model.addRow(new Object[]{pk, "null", "null"});
  69                 }
  70             }
  71         }
  72         revalidate();
  73     }
  74 
  75     /** This method is called from within the constructor to
  76      * initialize the form.
  77      * WARNING: Do NOT modify this code. The content of this method is
  78      * always regenerated by the Form Editor.
  79      */
  80     @SuppressWarnings("unchecked")
  81     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  82     private void initComponents() {
  83 
  84         jScrollPane1 = new javax.swing.JScrollPane();
  85         jTable1 = new javax.swing.JTable();
  86 
  87         jTable1.setModel(getTableModel());
  88         jScrollPane1.setViewportView(jTable1);
  89 
  90         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  91         this.setLayout(layout);
  92         layout.setHorizontalGroup(
  93             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  94             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
  95         );
  96         layout.setVerticalGroup(
  97             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
  99         );
 100     }// </editor-fold>//GEN-END:initComponents
 101     // Variables declaration - do not modify//GEN-BEGIN:variables
 102     private javax.swing.JScrollPane jScrollPane1;
 103     private javax.swing.JTable jTable1;
 104     // End of variables declaration//GEN-END:variables
 105 }