Source code: com/sunwheeltech/sirius/objbrowser/ObjectBrowser.java
1 package com.sunwheeltech.sirius.objbrowser;
2 /* GPL
3 ulunum java libraries for complex simulation modelling,
4 3d graphics, peer-to-peer networking and other purposes
5
6 version 0.1 released December 2001
7 see the file contents.html for a quick description of whats in
8 each package, and what you can expect to do with it
9
10 Copyright (C) December 2001 Dave Crane dave@cranepeople.co.uk
11
12
13 Find the GNU public license at:
14
15 http://www.gnu.org/copyleft/gpl.html
16
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License
19 as published by the Free Software Foundation; either version 2
20 of the License, or (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 */
31
32 import com.sunwheeltech.sirius.*;
33
34 import ulu.view.*;
35 import ulu.view.io.*;
36 import ulu.view.ui.*;
37 import ulu.view.sys.refl.*;
38 import ulu.view.ui.sirius.*;
39
40 import ulu.ut.*;
41 import dog.gui.*;
42 import java.awt.*;
43 import java.awt.event.*;
44 import java.beans.*;
45 import java.io.*;
46 import java.net.*;
47 import java.util.*;
48
49 /**
50 * <p>Top-level pane of the objectbrowser component, for inspecting any live java object
51 * and its children members using a file-explorer-like graphical interface.
52 *
53 * @javabean.class
54 * displayName="Object Browser"
55 * name="ObjectBrowser"
56 * shortDescription="Component allowing visual introspection and manipulation of any Java Object"
57 * defaultProperty="object"
58 * stopClass="java.awt.Component"
59 *
60 * @javabean.icons
61 * color16="/img/beans/obj-c16.gif"
62 * color32="/img/beans/obj-c32.gif"
63 * mono16="/img/beans/obj-m16.gif"
64 * mono32="/img/beans/obj-m32.gif"
65 *
66 * @javabean.attribute
67 * name="version"
68 * value="1.0"
69 *
70 * @javabean.attribute
71 * name="vendor"
72 * value="Sunwheel Technologies Ltd."
73 *
74 *
75 * @author Dave Crane Sunwheel Technologies Ltd February 2003
76 */
77 public class ObjectBrowser
78 extends GenericBrowserPanel{
79
80 /** get the root name for this bean type
81 @return root name
82 */
83 public String getRootName(){ return "objectbrowser"; }
84
85 /** constructor sets up the gui components */
86 public ObjectBrowser(){
87 super();
88 }
89
90 /** add custom toolbar widgets, including a group selector here
91 @param c container to add controls to
92 */
93 public void addToolbars(Container c){
94 NavBar navbar=new NavBar(
95 NavBar.BUTTON_NAVIGATE+NavBar.BUTTON_HISTORY+NavBar.BUTTON_SCRAPBOOK+NavBar.BUTTON_HOME
96 );
97 c.add(navbar);
98
99 AncestorChooser apane=new AncestorChooser();
100 c.add(apane);
101
102 GroupTabChooser gtpane=new GroupTabChooser();
103 gtpane.setTabbedFieldName(Flagged.FLAG_GROUP_MEMBERSHIP);
104 c.add(gtpane);
105 }
106
107
108 //--- exposed bean properties ------------------------------------------------------------------
109
110 /** get the Object being browsed
111 * @return object being browsed
112 *
113 * @javabean.property
114 * displayName="Object"
115 * shortDescription="Object being browsed"
116 * preferred="true"
117 * bound="true"
118 * readOnly="true"
119 * propertyEditor="com.sunwheeltech.sirius.support.SimpleReadOnlyPropertyEditor"
120 *
121 */
122 public Object getObject(){
123 Object ret=null;
124 View v=getView();
125 if (v!=null){ ret=v.getReference(); }
126 return ret;
127 }
128
129 /** set the object being browsed
130 * @param o object to browse
131 *
132 * @javabean.method
133 * name="setObject"
134 * displayName="Set Target Object"
135 * description="set the Object that will be browsed"
136 * preferred="true"
137 *
138 * @javabean.param
139 * name="obj"
140 * displayName="Target Object"
141 * description="The Object that will be browsed"
142 *
143 */
144 public void setObject(Object o){
145 View v=new ViewImpl();
146 if (!Beans.isDesignTime()){
147 ObjectShaper shaper=new ObjectShaper();
148 shaper.setObject(o);
149 shaper.modify(v);
150 }
151 changes.firePropertyChange("object",getObject(),o);
152 setView(v);
153 }
154
155 /** URL of a script to execute, accessible as a bean-like property */
156 URL scripturl=null;
157
158 /** get the URL of the initialisation script
159 *@return url of the script
160 *
161 */
162 public URL getScriptSource(){ return scripturl; }
163 /** set the URL of the initialisation script
164 * @param u url pointing to the script
165 *
166 * @javabean.property
167 * displayName="Startup-Script"
168 * shortDescription="Location of python script used to populate the scrapbook"
169 * preferred="true"
170 * bound="true"
171 * propertyEditor="com.sunwheeltech.sirius.support.ResourceURLPropertyEditor"
172 *
173 */
174 public void setScriptSource(URL u) throws IOException{
175 if (!Beans.isDesignTime()){
176 InputStream instr=u.openStream();
177 execScript(instr,true);
178 }
179 changes.firePropertyChange("scriptSource",scripturl,u);
180 scripturl=u;
181 }
182
183 /** add a method to the current default object
184 *@param method method to add
185 *
186 */
187 public void addMethod(UMethod method){
188 View v=getView();
189 if (v!=null){
190 v.addMethod(method);
191 }
192 }
193 /** add a method to the current default object
194 *@param method method to add
195 *
196 * @javabean.method
197 * name="addMethod"
198 * displayName="add method"
199 * description="add a Method to the Object that will be browsed"
200 * preferred="true"
201 *
202 * @javabean.param
203 * name="name"
204 * displayName="name of the method to add"
205 * description="The name of the method that will be added"
206 *
207 * @javabean.param
208 * name="grp"
209 * displayName="name of group to add the method to"
210 * description="name of group to add the method to"
211 *
212 * @javabean.param
213 * name="script"
214 * displayName="script to execute"
215 * description="piece of executable script to be run when this method is invoked"
216 *
217 */
218 public void addMethod(String name,String grp,String script){
219 addMethod(new ScriptedMethod(name,grp,script));
220 }
221 }