KickJava   Java API By Example, From Geeks To Geeks.

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


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
17 package com.buchuki.ensmer.builtin;
18
19 import com.buchuki.ensmer.*;
20 import com.buchuki.ensmer.object.Backend;
21 import com.buchuki.annotations.*;
22 import java.io.Serializable JavaDoc;
23 import javax.vecmath.Matrix4f;
24
25 /**
26  * Class representing a backend that essentially represents another backend, the
27  * Static class. This class is used in adding Static objects to the scene. It
28  * differs from static objects in that it allows you to instantiate an instance
29  * of the object. (The frontend differs in that it scales the object to a specific
30  * size). The icon also does not allow the selectable property; they are always
31  * selectable.
32  *
33  * @author Dusty Phillips [dusty@buchuki.com]
34  */

35 @Optimize("Static and StaticIcon can share an AbstractStatic superclass")
36 public class StaticIcon extends Backend {
37     
38     /**
39      * Construct a default instance
40      */

41     public StaticIcon() {}
42     
43     /**
44      * Construct a Serialized Instance.
45      *
46      * @param data the data to reconstruct from
47      */

48     public StaticIcon(Serializable JavaDoc data) {
49         this.filename = (String JavaDoc) data;
50     }
51     
52     /**
53      * Get the serializable object for the backend.
54      *
55      * @return an instance of StaticSerializable
56      */

57     @Override JavaDoc
58     public Serializable JavaDoc getSerializable() {
59         return filename;
60     }
61     
62     /**
63      * get the filename associated with this static backend
64      *
65      * @return the name of a file in the Static/ directory
66      */

67     public String JavaDoc getFilename() {
68         return filename;
69     }
70     
71     /**
72      * Set the filename associated with the static backend.
73      *
74      * @param filename the filename associated with the backend
75      */

76     public void setFilename(String JavaDoc filename) {
77         this.filename = filename;
78         fireChangeEvent();
79     }
80     
81     /**
82      * Create a new Static object and add it to the first previous area that
83      * is not read only (assuming one exists),
84      * THEN move to that area. This method is tightly coupled to
85      * the buildAddStaticArea() method
86      * in the SpecialAreaManager, and to the addObjectToPrevious() method in
87      * the ClassIcon method.
88      */

89     public void addStaticToPrevious() {
90         AreaManager man = EnsmerManager.instance().getAreaManager();
91         int count = 0;
92         Area prev;
93         do {
94             Long JavaDoc prevId = man.getHistoricalAreaID(count);
95             if (prevId == null) {
96                 return; //theoretically should never have to be called, as the original area should always be read only
97
}
98             prev = man.getArea(prevId);
99             count++;
100         } while (prev.isReadOnly());
101         Static obj = new Static();
102         obj.setFilename(filename);
103         Matrix4f location = SceneGraphUtils.positionInFrontOfUser(prev);
104         prev.newObject(obj, location);
105         //go to previous area where the object was added
106
for (int i = 0; i < count - 1; i++) {
107             man.previousArea();
108         }
109         //in case the area didn't get changed
110
EnsmerManager.instance().getUserManager().getInputManager().systemMode();
111         EnsmerManager.instance().getSelectionManager().clearSelection();
112         EnsmerManager.instance().getSelectionManager().toggleSelection(obj.getId());
113     }
114
115     /**
116      * The filename in the Static/ directory containing the object to be loaded
117      */

118     private String JavaDoc filename;
119 }
120
Popular Tags