|
@@ -1,137 +1,137 @@ |
1 |
|
- |
// This Source Code is Copyright & Licenced as indicated below |
2 |
|
- |
package org.litesoft.GWT.client.widgets.nonpublic.external; |
3 |
|
- |
/* |
4 |
|
- |
* Copyright 2007 Mat Gessel <mat.gessel@gmail.com> |
5 |
|
- |
* |
6 |
|
- |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
7 |
|
- |
* use this file except in compliance with the License. You may obtain a copy of |
8 |
|
- |
* the License at |
9 |
|
- |
* |
10 |
|
- |
* http://www.apache.org/licenses/LICENSE-2.0 |
11 |
|
- |
* |
12 |
|
- |
* Unless required by applicable law or agreed to in writing, software |
13 |
|
- |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14 |
|
- |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15 |
|
- |
* License for the specific language governing permissions and limitations under |
16 |
|
- |
* the License. |
17 |
|
- |
*/ |
18 |
|
- |
|
19 |
|
- |
import org.litesoft.GWT.client.*; |
20 |
|
- |
import org.litesoft.core.*; |
21 |
|
- |
|
22 |
|
- |
import com.google.gwt.core.client.*; |
23 |
|
- |
import com.google.gwt.user.client.*; |
24 |
|
- |
|
25 |
|
- |
public class MousePerformanceFilter extends MouseHandlerWrapper { |
26 |
|
- |
private static final MoveStrategy s_defaultImpl = (MoveStrategy) GWT.create( MoveStrategy.class ); |
27 |
|
- |
|
28 |
|
- |
private MoveStrategy m_MoveStrategy = s_defaultImpl; |
29 |
|
- |
|
30 |
|
- |
public MousePerformanceFilter( MouseHandler delegate ) { |
31 |
|
- |
super( delegate ); |
32 |
|
- |
} |
33 |
|
- |
|
34 |
|
- |
public MoveStrategy getMoveStrategy() { |
35 |
|
- |
return m_MoveStrategy; |
36 |
|
- |
} |
37 |
|
- |
|
38 |
|
- |
public void setMoveStrategy( MoveStrategy impl ) { |
39 |
|
- |
m_MoveStrategy = impl; |
40 |
|
- |
} |
41 |
|
- |
|
42 |
|
- |
@Override |
43 |
|
- |
public void onMouseMove( MouseEvent e ) { |
44 |
|
- |
getMoveStrategy().step( getDelegate(), e ); |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
@Override |
48 |
|
- |
public void onMouseUp( MouseEvent e ) { |
49 |
|
- |
getMoveStrategy().finish(); |
50 |
|
- |
super.onMouseUp( e ); |
51 |
|
- |
} |
52 |
|
- |
|
53 |
|
- |
public static abstract class MoveStrategy { |
54 |
|
- |
protected abstract void step( MouseHandler handler, MouseEvent e ); |
55 |
|
- |
|
56 |
|
- |
protected abstract void finish(); |
57 |
|
- |
} |
58 |
|
- |
|
59 |
|
- |
public static class MoveStrategyImmediate extends MoveStrategy { |
60 |
|
- |
@Override |
61 |
|
- |
protected void step( MouseHandler handler, MouseEvent e ) { |
62 |
|
- |
handler.onMouseMove( e ); |
63 |
|
- |
} |
64 |
|
- |
|
65 |
|
- |
@Override |
66 |
|
- |
protected void finish() { |
67 |
|
- |
} |
68 |
|
- |
} |
69 |
|
- |
|
70 |
|
- |
public static class MoveStrategyDeferred extends MoveStrategy { |
71 |
|
- |
/** |
72 |
|
- |
* Note: the timer is active if this field is not null |
73 |
|
- |
*/ |
74 |
|
- |
private StepTimer m_timer = null; |
75 |
|
- |
|
76 |
|
- |
@Override |
77 |
|
- |
protected void step( MouseHandler handler, MouseEvent moveEvent ) { |
78 |
|
- |
if ( m_timer != null ) { |
79 |
|
- |
m_timer.update( moveEvent ); |
80 |
|
- |
} else { |
81 |
|
- |
m_timer = new StepTimer( handler, moveEvent ); |
82 |
|
- |
m_timer.schedule( 1 ); |
83 |
|
- |
} |
84 |
|
- |
} |
85 |
|
- |
|
86 |
|
- |
@Override |
87 |
|
- |
protected void finish() { |
88 |
|
- |
if ( m_timer != null ) { |
89 |
|
- |
m_timer.cancel(); |
90 |
|
- |
m_timer.run(); |
91 |
|
- |
} |
92 |
|
- |
} |
93 |
|
- |
|
94 |
|
- |
private class StepTimer extends Timer { |
95 |
|
- |
private final MouseHandler m_handler; |
96 |
|
- |
|
97 |
|
- |
private MouseEvent m_moveEvent; |
98 |
|
- |
|
99 |
|
- |
public StepTimer( MouseHandler gesture, MouseEvent moveEvent ) { |
100 |
|
- |
m_handler = gesture; |
101 |
|
- |
update( moveEvent ); |
102 |
|
- |
} |
103 |
|
- |
|
104 |
|
- |
public void update( MouseEvent e ) { |
105 |
|
- |
m_moveEvent = e; |
106 |
|
- |
} |
107 |
|
- |
|
108 |
|
- |
@Override |
109 |
|
- |
public void run() { |
110 |
|
- |
m_timer = null; |
111 |
|
- |
m_handler.onMouseMove( m_moveEvent ); |
112 |
|
- |
} |
113 |
|
- |
} |
114 |
|
- |
} |
115 |
|
- |
|
116 |
|
- |
public static class MoveStrategyMozilla extends MoveStrategy { |
117 |
|
- |
private final MoveStrategy m_strategy; |
118 |
|
- |
|
119 |
|
- |
public MoveStrategyMozilla() { |
120 |
|
- |
if ( Platform.Other.equals( UserAgent.getInstance().getPlatform() ) ) { |
121 |
|
- |
m_strategy = new MoveStrategyDeferred(); |
122 |
|
- |
} else { |
123 |
|
- |
m_strategy = new MoveStrategyImmediate(); |
124 |
|
- |
} |
125 |
|
- |
} |
126 |
|
- |
|
127 |
|
- |
@Override |
128 |
|
- |
protected void step( MouseHandler handler, MouseEvent moveEvent ) { |
129 |
|
- |
m_strategy.step( handler, moveEvent ); |
130 |
|
- |
} |
131 |
|
- |
|
132 |
|
- |
@Override |
133 |
|
- |
protected void finish() { |
134 |
|
- |
m_strategy.finish(); |
135 |
|
- |
} |
136 |
|
- |
} |
137 |
|
- |
} |
|
1 |
+ |
// This Source Code is Copyright & Licenced as indicated below |
|
2 |
+ |
package org.litesoft.GWT.client.widgets.nonpublic.external; |
|
3 |
+ |
/* |
|
4 |
+ |
* Copyright 2007 Mat Gessel <mat.gessel@gmail.com> |
|
5 |
+ |
* |
|
6 |
+ |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
7 |
+ |
* use this file except in compliance with the License. You may obtain a copy of |
|
8 |
+ |
* the License at |
|
9 |
+ |
* |
|
10 |
+ |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11 |
+ |
* |
|
12 |
+ |
* Unless required by applicable law or agreed to in writing, software |
|
13 |
+ |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
14 |
+ |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
15 |
+ |
* License for the specific language governing permissions and limitations under |
|
16 |
+ |
* the License. |
|
17 |
+ |
*/ |
|
18 |
+ |
|
|
19 |
+ |
import org.litesoft.GWT.client.*; |
|
20 |
+ |
import org.litesoft.core.*; |
|
21 |
+ |
|
|
22 |
+ |
import com.google.gwt.core.client.*; |
|
23 |
+ |
import com.google.gwt.user.client.*; |
|
24 |
+ |
|
|
25 |
+ |
public class MousePerformanceFilter extends MouseHandlerWrapper { |
|
26 |
+ |
private static final MoveStrategy s_defaultImpl = (MoveStrategy) GWT.create( MoveStrategy.class ); |
|
27 |
+ |
|
|
28 |
+ |
private MoveStrategy m_MoveStrategy = s_defaultImpl; |
|
29 |
+ |
|
|
30 |
+ |
public MousePerformanceFilter( MouseHandler delegate ) { |
|
31 |
+ |
super( delegate ); |
|
32 |
+ |
} |
|
33 |
+ |
|
|
34 |
+ |
public MoveStrategy getMoveStrategy() { |
|
35 |
+ |
return m_MoveStrategy; |
|
36 |
+ |
} |
|
37 |
+ |
|
|
38 |
+ |
public void setMoveStrategy( MoveStrategy impl ) { |
|
39 |
+ |
m_MoveStrategy = impl; |
|
40 |
+ |
} |
|
41 |
+ |
|
|
42 |
+ |
@Override |
|
43 |
+ |
public void onMouseMove( MouseEvent e ) { |
|
44 |
+ |
getMoveStrategy().step( getDelegate(), e ); |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
@Override |
|
48 |
+ |
public void onMouseUp( MouseEvent e ) { |
|
49 |
+ |
getMoveStrategy().finish(); |
|
50 |
+ |
super.onMouseUp( e ); |
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
public static abstract class MoveStrategy { |
|
54 |
+ |
protected abstract void step( MouseHandler handler, MouseEvent e ); |
|
55 |
+ |
|
|
56 |
+ |
protected abstract void finish(); |
|
57 |
+ |
} |
|
58 |
+ |
|
|
59 |
+ |
public static class MoveStrategyImmediate extends MoveStrategy { |
|
60 |
+ |
@Override |
|
61 |
+ |
protected void step( MouseHandler handler, MouseEvent e ) { |
|
62 |
+ |
handler.onMouseMove( e ); |
|
63 |
+ |
} |
|
64 |
+ |
|
|
65 |
+ |
@Override |
|
66 |
+ |
protected void finish() { |
|
67 |
+ |
} |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
public static class MoveStrategyDeferred extends MoveStrategy { |
|
71 |
+ |
/** |
|
72 |
+ |
* Note: the timer is active if this field is not null |
|
73 |
+ |
*/ |
|
74 |
+ |
private StepTimer m_timer = null; |
|
75 |
+ |
|
|
76 |
+ |
@Override |
|
77 |
+ |
protected void step( MouseHandler handler, MouseEvent moveEvent ) { |
|
78 |
+ |
if ( m_timer != null ) { |
|
79 |
+ |
m_timer.update( moveEvent ); |
|
80 |
+ |
} else { |
|
81 |
+ |
m_timer = new StepTimer( handler, moveEvent ); |
|
82 |
+ |
m_timer.schedule( 1 ); |
|
83 |
+ |
} |
|
84 |
+ |
} |
|
85 |
+ |
|
|
86 |
+ |
@Override |
|
87 |
+ |
protected void finish() { |
|
88 |
+ |
if ( m_timer != null ) { |
|
89 |
+ |
m_timer.cancel(); |
|
90 |
+ |
m_timer.run(); |
|
91 |
+ |
} |
|
92 |
+ |
} |
|
93 |
+ |
|
|
94 |
+ |
private class StepTimer extends Timer { |
|
95 |
+ |
private final MouseHandler m_handler; |
|
96 |
+ |
|
|
97 |
+ |
private MouseEvent m_moveEvent; |
|
98 |
+ |
|
|
99 |
+ |
public StepTimer( MouseHandler gesture, MouseEvent moveEvent ) { |
|
100 |
+ |
m_handler = gesture; |
|
101 |
+ |
update( moveEvent ); |
|
102 |
+ |
} |
|
103 |
+ |
|
|
104 |
+ |
public void update( MouseEvent e ) { |
|
105 |
+ |
m_moveEvent = e; |
|
106 |
+ |
} |
|
107 |
+ |
|
|
108 |
+ |
@Override |
|
109 |
+ |
public void run() { |
|
110 |
+ |
m_timer = null; |
|
111 |
+ |
m_handler.onMouseMove( m_moveEvent ); |
|
112 |
+ |
} |
|
113 |
+ |
} |
|
114 |
+ |
} |
|
115 |
+ |
|
|
116 |
+ |
public static class MoveStrategyMozilla extends MoveStrategy { |
|
117 |
+ |
private final MoveStrategy m_strategy; |
|
118 |
+ |
|
|
119 |
+ |
public MoveStrategyMozilla() { |
|
120 |
+ |
if ( Platform.Other.equals( UserAgent.getInstance().getPlatform() ) ) { |
|
121 |
+ |
m_strategy = new MoveStrategyDeferred(); |
|
122 |
+ |
} else { |
|
123 |
+ |
m_strategy = new MoveStrategyImmediate(); |
|
124 |
+ |
} |
|
125 |
+ |
} |
|
126 |
+ |
|
|
127 |
+ |
@Override |
|
128 |
+ |
protected void step( MouseHandler handler, MouseEvent moveEvent ) { |
|
129 |
+ |
m_strategy.step( handler, moveEvent ); |
|
130 |
+ |
} |
|
131 |
+ |
|
|
132 |
+ |
@Override |
|
133 |
+ |
protected void finish() { |
|
134 |
+ |
m_strategy.finish(); |
|
135 |
+ |
} |
|
136 |
+ |
} |
|
137 |
+ |
} |