View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans.
5    *
6    * CosyBeans is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * CosyBeans is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.infopanel;
21  
22  import java.awt.BorderLayout;
23  import java.beans.IntrospectionException;
24  import java.lang.reflect.InvocationTargetException;
25  
26  import javax.swing.JPanel;
27  import javax.swing.JScrollPane;
28  
29  import com.cosylab.gui.components.introspection.PropertiesTable;
30  
31  /**
32   * <code>PropertiesPanel</code> shows a table with all properties and their values
33   * of the set bean.
34   * 
35   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
36   * @version $Id: PropertiesPanel.java,v 1.4 2008-04-22 12:31:02 jbobnar Exp $
37   *
38   */
39  public class PropertiesPanel extends JPanel {
40  
41  	private static final long serialVersionUID = 1523647646017553287L;
42  	private PropertiesTable table;
43  	private JScrollPane tableScroll;
44  	private Object bean;
45  	
46  	/**
47  	 * Constructs a new PropertiesPanel.
48  	 *
49  	 */
50  	public PropertiesPanel() {
51  		super();
52  		initialize();
53  	}
54  	
55  	private void initialize() {
56  		this.setLayout(new BorderLayout());
57  		table = new PropertiesTable();
58  		table.setEnabled(false);
59  		tableScroll = new JScrollPane(table);
60  		this.add(tableScroll, BorderLayout.CENTER);
61  	}
62  	
63  	/**
64  	 * Sets the bean, which provides the data.
65  	 * 
66  	 * @param bean
67  	 */
68  	public void setBean(Object bean) {
69  		this.bean = bean;
70  		try {
71  			table.setBean(bean);
72  		} catch (IntrospectionException e) {
73  			e.printStackTrace();
74  		} catch (IllegalAccessException e) {
75  			e.printStackTrace();
76  		} catch (InvocationTargetException e) {
77  			e.printStackTrace();
78  		}			
79  	}
80  	
81  	/**
82  	 * Returns the bean, which the data belongs to.
83  	 * 
84  	 * @return
85  	 */
86  	public Object getBean() {
87  		return bean;
88  	}
89  }