Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright 2007 Mat Gessel <mat.gessel@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.litesoft.GWT.client.widgets.nonpublic.external;

/**
 * Contains information used by drag operations to position elements in the UI.
 * Different drag operations require different coordinates, so we pass all
 * coordinates to operations using this object. Also encapsulates coordinate
 * calulations.
 */
/*
 * Extends MouseEvent so that both types may be used polymorphically. For
 * example, a slider will process both mouse down and mouse drag (but not mouse
 * move).
 */
public class DragEvent extends MouseEvent
{
    private static final long serialVersionUID = -60876731058183754L;

    private final int m_deltaX, m_deltaY;
    private final int m_cumulativeX, m_cumulativeY;

    /**
     * @param receiver      the widget which is receiving the mouse event
     * @param mouseEvent    a <code>mousedown</code>, <code>mousemove</code> or <code>mouseup</code> event
     * @param previousEvent
     */
    public DragEvent( MouseEvent mouseMove, MouseEvent mouseDown, MouseEvent previousEvent )
    {
        super( mouseMove );

        if ( previousEvent != null )
        {
            /*
                * Calculate the delta relative to the last event, adjusting for a
                * possibly moving coordinate space
                */
            m_deltaX = mouseMove.getWidgetLeft() - previousEvent.getWidgetLeft() + mouseMove.getWidgetX() -
                       previousEvent.getWidgetX();
            m_deltaY = mouseMove.getWidgetTop() - previousEvent.getWidgetTop() + mouseMove.getWidgetY() -
                       previousEvent.getWidgetY();
            m_cumulativeX = mouseMove.getWidgetX() - mouseDown.getWidgetX();
            m_cumulativeY = mouseMove.getWidgetY() - mouseDown.getWidgetY();
        }
        else
        {
            m_deltaX = m_deltaY = 0;
            m_cumulativeX = m_cumulativeY = 0;
        }
    }

    /**
     * Get the distance moved horizontally, relative to the last event. Returns
     * a useful value even if the document is scrolled or the widget has moved
     * since the last event.
     */
    public int getDeltaX()
    {
        return m_deltaX;
    }

    /**
     * Get the distance moved vertically, relative to the last event. Returns
     * a useful value even if the document is scrolled or the widget has moved
     * since the last event.
     */
    public int getDeltaY()
    {
        return m_deltaY;
    }

    public int getCumulativeX()
    {
        return m_cumulativeX;
    }

    public int getCumulativeY()
    {
        return m_cumulativeY;
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/external/DragEvent.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000