KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > buchuki > ensmer > input > Selector


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.input;
17
18 import com.buchuki.ensmer.EnsmerManager;
19 import java.awt.event.MouseEvent JavaDoc;
20 import com.buchuki.ensmer.input.command.*;
21 import com.buchuki.ensmer.input.event.*;
22 import com.sun.j3d.utils.picking.PickCanvas;
23 import com.sun.j3d.utils.picking.PickResult;
24 import java.awt.Point JavaDoc;
25 import javax.media.j3d.Node;
26
27 /**
28  * Class to process Selection mode events. The events in this module manage
29  * selections in the current Area's selection manager.
30  *
31  * @author Dusty Phillips [dusty@buchuki.com]
32  */

33 public class Selector implements InputProcessor {
34     
35     /**
36      * Construct the Selector. Sets up the available commands.
37      */

38     public Selector() {
39         CommandMap map = InputManager.getCommandMap();
40         Command toggleSelection =
41         new Command() {
42             public boolean execute(EnsmerInputEvent event) {
43                 selectionPicked(((MouseEvent JavaDoc) event.getInputEvent()).getPoint());
44                 return true;
45             }
46         };
47         
48         map.addCommand(this, toggleSelection, new MousePressEvent(MouseEvent.BUTTON1));
49     }
50     
51     /**
52      * Process an EnsmerInputEvent that occurs. The navigator looks up the
53      * possible actions in the CommandMap and acts on them.
54      *
55      * @param event the event that needs to be processed by the navigator
56      */

57     public void processInput(EnsmerInputEvent event) {
58         CommandMap map = InputManager.getCommandMap();
59         map.interpretEvent(this, event);
60     }
61     
62     /**
63      * Perform the action of toggling a selection on an object. It first uses Java 3D picking and the Canvas 3D
64      * to determine what object was clicked, if any, and then toggles the selection on that object.
65      *
66      * @param point the point on the canvas that was clicked
67      */

68     private void selectionPicked(Point JavaDoc point){
69         Long JavaDoc id = EnsmerManager.instance().getInterfaceManager().pickObject(point.x, point.y);
70         if (id != null) {
71             EnsmerManager.instance().getSelectionManager().toggleSelection(id);
72         }
73     }
74 }
75
76
Popular Tags