1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   3  *
   4  * Copyright 2007-2009 Sun Microsystems, Inc. All rights reserved.
   5  *
   6  * The contents of this file are subject to the terms of the
   7  * Common Development and Distribution License (the "License").
   8  * You may not use this file except in compliance with the License.
   9  *
  10  * You can obtain a copy of the license at LICENSE.html or
  11  * http://www.sun.com/cddl.
  12  * See the License for the specific language governing permissions
  13  * and limitations under the License.
  14  *
  15  * When distributing Covered Code, include this License Header
  16  * Notice in each file.
  17  *
  18  * If applicable, add the following below the
  19  * License Header, with the fields enclosed by brackets [] replaced by
  20  * your own identifying information:
  21  * "Portions Copyrighted [year] [name of copyright owner]"
  22  *
  23  * Contributor(s): Alexandre (Shura) Iline. (shurymury@gmail.com)
  24  *
  25  * The Original Software is the Jemmy library.
  26  * The Initial Developer of the Original Software is Alexandre Iline.
  27  * All Rights Reserved.
  28  *
  29  */
  30 
  31 /*
  32  * PropertiesPanel.java
  33  *
  34  * Created on Nov 24, 2009, 10:15:05 PM
  35  */
  36 package org.jemmy.browser;
  37 
  38 import java.util.ArrayList;
  39 import java.util.Collection;
  40 import java.util.Collections;
  41 import java.util.HashMap;
  42 import javax.swing.table.DefaultTableModel;
  43 import org.jemmy.control.Wrap;
  44 
  45 /**
  46  *
  47  * @author shura
  48  */
  49 public class PropertiesPanel extends javax.swing.JPanel {
  50 
  51     DefaultTableModel model;
  52 
  53     /** Creates new form PropertiesPanel */
  54     public PropertiesPanel() {
  55         model = new DefaultTableModel();
  56         model.addColumn("Property");
  57         model.addColumn("Class");
  58         model.addColumn("Value");
  59         initComponents();
  60     }
  61 
  62     public DefaultTableModel getTableModel() {
  63         return model;
  64     }
  65 
  66     public void setWrap(Wrap<?> control) {
  67         while (getTableModel().getRowCount() > 0) {
  68             getTableModel().removeRow(0);
  69         }
  70         if (control != null) {
  71             HashMap<String, Object> props = control.getPropertiesQiuet();
  72             Object val;
  73             ArrayList<String> propNames = new ArrayList<String>(props.keySet());
  74             Collections.sort(propNames);
  75             for (String pk : propNames) {
  76                 val = props.get(pk);
  77                 if(val != null) {
  78                     model.addRow(new Object[]{pk, val.getClass().getName(), val.toString()});
  79                 } else {
  80                     model.addRow(new Object[]{pk, "null", "null"});
  81                 }
  82             }
  83         }
  84         revalidate();
  85     }
  86 
  87     /** This method is called from within the constructor to
  88      * initialize the form.
  89      * WARNING: Do NOT modify this code. The content of this method is
  90      * always regenerated by the Form Editor.
  91      */
  92     @SuppressWarnings("unchecked")
  93     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  94     private void initComponents() {
  95 
  96         jScrollPane1 = new javax.swing.JScrollPane();
  97         jTable1 = new javax.swing.JTable();
  98 
  99         jTable1.setModel(getTableModel());
 100         jScrollPane1.setViewportView(jTable1);
 101 
 102         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
 103         this.setLayout(layout);
 104         layout.setHorizontalGroup(
 105             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 106             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
 107         );
 108         layout.setVerticalGroup(
 109             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 110             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
 111         );
 112     }// </editor-fold>//GEN-END:initComponents
 113     // Variables declaration - do not modify//GEN-BEGIN:variables
 114     private javax.swing.JScrollPane jScrollPane1;
 115     private javax.swing.JTable jTable1;
 116     // End of variables declaration//GEN-END:variables
 117 }