001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/interposerext/InterposerCallbacks.java,v 1.2 2005/04/22 18:35:33 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.interposerext;
019:
020: import java.lang.reflect.Constructor;
021:
022: /**
023: *
024: * @author paulby
025: */
026: public class InterposerCallbacks {
027:
028: private static final int LOCALE_ADD_BRANCH_GRAPH = 0;
029: private static final int LOCALE_REMOVE_BRANCH_GRAPH = 1;
030: private static final int GROUP_ADD_CHILD = 2;
031: private static final int GROUP_REMOVE_CHILD = 3;
032: private static final int TRANSFORMGROUP_SET_TRANSFORM = 4;
033:
034: private static int[] data = new int[5];
035:
036: private static int frameCount = 0;
037: private static Object editor = null;
038: private static boolean editorStarting = false;
039:
040: private static InterposerListenerInterface listener = null;
041:
042: public static void localeAddBranchGraph(Object locale, Object bg) {
043: data[LOCALE_ADD_BRANCH_GRAPH]++;
044: if (!editorStarting)
045: startEditor(locale);
046:
047: if (listener != null)
048: listener.localeAddBranchGraph(locale, bg);
049: }
050:
051: public static void localeRemoveBranchGraph(Object locale, Object bg) {
052: data[LOCALE_REMOVE_BRANCH_GRAPH]++;
053: if (listener != null)
054: listener.localeRemoveBranchGraph(locale, bg);
055: }
056:
057: public static void groupAddChild(Object group, Object child) {
058: data[GROUP_ADD_CHILD]++;
059:
060: if (listener != null)
061: listener.groupAddChild(group, child);
062: }
063:
064: public static void groupSetChild(Object group, Object child,
065: int index) {
066: //data[GROUP_ADD_CHILD]++;
067:
068: if (listener != null)
069: listener.groupSetChild(group, child, index);
070: }
071:
072: public static void groupRemoveAllChildren(Object group) {
073: if (listener != null)
074: listener.groupRemoveAllChildren(group);
075: }
076:
077: public static void groupRemoveChild(Object group, Object child) {
078: data[GROUP_REMOVE_CHILD]++;
079:
080: if (listener != null)
081: listener.groupRemoveChild(group, child);
082: }
083:
084: public static void groupRemoveChild(Object group, int childIndex) {
085: data[GROUP_REMOVE_CHILD]++;
086:
087: if (listener != null)
088: listener.groupRemoveChild(group, childIndex);
089: }
090:
091: public static void tgSetTransform() {
092: data[TRANSFORMGROUP_SET_TRANSFORM]++;
093: }
094:
095: public static void finishedFrame() {
096: System.out.println("Finished Frame " + frameCount);
097: System.out.println("Locale add : remove "
098: + data[LOCALE_ADD_BRANCH_GRAPH] + " : "
099: + data[LOCALE_REMOVE_BRANCH_GRAPH]);
100: System.out.println("Group addChild : removeChild "
101: + data[GROUP_ADD_CHILD] + " : "
102: + data[GROUP_REMOVE_CHILD]);
103: System.out.println("TransformGroup setTransform "
104: + data[TRANSFORMGROUP_SET_TRANSFORM]);
105:
106: resetData();
107: frameCount++;
108: }
109:
110: private static void resetData() {
111: for (int i = 0; i < data.length; i++)
112: data[i] = 0;
113: }
114:
115: private static void startEditor(Object locale) {
116: System.out.println("Starting Editor");
117:
118: editorStarting = true;
119: ClassLoader loader = ClassLoader.getSystemClassLoader();
120:
121: try {
122: Class editClass = loader
123: .loadClass("org.jdesktop.j3dedit.J3dEdit");
124: Constructor constructor = editClass
125: .getConstructor(new Class[] {
126: InterposerCallbacks.class, Object.class });
127:
128: editor = constructor.newInstance(new Object[] {
129: new InterposerCallbacks(), locale });
130: } catch (Exception e) {
131: e.printStackTrace();
132: System.exit(1);
133: }
134: System.out
135: .println("----------------------- Editor Started -----------------");
136: }
137:
138: public void setInterposerListener(InterposerListenerInterface listen) {
139: listener = listen;
140: }
141:
142: }
|