|
@@ -1,78 +1,78 @@ |
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 |
|
- |
/** |
20 |
|
- |
* A DragGesture wrapper which prevents the wrapped gesture's step action |
21 |
|
- |
* from occuring until a specified distance is exceeded. This can be used to |
22 |
|
- |
* prevent accidental manipulation or to pervent the wrapped gesture's start |
23 |
|
- |
* action from being executed until the mouse is moved. |
24 |
|
- |
*/ |
25 |
|
- |
public class DragThresholdFilter extends DragGestureWrapper { |
26 |
|
- |
private final int m_threshold; |
27 |
|
- |
|
28 |
|
- |
private MouseEvent m_start; |
29 |
|
- |
private boolean m_started = false; |
30 |
|
- |
|
31 |
|
- |
/** |
32 |
|
- |
* Creates a new DragGesture with the specified threshold. |
33 |
|
- |
* |
34 |
|
- |
* @param distance the distance in screen pixels to move before taking an |
35 |
|
- |
* action, or <code>0</code> |
36 |
|
- |
*/ |
37 |
|
- |
public DragThresholdFilter( int distance, DragGesture delegate ) { |
38 |
|
- |
super( delegate ); |
39 |
|
- |
|
40 |
|
- |
if ( distance < 0 ) { |
41 |
|
- |
throw new IllegalArgumentException( String.valueOf( distance ) ); |
42 |
|
- |
} |
43 |
|
- |
|
44 |
|
- |
m_threshold = distance; |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
protected boolean equalsThreshold( int deltaX, int deltaY ) { |
48 |
|
- |
return Math.abs( deltaX ) >= m_threshold || Math.abs( deltaY ) >= m_threshold; |
49 |
|
- |
} |
50 |
|
- |
|
51 |
|
- |
@Override |
52 |
|
- |
public void start( MouseEvent e ) { |
53 |
|
- |
if ( m_threshold == 0 ) { |
54 |
|
- |
m_started = true; |
55 |
|
- |
super.start( e ); |
56 |
|
- |
} else { |
57 |
|
- |
m_start = e; |
58 |
|
- |
} |
59 |
|
- |
} |
60 |
|
- |
|
61 |
|
- |
@Override |
62 |
|
- |
public void step( DragEvent e ) { |
63 |
|
- |
if ( !m_started && equalsThreshold( e.getDeltaX(), e.getDeltaY() ) ) { |
64 |
|
- |
m_started = true; |
65 |
|
- |
super.start( m_start ); |
66 |
|
- |
} |
67 |
|
- |
if ( m_started ) { |
68 |
|
- |
super.step( e ); |
69 |
|
- |
} |
70 |
|
- |
} |
71 |
|
- |
|
72 |
|
- |
@Override |
73 |
|
- |
public void finish() { |
74 |
|
- |
super.finish(); |
75 |
|
- |
m_started = false; |
76 |
|
- |
m_start = null; |
77 |
|
- |
} |
78 |
|
- |
} |
|
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 |
+ |
/** |
|
20 |
+ |
* A DragGesture wrapper which prevents the wrapped gesture's step action |
|
21 |
+ |
* from occuring until a specified distance is exceeded. This can be used to |
|
22 |
+ |
* prevent accidental manipulation or to pervent the wrapped gesture's start |
|
23 |
+ |
* action from being executed until the mouse is moved. |
|
24 |
+ |
*/ |
|
25 |
+ |
public class DragThresholdFilter extends DragGestureWrapper { |
|
26 |
+ |
private final int m_threshold; |
|
27 |
+ |
|
|
28 |
+ |
private MouseEvent m_start; |
|
29 |
+ |
private boolean m_started = false; |
|
30 |
+ |
|
|
31 |
+ |
/** |
|
32 |
+ |
* Creates a new DragGesture with the specified threshold. |
|
33 |
+ |
* |
|
34 |
+ |
* @param distance the distance in screen pixels to move before taking an |
|
35 |
+ |
* action, or <code>0</code> |
|
36 |
+ |
*/ |
|
37 |
+ |
public DragThresholdFilter( int distance, DragGesture delegate ) { |
|
38 |
+ |
super( delegate ); |
|
39 |
+ |
|
|
40 |
+ |
if ( distance < 0 ) { |
|
41 |
+ |
throw new IllegalArgumentException( String.valueOf( distance ) ); |
|
42 |
+ |
} |
|
43 |
+ |
|
|
44 |
+ |
m_threshold = distance; |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
protected boolean equalsThreshold( int deltaX, int deltaY ) { |
|
48 |
+ |
return Math.abs( deltaX ) >= m_threshold || Math.abs( deltaY ) >= m_threshold; |
|
49 |
+ |
} |
|
50 |
+ |
|
|
51 |
+ |
@Override |
|
52 |
+ |
public void start( MouseEvent e ) { |
|
53 |
+ |
if ( m_threshold == 0 ) { |
|
54 |
+ |
m_started = true; |
|
55 |
+ |
super.start( e ); |
|
56 |
+ |
} else { |
|
57 |
+ |
m_start = e; |
|
58 |
+ |
} |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
@Override |
|
62 |
+ |
public void step( DragEvent e ) { |
|
63 |
+ |
if ( !m_started && equalsThreshold( e.getDeltaX(), e.getDeltaY() ) ) { |
|
64 |
+ |
m_started = true; |
|
65 |
+ |
super.start( m_start ); |
|
66 |
+ |
} |
|
67 |
+ |
if ( m_started ) { |
|
68 |
+ |
super.step( e ); |
|
69 |
+ |
} |
|
70 |
+ |
} |
|
71 |
+ |
|
|
72 |
+ |
@Override |
|
73 |
+ |
public void finish() { |
|
74 |
+ |
super.finish(); |
|
75 |
+ |
m_started = false; |
|
76 |
+ |
m_start = null; |
|
77 |
+ |
} |
|
78 |
+ |
} |