View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans-Common.
5    *
6    * CosyBeans-Common 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-Common 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-Common.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.components.introspection;
21  
22  import java.awt.CardLayout;
23  import java.lang.reflect.Method;
24  
25  import javax.swing.JFrame;
26  import javax.swing.JPanel;
27  import javax.swing.JScrollPane;
28  
29  import com.cosylab.introspection.ClassIntrospector;
30  
31  /**
32   * Creation date: (18.1.2002 18:29:16)
33   *  
34   * @author <a href="mailto:miha.kadunc@cosylab.com">Miha Kadunc</a>
35   * @version $id$
36   */
37  public class ParametersTable extends DefaultPropertiesTable
38  {
39  	private static final long serialVersionUID = 1L;
40  	private java.lang.reflect.Method fieldMethod = null;
41  	
42  /**
43   * ParametersTable constructor comment.
44   */
45  public ParametersTable() {
46  	super();
47  }
48  /**
49   * Gets the method property (java.lang.reflect.Method) value.
50   * @return The method property value.
51   * @see #setMethod
52   */
53  public java.lang.reflect.Method getMethod() {
54  	return fieldMethod;
55  }
56  
57  
58  /**
59   * main entrypoint - starts the part when it is run as an application
60   * @param args java.lang.String[]
61   */
62  public static void main(java.lang.String[] args) {
63  	try {
64  		JFrame frame = new JFrame();
65  		JPanel panel=new JPanel();
66  		JScrollPane sp=new JScrollPane();
67  		ParametersTable aParametersTable;
68  		aParametersTable = new ParametersTable();
69  
70  		sp.add(aParametersTable);
71  		sp.setViewportView(aParametersTable);
72  		panel.setLayout(new CardLayout());
73  		panel.add(sp,"ScrollPane");
74  		frame.setContentPane(panel);
75  		frame.setSize(200,100);
76  		frame.addWindowListener(new java.awt.event.WindowAdapter() {
77  			public void windowClosing(java.awt.event.WindowEvent e) {
78  				System.exit(0);
79  			};
80  		});
81  		PropertiesTableModel ptm = new PropertiesTableModel(
82  				new String[] {"name","class","value","shown"},
83  				new Class[] {String.class,Class.class,Integer.TYPE,Boolean.TYPE},
84  				new Object[]{"krneki",int.class,new Integer(8),new Boolean(false)
85  		});
86  		aParametersTable.setModel(ptm);
87  		java.awt.Insets insets = frame.getInsets();
88  		frame.setSize(frame.getWidth() + insets.left + insets.right, frame.getHeight() + insets.top + insets.bottom);
89  		frame.setVisible(true);
90  	} catch (Throwable exception) {
91  		System.err.println("Exception occurred in main() of com.cosylab.introspection.ParametersTable");
92  		exception.printStackTrace(System.out);
93  	}
94  }
95  /**
96   * Sets the method property (java.lang.reflect.Method) value.
97   * @param method The new value for the property.
98   * @see #getMethod
99   */
100 public void setMethod(java.lang.reflect.Method method) {
101   Method oldValue = fieldMethod;
102   fieldMethod = method;
103   PropertiesTableModel m =
104     new PropertiesTableModel(
105       ClassIntrospector.getParameterNames(method),
106       method.getParameterTypes(),
107       new Object[method.getParameterTypes().length]);  
108   setModel(m);
109   firePropertyChange("method", oldValue, method);
110   revalidate();
111 }
112 
113 }