001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/InterposerListener.java,v 1.1 2005/04/20 22:20:44 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegrapheditor;
019:
020: import javax.media.j3d.BranchGroup;
021: import javax.media.j3d.Group;
022: import javax.media.j3d.Locale;
023:
024: import org.jdesktop.j3dedit.interposerext.InterposerListenerInterface;
025:
026: import org.jdesktop.j3dedit.J3dEditContext;
027: import org.jdesktop.j3dedit.interposer.InterposerLocale;
028: import org.jdesktop.j3dedit.scenegraph.SGGroup;
029: import org.jdesktop.j3dfly.utils.developmenttools.DevelopmentLocale;
030:
031: /**
032: *
033: * @author Paul Byrne
034: * @version $Id: InterposerListener.java,v 1.1 2005/04/20 22:20:44 paulby Exp $
035: */
036: public class InterposerListener implements InterposerListenerInterface {
037:
038: private final static boolean DEBUG_CALLS = false;
039:
040: private J3dEditContext context;
041:
042: /** Creates a new instance of InterposerListener */
043: public InterposerListener() {
044: }
045:
046: public void setContext(J3dEditContext context) {
047: this .context = context;
048: }
049:
050: public void localeAddBranchGraph(Object locale, Object bg) {
051: if (DEBUG_CALLS)
052: System.out.println("localeAddBranchGraph " + locale + " "
053: + bg);
054:
055: if (context == null) {
056: System.out
057: .println("Context is null in localeAddBranchGraph*************");
058: return;
059: }
060:
061: DevelopmentLocale interposerLocale = getInterposerLocale((Locale) locale);
062:
063: if (interposerLocale == null) {
064: System.out.println("MULTIPLE LOCALES*********************");
065: interposerLocale = new InterposerLocale(
066: (javax.media.j3d.Locale) locale);
067: context.addLocale(interposerLocale);
068: interposerLocale
069: .setSceneGraphChangeListeners(((InterposerLocale) context
070: .getLocale(0))
071: .getSceneGraphChangeListeners());
072: }
073:
074: // Need the if check because the locale may be a DevelopmentLocale
075: if (interposerLocale instanceof InterposerLocale)
076: interposerLocale.addBranchGraph((BranchGroup) bg);
077: }
078:
079: private DevelopmentLocale getInterposerLocale(Locale realLocale) {
080: if (realLocale == null)
081: return null;
082:
083: if (realLocale instanceof DevelopmentLocale)
084: return (DevelopmentLocale) realLocale;
085:
086: Locale locale;
087:
088: for (int i = 0; i < context.numLocales(); i++) {
089: locale = context.getLocale(i);
090: if (locale instanceof InterposerLocale
091: && ((InterposerLocale) locale).getActualLocale() == realLocale)
092: return (InterposerLocale) locale;
093: }
094:
095: return null;
096: }
097:
098: public void localeRemoveBranchGraph(Object locale, Object bg) {
099: if (DEBUG_CALLS)
100: System.out.println("localeRemoveBranchGraph " + bg);
101:
102: DevelopmentLocale interposerLocale = getInterposerLocale((Locale) locale);
103: if (interposerLocale != null
104: && interposerLocale instanceof InterposerLocale) {
105: interposerLocale.removeBranchGraph((BranchGroup) bg);
106: }
107: }
108:
109: public void groupAddChild(Object group, Object child) {
110: // Only interested in add's to live nodes.
111: if (!((Group) group).isLive())
112: return;
113:
114: if (DEBUG_CALLS)
115: System.out.println("groupAddChild " + child);
116:
117: DevelopmentLocale locale = getLocale(group);
118: if (locale == null)
119: return;
120: // This method is called before before the actual addChild
121: // takes place, so group is live, but child is not live
122: locale.notifyGroupAddChild((Group) group, (BranchGroup) child);
123: }
124:
125: public void groupSetChild(Object group, Object child, int index) {
126: if (!((Group) group).isLive())
127: return;
128:
129: if (DEBUG_CALLS)
130: System.out.println("groupSetChild " + child);
131:
132: DevelopmentLocale locale = getLocale(group);
133: if (locale == null)
134: return;
135:
136: locale.notifyGroupSetChild((Group) group, (BranchGroup) child,
137: index);
138: }
139:
140: public void groupRemoveAllChildren(Object group) {
141: if (!((Group) group).isLive())
142: return;
143:
144: if (DEBUG_CALLS)
145: System.out.println("groupRemoveAllChildren " + group);
146:
147: DevelopmentLocale locale = getLocale(group);
148: if (locale == null)
149: return;
150:
151: locale.notifyGroupRemoveAllChildren((Group) group);
152: }
153:
154: public void groupRemoveChild(Object group, Object child) {
155: if (!((Group) group).isLive())
156: return;
157:
158: if (DEBUG_CALLS)
159: System.out.println("groupRemoveChild " + child);
160:
161: DevelopmentLocale locale = getLocale(group);
162: if (locale == null)
163: return;
164:
165: locale.notifyGroupRemoveChild((Group) group,
166: (BranchGroup) child);
167: }
168:
169: public void groupRemoveChild(Object group, int childIndex) {
170: if (!((Group) group).isLive())
171: return;
172:
173: if (DEBUG_CALLS)
174: System.out.println("groupAddChild "
175: + ((Group) group).getChild(childIndex));
176:
177: DevelopmentLocale locale = getLocale(group);
178: if (locale == null)
179: return;
180:
181: // TODO - figure out which child is being removed
182: locale.notifyGroupRemoveChild((Group) group,
183: (BranchGroup) ((Group) group).getChild(childIndex));
184: }
185:
186: private DevelopmentLocale getLocale(Object node) {
187: Locale l = context.getSceneGraphControl().getLocale(
188: (javax.media.j3d.Node) node);
189:
190: return getInterposerLocale(l);
191: }
192:
193: }
|