KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > buchuki > ensmer > builtin > Static


1 /*
2  * Copyright 2004 Dusty Phillips
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.buchuki.ensmer.builtin;
17
18 import java.io.Serializable JavaDoc;
19 import com.buchuki.ensmer.object.*;
20 import com.sun.j3d.utils.geometry.Text2D;
21 import java.awt.Font JavaDoc;
22 import java.awt.event.KeyEvent JavaDoc;
23 import javax.media.j3d.Appearance;
24 import javax.media.j3d.BranchGroup;
25 import javax.media.j3d.PolygonAttributes;
26 import javax.vecmath.Color3f;
27
28 /**
29  * Class to represent static geometries in the object backend. This class
30  * differs from most backends in that it stores reference to the geometry in
31  * the actual object data. This is as a convenience; static backend objects
32  * are not interactive and its more convenient to have a single backend than
33  * having to implement a different frontend for every non-interactive object
34  * in the scene.
35  *
36  * @author Dusty Phillips [dusty@buchuki.com]
37  */

38 public class Static extends Backend {
39     
40     /**
41      * Set up and initialize a default Static object.
42      */

43     public Static() {
44         filename = "table.wrl"; //just in case, but should be set by caller
45
}
46     
47     /**
48      * Construct a Static object based on previously serialized data.
49      * Contains references to the filename and selectable property
50      * @param data the data to reconstruct a Static object from
51      */

52     public Static(Serializable JavaDoc data) {
53         this();
54         Object JavaDoc[] arr = (Object JavaDoc[]) data;
55         this.filename = (String JavaDoc) arr[0];
56         this.selectable = (Boolean JavaDoc) arr[1];
57     }
58     
59     /**
60      * Get the serializable object for the backend.
61      *
62      * @return an instance of StaticSerializable
63      */

64     @Override JavaDoc
65     public Serializable JavaDoc getSerializable() {
66         return new Object JavaDoc[] {filename, selectable};
67     }
68     
69     /**
70      * get the filename associated with this static backend
71      *
72      * @return the name of a file in the Static/ directory
73      */

74     public String JavaDoc getFilename() {
75         return filename;
76     }
77     
78     /**
79      * get whether or not this object should be selectable by the user.
80      *
81      * @return whether or not this object should be selected
82      */

83     public boolean isSelectable() {
84         return selectable;
85     }
86     
87     /**
88      * Set the filename associated with the static backend.
89      *
90      * @param filename the filename associated with the backend
91      */

92     public void setFilename(String JavaDoc filename) {
93         this.filename = filename;
94         fireChangeEvent();
95     }
96     
97     /**
98      * set whether or not this object should be selectable by the user. The
99      * default is to allow objects to be selectable.
100      *
101      * @param selectable true if this object can be selected, false otherwise
102      */

103     public void setSelectable(boolean selectable) {
104         this.selectable = selectable;
105         fireChangeEvent();
106     }
107     
108     /**
109      * Return a Branchgroup representing the <b>type</b> of this object so that
110      * Static objects can be manually added to the scene. Probably an interesting
111      * objicon could be created, but for now it simply creates a text2D containing
112      * the word 'Static'.
113      *
114      * @return a branchgroup representing the class of Static objects
115      */

116     @Override JavaDoc
117     public static BranchGroup getRepresentation() {
118         Text2D text = new Text2D("Static", new Color3f(0f, 0f, 1f), "Times", 16, Font.BOLD);
119         BranchGroup ret = new BranchGroup();
120         Appearance app = text.getAppearance();
121         PolygonAttributes poly = new PolygonAttributes();
122         poly.setCullFace(poly.CULL_NONE);
123         app.setPolygonAttributes(poly);
124         ret.addChild(text);
125         return ret;
126     }
127     
128     /**
129      * The string filename that contains a Static scene to be loaded. This file
130      * is relative to the static/ directory
131      */

132     private String JavaDoc filename;
133     
134     /**
135      * Whether or not this object is currently selectable. true by default
136      */

137     private boolean selectable = true;
138 }
139
Popular Tags