001: /*
002: * $RCSfile: ViewSpecificGroupRetained.java,v $
003: *
004: * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.9 $
028: * $Date: 2008/02/28 20:17:33 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.*;
035:
036: /**
037: * The ViewSpecificGroup node retained object.
038: */
039:
040: class ViewSpecificGroupRetained extends GroupRetained {
041:
042: ArrayList apiViewList = new ArrayList();
043:
044: // Used by leaf objects particularly GAs
045: // Updated in a MT Safe manner and also used by RenderBin
046: ArrayList cachedViewList = new ArrayList();
047:
048: // The object that contains the dynamic HashKey - a string type object
049: // Used in scoping
050: HashKey tempKey = new HashKey(250);
051:
052: // ArrayList of Integer indices
053: ArrayList parentLists = new ArrayList();
054:
055: static final int SET_VIEW = 0x1;
056: static final int ADD_VIEW = 0x2;
057: static final int REMOVE_VIEW = 0x4;
058:
059: // Construct retained object
060: ViewSpecificGroupRetained() {
061: this .nodeType = NodeRetained.VIEWSPECIFICGROUP;
062: viewLists = new ArrayList();
063: }
064:
065: void addView(View view) {
066: int i;
067: Integer mtype = new Integer(ADD_VIEW);
068:
069: apiViewList.add(view);
070: if (source.isLive() && view != null) {
071: // Gather all affected leaf nodes and send a message to
072: // RenderingEnv and RenderBin
073: if (inSharedGroup) {
074: ArrayList parentList;
075: for (int k = 0; k < localToVworldKeys.length; k++) {
076: parentList = (ArrayList) parentLists.get(k);
077: // If the parentList contains this view or if this is the
078: // first VSG then ..
079: if (parentList == null || parentList.contains(view)) {
080: Object[] objAry = new Object[4];
081: ArrayList addVsgList = new ArrayList();
082: ArrayList addLeafList = new ArrayList();
083: int[] addKeyList = new int[10];
084:
085: HashKey key = localToVworldKeys[k];
086: addVsgList.add(this );
087: addKeyList[0] = k;
088: objAry[0] = view;
089: objAry[1] = addVsgList;
090: objAry[2] = addLeafList;
091: /*
092: for (int n = 0; n < addLeafList.size(); n++) {
093: System.err.println("Shared:n = "+n+" addLeafList = "+addLeafList.get(n));
094: }
095: */
096: objAry[3] = super .processViewSpecificInfo(
097: ADD_VIEW, (HashKey) key, view,
098: addVsgList, addKeyList, addLeafList);
099: J3dMessage message = new J3dMessage();
100: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
101: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
102: | J3dThread.UPDATE_RENDER
103: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
104: message.universe = universe;
105: message.args[0] = mtype;
106: message.args[1] = objAry;
107: VirtualUniverse.mc.processMessage(message);
108: }
109: }
110:
111: } else {
112: ArrayList parentList = (ArrayList) parentLists.get(0);
113:
114: // If the parentList contains this view or if this is the
115: // first VSG then ..
116: if (parentList == null || parentList.contains(view)) {
117: Object[] objAry = new Object[4];
118: ArrayList addVsgList = new ArrayList();
119: ArrayList addLeafList = new ArrayList();
120: int[] addKeyList = new int[10];
121:
122: objAry[0] = view;
123: objAry[1] = addVsgList;
124: objAry[2] = addLeafList;
125:
126: addVsgList.add(this );
127: addKeyList[0] = 0;
128: tempKey.reset();
129: objAry[3] = super .processViewSpecificInfo(ADD_VIEW,
130: tempKey, view, addVsgList, addKeyList,
131: addLeafList);
132:
133: /*
134: for (int n = 0; n < addLeafList.size(); n++) {
135: System.err.println("n = "+n+" addLeafList = "+addLeafList.get(n));
136: }
137: */
138:
139: J3dMessage message = new J3dMessage();
140: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
141: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
142: | J3dThread.UPDATE_RENDER
143: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
144: message.universe = universe;
145: message.args[0] = mtype;
146: message.args[1] = objAry;
147: VirtualUniverse.mc.processMessage(message);
148: }
149: }
150:
151: }
152: }
153:
154: void setView(View view, int index) {
155: int i;
156:
157: View oldView = (View) apiViewList.get(index);
158: Integer mtype = new Integer(SET_VIEW);
159:
160: if (oldView == view)
161: return;
162:
163: apiViewList.set(index, view);
164: if (source.isLive()) {
165: // Gather all affected leaf nodes and send a message to
166: // RenderingEnv and RenderBin
167: if (inSharedGroup) {
168: ArrayList parentList;
169: for (int k = 0; k < localToVworldKeys.length; k++) {
170: parentList = (ArrayList) parentLists.get(k);
171: Object[] objAry = new Object[8];
172: ArrayList addVsgList = new ArrayList();
173: ArrayList removeVsgList = new ArrayList();
174: ArrayList addLeafList = new ArrayList();
175: ArrayList removeLeafList = new ArrayList();
176: int[] addKeyList = new int[10];
177: int[] removeKeyList = new int[10];
178:
179: objAry[0] = view;
180: objAry[1] = addVsgList;
181: objAry[2] = addLeafList;
182: objAry[4] = oldView;
183: objAry[5] = removeVsgList;
184: objAry[6] = removeLeafList;
185:
186: HashKey key = localToVworldKeys[k];
187: if (oldView != null
188: && (parentList == null || parentList
189: .contains(oldView))) {
190: removeVsgList.add(this );
191: removeKeyList[0] = k;
192: objAry[7] = super .processViewSpecificInfo(
193: REMOVE_VIEW, (HashKey) key, oldView,
194: removeVsgList, removeKeyList,
195: removeLeafList);
196: }
197:
198: if (view != null
199: && (parentList == null || parentList
200: .contains(view))) {
201: addVsgList.add(this );
202: addKeyList[0] = k;
203: objAry[3] = super .processViewSpecificInfo(
204: ADD_VIEW, (HashKey) key, view,
205: addVsgList, addKeyList, addLeafList);
206: }
207: J3dMessage message = new J3dMessage();
208: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
209: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
210: | J3dThread.UPDATE_RENDER
211: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
212: message.universe = universe;
213: message.args[0] = mtype;
214: message.args[1] = objAry;
215: VirtualUniverse.mc.processMessage(message);
216: }
217:
218: } else {
219: ArrayList parentList = (ArrayList) parentLists.get(0);
220: Object[] objAry = new Object[8];
221: ArrayList addVsgList = new ArrayList();
222: ArrayList removeVsgList = new ArrayList();
223: ArrayList addLeafList = new ArrayList();
224: ArrayList removeLeafList = new ArrayList();
225: int[] addKeyList = new int[10];
226: int[] removeKeyList = new int[10];
227:
228: objAry[0] = view;
229: objAry[1] = addVsgList;
230: objAry[2] = addLeafList;
231: objAry[4] = oldView;
232: objAry[5] = removeVsgList;
233: objAry[6] = removeLeafList;
234:
235: tempKey.reset();
236: if (oldView != null
237: && (parentList == null || parentList
238: .contains(oldView))) {
239: removeVsgList.add(this );
240: removeKeyList[0] = 0;
241: objAry[7] = super .processViewSpecificInfo(
242: REMOVE_VIEW, (HashKey) tempKey, oldView,
243: removeVsgList, removeKeyList,
244: removeLeafList);
245: }
246: if (view != null
247: && (parentList == null || parentList
248: .contains(view))) {
249: tempKey.reset();
250: addVsgList.add(this );
251: addKeyList[0] = 0;
252: objAry[3] = super .processViewSpecificInfo(ADD_VIEW,
253: (HashKey) tempKey, view, addVsgList,
254: addKeyList, addLeafList);
255: }
256: J3dMessage message = new J3dMessage();
257: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
258: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
259: | J3dThread.UPDATE_RENDER
260: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
261:
262: message.universe = universe;
263: message.args[0] = mtype;
264: message.args[1] = objAry;
265: VirtualUniverse.mc.processMessage(message);
266: }
267:
268: }
269:
270: }
271:
272: int[] processViewSpecificInfo(int mode, HashKey key, View v,
273: ArrayList vsgList, int[] keyList, ArrayList leaflist) {
274: int hkIndex = 0;
275: Integer hashInt = null;
276: int[] newKeyList = null;
277: // Get the intersection of the viewList with this view,
278:
279: if (source.isLive()) {
280: if (inSharedGroup) {
281: hkIndex = key.equals(localToVworldKeys, 0,
282: localToVworldKeys.length);
283: }
284:
285: if (mode == ADD_VIEW) {
286: ArrayList parentList = (ArrayList) parentLists
287: .get(hkIndex);
288: parentList.add(v);
289: } else if (mode == REMOVE_VIEW) {
290: ArrayList parentList = (ArrayList) parentLists
291: .get(hkIndex);
292: parentList.remove(v);
293: }
294: if (apiViewList.contains(v)) {
295: // System.err.println("processViewSpecificInfo, this = "+this+" key = "+key);
296: vsgList.add(this );
297: if (keyList.length < vsgList.size()) {
298: // System.err.println("====> allocating new array");
299: newKeyList = new int[keyList.length + 20];
300: System.arraycopy(keyList, 0, newKeyList, 0,
301: keyList.length);
302: keyList = newKeyList;
303: }
304: if (mode == ADD_VIEW) {
305: if (inSharedGroup) {
306: keyList[vsgList.size() - 1] = hkIndex;
307:
308: } else {
309: keyList[vsgList.size() - 1] = 0;
310: }
311: } else if (mode == REMOVE_VIEW) {
312: if (inSharedGroup) {
313: keyList[vsgList.size() - 1] = hkIndex;
314: } else {
315: keyList[vsgList.size() - 1] = 0;
316: }
317: }
318: return super .processViewSpecificInfo(mode, key, v,
319: vsgList, keyList, leaflist);
320: }
321: }
322: return keyList;
323: }
324:
325: View getView(int index) {
326: return (View) apiViewList.get(index);
327: }
328:
329: void insertView(View view, int index) {
330: int i;
331: Integer mtype = new Integer(ADD_VIEW);
332:
333: apiViewList.add(index, view);
334: if (source.isLive() && view != null) {
335: // Gather all affected leaf nodes and send a message to
336: // RenderingEnv and RenderBin
337: if (inSharedGroup) {
338: ArrayList parentList;
339: for (int k = 0; k < localToVworldKeys.length; k++) {
340: parentList = (ArrayList) parentLists.get(k);
341: // If the parentList contains this view or if this is the
342: // first VSG then ..
343: if (parentList == null || parentList.contains(view)) {
344: Object[] objAry = new Object[4];
345: ArrayList addVsgList = new ArrayList();
346: ArrayList addLeafList = new ArrayList();
347: int[] addKeyList = new int[10];
348:
349: HashKey key = localToVworldKeys[k];
350: addVsgList.add(this );
351: addKeyList[0] = k;
352: objAry[0] = view;
353: objAry[1] = addVsgList;
354: objAry[2] = addLeafList;
355: /*
356: for (int n = 0; n < addLeafList.size(); n++) {
357: System.err.println("Shared:n = "+n+" addLeafList = "+addLeafList.get(n));
358: }
359: */
360: objAry[3] = super .processViewSpecificInfo(
361: ADD_VIEW, (HashKey) key, view,
362: addVsgList, addKeyList, addLeafList);
363: J3dMessage message = new J3dMessage();
364: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
365: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
366: | J3dThread.UPDATE_RENDER
367: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
368: message.universe = universe;
369: message.args[0] = mtype;
370: message.args[1] = objAry;
371: VirtualUniverse.mc.processMessage(message);
372: }
373: }
374:
375: } else {
376: ArrayList parentList = (ArrayList) parentLists.get(0);
377:
378: // If the parentList contains this view or if this is the
379: // first VSG then ..
380: if (parentList == null || parentList.contains(view)) {
381: Object[] objAry = new Object[4];
382: ArrayList addVsgList = new ArrayList();
383: ArrayList addLeafList = new ArrayList();
384: int[] addKeyList = new int[10];
385:
386: objAry[0] = view;
387: objAry[1] = addVsgList;
388: objAry[2] = addLeafList;
389:
390: addVsgList.add(this );
391: addKeyList[0] = 0;
392: tempKey.reset();
393: objAry[3] = super .processViewSpecificInfo(ADD_VIEW,
394: tempKey, view, addVsgList, addKeyList,
395: addLeafList);
396:
397: /*
398: for (int n = 0; n < addLeafList.size(); n++) {
399: System.err.println("n = "+n+" addLeafList = "+addLeafList.get(n));
400: }
401: */
402:
403: J3dMessage message = new J3dMessage();
404: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
405: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
406: | J3dThread.UPDATE_RENDER
407: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
408: message.universe = universe;
409: message.args[0] = mtype;
410: message.args[1] = objAry;
411: VirtualUniverse.mc.processMessage(message);
412: }
413: }
414:
415: }
416: }
417:
418: void removeView(int index) {
419: int i;
420: View v = (View) apiViewList.remove(index);
421: if (source.isLive() && v != null) {
422: // Gather all affected leaf nodes and send a message to
423: // RenderingEnv and RenderBin
424: if (inSharedGroup) {
425: ArrayList parentList;
426: for (int k = 0; k < localToVworldKeys.length; k++) {
427: parentList = (ArrayList) parentLists.get(k);
428: // If the parentList contains this view or if this is the
429: // first VSG then ..
430: if (parentList == null || parentList.contains(v)) {
431: Object[] objAry = new Object[4];
432: ArrayList removeVsgList = new ArrayList();
433: ArrayList removeLeafList = new ArrayList();
434: int[] removeKeyList = new int[10];
435:
436: objAry[0] = v;
437: objAry[1] = removeVsgList;
438: objAry[2] = removeLeafList;
439: HashKey key = localToVworldKeys[k];
440:
441: removeVsgList.add(this );
442: removeKeyList[0] = k;
443:
444: objAry[3] = super .processViewSpecificInfo(
445: REMOVE_VIEW, (HashKey) key, v,
446: removeVsgList, removeKeyList,
447: removeLeafList);
448:
449: J3dMessage message = new J3dMessage();
450: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
451: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
452: | J3dThread.UPDATE_RENDER
453: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
454: message.universe = universe;
455: message.args[0] = new Integer(REMOVE_VIEW);
456: message.args[1] = objAry;
457: VirtualUniverse.mc.processMessage(message);
458: }
459: }
460:
461: } else {
462: ArrayList parentList = (ArrayList) parentLists.get(0);
463:
464: // If the parentList contains this view or if this is the
465: // first VSG then ..
466: if (parentList == null || parentList.contains(v)) {
467: Object[] objAry = new Object[4];
468: ArrayList removeVsgList = new ArrayList();
469: ArrayList removeLeafList = new ArrayList();
470: int[] removeKeyList = new int[10];
471:
472: objAry[0] = v;
473: objAry[1] = removeVsgList;
474: objAry[2] = removeLeafList;
475: removeVsgList.add(this );
476: removeKeyList[0] = 0;
477:
478: tempKey.reset();
479: objAry[3] = super .processViewSpecificInfo(
480: REMOVE_VIEW, (HashKey) tempKey, v,
481: removeVsgList, removeKeyList,
482: removeLeafList);
483:
484: /*
485: for (int n = 0; n < removeKeyList.size(); n++) {
486: System.err.println("n = "+n+" keyValue = "+removeKeyList.get(n));
487: }
488: */
489: J3dMessage message = new J3dMessage();
490: message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED;
491: message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT
492: | J3dThread.UPDATE_RENDER
493: | J3dThread.UPDATE_SOUND | J3dThread.SOUND_SCHEDULER);
494: message.universe = universe;
495: message.args[0] = new Integer(REMOVE_VIEW);
496: message.args[1] = objAry;
497: VirtualUniverse.mc.processMessage(message);
498: }
499: }
500:
501: }
502: }
503:
504: Enumeration getAllViews() {
505: Vector viewList = new Vector();
506: for (int i = 0; i < apiViewList.size(); i++) {
507: viewList.add(apiViewList.get(i));
508: }
509: return viewList.elements();
510: }
511:
512: int numViews() {
513: return apiViewList.size();
514: }
515:
516: int indexOfView(View view) {
517: return apiViewList.indexOf(view);
518: }
519:
520: void removeView(View view) {
521: removeView(apiViewList.indexOf(view));
522: }
523:
524: void removeAllViews() {
525: int size = apiViewList.size();
526: for (int i = 0; i < size; i++) {
527: removeView(0);
528: }
529: }
530:
531: void compile(CompileState compState) {
532: super .compile(compState);
533:
534: // don't remove this group node
535: mergeFlag = SceneGraphObjectRetained.DONT_MERGE;
536:
537: // XXXX: complete this
538: }
539:
540: void setLive(SetLiveState s) {
541: if (inBackgroundGroup) {
542: throw new IllegalSceneGraphException(J3dI18N
543: .getString("ViewSpecificGroup3"));
544: }
545:
546: s.inViewSpecificGroup = true;
547: ArrayList savedViewList = s.viewLists;
548: if (s.changedViewGroup == null) {
549: s.changedViewGroup = new ArrayList();
550: s.changedViewList = new ArrayList();
551: s.keyList = new int[10];
552: s.viewScopedNodeList = new ArrayList();
553: s.scopedNodesViewList = new ArrayList();
554: }
555: super .setLive(s);
556: s.viewLists = savedViewList;
557:
558: }
559:
560: void clearLive(SetLiveState s) {
561: ArrayList savedViewList = s.viewLists;
562: if (s.changedViewGroup == null) {
563: s.changedViewGroup = new ArrayList();
564: s.changedViewList = new ArrayList();
565: s.keyList = new int[10];
566: s.viewScopedNodeList = new ArrayList();
567: s.scopedNodesViewList = new ArrayList();
568: }
569: // XXXX: This is a hack since removeNodeData is called before
570: // children are clearLives
571: int[] tempIndex = null;
572: // Don't keep the indices if everything will be cleared
573: if (inSharedGroup && (s.keys.length != localToVworld.length)) {
574: tempIndex = new int[s.keys.length];
575: for (int i = 0; i < s.keys.length; i++) {
576: tempIndex[i] = s.keys[i].equals(localToVworldKeys, 0,
577: localToVworldKeys.length);
578: }
579: }
580: super .clearLive(s);
581: // Do this after children clearlive since part of the viewLists may get cleared
582: // during removeNodeData
583:
584: // If the last SharedGroup is being cleared
585: if ((!inSharedGroup) || (localToVworld == null)) {
586: viewLists.clear();
587: } else {
588: // Must be in reverse, to preserve right indexing.
589: for (int i = tempIndex.length - 1; i >= 0; i--) {
590: if (tempIndex[i] >= 0) {
591: viewLists.remove(tempIndex[i]);
592: }
593: }
594: }
595: s.viewLists = savedViewList;
596: }
597:
598: void removeNodeData(SetLiveState s) {
599: if ((!inSharedGroup) || (s.keys.length == localToVworld.length)) {
600: s.changedViewGroup.add(this );
601: // Remove everything ..
602: int size = s.changedViewGroup.size();
603: if (s.keyList.length < size) {
604: int[] newKeyList = new int[s.keyList.length + 20];
605: System.arraycopy(s.keyList, 0, newKeyList, 0,
606: s.keyList.length);
607: s.keyList = newKeyList;
608: // System.err.println("====> RemovedNodeData: Allocating Non-shared");
609: }
610: s.keyList[size - 1] = -1;
611: parentLists.clear();
612: }
613: // A path of the shared group is removed
614: else {
615: int i, index;
616: int size = s.changedViewGroup.size();
617: if (s.keyList.length < size + 1 + s.keys.length) {
618: int[] newKeyList = new int[s.keyList.length
619: + s.keys.length + 20];
620: System.arraycopy(s.keyList, 0, newKeyList, 0,
621: s.keyList.length);
622: s.keyList = newKeyList;
623: // System.err.println("====> RemovedNodeData: Allocating Shared");
624: }
625: // Must be in reverse, to preserve right indexing.
626: for (i = s.keys.length - 1; i >= 0; i--) {
627: index = s.keys[i].equals(localToVworldKeys, 0,
628: localToVworldKeys.length);
629: if (index >= 0) {
630: s.changedViewGroup.add(this );
631: s.keyList[s.changedViewGroup.size() - 1] = index;
632: parentLists.remove(index);
633: }
634: }
635: }
636: s.viewLists = viewLists;
637: super .removeNodeData(s);
638: }
639:
640: void updateCachedInformation(int component, View view, int index) {
641: ArrayList list = (ArrayList) cachedViewList.get(index);
642:
643: /*
644: System.err.println("updateCachedInformation v = "+this+" index = "+index+" list = "+list+" cachedViewList.size() = "+cachedViewList.size());
645: for (int k = 0; k < cachedViewList.size(); k++) {
646: System.err.println("v = "+this+" k = "+k+" v.cachedViewList.get(k) = "+cachedViewList.get(k));
647: }
648: */
649: if ((component & ADD_VIEW) != 0) {
650: list.add(view);
651: } else if ((component & REMOVE_VIEW) != 0) {
652: list.remove(view);
653: }
654: /*
655: System.err.println("After updateCachedInformation v = "+this+" index = "+index+" list = "+list+" cachedViewList.size() = "+cachedViewList.size());
656: for (int k = 0; k < cachedViewList.size(); k++) {
657: System.err.println("v = "+this+" k = "+k+" v.cachedViewList.get(k) = "+cachedViewList.get(k));
658: }
659: */
660:
661: }
662:
663: void setNodeData(SetLiveState s) {
664: super .setNodeData(s);
665: if (!inSharedGroup) {
666: int size = s.changedViewGroup.size();
667: if (s.keyList.length < size + 1) {
668: int[] newKeyList = new int[s.keyList.length + 20];
669: System.arraycopy(s.keyList, 0, newKeyList, 0,
670: s.keyList.length);
671: s.keyList = newKeyList;
672: // System.err.println("====> setNodeData: Allocating Non-shared");
673: }
674: setAuxData(s, 0, 0);
675: } else {
676: // For inSharedGroup case.
677: int j, hkIndex;
678:
679: int size = s.changedViewGroup.size();
680: if (s.keyList.length < size + 1 + s.keys.length) {
681: int[] newKeyList = new int[s.keyList.length
682: + s.keys.length + 20];
683: System.arraycopy(s.keyList, 0, newKeyList, 0,
684: s.keyList.length);
685: s.keyList = newKeyList;
686: // System.err.println("====> setNodeData: Allocating Shared");
687: }
688:
689: for (j = 0; j < s.keys.length; j++) {
690: hkIndex = s.keys[j].equals(localToVworldKeys, 0,
691: localToVworldKeys.length);
692:
693: if (hkIndex >= 0) {
694: setAuxData(s, j, hkIndex);
695:
696: } else {
697: MasterControl
698: .getCoreLogger()
699: .severe(
700: "Can't Find matching hashKey in setNodeData.");
701: }
702: }
703: }
704: // Make the VSG's viewLists as the relavant one for its children
705: s.viewLists = viewLists;
706:
707: }
708:
709: void setAuxData(SetLiveState s, int index, int hkIndex) {
710: ArrayList vl;
711: ArrayList parentList = null;
712: int size = apiViewList.size();
713: if (s.viewLists != null) {
714: // System.err.println("=====> VSG: = "+this+" hkIndex = "+hkIndex+" s.viewLists = "+s.viewLists);
715: parentList = (ArrayList) s.viewLists.get(hkIndex);
716: if (parentList != null) {
717: vl = new ArrayList();
718: for (int i = 0; i < size; i++) {
719: Object obj1 = apiViewList.get(i);
720: // Get the intersection of the parentlist and this vsg's api list
721: for (int j = 0; j < parentList.size(); j++) {
722: if (obj1 == parentList.get(j)) {
723: vl.add(obj1);
724: break;
725: }
726: }
727: }
728: } else {
729: vl = new ArrayList();
730: // Only include the non null ones in the apiViewList
731: for (int i = 0; i < size; i++) {
732: Object obj = apiViewList.get(i);
733: if (obj != null) {
734: vl.add(obj);
735: }
736: }
737: }
738: } else {
739: vl = new ArrayList();
740: // Only include the non null ones in the apiViewList
741: for (int i = 0; i < size; i++) {
742: Object obj = apiViewList.get(i);
743: if (obj != null) {
744: vl.add(obj);
745: }
746: }
747: }
748: if (parentList != null) {
749: parentLists.add(hkIndex, parentList.clone());
750: } else {
751: parentLists.add(hkIndex, null);
752: }
753:
754: viewLists.add(hkIndex, vl);
755: s.changedViewGroup.add(this );
756: s.changedViewList.add(vl);
757: if (localToVworldKeys != null) {
758: s.keyList[s.changedViewGroup.size() - 1] = hkIndex;
759: } else {
760: s.keyList[s.changedViewGroup.size() - 1] = 0;
761: }
762:
763: }
764:
765: }
|