Source code: com/xerox/VTM/demo/AnimationEvtHdlr.java
1 /* FILE: AnimationEvtHdlr.java
2 * DATE OF CREATION: Dec 08 2000
3 * AUTHOR : Emmanuel Pietriga (emmanuel.pietriga@xrce.xerox.com)
4 * MODIF: Wed Jan 15 15:11:06 2003 by Emmanuel Pietriga
5 * Copyright (c) Xerox Corporation, XRCE/Contextual Computing, 2002. All Rights Reserved
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * For full terms see the file COPYING.
18 */
19
20 package com.xerox.VTM.demo;
21
22 import java.util.Vector;
23 import java.awt.event.KeyEvent;
24 import com.xerox.VTM.engine.*;
25 import com.xerox.VTM.glyphs.*;
26
27 public class AnimationEvtHdlr extends AppEventHandler {
28
29 Introduction application;
30
31 long lastX,lastY,lastJPX,lastJPY; //remember last mouse coords to compute translation (dragging)
32 float tfactor;
33 float cfactor=40.0f;
34
35 VSegment navSeg;
36
37 Camera activeCam;
38
39 Glyph orientation;Glyph size;Glyph color;Glyph translation; //type of animation
40 Glyph linear;Glyph exponential;Glyph sigmoid; //temporal scheme
41
42 AnimationEvtHdlr(Introduction appli,Glyph o,Glyph s,Glyph c,Glyph t,Glyph l,Glyph e,Glyph sg){
43 application=appli;
44 orientation=o;size=s;color=c;translation=t;
45 linear=l;exponential=e;sigmoid=sg;
46 }
47
48 public void press1(ViewPanel v,int mod,int jpx,int jpy){
49 try {
50 Glyph g=v.lastGlyphEntered();
51 if (g!=null && g.getType().equals("an")){
52 if (g.getCGlyph()!=null){
53 application.vsm.stickToMouse(g.getCGlyph());
54 }
55 else {
56 application.vsm.stickToMouse(g);
57 }
58 }
59 }
60 catch (NullPointerException e){}
61 application.vsm.activeView.mouse.setSensitivity(false);
62 }
63
64 public void release1(ViewPanel v,int mod,int jpx,int jpy){
65 application.vsm.activeView.mouse.setSensitivity(true);
66 application.vsm.unstickFromMouse();
67 }
68
69 public void click1(ViewPanel v,int mod,int jpx,int jpy,int clickNumber){
70 Glyph a;
71 if ((a=v.lastGlyphEntered())!=null){
72 String t=a.getType();
73 if (t.equals("an")){
74 if (a.getCGlyph()!=null){application.animate(a.getCGlyph());}
75 else {application.animate(a);}
76 }
77 else if (t.equals("orient")){
78 if (application.animType.equals("orient")){
79 application.animType="";
80 orientation.setHSVColor(0.36f,1.0f,0.6f);
81 }
82 else{
83 application.animType="orient";
84 orientation.setHSVColor(0.0f,1.0f,0.7f);
85 color.setHSVColor(0.36f,1.0f,0.6f);
86 size.setHSVColor(0.36f,1.0f,0.6f);
87 translation.setHSVColor(0.36f,1.0f,0.6f);
88 }
89 }
90 else if (t.equals("size")){
91 if (application.animType.equals("size")){
92 application.animType="";
93 size.setHSVColor(0.36f,1.0f,0.6f);
94 }
95 else{
96 application.animType="size";
97 orientation.setHSVColor(0.36f,1.0f,0.6f);
98 color.setHSVColor(0.36f,1.0f,0.6f);
99 size.setHSVColor(0.0f,1.0f,0.7f);
100 translation.setHSVColor(0.36f,1.0f,0.6f);
101 }
102 }
103 else if (t.equals("col")){
104 if (application.animType.equals("col")){
105 application.animType="";
106 a.setHSVColor(0.36f,1.0f,0.6f);
107 }
108 else{
109 application.animType="col";
110 orientation.setHSVColor(0.36f,1.0f,0.6f);
111 color.setHSVColor(0.0f,1.0f,0.7f);
112 size.setHSVColor(0.36f,1.0f,0.6f);
113 translation.setHSVColor(0.36f,1.0f,0.6f);
114 }
115 }
116 else if (t.equals("pos")){
117 if (application.animType.equals("trans")){
118 application.animType="";
119 a.setHSVColor(0.36f,1.0f,0.6f);
120 }
121 else{
122 application.animType="trans";
123 orientation.setHSVColor(0.36f,1.0f,0.6f);
124 color.setHSVColor(0.36f,1.0f,0.6f);
125 size.setHSVColor(0.36f,1.0f,0.6f);
126 translation.setHSVColor(0.0f,1.0f,0.7f);
127 }
128 }
129 else if (t.equals("lin")){
130 if (application.animScheme.equals("lin")){
131 application.animScheme="";
132 linear.setHSVColor(0.36f,1.0f,0.6f);
133 }
134 else{
135 application.animScheme="lin";
136 exponential.setHSVColor(0.36f,1.0f,0.6f);
137 sigmoid.setHSVColor(0.36f,1.0f,0.6f);
138 linear.setHSVColor(0.0f,1.0f,0.7f);
139 }
140 }
141 else if (t.equals("exp")){
142 if (application.animScheme.equals("exp")){
143 application.animScheme="";
144 exponential.setHSVColor(0.36f,1.0f,0.6f);
145 }
146 else{
147 application.animScheme="exp";
148 linear.setHSVColor(0.36f,1.0f,0.6f);
149 sigmoid.setHSVColor(0.36f,1.0f,0.6f);
150 exponential.setHSVColor(0.0f,1.0f,0.7f);
151 }
152 }
153 else if (t.equals("sig")){
154 if (application.animScheme.equals("sig")){
155 application.animScheme="";
156 sigmoid.setHSVColor(0.36f,1.0f,0.6f);
157 }
158 else{
159 application.animScheme="sig";
160 exponential.setHSVColor(0.36f,1.0f,0.6f);
161 linear.setHSVColor(0.36f,1.0f,0.6f);
162 sigmoid.setHSVColor(0.0f,1.0f,0.7f);
163 }
164 }
165 application.vsm.repaintNow();
166 }
167 }
168
169 public void press2(ViewPanel v,int mod,int jpx,int jpy){}
170 public void release2(ViewPanel v,int mod,int jpx,int jpy){}
171 public void click2(ViewPanel v,int mod,int jpx,int jpy,int clickNumber){}
172
173 public void press3(ViewPanel v,int mod,int jpx,int jpy){
174 lastJPX=jpx;
175 lastJPY=jpy;
176 //application.vsm.setActiveCamera(v.cams[0]);
177 v.setDrawDrag(true);
178 application.vsm.activeView.mouse.setSensitivity(false); //because we would not be consistent (when dragging the mouse, we computeMouseOverList, but if there is an anim triggered by {X,Y,A}speed, and if the mouse is not moving, this list is not computed - so here we choose to disable this computation when dragging the mouse with button 3 pressed)
179 activeCam=v.cams[0];
180 }
181
182 public void release3(ViewPanel v,int mod,int jpx,int jpy){
183 application.vsm.animator.Xspeed=0;
184 application.vsm.animator.Yspeed=0;
185 application.vsm.animator.Aspeed=0;
186 v.setDrawDrag(false);
187 application.vsm.activeView.mouse.setSensitivity(true);
188 }
189
190 public void click3(ViewPanel v,int mod,int jpx,int jpy,int clickNumber){}
191
192 public void mouseMoved(ViewPanel v,int jpx,int jpy){}
193
194 public void mouseDragged(ViewPanel v,int mod,int buttonNumber,int jpx,int jpy){
195 if (buttonNumber==3){
196 tfactor=(activeCam.focal+Math.abs(activeCam.altitude))/activeCam.focal;
197 if (mod==1) {
198 application.vsm.animator.Xspeed=0;
199 application.vsm.animator.Yspeed=0;
200 application.vsm.animator.Aspeed=(activeCam.altitude>0) ? (long)((lastJPY-jpy)*(tfactor/cfactor)) : (long)((lastJPY-jpy)/(tfactor*cfactor)); //50 is just a speed factor (too fast otherwise)
201 }
202 else {
203 application.vsm.animator.Xspeed=(activeCam.altitude>0) ? (long)((jpx-lastJPX)*(tfactor/cfactor)) : (long)((jpx-lastJPX)/(tfactor*cfactor));
204 application.vsm.animator.Yspeed=(activeCam.altitude>0) ? (long)((lastJPY-jpy)*(tfactor/cfactor)) : (long)((lastJPY-jpy)/(tfactor*cfactor));
205 application.vsm.animator.Aspeed=0;
206 }
207 }
208 }
209
210 public void enterGlyph(Glyph g,ViewPanel v){super.enterGlyph(g);}
211
212 public void exitGlyph(Glyph g,ViewPanel v){
213 super.exitGlyph(g);
214 }
215
216 public void Ktype(ViewPanel v,char c,int code,int mod){
217 switch(c){
218 case 'c':{
219 application.vsm.getGlobalView(application.vsm.getActiveCamera(),200);
220 break;
221 }
222 }
223 }
224
225 public void Kpress(ViewPanel v,char c,int code,int mod){}
226
227 public void Krelease(ViewPanel v,char c,int code,int mod){}
228
229 public void viewActivated(View v){}
230
231 public void viewDeactivated(View v){}
232
233 public void viewIconified(View v){}
234
235 public void viewDeiconified(View v){}
236
237 public void viewClosing(View v){System.exit(0);}
238
239 public String toString(){return "CameraDemoEvtHdlr";}
240
241 }