jaroslav@0
|
1 |
package xelfi.design.inspector;
|
jaroslav@0
|
2 |
|
jaroslav@0
|
3 |
import java.awt.*;
|
jaroslav@0
|
4 |
import java.util.Vector;
|
jaroslav@0
|
5 |
|
jaroslav@0
|
6 |
import xelfi.awt.TabControl;
|
jaroslav@0
|
7 |
import xelfi.design.components.*;
|
jaroslav@0
|
8 |
import xelfi.design.components.property.*;
|
jaroslav@0
|
9 |
import xelfi.design.forms.XelfiDesignForm;
|
jaroslav@0
|
10 |
import xelfi.design.forms.XFInstalledLayouts;
|
jaroslav@0
|
11 |
import xelfi.design.util.XFDesignConstants;
|
jaroslav@0
|
12 |
import xelfi.util.Debug;
|
jaroslav@0
|
13 |
|
jaroslav@0
|
14 |
/**
|
jaroslav@0
|
15 |
* XFCommonProperties holds a list of currently selected components,
|
jaroslav@0
|
16 |
* list of their common properties and
|
jaroslav@0
|
17 |
* properties and events.
|
jaroslav@0
|
18 |
*
|
jaroslav@0
|
19 |
* @author Dafe
|
jaroslav@0
|
20 |
* version 1.22, 24 Nov 1996 - Name, X, Y....props included
|
jaroslav@0
|
21 |
* version 1.23, 13 Dec 1996 - small bug in non-visual comps repaired
|
jaroslav@0
|
22 |
* version 1.24, 22 Dec 1996 - large changes -
|
jaroslav@0
|
23 |
* methods like getProperties,setProperties added
|
jaroslav@0
|
24 |
* version 1.30, 17 Jan 1997 - bugs in layouts repaired,
|
jaroslav@0
|
25 |
* event calling added
|
jaroslav@0
|
26 |
*
|
jaroslav@0
|
27 |
* @version 1.30, 17 Jan 1997
|
jaroslav@0
|
28 |
Last change: DF 17 Feb 97 8:22 pm
|
jaroslav@0
|
29 |
*/
|
jaroslav@0
|
30 |
|
jaroslav@0
|
31 |
class XFCommonProperties {
|
jaroslav@0
|
32 |
|
jaroslav@0
|
33 |
// indexes for properties every component has
|
jaroslav@0
|
34 |
private static final int NAME_INDEX = -5;
|
jaroslav@0
|
35 |
private static final int X_INDEX = -4;
|
jaroslav@0
|
36 |
private static final int Y_INDEX = -3;
|
jaroslav@0
|
37 |
private static final int WIDTH_INDEX = -2;
|
jaroslav@0
|
38 |
private static final int HEIGHT_INDEX = -1;
|
jaroslav@0
|
39 |
private static final int LAYOUT_INDEX = -6;
|
jaroslav@0
|
40 |
// names of well-known properties
|
jaroslav@0
|
41 |
private static final String NameName = "Name";
|
jaroslav@0
|
42 |
private static final String XName = "X";
|
jaroslav@0
|
43 |
private static final String YName = "Y";
|
jaroslav@0
|
44 |
private static final String WidthName = "Width";
|
jaroslav@0
|
45 |
private static final String HeightName = "Height";
|
jaroslav@0
|
46 |
private static final String LayoutName = "Layout";
|
jaroslav@0
|
47 |
// event names comparison constants
|
jaroslav@0
|
48 |
private static final int NEW_NAME = 1;
|
jaroslav@0
|
49 |
private static final int DELETED_NAME = 2;
|
jaroslav@0
|
50 |
private static final int CHANGED_NAME = 3;
|
jaroslav@0
|
51 |
private static final int SAME_NAME = 4;
|
jaroslav@0
|
52 |
// start of event names
|
jaroslav@0
|
53 |
private static final String eventStart = "On";
|
jaroslav@0
|
54 |
private static final String defEventNameStart = "on";
|
jaroslav@0
|
55 |
|
jaroslav@0
|
56 |
private Vector allComponents;
|
jaroslav@0
|
57 |
private Vector selectedComponents;
|
jaroslav@0
|
58 |
private Vector propertiesIndexes = null, eventsIndexes = null,
|
jaroslav@0
|
59 |
layoutIndexes = null;
|
jaroslav@0
|
60 |
private int page;
|
jaroslav@0
|
61 |
|
jaroslav@0
|
62 |
|
jaroslav@0
|
63 |
XFCommonProperties (Vector allComponents, Vector selectedComponents,
|
jaroslav@0
|
64 |
int page, TabControl pageTab) {
|
jaroslav@0
|
65 |
this.allComponents = allComponents;
|
jaroslav@0
|
66 |
this.selectedComponents = selectedComponents;
|
jaroslav@0
|
67 |
this.page = page;
|
jaroslav@0
|
68 |
boolean layoutAvail = isLayoutPageAvailable();
|
jaroslav@0
|
69 |
int pageCount = pageTab.getTabCount();
|
jaroslav@0
|
70 |
if ((this.page==XFDesignConstants.CI_PG_LAYOUT)&&(!layoutAvail)) {
|
jaroslav@0
|
71 |
this.page = XFDesignConstants.CI_PG_PROPERTIES;
|
jaroslav@0
|
72 |
}
|
jaroslav@0
|
73 |
// add or remove layout page
|
jaroslav@0
|
74 |
if ((layoutAvail) && (pageCount<3))
|
jaroslav@0
|
75 |
pageTab.addTab("Layout");
|
jaroslav@0
|
76 |
if ((!layoutAvail) && (pageCount>=3))
|
jaroslav@0
|
77 |
pageTab.removeTabAt(2);
|
jaroslav@0
|
78 |
|
jaroslav@0
|
79 |
buildIndexes();
|
jaroslav@0
|
80 |
}
|
jaroslav@0
|
81 |
|
jaroslav@0
|
82 |
Vector getAllComponents () {
|
jaroslav@0
|
83 |
return allComponents;
|
jaroslav@0
|
84 |
}
|
jaroslav@0
|
85 |
|
jaroslav@0
|
86 |
Vector getSelectedComponents () {
|
jaroslav@0
|
87 |
return selectedComponents;
|
jaroslav@0
|
88 |
}
|
jaroslav@0
|
89 |
|
jaroslav@0
|
90 |
int getPage () {
|
jaroslav@0
|
91 |
return page;
|
jaroslav@0
|
92 |
}
|
jaroslav@0
|
93 |
|
jaroslav@0
|
94 |
boolean setPage (int page) {
|
jaroslav@0
|
95 |
if (page==XFDesignConstants.CI_PG_LAYOUT)
|
jaroslav@0
|
96 |
// check if layout page is available
|
jaroslav@0
|
97 |
if (!isLayoutPageAvailable()) return false;
|
jaroslav@0
|
98 |
this.page = page;
|
jaroslav@0
|
99 |
buildIndexes();
|
jaroslav@0
|
100 |
return true;
|
jaroslav@0
|
101 |
}
|
jaroslav@0
|
102 |
|
jaroslav@0
|
103 |
Vector getIndexes (int index) {
|
jaroslav@0
|
104 |
switch (page) {
|
jaroslav@0
|
105 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
106 |
return (Vector)(propertiesIndexes.elementAt(index));
|
jaroslav@0
|
107 |
case XFDesignConstants.CI_PG_EVENTS:
|
jaroslav@0
|
108 |
return (Vector)(eventsIndexes.elementAt(index));
|
jaroslav@0
|
109 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
110 |
return (Vector)(layoutIndexes.elementAt(index));
|
jaroslav@0
|
111 |
}
|
jaroslav@0
|
112 |
return null;
|
jaroslav@0
|
113 |
}
|
jaroslav@0
|
114 |
|
jaroslav@0
|
115 |
Vector getIndexes () {
|
jaroslav@0
|
116 |
switch (page) {
|
jaroslav@0
|
117 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
118 |
return propertiesIndexes;
|
jaroslav@0
|
119 |
case XFDesignConstants.CI_PG_EVENTS:
|
jaroslav@0
|
120 |
return eventsIndexes;
|
jaroslav@0
|
121 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
122 |
return layoutIndexes;
|
jaroslav@0
|
123 |
}
|
jaroslav@0
|
124 |
return null;
|
jaroslav@0
|
125 |
}
|
jaroslav@0
|
126 |
|
jaroslav@0
|
127 |
/**
|
jaroslav@0
|
128 |
* Returns property with index "propIndex" in specified component
|
jaroslav@0
|
129 |
* and in specified page.
|
jaroslav@0
|
130 |
* Throws an exception if index is out of bounds
|
jaroslav@0
|
131 |
*/
|
jaroslav@0
|
132 |
Object getProperty (int compIndex, int propIndex)
|
jaroslav@0
|
133 |
throws XFPropertyIndexOutOfBoundsException,
|
jaroslav@0
|
134 |
XFNameNotFoundException {
|
jaroslav@0
|
135 |
// get the component
|
jaroslav@0
|
136 |
XelfiDesignComponent comp =
|
jaroslav@0
|
137 |
(XelfiDesignComponent)selectedComponents.elementAt(compIndex);
|
jaroslav@0
|
138 |
int realIndex = ((Integer)getIndexes(propIndex).
|
jaroslav@0
|
139 |
elementAt(compIndex)).intValue();
|
jaroslav@0
|
140 |
switch (page) {
|
jaroslav@0
|
141 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
142 |
if (realIndex<0) {
|
jaroslav@0
|
143 |
// well-known props...i can't ask component about property value
|
jaroslav@0
|
144 |
// through getProperty method...I have to use special methods
|
jaroslav@0
|
145 |
switch (realIndex) {
|
jaroslav@0
|
146 |
case X_INDEX:
|
jaroslav@0
|
147 |
return new Integer(((XelfiVisualComponent)comp).
|
jaroslav@0
|
148 |
getPosition().x);
|
jaroslav@0
|
149 |
case Y_INDEX:
|
jaroslav@0
|
150 |
return new Integer(((XelfiVisualComponent)comp).
|
jaroslav@0
|
151 |
getPosition().y);
|
jaroslav@0
|
152 |
case WIDTH_INDEX:
|
jaroslav@0
|
153 |
return new Integer(((XelfiVisualComponent)comp).
|
jaroslav@0
|
154 |
getSize().width);
|
jaroslav@0
|
155 |
case HEIGHT_INDEX:
|
jaroslav@0
|
156 |
return new Integer(((XelfiVisualComponent)comp).
|
jaroslav@0
|
157 |
getSize().height);
|
jaroslav@0
|
158 |
case NAME_INDEX:
|
jaroslav@0
|
159 |
return comp.getName();
|
jaroslav@0
|
160 |
case LAYOUT_INDEX:
|
jaroslav@0
|
161 |
return ((XelfiVisualContainer)comp).getDesignLayout();
|
jaroslav@0
|
162 |
}
|
jaroslav@0
|
163 |
} else {
|
jaroslav@0
|
164 |
// ask component about property
|
jaroslav@0
|
165 |
return comp.getProperty(realIndex);
|
jaroslav@0
|
166 |
}
|
jaroslav@0
|
167 |
case XFDesignConstants.CI_PG_EVENTS:
|
jaroslav@0
|
168 |
return comp.getEvent(realIndex);
|
jaroslav@0
|
169 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
170 |
XelfiDesignLayout xdl = ((XelfiVisualContainer)((Component)comp).
|
jaroslav@0
|
171 |
getParent()).getDesignLayout();
|
jaroslav@0
|
172 |
return xdl.getProperty((XelfiVisualComponent)comp, realIndex);
|
jaroslav@0
|
173 |
}
|
jaroslav@0
|
174 |
// wrong page number - return null
|
jaroslav@0
|
175 |
return null;
|
jaroslav@0
|
176 |
}
|
jaroslav@0
|
177 |
|
jaroslav@0
|
178 |
/**
|
jaroslav@0
|
179 |
* Returns value of specified property in selected components
|
jaroslav@0
|
180 |
* Returns null if values are not the same in all selected components
|
jaroslav@0
|
181 |
*/
|
jaroslav@0
|
182 |
Object getPropertiesValue (int propIndex, int viewerType) {
|
jaroslav@0
|
183 |
// return if no comps selected
|
jaroslav@0
|
184 |
if ( selectedComponents.size()==0 ) return null;
|
jaroslav@0
|
185 |
// get property value object from first selected component
|
jaroslav@0
|
186 |
Object firstValue = null;
|
jaroslav@0
|
187 |
try {
|
jaroslav@0
|
188 |
firstValue = getProperty(0, propIndex);
|
jaroslav@0
|
189 |
} catch (XFPropertyIndexOutOfBoundsException e) {
|
jaroslav@0
|
190 |
System.err.println(e.getMessage());
|
jaroslav@0
|
191 |
e.printStackTrace(System.err);
|
jaroslav@0
|
192 |
} catch (XFNameNotFoundException e) {
|
jaroslav@0
|
193 |
System.err.println(e.getMessage());
|
jaroslav@0
|
194 |
e.printStackTrace(System.err);
|
jaroslav@0
|
195 |
}
|
jaroslav@0
|
196 |
//check if all values are the same
|
jaroslav@0
|
197 |
boolean valuesIdentic = true;
|
jaroslav@0
|
198 |
Object propertyValue = null;
|
jaroslav@0
|
199 |
for (int i=1; i<selectedComponents.size(); i++) {
|
jaroslav@0
|
200 |
try {
|
jaroslav@0
|
201 |
propertyValue = getProperty(i, propIndex);
|
jaroslav@0
|
202 |
} catch (XFPropertyIndexOutOfBoundsException e) {
|
jaroslav@0
|
203 |
System.err.println(e.getMessage());
|
jaroslav@0
|
204 |
e.printStackTrace(System.err);
|
jaroslav@0
|
205 |
} catch (XFNameNotFoundException e) {
|
jaroslav@0
|
206 |
System.err.println(e.getMessage());
|
jaroslav@0
|
207 |
e.printStackTrace(System.err);
|
jaroslav@0
|
208 |
}
|
jaroslav@0
|
209 |
if (compareProperties(firstValue, propertyValue,viewerType)!=true) {
|
jaroslav@0
|
210 |
valuesIdentic = false;
|
jaroslav@0
|
211 |
break;
|
jaroslav@0
|
212 |
}
|
jaroslav@0
|
213 |
}
|
jaroslav@0
|
214 |
return valuesIdentic==true ? firstValue : null;
|
jaroslav@0
|
215 |
}
|
jaroslav@0
|
216 |
|
jaroslav@0
|
217 |
/**
|
jaroslav@0
|
218 |
* Compares two properties. Their type is set from viewerType constant.
|
jaroslav@0
|
219 |
* Returns true if values are the same, false otherwise.
|
jaroslav@0
|
220 |
*/
|
jaroslav@0
|
221 |
private boolean compareProperties (Object first, Object second,
|
jaroslav@0
|
222 |
int viewerType) {
|
jaroslav@0
|
223 |
if ((first==null)||(second==null))
|
jaroslav@0
|
224 |
return false;
|
jaroslav@0
|
225 |
switch (viewerType) {
|
jaroslav@0
|
226 |
case XFDesignConstants.PVT_CHECK:
|
jaroslav@0
|
227 |
return ((Boolean)first).booleanValue()==
|
jaroslav@0
|
228 |
((Boolean)second).booleanValue();
|
jaroslav@0
|
229 |
|
jaroslav@0
|
230 |
case XFDesignConstants.PVT_INPUT_INT:
|
jaroslav@0
|
231 |
return ((Integer)first).intValue()==
|
jaroslav@0
|
232 |
((Integer)second).intValue();
|
jaroslav@0
|
233 |
|
jaroslav@0
|
234 |
case XFDesignConstants.PVT_INPUT_FLOAT:
|
jaroslav@0
|
235 |
return ((Double)first).floatValue()==
|
jaroslav@0
|
236 |
((Double)second).floatValue();
|
jaroslav@0
|
237 |
|
jaroslav@0
|
238 |
case XFDesignConstants.PVT_INPUT_STRING:
|
jaroslav@0
|
239 |
return ((String)first).compareTo((String)second)==0;
|
jaroslav@0
|
240 |
|
jaroslav@0
|
241 |
case XFDesignConstants.PVT_INPUT_CHAR:
|
jaroslav@0
|
242 |
return ((Character)first).charValue()==
|
jaroslav@0
|
243 |
((Character)second).charValue();
|
jaroslav@0
|
244 |
// [PENDING] - other types not implem. yet
|
jaroslav@0
|
245 |
}
|
jaroslav@0
|
246 |
return false;
|
jaroslav@0
|
247 |
}
|
jaroslav@0
|
248 |
|
jaroslav@0
|
249 |
/**
|
jaroslav@0
|
250 |
* Sets the property with index "propIndex" in specified component
|
jaroslav@0
|
251 |
* and in specified page.
|
jaroslav@0
|
252 |
* Throws an exception if index is out of bounds or bad property has
|
jaroslav@0
|
253 |
* bad type.
|
jaroslav@0
|
254 |
*/
|
jaroslav@0
|
255 |
int setProperty (int compIndex, int propIndex, Object value)
|
jaroslav@0
|
256 |
throws XFPropertyIndexOutOfBoundsException,
|
jaroslav@0
|
257 |
XFPropertyBadValueTypeException,
|
jaroslav@0
|
258 |
XFNameNotFoundException {
|
jaroslav@0
|
259 |
// check property, if value is the same or different
|
jaroslav@0
|
260 |
int viewerType = getPropertyViewerType(propIndex);
|
jaroslav@0
|
261 |
if (compareProperties(value, getProperty(compIndex, propIndex),
|
jaroslav@0
|
262 |
viewerType)) {
|
jaroslav@0
|
263 |
// values are the same, no need to set it again
|
jaroslav@0
|
264 |
return 0;
|
jaroslav@0
|
265 |
}
|
jaroslav@0
|
266 |
// get the component
|
jaroslav@0
|
267 |
XelfiDesignComponent comp =
|
jaroslav@0
|
268 |
(XelfiDesignComponent)selectedComponents.elementAt(compIndex);
|
jaroslav@0
|
269 |
int realIndex = ((Integer)getIndexes(propIndex).
|
jaroslav@0
|
270 |
elementAt(compIndex)).intValue();
|
jaroslav@0
|
271 |
int result = 0;
|
jaroslav@0
|
272 |
switch (page) {
|
jaroslav@0
|
273 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
274 |
if (realIndex<0) {
|
jaroslav@0
|
275 |
// well-known props...i can't set property value
|
jaroslav@0
|
276 |
// through setproperty...I have to use special methods
|
jaroslav@0
|
277 |
if (comp instanceof XelfiVisualComponent) {
|
jaroslav@0
|
278 |
}
|
jaroslav@0
|
279 |
switch (realIndex) {
|
jaroslav@0
|
280 |
case X_INDEX:
|
jaroslav@0
|
281 |
((XelfiVisualComponent)comp).setPosition(
|
jaroslav@0
|
282 |
((Integer)value).intValue(),
|
jaroslav@0
|
283 |
((XelfiVisualComponent)comp).getPosition().y);
|
jaroslav@0
|
284 |
break;
|
jaroslav@0
|
285 |
case Y_INDEX:
|
jaroslav@0
|
286 |
((XelfiVisualComponent)comp).setPosition(
|
jaroslav@0
|
287 |
((XelfiVisualComponent)comp).getPosition().x,
|
jaroslav@0
|
288 |
((Integer)value).intValue());
|
jaroslav@0
|
289 |
break;
|
jaroslav@0
|
290 |
case WIDTH_INDEX:
|
jaroslav@6
|
291 |
((XelfiVisualComponent)comp).setDesignSize(
|
jaroslav@0
|
292 |
((Integer)value).intValue(),
|
jaroslav@0
|
293 |
((XelfiVisualComponent)comp).getSize().height);
|
jaroslav@0
|
294 |
break;
|
jaroslav@0
|
295 |
case HEIGHT_INDEX:
|
jaroslav@6
|
296 |
((XelfiVisualComponent)comp).setDesignSize(
|
jaroslav@0
|
297 |
((XelfiVisualComponent)comp).getSize().width,
|
jaroslav@0
|
298 |
((Integer)value).intValue());
|
jaroslav@0
|
299 |
break;
|
jaroslav@0
|
300 |
case NAME_INDEX:
|
jaroslav@0
|
301 |
// transfers the work of setting the name to parent form
|
jaroslav@0
|
302 |
// parent form will decide, whether this name is allowed or not
|
jaroslav@0
|
303 |
if (comp instanceof XelfiDesignForm) {
|
jaroslav@6
|
304 |
comp.setDesignName((String)value);
|
jaroslav@0
|
305 |
} else {
|
jaroslav@0
|
306 |
XelfiDesignForm parentForm = comp.getParentForm();
|
jaroslav@0
|
307 |
if (parentForm==null) {
|
jaroslav@0
|
308 |
Debug.debug(Debug.INSPECTOR, "Error: Parent Form is null...");
|
jaroslav@0
|
309 |
break;
|
jaroslav@0
|
310 |
}
|
jaroslav@0
|
311 |
if (!parentForm.setComponentName(comp, (String)value))
|
jaroslav@0
|
312 |
Debug.debug(Debug.INSPECTOR, "Error: Property name duplication occured...");
|
jaroslav@0
|
313 |
}
|
jaroslav@0
|
314 |
break;
|
jaroslav@0
|
315 |
case LAYOUT_INDEX:
|
jaroslav@0
|
316 |
((XelfiVisualContainer)comp).setDesignLayout(
|
jaroslav@0
|
317 |
buildLayoutFromIndex(((Integer)value).intValue()));
|
jaroslav@0
|
318 |
break;
|
jaroslav@0
|
319 |
}
|
jaroslav@0
|
320 |
} else {
|
jaroslav@0
|
321 |
// int viewerType = comp.getPropertyViewerType(realIndex);
|
jaroslav@0
|
322 |
if ((viewerType==XFDesignConstants.PVT_CHOICE_STRICT) ||
|
jaroslav@0
|
323 |
(viewerType==XFDesignConstants.PVT_CHOICE_FREE)) {
|
jaroslav@0
|
324 |
Object[] valueValues = comp.getPropertyValueValues(realIndex);
|
jaroslav@0
|
325 |
String[] valueNames = comp.getPropertyValueNames(realIndex);
|
jaroslav@0
|
326 |
switch (viewerType) {
|
jaroslav@0
|
327 |
case XFDesignConstants.PVT_CHOICE_STRICT:
|
jaroslav@0
|
328 |
// strict choice = we 've got selected index in parameter
|
jaroslav@0
|
329 |
result = comp.setProperty(realIndex,
|
jaroslav@0
|
330 |
valueValues[((Integer)value).intValue()]);
|
jaroslav@0
|
331 |
break;
|
jaroslav@0
|
332 |
case XFDesignConstants.PVT_CHOICE_FREE:
|
jaroslav@0
|
333 |
// free choice - value can be integer (index)
|
jaroslav@0
|
334 |
// or direct value (string)
|
jaroslav@0
|
335 |
if ( value instanceof Integer ) {
|
jaroslav@0
|
336 |
result = comp.setProperty(realIndex,
|
jaroslav@0
|
337 |
valueValues[((Integer)value).intValue()]);
|
jaroslav@0
|
338 |
} else {
|
jaroslav@0
|
339 |
// [PENDING] - we can save only strings now...
|
jaroslav@0
|
340 |
result = comp.setProperty(realIndex, value);
|
jaroslav@0
|
341 |
}
|
jaroslav@0
|
342 |
break;
|
jaroslav@0
|
343 |
}
|
jaroslav@0
|
344 |
} else {
|
jaroslav@0
|
345 |
// ok, finally some normal property :-) ... so set the value
|
jaroslav@0
|
346 |
result = comp.setProperty(realIndex, value);
|
jaroslav@0
|
347 |
}
|
jaroslav@0
|
348 |
}
|
jaroslav@0
|
349 |
break;
|
jaroslav@0
|
350 |
case XFDesignConstants.CI_PG_EVENTS:
|
jaroslav@0
|
351 |
// retrieve old value of event prop
|
jaroslav@0
|
352 |
String oldEventName = (String)getProperty(compIndex, propIndex);
|
jaroslav@0
|
353 |
String newEventName = (String)value;
|
jaroslav@0
|
354 |
|
jaroslav@0
|
355 |
XelfiDesignForm parentForm = null;
|
jaroslav@0
|
356 |
if (comp instanceof XelfiDesignForm)
|
jaroslav@0
|
357 |
parentForm = (XelfiDesignForm)comp;
|
jaroslav@0
|
358 |
else
|
jaroslav@0
|
359 |
parentForm = comp.getParentForm();
|
jaroslav@0
|
360 |
if (parentForm==null) {
|
jaroslav@0
|
361 |
System.err.println("Error: Parent form is null...");
|
jaroslav@0
|
362 |
break;
|
jaroslav@0
|
363 |
}
|
jaroslav@0
|
364 |
switch ( compareEvents(oldEventName, newEventName) )
|
jaroslav@0
|
365 |
{
|
jaroslav@0
|
366 |
case NEW_NAME:
|
jaroslav@0
|
367 |
Debug.debug(Debug.INSPECTOR, "calling assignEvent");
|
jaroslav@0
|
368 |
parentForm.assignEvent(comp, realIndex, newEventName);
|
jaroslav@0
|
369 |
parentForm.focusEvent(newEventName);
|
jaroslav@0
|
370 |
break;
|
jaroslav@0
|
371 |
case CHANGED_NAME:
|
jaroslav@0
|
372 |
Debug.debug(Debug.INSPECTOR, "calling renameEvent");
|
jaroslav@0
|
373 |
parentForm.renameEvent(oldEventName, newEventName);
|
jaroslav@0
|
374 |
break;
|
jaroslav@0
|
375 |
case DELETED_NAME:
|
jaroslav@0
|
376 |
Debug.debug(Debug.INSPECTOR, "calling releaseEvent");
|
jaroslav@0
|
377 |
parentForm.releaseEvent(comp, realIndex);
|
jaroslav@0
|
378 |
break;
|
jaroslav@0
|
379 |
case SAME_NAME:
|
jaroslav@0
|
380 |
break;
|
jaroslav@0
|
381 |
}
|
jaroslav@0
|
382 |
break;
|
jaroslav@0
|
383 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
384 |
// [PENDING] - maybe not finished yet
|
jaroslav@0
|
385 |
XelfiDesignLayout xdl = ((XelfiVisualContainer)((Component)comp).
|
jaroslav@0
|
386 |
getParent()).getDesignLayout();
|
jaroslav@0
|
387 |
xdl.setProperty((XelfiVisualComponent)comp, realIndex, value);
|
jaroslav@0
|
388 |
break;
|
jaroslav@0
|
389 |
}
|
jaroslav@0
|
390 |
// refresh component if needed
|
jaroslav@0
|
391 |
refreshComponent(comp, result);
|
jaroslav@0
|
392 |
|
jaroslav@0
|
393 |
return result;
|
jaroslav@0
|
394 |
}
|
jaroslav@0
|
395 |
|
jaroslav@0
|
396 |
/**
|
jaroslav@0
|
397 |
* Performs an action of setting new property value of given index
|
jaroslav@0
|
398 |
* into selected components
|
jaroslav@0
|
399 |
*/
|
jaroslav@0
|
400 |
int setProperties (int propIndex, Object newValue) {
|
jaroslav@0
|
401 |
// iterate through the set of selected components and set new value
|
jaroslav@0
|
402 |
// at specified indexes
|
jaroslav@0
|
403 |
int result = 0;
|
jaroslav@0
|
404 |
for (int i=0; i<getSelectedComponents().size(); i++) {
|
jaroslav@0
|
405 |
try {
|
jaroslav@0
|
406 |
result |= setProperty(i, propIndex, newValue);
|
jaroslav@0
|
407 |
} catch (XFPropertyIndexOutOfBoundsException e) {
|
jaroslav@0
|
408 |
// prints an error if property index is out of bounds
|
jaroslav@0
|
409 |
System.err.println(e.getMessage());
|
jaroslav@0
|
410 |
e.printStackTrace(System.err);
|
jaroslav@0
|
411 |
} catch (XFPropertyBadValueTypeException e) {
|
jaroslav@0
|
412 |
// prints an error if bad type of property wanted to be set
|
jaroslav@0
|
413 |
System.err.println(e.getMessage());
|
jaroslav@0
|
414 |
e.printStackTrace(System.err);
|
jaroslav@0
|
415 |
} catch (XFNameNotFoundException e) {
|
jaroslav@0
|
416 |
// prints an error if bad name in layout is given
|
jaroslav@0
|
417 |
System.err.println(e.getMessage());
|
jaroslav@0
|
418 |
e.printStackTrace(System.err);
|
jaroslav@0
|
419 |
}
|
jaroslav@0
|
420 |
}
|
jaroslav@0
|
421 |
return result;
|
jaroslav@0
|
422 |
}
|
jaroslav@0
|
423 |
|
jaroslav@0
|
424 |
/**
|
jaroslav@0
|
425 |
* Gets the property in string form with index "propIndex"
|
jaroslav@0
|
426 |
* in specified component and in specified page.
|
jaroslav@0
|
427 |
* Throws an exception if index is out of bounds.
|
jaroslav@0
|
428 |
*/
|
jaroslav@0
|
429 |
String getPropertyString (int compIndex, int propIndex)
|
jaroslav@0
|
430 |
throws XFPropertyIndexOutOfBoundsException,
|
jaroslav@0
|
431 |
XFNameNotFoundException {
|
jaroslav@0
|
432 |
// get the component
|
jaroslav@0
|
433 |
XelfiDesignComponent comp =
|
jaroslav@0
|
434 |
(XelfiDesignComponent)selectedComponents.elementAt(compIndex);
|
jaroslav@0
|
435 |
// get the index
|
jaroslav@0
|
436 |
int realIndex = ((Integer)getIndexes(propIndex).
|
jaroslav@0
|
437 |
elementAt(compIndex)).intValue();
|
jaroslav@0
|
438 |
String result = null;
|
jaroslav@0
|
439 |
switch (page) {
|
jaroslav@0
|
440 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
441 |
if (realIndex<0) {
|
jaroslav@0
|
442 |
// well-known props...i can't ask for property string
|
jaroslav@0
|
443 |
// I have to return it by myself
|
jaroslav@0
|
444 |
switch (realIndex) {
|
jaroslav@0
|
445 |
case X_INDEX:
|
jaroslav@0
|
446 |
result = String.valueOf(((XelfiVisualComponent)comp).
|
jaroslav@0
|
447 |
getPosition().x);
|
jaroslav@0
|
448 |
break;
|
jaroslav@0
|
449 |
case Y_INDEX:
|
jaroslav@0
|
450 |
result = String.valueOf(((XelfiVisualComponent)comp).
|
jaroslav@0
|
451 |
getPosition().y);
|
jaroslav@0
|
452 |
break;
|
jaroslav@0
|
453 |
case WIDTH_INDEX:
|
jaroslav@0
|
454 |
result = String.valueOf(((XelfiVisualComponent)comp).
|
jaroslav@0
|
455 |
getSize().width);
|
jaroslav@0
|
456 |
break;
|
jaroslav@0
|
457 |
case HEIGHT_INDEX:
|
jaroslav@0
|
458 |
result = String.valueOf(((XelfiVisualComponent)comp).
|
jaroslav@0
|
459 |
getSize().height);
|
jaroslav@0
|
460 |
break;
|
jaroslav@0
|
461 |
case NAME_INDEX:
|
jaroslav@0
|
462 |
result = comp.getName();
|
jaroslav@0
|
463 |
break;
|
jaroslav@0
|
464 |
case LAYOUT_INDEX:
|
jaroslav@0
|
465 |
result = ((XelfiVisualContainer)comp).getDesignLayout().
|
jaroslav@0
|
466 |
getClassName();
|
jaroslav@0
|
467 |
break;
|
jaroslav@0
|
468 |
}
|
jaroslav@0
|
469 |
} else {
|
jaroslav@0
|
470 |
int viewerType = comp.getPropertyViewerType(realIndex);
|
jaroslav@0
|
471 |
if ((viewerType==XFDesignConstants.PVT_CHOICE_FREE) ||
|
jaroslav@0
|
472 |
(viewerType==XFDesignConstants.PVT_CHOICE_STRICT)) {
|
jaroslav@0
|
473 |
// choice = we can't use getPropertyString
|
jaroslav@0
|
474 |
String[] valueNames = comp.getPropertyValueNames(realIndex);
|
jaroslav@0
|
475 |
Object[] valueValues = comp.getPropertyValueValues(realIndex);
|
jaroslav@0
|
476 |
Object value = comp.getProperty(realIndex);
|
jaroslav@0
|
477 |
// find the name of the value
|
jaroslav@0
|
478 |
for (int i=0; i<valueValues.length; i++) {
|
jaroslav@0
|
479 |
if (valueValues[i].equals(value)) {
|
jaroslav@0
|
480 |
result = valueNames[i];
|
jaroslav@0
|
481 |
break;
|
jaroslav@0
|
482 |
}
|
jaroslav@0
|
483 |
}
|
jaroslav@0
|
484 |
} else {
|
jaroslav@0
|
485 |
result = comp.getPropertyString(realIndex);
|
jaroslav@0
|
486 |
}
|
jaroslav@0
|
487 |
}
|
jaroslav@0
|
488 |
break;
|
jaroslav@0
|
489 |
case XFDesignConstants.CI_PG_EVENTS:
|
jaroslav@0
|
490 |
result = comp.getEvent(realIndex);
|
jaroslav@0
|
491 |
// modify a string if there's none event handling method
|
jaroslav@0
|
492 |
if ((result==null) || (result.compareTo("")==0))
|
jaroslav@0
|
493 |
result = "[none]";
|
jaroslav@0
|
494 |
break;
|
jaroslav@0
|
495 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
496 |
// [PENDING] - unresolved yet
|
jaroslav@0
|
497 |
XelfiDesignLayout xdl = ((XelfiVisualContainer)((Component)comp).
|
jaroslav@0
|
498 |
getParent()).getDesignLayout();
|
jaroslav@0
|
499 |
result = xdl.getPropertyString((XelfiVisualComponent)comp, realIndex);
|
jaroslav@0
|
500 |
break;
|
jaroslav@0
|
501 |
}
|
jaroslav@0
|
502 |
return result==null ? "" : result;
|
jaroslav@0
|
503 |
}
|
jaroslav@0
|
504 |
|
jaroslav@0
|
505 |
/**
|
jaroslav@0
|
506 |
* Returns string representation of property value
|
jaroslav@0
|
507 |
* in selected components if values are the same.<br>
|
jaroslav@0
|
508 |
* Returns null otherwise or when no comps are selected.
|
jaroslav@0
|
509 |
*/
|
jaroslav@0
|
510 |
String getPropertiesString (int propIndex) {
|
jaroslav@0
|
511 |
if ( selectedComponents.size()==0 ) return null;
|
jaroslav@0
|
512 |
// get property value string from first selected component
|
jaroslav@0
|
513 |
String firstString = null;
|
jaroslav@0
|
514 |
try {
|
jaroslav@0
|
515 |
firstString = getPropertyString(0, propIndex);
|
jaroslav@0
|
516 |
} catch (XFPropertyIndexOutOfBoundsException e) {
|
jaroslav@0
|
517 |
System.err.println(e.getMessage());
|
jaroslav@0
|
518 |
e.printStackTrace(System.err);
|
jaroslav@0
|
519 |
} catch (XFNameNotFoundException e) {
|
jaroslav@0
|
520 |
System.err.println(e.getMessage());
|
jaroslav@0
|
521 |
e.printStackTrace(System.err);
|
jaroslav@0
|
522 |
}
|
jaroslav@0
|
523 |
//check if all values are the same
|
jaroslav@0
|
524 |
boolean propertiesIdentic = true;
|
jaroslav@0
|
525 |
String propertyString = null;
|
jaroslav@0
|
526 |
for (int i=1; i<selectedComponents.size(); i++) {
|
jaroslav@0
|
527 |
try {
|
jaroslav@0
|
528 |
propertyString = getPropertyString(i, propIndex);
|
jaroslav@0
|
529 |
} catch (XFPropertyIndexOutOfBoundsException e) {
|
jaroslav@0
|
530 |
System.err.println(e.getMessage());
|
jaroslav@0
|
531 |
e.printStackTrace(System.err);
|
jaroslav@0
|
532 |
} catch (XFNameNotFoundException e) {
|
jaroslav@0
|
533 |
System.err.println(e.getMessage());
|
jaroslav@0
|
534 |
e.printStackTrace(System.err);
|
jaroslav@0
|
535 |
}
|
jaroslav@0
|
536 |
if (propertyString.compareTo(firstString)!=0) {
|
jaroslav@0
|
537 |
propertiesIdentic = false;
|
jaroslav@0
|
538 |
break;
|
jaroslav@0
|
539 |
}
|
jaroslav@0
|
540 |
}
|
jaroslav@0
|
541 |
return propertiesIdentic==true ? firstString : null;
|
jaroslav@0
|
542 |
}
|
jaroslav@0
|
543 |
|
jaroslav@0
|
544 |
/**
|
jaroslav@0
|
545 |
* Returns property viewer type constant.
|
jaroslav@0
|
546 |
*/
|
jaroslav@0
|
547 |
int getPropertyViewerType (int propIndex)
|
jaroslav@0
|
548 |
throws XFPropertyIndexOutOfBoundsException,
|
jaroslav@0
|
549 |
XFNameNotFoundException {
|
jaroslav@0
|
550 |
// get the component - we can find out viewer type from first comp
|
jaroslav@0
|
551 |
XelfiDesignComponent comp =
|
jaroslav@0
|
552 |
(XelfiDesignComponent)selectedComponents.elementAt(0);
|
jaroslav@0
|
553 |
// get the property index in first comp
|
jaroslav@0
|
554 |
int realIndex = ((Integer)getIndexes(propIndex).
|
jaroslav@0
|
555 |
elementAt(0)).intValue();
|
jaroslav@0
|
556 |
// retrieve viewer type
|
jaroslav@0
|
557 |
int result = -1;
|
jaroslav@0
|
558 |
switch (page) {
|
jaroslav@0
|
559 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
560 |
if (realIndex<0) {
|
jaroslav@0
|
561 |
// well-known props...i can't ask for property viewer type,
|
jaroslav@0
|
562 |
// I have to set it directly
|
jaroslav@0
|
563 |
switch (realIndex) {
|
jaroslav@0
|
564 |
case X_INDEX:
|
jaroslav@0
|
565 |
case Y_INDEX:
|
jaroslav@0
|
566 |
case WIDTH_INDEX:
|
jaroslav@0
|
567 |
case HEIGHT_INDEX:
|
jaroslav@0
|
568 |
result = XFDesignConstants.PVT_INPUT_INT;
|
jaroslav@0
|
569 |
break;
|
jaroslav@0
|
570 |
case NAME_INDEX:
|
jaroslav@0
|
571 |
result = XFDesignConstants.PVT_INPUT_STRING;
|
jaroslav@0
|
572 |
break;
|
jaroslav@0
|
573 |
case LAYOUT_INDEX:
|
jaroslav@0
|
574 |
result = XFDesignConstants.PVT_CHOICE_STRICT;
|
jaroslav@0
|
575 |
break;
|
jaroslav@0
|
576 |
}
|
jaroslav@0
|
577 |
} else {
|
jaroslav@0
|
578 |
result = comp.getPropertyViewerType(realIndex);
|
jaroslav@0
|
579 |
}
|
jaroslav@0
|
580 |
break;
|
jaroslav@0
|
581 |
case XFDesignConstants.CI_PG_EVENTS:
|
jaroslav@0
|
582 |
result = XFDesignConstants.PVT_INPUT_STRING;
|
jaroslav@0
|
583 |
break;
|
jaroslav@0
|
584 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
585 |
XelfiDesignLayout xdl = ((XelfiVisualContainer)((Component)comp).
|
jaroslav@0
|
586 |
getParent()).getDesignLayout();
|
jaroslav@0
|
587 |
result = xdl.getPropertyViewerType(realIndex);
|
jaroslav@0
|
588 |
break;
|
jaroslav@0
|
589 |
}
|
jaroslav@0
|
590 |
return result;
|
jaroslav@0
|
591 |
}
|
jaroslav@0
|
592 |
|
jaroslav@0
|
593 |
boolean isLayoutPageAvailable () {
|
jaroslav@0
|
594 |
// check if all selected components hava the same parent
|
jaroslav@0
|
595 |
Object temp = selectedComponents.elementAt(0);
|
jaroslav@0
|
596 |
if (!(temp instanceof Component)) return false;
|
jaroslav@0
|
597 |
Component parent = ((Component)temp).getParent();
|
jaroslav@0
|
598 |
for (int i=1; i<selectedComponents.size(); i++) {
|
jaroslav@0
|
599 |
temp = selectedComponents.elementAt(i);
|
jaroslav@0
|
600 |
if (!(temp instanceof Component)) return false;
|
jaroslav@0
|
601 |
if (!((Component)temp).getParent().equals(parent)) return false;
|
jaroslav@0
|
602 |
}
|
jaroslav@0
|
603 |
// check if parent is XelfiVisualContainer
|
jaroslav@0
|
604 |
if (!(parent instanceof XelfiVisualContainer)) return false;
|
jaroslav@0
|
605 |
return true;
|
jaroslav@0
|
606 |
}
|
jaroslav@0
|
607 |
|
jaroslav@0
|
608 |
/**
|
jaroslav@0
|
609 |
* Returns the name (string) of the well known property
|
jaroslav@0
|
610 |
* which belongs to index.<br>
|
jaroslav@0
|
611 |
* Returns null if index is bad.
|
jaroslav@0
|
612 |
*/
|
jaroslav@0
|
613 |
String getWellKnownPropertyName (int index) {
|
jaroslav@0
|
614 |
switch (index) {
|
jaroslav@0
|
615 |
case X_INDEX:
|
jaroslav@0
|
616 |
return XName;
|
jaroslav@0
|
617 |
case Y_INDEX:
|
jaroslav@0
|
618 |
return YName;
|
jaroslav@0
|
619 |
case WIDTH_INDEX:
|
jaroslav@0
|
620 |
return WidthName;
|
jaroslav@0
|
621 |
case HEIGHT_INDEX:
|
jaroslav@0
|
622 |
return HeightName;
|
jaroslav@0
|
623 |
case NAME_INDEX:
|
jaroslav@0
|
624 |
return NameName;
|
jaroslav@0
|
625 |
case LAYOUT_INDEX:
|
jaroslav@0
|
626 |
return LayoutName;
|
jaroslav@0
|
627 |
}
|
jaroslav@0
|
628 |
return null;
|
jaroslav@0
|
629 |
}
|
jaroslav@0
|
630 |
|
jaroslav@0
|
631 |
/**
|
jaroslav@0
|
632 |
* Returns an array of constants' names for specified property,
|
jaroslav@0
|
633 |
* exception if an error occurs
|
jaroslav@0
|
634 |
*/
|
jaroslav@0
|
635 |
String[] getPropertyValueNames (int propIndex)
|
jaroslav@0
|
636 |
throws XFPropertyIndexOutOfBoundsException {
|
jaroslav@0
|
637 |
// get the component - we can find out value names from first comp
|
jaroslav@0
|
638 |
XelfiDesignComponent comp =
|
jaroslav@0
|
639 |
(XelfiDesignComponent)selectedComponents.elementAt(0);
|
jaroslav@0
|
640 |
// get the property index in first comp
|
jaroslav@0
|
641 |
int realIndex = ((Integer)getIndexes(propIndex).
|
jaroslav@0
|
642 |
elementAt(0)).intValue();
|
jaroslav@0
|
643 |
// get value names and return
|
jaroslav@0
|
644 |
switch (page) {
|
jaroslav@0
|
645 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
646 |
if (realIndex<0) {
|
jaroslav@0
|
647 |
switch (realIndex) {
|
jaroslav@0
|
648 |
case LAYOUT_INDEX:
|
jaroslav@0
|
649 |
// return names of installed layouts
|
jaroslav@0
|
650 |
return XFInstalledLayouts.getAllLayoutNames();
|
jaroslav@0
|
651 |
}
|
jaroslav@0
|
652 |
}
|
jaroslav@0
|
653 |
return comp.getPropertyValueNames(realIndex);
|
jaroslav@0
|
654 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
655 |
// [PENDING] - maybe not finished yet
|
jaroslav@0
|
656 |
XelfiDesignLayout xdl = ((XelfiVisualContainer)((Component)comp).
|
jaroslav@0
|
657 |
getParent()).getDesignLayout();
|
jaroslav@0
|
658 |
return xdl.getPropertyValueNames(realIndex);
|
jaroslav@0
|
659 |
}
|
jaroslav@0
|
660 |
return null;
|
jaroslav@0
|
661 |
}
|
jaroslav@0
|
662 |
|
jaroslav@0
|
663 |
/**
|
jaroslav@0
|
664 |
* Runs special property editing dialog.
|
jaroslav@0
|
665 |
*/
|
jaroslav@0
|
666 |
void specialPropertyInput (Frame parent, int propIndex)
|
jaroslav@0
|
667 |
throws XFPropertyIndexOutOfBoundsException,
|
jaroslav@0
|
668 |
XFPropertyNoSpecialInputException,
|
jaroslav@0
|
669 |
XFNameNotFoundException {
|
jaroslav@0
|
670 |
// get the component - we can find out dialog from first comp
|
jaroslav@0
|
671 |
XelfiDesignComponent comp =
|
jaroslav@0
|
672 |
(XelfiDesignComponent)selectedComponents.elementAt(0);
|
jaroslav@0
|
673 |
// get the property index in first comp
|
jaroslav@0
|
674 |
int realIndex = ((Integer)getIndexes(propIndex).
|
jaroslav@0
|
675 |
elementAt(0)).intValue();
|
jaroslav@0
|
676 |
// Debug.debug(Debug.INSPECTOR, "I'm in special input...");
|
jaroslav@0
|
677 |
// try to run dialog
|
jaroslav@0
|
678 |
switch (page) {
|
jaroslav@0
|
679 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
680 |
comp.specialPropertyInput(parent, realIndex);
|
jaroslav@0
|
681 |
break;
|
jaroslav@0
|
682 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
683 |
// [PENDING] - maybe not good
|
jaroslav@0
|
684 |
XelfiDesignLayout xdl = ((XelfiVisualContainer)((Component)comp).
|
jaroslav@0
|
685 |
getParent()).getDesignLayout();
|
jaroslav@0
|
686 |
xdl.specialPropertyInput(parent, (XelfiVisualComponent)comp, realIndex);
|
jaroslav@0
|
687 |
break;
|
jaroslav@0
|
688 |
}
|
jaroslav@0
|
689 |
}
|
jaroslav@0
|
690 |
|
jaroslav@0
|
691 |
/**
|
jaroslav@0
|
692 |
* Returns default event name for specified property.
|
jaroslav@0
|
693 |
* Returns null if property is not an event prop.
|
jaroslav@0
|
694 |
*/
|
jaroslav@0
|
695 |
String getDefaultEventName (int propIndex) {
|
jaroslav@0
|
696 |
if (getPage()!=XFDesignConstants.CI_PG_EVENTS) return null;
|
jaroslav@0
|
697 |
// get the first component - we take into count name of the first
|
jaroslav@0
|
698 |
// selected component only for now....(change is possible in future)
|
jaroslav@0
|
699 |
XelfiDesignComponent comp =
|
jaroslav@0
|
700 |
(XelfiDesignComponent)selectedComponents.elementAt(0);
|
jaroslav@0
|
701 |
// get the property index in first comp
|
jaroslav@0
|
702 |
int realIndex = ((Integer)getIndexes(propIndex).
|
jaroslav@0
|
703 |
elementAt(0)).intValue();
|
jaroslav@0
|
704 |
// get the name of the component
|
jaroslav@0
|
705 |
String compName = comp.getName();
|
jaroslav@0
|
706 |
// get property name string
|
jaroslav@0
|
707 |
String propName = (comp.getEventNames())[realIndex];
|
jaroslav@0
|
708 |
// merge names and create default event name
|
jaroslav@0
|
709 |
return createDefaultEventName(compName, propName);
|
jaroslav@0
|
710 |
}
|
jaroslav@0
|
711 |
|
jaroslav@0
|
712 |
/**
|
jaroslav@0
|
713 |
* Merges given comp and prop names and creates default event name
|
jaroslav@0
|
714 |
*/
|
jaroslav@0
|
715 |
private String createDefaultEventName(String compName, String propName) {
|
jaroslav@0
|
716 |
/* String restOfEventName = propName.startsWith(eventStart)
|
jaroslav@0
|
717 |
? propName.substring(eventStart.length(), propName.length())
|
jaroslav@0
|
718 |
: propName; */
|
jaroslav@0
|
719 |
return new String(compName+propName);
|
jaroslav@0
|
720 |
}
|
jaroslav@0
|
721 |
|
jaroslav@0
|
722 |
/**
|
jaroslav@0
|
723 |
* Builds indexes for specified page if they are not created yet
|
jaroslav@0
|
724 |
*/
|
jaroslav@0
|
725 |
private void buildIndexes () {
|
jaroslav@0
|
726 |
switch (page) {
|
jaroslav@0
|
727 |
case XFDesignConstants.CI_PG_PROPERTIES:
|
jaroslav@0
|
728 |
if (propertiesIndexes==null)
|
jaroslav@0
|
729 |
propertiesIndexes = buildPropertiesIndexes();
|
jaroslav@0
|
730 |
break;
|
jaroslav@0
|
731 |
case XFDesignConstants.CI_PG_EVENTS:
|
jaroslav@0
|
732 |
if (eventsIndexes==null)
|
jaroslav@0
|
733 |
eventsIndexes = buildEventsIndexes();
|
jaroslav@0
|
734 |
break;
|
jaroslav@0
|
735 |
case XFDesignConstants.CI_PG_LAYOUT:
|
jaroslav@0
|
736 |
if (layoutIndexes==null)
|
jaroslav@0
|
737 |
layoutIndexes = buildLayoutIndexes();
|
jaroslav@0
|
738 |
break;
|
jaroslav@0
|
739 |
}
|
jaroslav@0
|
740 |
}
|
jaroslav@0
|
741 |
|
jaroslav@0
|
742 |
/**
|
jaroslav@0
|
743 |
* Constructs a vector of indexes for properties in selected
|
jaroslav@0
|
744 |
* components. Indexes vector says us at which index which
|
jaroslav@0
|
745 |
* property can be found in selected components
|
jaroslav@0
|
746 |
* (yep, that's the point, the same property can be at different
|
jaroslav@0
|
747 |
* indexes in different selected components - that's why indexes
|
jaroslav@0
|
748 |
* vector exists).
|
jaroslav@0
|
749 |
*/
|
jaroslav@0
|
750 |
private Vector buildPropertiesIndexes () {
|
jaroslav@0
|
751 |
if (selectedComponents==null) return null;
|
jaroslav@0
|
752 |
Vector indexes = new Vector(10, 10);
|
jaroslav@0
|
753 |
Vector propertyIndexes = null;
|
jaroslav@0
|
754 |
XelfiDesignComponent first =
|
jaroslav@0
|
755 |
(XelfiDesignComponent)(selectedComponents.elementAt(0));
|
jaroslav@0
|
756 |
int selCount = selectedComponents.size();
|
jaroslav@0
|
757 |
// adds Name property
|
jaroslav@0
|
758 |
if (selCount==1) {
|
jaroslav@0
|
759 |
propertyIndexes = new Vector();
|
jaroslav@0
|
760 |
propertyIndexes.addElement((Object)(new Integer(NAME_INDEX)));
|
jaroslav@0
|
761 |
indexes.addElement((Object)propertyIndexes);
|
jaroslav@0
|
762 |
}
|
jaroslav@0
|
763 |
if (allSelectedAreVisual()) {
|
jaroslav@0
|
764 |
// selected comps are visual, so add props for position
|
jaroslav@0
|
765 |
// and these are X, Y, Width, Height
|
jaroslav@0
|
766 |
propertyIndexes = new Vector();
|
jaroslav@0
|
767 |
fillVector(propertyIndexes, X_INDEX, selCount);
|
jaroslav@0
|
768 |
indexes.addElement((Object)propertyIndexes);
|
jaroslav@0
|
769 |
propertyIndexes = new Vector();
|
jaroslav@0
|
770 |
fillVector(propertyIndexes, Y_INDEX, selCount);
|
jaroslav@0
|
771 |
indexes.addElement((Object)propertyIndexes);
|
jaroslav@0
|
772 |
propertyIndexes = new Vector();
|
jaroslav@0
|
773 |
fillVector(propertyIndexes, WIDTH_INDEX, selCount);
|
jaroslav@0
|
774 |
indexes.addElement((Object)propertyIndexes);
|
jaroslav@0
|
775 |
propertyIndexes = new Vector();
|
jaroslav@0
|
776 |
fillVector(propertyIndexes, HEIGHT_INDEX, selCount);
|
jaroslav@0
|
777 |
indexes.addElement((Object)propertyIndexes);
|
jaroslav@0
|
778 |
}
|
jaroslav@0
|
779 |
// add layout property, if comp is a container and
|
jaroslav@0
|
780 |
// only and only one component is selected
|
jaroslav@0
|
781 |
if ((selCount==1)&&(first instanceof XelfiVisualContainer)) {
|
jaroslav@0
|
782 |
propertyIndexes = new Vector();
|
jaroslav@0
|
783 |
propertyIndexes.addElement((Object)(new Integer(LAYOUT_INDEX)));
|
jaroslav@0
|
784 |
indexes.addElement((Object)propertyIndexes);
|
jaroslav@0
|
785 |
}
|
jaroslav@0
|
786 |
|
jaroslav@0
|
787 |
// iterates through selected components and finds common set
|
jaroslav@0
|
788 |
// saves indexes of found common properties into indexes structure
|
jaroslav@0
|
789 |
String[] firstPropertyNames = first.getPropertyNames();
|
jaroslav@0
|
790 |
for (int i=0; i<first.getPropertyCount(); i++) {
|
jaroslav@0
|
791 |
boolean isCommon = true;
|
jaroslav@0
|
792 |
propertyIndexes = new Vector();
|
jaroslav@0
|
793 |
propertyIndexes.addElement((Object)(new Integer(i)));
|
jaroslav@0
|
794 |
for (int y=1; y<selectedComponents.size(); y++) {
|
jaroslav@0
|
795 |
int propertyIndex = propertyExist(first, i, firstPropertyNames[i],
|
jaroslav@0
|
796 |
(XelfiDesignComponent)(selectedComponents.elementAt(y)));
|
jaroslav@0
|
797 |
if (propertyIndex>=0) {
|
jaroslav@0
|
798 |
propertyIndexes.addElement((Object)(new Integer(propertyIndex)));
|
jaroslav@0
|
799 |
} else {
|
jaroslav@0
|
800 |
isCommon = false;
|
jaroslav@0
|
801 |
break;
|
jaroslav@0
|
802 |
}
|
jaroslav@0
|
803 |
}
|
jaroslav@0
|
804 |
if (isCommon==true) indexes.addElement((Object)propertyIndexes);
|
jaroslav@0
|
805 |
}
|
jaroslav@0
|
806 |
return indexes;
|
jaroslav@0
|
807 |
}
|
jaroslav@0
|
808 |
|
jaroslav@0
|
809 |
/**
|
jaroslav@0
|
810 |
* Checks if all of selected components are visual component.
|
jaroslav@0
|
811 |
*/
|
jaroslav@0
|
812 |
private boolean allSelectedAreVisual () {
|
jaroslav@0
|
813 |
for (int i=0; i<selectedComponents.size(); i++) {
|
jaroslav@0
|
814 |
if (!(selectedComponents.elementAt(i)
|
jaroslav@0
|
815 |
instanceof XelfiVisualComponent))
|
jaroslav@0
|
816 |
return false;
|
jaroslav@0
|
817 |
}
|
jaroslav@0
|
818 |
return true;
|
jaroslav@0
|
819 |
}
|
jaroslav@0
|
820 |
|
jaroslav@0
|
821 |
/**
|
jaroslav@0
|
822 |
* Fills vector with integer objects created from given index.
|
jaroslav@0
|
823 |
*/
|
jaroslav@0
|
824 |
void fillVector (Vector vector, int index, int count) {
|
jaroslav@0
|
825 |
for (int i=0; i<count; i++) {
|
jaroslav@0
|
826 |
vector.addElement((Object)(new Integer(index)));
|
jaroslav@0
|
827 |
}
|
jaroslav@0
|
828 |
}
|
jaroslav@0
|
829 |
|
jaroslav@0
|
830 |
/**
|
jaroslav@0
|
831 |
* Searches second component for property which is the same as
|
jaroslav@0
|
832 |
* property of first component at index "index".
|
jaroslav@0
|
833 |
* Returns index of found property or -1 on error.
|
jaroslav@0
|
834 |
*/
|
jaroslav@0
|
835 |
private int propertyExist (XelfiDesignComponent first, int index,
|
jaroslav@0
|
836 |
String firstName,
|
jaroslav@0
|
837 |
XelfiDesignComponent second) {
|
jaroslav@0
|
838 |
// searches for the property in "second" component
|
jaroslav@0
|
839 |
// which is equal to property of "first" component at index "index"
|
jaroslav@0
|
840 |
String[] secondNames = second.getPropertyNames();
|
jaroslav@0
|
841 |
for (int i=0; i<second.getPropertyCount(); i++) {
|
jaroslav@0
|
842 |
try {
|
jaroslav@0
|
843 |
// compares names and viewer types of properties
|
jaroslav@0
|
844 |
if ((firstName.compareTo(secondNames[i])==0) &&
|
jaroslav@0
|
845 |
(first.getPropertyViewerType(index)==
|
jaroslav@0
|
846 |
second.getPropertyViewerType(i)))
|
jaroslav@0
|
847 |
return i;
|
jaroslav@0
|
848 |
} catch (XFPropertyIndexOutOfBoundsException e) {};
|
jaroslav@0
|
849 |
}
|
jaroslav@0
|
850 |
// nothing found - return non-existing index
|
jaroslav@0
|
851 |
return -1;
|
jaroslav@0
|
852 |
}
|
jaroslav@0
|
853 |
|
jaroslav@0
|
854 |
/**
|
jaroslav@0
|
855 |
* Builds indexes structure for events.
|
jaroslav@0
|
856 |
*/
|
jaroslav@0
|
857 |
private Vector buildEventsIndexes () {
|
jaroslav@0
|
858 |
if (selectedComponents==null) return null;
|
jaroslav@0
|
859 |
Vector indexes = new Vector(10, 10);
|
jaroslav@0
|
860 |
|
jaroslav@0
|
861 |
// iterates through selected components and finds common set of events
|
jaroslav@0
|
862 |
// saves indexes of found common events into indexes structure
|
jaroslav@0
|
863 |
XelfiDesignComponent first =
|
jaroslav@0
|
864 |
(XelfiDesignComponent)(selectedComponents.elementAt(0));
|
jaroslav@0
|
865 |
String[] firstEventNames = first.getEventNames();
|
jaroslav@0
|
866 |
for (int i=0; i<first.getEventCount(); i++) {
|
jaroslav@0
|
867 |
boolean isCommon = true;
|
jaroslav@0
|
868 |
Vector eventIndexes = new Vector();
|
jaroslav@0
|
869 |
eventIndexes.addElement((Object)(new Integer(i)));
|
jaroslav@0
|
870 |
for (int y=1; y<selectedComponents.size(); y++) {
|
jaroslav@0
|
871 |
int eventIndex = eventExist(first, i, firstEventNames[i],
|
jaroslav@0
|
872 |
(XelfiDesignComponent)(selectedComponents.elementAt(y)));
|
jaroslav@0
|
873 |
if (eventIndex>=0) {
|
jaroslav@0
|
874 |
eventIndexes.addElement((Object)(new Integer(eventIndex)));
|
jaroslav@0
|
875 |
} else {
|
jaroslav@0
|
876 |
isCommon = false;
|
jaroslav@0
|
877 |
break;
|
jaroslav@0
|
878 |
}
|
jaroslav@0
|
879 |
}
|
jaroslav@0
|
880 |
if (isCommon==true) indexes.addElement((Object)eventIndexes);
|
jaroslav@0
|
881 |
}
|
jaroslav@0
|
882 |
return indexes;
|
jaroslav@0
|
883 |
}
|
jaroslav@0
|
884 |
|
jaroslav@0
|
885 |
/**
|
jaroslav@0
|
886 |
* Searches second component for an event property.
|
jaroslav@0
|
887 |
* Returns index of event property.
|
jaroslav@0
|
888 |
*/
|
jaroslav@0
|
889 |
private int eventExist (XelfiDesignComponent first, int index,
|
jaroslav@0
|
890 |
String firstName,
|
jaroslav@0
|
891 |
XelfiDesignComponent second) {
|
jaroslav@0
|
892 |
// searches for the event property in "second" component
|
jaroslav@0
|
893 |
// which is equal to event property of "first" component at index "index"
|
jaroslav@0
|
894 |
String[] secondNames = second.getEventNames();
|
jaroslav@0
|
895 |
for (int i=0; i<second.getEventCount(); i++) {
|
jaroslav@0
|
896 |
// compares names of event properties
|
jaroslav@0
|
897 |
if (firstName.compareTo(secondNames[i])==0)
|
jaroslav@0
|
898 |
return i;
|
jaroslav@0
|
899 |
}
|
jaroslav@0
|
900 |
// nothing found - return non-existing index
|
jaroslav@0
|
901 |
return -1;
|
jaroslav@0
|
902 |
}
|
jaroslav@0
|
903 |
|
jaroslav@0
|
904 |
|
jaroslav@0
|
905 |
private Vector buildLayoutIndexes () {
|
jaroslav@0
|
906 |
if (selectedComponents==null) return null;
|
jaroslav@0
|
907 |
Vector indexes = new Vector(10, 10);
|
jaroslav@0
|
908 |
Component parent =
|
jaroslav@0
|
909 |
((Component)selectedComponents.elementAt(0)).getParent();
|
jaroslav@0
|
910 |
XelfiDesignLayout xdl = ((XelfiVisualContainer)parent).getDesignLayout();
|
jaroslav@0
|
911 |
String[] firstPropertyNames = xdl.getPropertyNames();
|
jaroslav@0
|
912 |
for (int i=0; i<xdl.getPropertyCount(); i++) {
|
jaroslav@0
|
913 |
Vector layoutIndexes = new Vector();
|
jaroslav@0
|
914 |
layoutIndexes.addElement((Object)(new Integer(i)));
|
jaroslav@0
|
915 |
indexes.addElement((Object)layoutIndexes);
|
jaroslav@0
|
916 |
// debug
|
jaroslav@0
|
917 |
// Debug.debug(Debug.INSPECTOR, firstPropertyNames[i]);
|
jaroslav@0
|
918 |
}
|
jaroslav@0
|
919 |
return indexes;
|
jaroslav@0
|
920 |
}
|
jaroslav@0
|
921 |
|
jaroslav@0
|
922 |
/**
|
jaroslav@0
|
923 |
* Compares names of the events.
|
jaroslav@0
|
924 |
*/
|
jaroslav@0
|
925 |
private int compareEvents (String oldName, String newName) {
|
jaroslav@0
|
926 |
if ( oldName==null || (oldName.compareTo("")==0) ) {
|
jaroslav@0
|
927 |
if ( newName!=null && (newName.compareTo("")!=0) )
|
jaroslav@0
|
928 |
return NEW_NAME;
|
jaroslav@0
|
929 |
} else {
|
jaroslav@0
|
930 |
if ( newName==null || (newName.compareTo("")==0) )
|
jaroslav@0
|
931 |
return DELETED_NAME;
|
jaroslav@0
|
932 |
else {
|
jaroslav@0
|
933 |
if ( oldName.compareTo(newName)!=0 )
|
jaroslav@0
|
934 |
return CHANGED_NAME;
|
jaroslav@0
|
935 |
}
|
jaroslav@0
|
936 |
}
|
jaroslav@0
|
937 |
return SAME_NAME;
|
jaroslav@0
|
938 |
}
|
jaroslav@0
|
939 |
|
jaroslav@0
|
940 |
|
jaroslav@0
|
941 |
/**
|
jaroslav@0
|
942 |
* Finds and creates layout from given index.
|
jaroslav@0
|
943 |
* Index means index into array of installed layout names.
|
jaroslav@0
|
944 |
*/
|
jaroslav@0
|
945 |
private XelfiDesignLayout buildLayoutFromIndex (int index) {
|
jaroslav@0
|
946 |
// get layout names
|
jaroslav@0
|
947 |
String[] layoutNames = XFInstalledLayouts.getAllLayoutNames();
|
jaroslav@0
|
948 |
// create specified layout
|
jaroslav@0
|
949 |
return XFInstalledLayouts.createLayout(layoutNames[index]);
|
jaroslav@0
|
950 |
}
|
jaroslav@0
|
951 |
|
jaroslav@0
|
952 |
/**
|
jaroslav@0
|
953 |
* Refreshes the component according to the given
|
jaroslav@0
|
954 |
* value of refresh type
|
jaroslav@0
|
955 |
*/
|
jaroslav@0
|
956 |
private void refreshComponent (XelfiDesignComponent xdc, int refreshType) {
|
jaroslav@0
|
957 |
if (!(xdc instanceof Component)) return;
|
jaroslav@0
|
958 |
Component comp = (Component)xdc;
|
jaroslav@0
|
959 |
switch (refreshType) {
|
jaroslav@0
|
960 |
case XFDesignConstants.RSP_REPAINT_COMP:
|
jaroslav@0
|
961 |
comp.repaint();
|
jaroslav@0
|
962 |
break;
|
jaroslav@0
|
963 |
case XFDesignConstants.RSP_SHOW_HIDE:
|
jaroslav@0
|
964 |
comp.hide();
|
jaroslav@0
|
965 |
comp.show();
|
jaroslav@0
|
966 |
break;
|
jaroslav@0
|
967 |
case XFDesignConstants.RSP_VALIDATE:
|
jaroslav@0
|
968 |
comp.invalidate();
|
jaroslav@0
|
969 |
comp.validate();
|
jaroslav@0
|
970 |
break;
|
jaroslav@0
|
971 |
case XFDesignConstants.RSP_VALIDATE_PARENT:
|
jaroslav@0
|
972 |
comp.invalidate();
|
jaroslav@0
|
973 |
comp.getParent().validate();
|
jaroslav@0
|
974 |
break;
|
jaroslav@0
|
975 |
}
|
jaroslav@0
|
976 |
}
|
jaroslav@0
|
977 |
|
jaroslav@0
|
978 |
}
|
jaroslav@0
|
979 |
|