001: /*
002: * $RCSfile: OrderedBin.java,v $
003: *
004: * Copyright 1999-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.5 $
028: * $Date: 2008/02/28 20:17:27 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.ArrayList;
035:
036: /**
037: * An OrderedBin contains an array of OrderedCollection, each represents
038: * a child of the OrderedGroup
039: */
040: class OrderedBin extends Object {
041: // ArrayList of orderedCollection, one for each child of the orderedGroup
042: ArrayList orderedCollections = new ArrayList();
043:
044: // orderedGroup source
045: OrderedGroupRetained source;
046: OrderedChildInfo childInfoList = null;
047: OrderedChildInfo lastChildInfo = null;
048:
049: boolean onUpdateList = false;
050:
051: // Value of already existing orderedCollection
052: ArrayList setOCForCI = new ArrayList();
053: ArrayList valueOfSetOCForCI = new ArrayList();
054:
055: // Value of orderedCollection based on oi, these arrays
056: // have size > 0 only during update_view;
057: ArrayList setOCForOI = new ArrayList();
058: ArrayList valueOfSetOCForOI = new ArrayList();
059:
060: OrderedBin(int nchildren, OrderedGroupRetained src) {
061: int i;
062: for (i = 0; i < nchildren; i++) {
063: orderedCollections.add(null);
064: }
065: source = src;
066: }
067:
068: void addRemoveOrderedCollection() {
069: int i, index;
070:
071: // Add the setValues first, since they reflect already existing
072: // orderedCollection
073: for (i = 0; i < setOCForCI.size(); i++) {
074: index = ((Integer) setOCForCI.get(i)).intValue();
075: OrderedCollection oc = (OrderedCollection) valueOfSetOCForCI
076: .get(i);
077: orderedCollections.set(index, oc);
078: }
079:
080: setOCForCI.clear();
081: valueOfSetOCForCI.clear();
082:
083: while (childInfoList != null) {
084: if (childInfoList.type == OrderedChildInfo.ADD) {
085: orderedCollections.add(childInfoList.childId,
086: childInfoList.value);
087: } else if (childInfoList.type == OrderedChildInfo.REMOVE) {
088: orderedCollections.remove(childInfoList.childId);
089: }
090: childInfoList = childInfoList.next;
091: }
092:
093: // Now update the sets based on oi, since the og.orderedChildIdTable reflects
094: // the childIds for the next frame, use the table to set the oc at the
095: // correct place
096: for (i = 0; i < setOCForOI.size(); i++) {
097: index = ((Integer) setOCForOI.get(i)).intValue();
098: OrderedCollection oc = (OrderedCollection) valueOfSetOCForOI
099: .get(i);
100: int ci = source.orderedChildIdTable[index];
101: orderedCollections.set(ci, oc);
102: }
103: setOCForOI.clear();
104: valueOfSetOCForOI.clear();
105:
106: onUpdateList = false;
107: lastChildInfo = null;
108:
109: }
110:
111: void addChildInfo(OrderedChildInfo cinfo) {
112: // Add this cinfo at the end
113: if (childInfoList == null) {
114: childInfoList = cinfo;
115: lastChildInfo = cinfo;
116: } else {
117: // Add at the end
118: cinfo.prev = lastChildInfo;
119: lastChildInfo.next = cinfo;
120: cinfo.next = null;
121: // Update this to be the last child
122: lastChildInfo = cinfo;
123: }
124:
125: }
126:
127: }
|