001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/NameGenerator.java,v 1.1 2005/04/20 22:20:46 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.*;
021: import com.sun.j3d.utils.behaviors.interpolators.KBRotPosScaleSplinePathInterpolator;
022:
023: /**
024: * Autogenerates names for the user.
025: */
026: public class NameGenerator {
027:
028: private final static String GROUP = "grp";
029: private final static String BRANCHGROUP = "bg";
030: private final static String TRANSFORMGROUP = "tg";
031: private final static String LIGHT = "light";
032: private final static String BEHAVIOR = "behavior";
033: private final static String INTERPOLATOR = "interp";
034: private final static String OBJ_LOADER = "obj";
035: private final static String LW3D_LOADER = "lw3d";
036: private final static String SIMPLE_UNIVERSE = "u";
037: private final static String SIMPLE_GEOM = "geom";
038: private final static String ALPHA = "alpha";
039: private final static String SOUND = "sound";
040: private final static String FOG = "fog";
041: private final static String KB_ROT_POS_INTERP = "kbInterp";
042: private final static String BACKGROUND = "background";
043:
044: private int light = 0;
045: private int group = 0;
046: private int branchGroup = 0;
047: private int transformGroup = 0;
048: private int behavior = 0;
049: private int interpolator = 0;
050: private int objLoader = 0;
051: private int lw3dLoader = 0;
052: private int simpleUniverse = 0;
053: private int simpleGeom = 0;
054: private int alpha = 0;
055: private int sound = 0;
056: private int kbInterp = 0;
057: private int fog = 0;
058: private int background = 0;
059:
060: private int unknown = 0;
061:
062: private static NameGenerator nameControl = null;
063:
064: public NameGenerator() {
065: }
066:
067: public static NameGenerator getNameControl() {
068: if (nameControl == null)
069: nameControl = new NameGenerator();
070:
071: return nameControl;
072: }
073:
074: public String getGroupName() {
075: return GROUP + group++;
076: }
077:
078: public String getBranchGroupName() {
079: return BRANCHGROUP + branchGroup++;
080: }
081:
082: public String getTransformGroupName() {
083: return TRANSFORMGROUP + transformGroup++;
084: }
085:
086: public String getBehaviorName() {
087: return BEHAVIOR + behavior++;
088: }
089:
090: public String getInterpolaterName() {
091: return INTERPOLATOR + interpolator++;
092: }
093:
094: public String getLightName() {
095: return LIGHT + light++;
096: }
097:
098: public String getObjLoaderName() {
099: return OBJ_LOADER + objLoader++;
100: }
101:
102: public String getLw3DLoaderName() {
103: return LW3D_LOADER + lw3dLoader++;
104: }
105:
106: public String getSimpleUniverseName() {
107: return SIMPLE_UNIVERSE + simpleUniverse++;
108: }
109:
110: public String getSimpleGeomName() {
111: return SIMPLE_GEOM + simpleGeom++;
112: }
113:
114: public String getAlphaName() {
115: return ALPHA + alpha++;
116: }
117:
118: public String getSoundName() {
119: return SOUND + sound++;
120: }
121:
122: public String getKBInterpName() {
123: return KB_ROT_POS_INTERP + kbInterp++;
124: }
125:
126: public String getFogName() {
127: return FOG + fog++;
128: }
129:
130: public String getBackgroundName() {
131: return BACKGROUND + background++;
132: }
133:
134: public String getName(javax.media.j3d.SceneGraphObject node) {
135: if (node instanceof KBRotPosScaleSplinePathInterpolator)
136: return getKBInterpName();
137: else if (node instanceof TransformGroup)
138: return getTransformGroupName();
139: else if (node instanceof Group)
140: return getGroupName();
141: else if (node instanceof AmbientLight)
142: return getLightName();
143: else if (node instanceof PointLight)
144: return getLightName();
145: else if (node instanceof SpotLight)
146: return getLightName();
147: else if (node instanceof DirectionalLight)
148: return getLightName();
149: else if (node instanceof Behavior)
150: return getBehaviorName();
151: else if (node instanceof Fog)
152: return getFogName();
153: else if (node instanceof Background)
154: return getBackgroundName();
155: // else if (node instanceof ESound)
156: // return getSoundName();
157:
158: System.out.println("WARNING - no name for "
159: + node.getClass().getName());
160: return "unknown" + unknown++;
161: }
162:
163: /**
164: * Reset the names to their initial state
165: */
166: public void resetNames() {
167: light = 0;
168: group = 0;
169: branchGroup = 0;
170: transformGroup = 0;
171: behavior = 0;
172: interpolator = 0;
173: objLoader = 0;
174: simpleUniverse = 0;
175: simpleGeom = 0;
176: alpha = 0;
177: sound = 0;
178: kbInterp = 0;
179: }
180:
181: }
|