KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2005 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.input.InputManager;
20 import com.buchuki.ensmer.input.command.*;
21 import com.buchuki.ensmer.input.event.*;
22 import com.buchuki.ensmer.object.Backend;
23 import com.buchuki.ensmer.text.TextInput;
24 import com.sun.j3d.utils.geometry.Text2D;
25 import java.awt.Font JavaDoc;
26 import java.io.Serializable JavaDoc;
27 import javax.media.j3d.Appearance;
28 import javax.media.j3d.BranchGroup;
29 import javax.media.j3d.PolygonAttributes;
30 import javax.vecmath.Color3f;
31
32
33
34 /**
35  * Class to represent an editable note (text) displayed on the screen.
36  *
37  * @author Dusty Phillips [dusty@buchuki.com]
38  */

39 public class Note extends Backend {
40     
41     /**
42      * Creates a new instance of a default (empty) note.
43      */

44     public Note() {
45         text = new TextInput();
46         text.setFocused(true);
47     }
48     
49     /**
50      * Construct a note based on previously serialized data representing
51      * the note's contents
52      * @param data the serialized data to rebuild a note from
53      */

54     public Note(Serializable JavaDoc data) {
55         text = (TextInput) data;
56     }
57     
58     /**
59      * Get the Serializable object for the backend
60      *
61      * @return a TextInput objec
62      */

63     public Serializable JavaDoc getSerializable() {
64         return text;
65     }
66     
67     /**
68      * Get the TextInput representing the note's contents
69      *
70      * @return the note's contents
71      */

72     public TextInput getText() {
73         return text;
74     }
75     
76     /**
77      * Process an InputEvent to be forwarded to the TextInput object.
78      *
79      * @param event the Event to be processed
80      */

81     public void processText(EnsmerInputEvent event) {
82         text.processInput(event);
83         fireChangeEvent();
84     }
85     
86     /**
87      * Return a Branchgroup representing the <b>type</b> of this object so that
88      * Note objects can be manually added to the scene. Probably an interesting
89      * objicon could be created, but for now it simply creates a text2D containing
90      * the word 'Note'.
91      *
92      * @return a branchgroup representing the class of Static objects
93      */

94     @Override JavaDoc
95     public static BranchGroup getRepresentation() {
96         Text2D text = new Text2D("Note", new Color3f(.7f, .2f, .1f), "Times",
97                 16, Font.BOLD);
98         Appearance app = text.getAppearance();
99         PolygonAttributes poly = new PolygonAttributes();
100         poly.setCullFace(poly.CULL_NONE);
101         app.setPolygonAttributes(poly);
102         BranchGroup ret = new BranchGroup();
103         ret.addChild(text);
104         return ret;
105     }
106     
107     /**
108      * The TextInput representing the note's contents.
109      */

110     private TextInput text;
111     
112 }
113
Popular Tags