public void onMouseDown(MouseDownEvent event) {

        if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
            // only act on left button down, ignore right click
            return;
        }
        cacheElementSize();
        switch (m_state) {
            case EMPTY:
                DOM.setCapture(getElement());
                m_state = State.SELECTING;
                m_firstX = event.getRelativeX(getElement());
                m_firstY = event.getRelativeY(getElement());
                m_currentSelection = new CmsPositionBean();
                setSelectPosition(m_firstX, m_firstY, 0, 0);
                showSelect(true);

                break;
            case SELECTED:

                m_firstX = event.getRelativeX(getElement());
                m_firstY = event.getRelativeY(getElement());
                if (m_mouseOverArea == null) {
                    // mouse not over selection, remove selection
                    clearSelection();
                    fireChangeEvent(true);
                    break;
                }
                switch (m_mouseOverArea) {
                    case BORDER_TOP:
                        m_state = State.RESIZE_HEIGHT;

                        // fixing opposite border
                        m_firstX = m_currentSelection.getLeft();
                        m_firstY = m_currentSelection.getTop() + m_currentSelection.getHeight();
                        break;
                    case BORDER_BOTTOM:
                        m_state = State.RESIZE_HEIGHT;

                        // fixing opposite border
                        m_firstX = m_currentSelection.getLeft();
                        m_firstY = m_currentSelection.getTop();
                        break;
                    case BORDER_LEFT:
                        m_state = State.RESIZE_WIDTH;

                        // fixing opposite border
                        m_firstX = m_currentSelection.getLeft() + m_currentSelection.getWidth();
                        m_firstY = m_currentSelection.getTop();
                        break;
                    case BORDER_RIGHT:
                        m_state = State.RESIZE_WIDTH;

                        // fixing opposite border
                        m_firstX = m_currentSelection.getLeft();
                        m_firstY = m_currentSelection.getTop();
                        break;
                    case CENTER:
                        m_state = State.DRAGGING;
                        m_moveOffsetX = m_firstX - m_currentSelection.getLeft();
                        m_moveOffsetY = m_firstY - m_currentSelection.getTop();
                        break;
                    case CORNER_BOTTOM_LEFT:
                        m_state = State.SELECTING;

                        // fixing opposite corner
                        m_firstX = m_currentSelection.getLeft() + m_currentSelection.getWidth();
                        m_firstY = m_currentSelection.getTop();
                        break;
                    case CORNER_BOTTOM_RIGHT:
                        m_state = State.SELECTING;
                        // fixing opposite corner
                        m_firstX = m_currentSelection.getLeft();
                        m_firstY = m_currentSelection.getTop();
                        break;
                    case CORNER_TOP_LEFT:
                        m_state = State.SELECTING;

                        // fixing opposite corner
                        m_firstX = m_currentSelection.getLeft() + m_currentSelection.getWidth();
                        m_firstY = m_currentSelection.getTop() + m_currentSelection.getHeight();
                        break;
                    case CORNER_TOP_RIGHT:
                        m_state = State.SELECTING;

                        // fixing opposite corner
                        m_firstX = m_currentSelection.getLeft();
                        m_firstY = m_currentSelection.getTop() + m_currentSelection.getHeight();
                        break;
                    default:
                }
                DOM.setCapture(getElement());

                break;
            case DRAGGING:
            case RESIZE_HEIGHT:
            case RESIZE_WIDTH:
            case SELECTING:
            default:
                // Messed up selection state.
                // May happen if mouse-cursor was moved outside the window or frame while button pressed and button was released outside.
                if (m_currentSelection != null) {
                    m_state = State.SELECTED;
                    fireChangeEvent(true);
                } else {
                    // this should never happen
                    clearSelection();
                }
        }

        event.preventDefault();
        event.stopPropagation();
    }
public void onMouseDown ( MouseDownEvent event ) { if ( event . getNativeButton ( ) != NativeEvent . BUTTON_LEFT ) { return ; } cacheElementSize ( ) ; switch ( m_state ) { case EMPTY : DOM . setCapture ( getElement ( ) ) ; m_state = State . SELECTING ; m_firstX = event . getRelativeX ( getElement ( ) ) ; m_firstY = event . getRelativeY ( getElement ( ) ) ; m_currentSelection = new CmsPositionBean ( ) ; setSelectPosition ( m_firstX , m_firstY , 0 , 0 ) ; showSelect ( true ) ; break ; case SELECTED : m_firstX = event . getRelativeX ( getElement ( ) ) ; m_firstY = event . getRelativeY ( getElement ( ) ) ; if ( m_mouseOverArea == null ) { clearSelection ( ) ; fireChangeEvent ( true ) ; break ; } switch ( m_mouseOverArea ) { case BORDER_TOP : m_state = State . RESIZE_HEIGHT ; m_firstX = m_currentSelection . getLeft ( ) ; m_firstY = m_currentSelection . getTop ( ) + m_currentSelection . getHeight ( ) ; break ; case BORDER_BOTTOM : m_state = State . RESIZE_HEIGHT ; m_firstX = m_currentSelection . getLeft ( ) ; m_firstY = m_currentSelection . getTop ( ) ; break ; case BORDER_LEFT : m_state = State . RESIZE_WIDTH ; m_firstX = m_currentSelection . getLeft ( ) + m_currentSelection . getWidth ( ) ; m_firstY = m_currentSelection . getTop ( ) ; break ; case BORDER_RIGHT : m_state = State . RESIZE_WIDTH ; m_firstX = m_currentSelection . getLeft ( ) ; m_firstY = m_currentSelection . getTop ( ) ; break ; case CENTER : m_state = State . DRAGGING ; m_moveOffsetX = m_firstX - m_currentSelection . getLeft ( ) ; m_moveOffsetY = m_firstY - m_currentSelection . getTop ( ) ; break ; case CORNER_BOTTOM_LEFT : m_state = State . SELECTING ; m_firstX = m_currentSelection . getLeft ( ) + m_currentSelection . getWidth ( ) ; m_firstY = m_currentSelection . getTop ( ) ; break ; case CORNER_BOTTOM_RIGHT : m_state = State . SELECTING ; m_firstX = m_currentSelection . getLeft ( ) ; m_firstY = m_currentSelection . getTop ( ) ; break ; case CORNER_TOP_LEFT : m_state = State . SELECTING ; m_firstX = m_currentSelection . getLeft ( ) + m_currentSelection . getWidth ( ) ; m_firstY = m_currentSelection . getTop ( ) + m_currentSelection . getHeight ( ) ; break ; case CORNER_TOP_RIGHT : m_state = State . SELECTING ; m_firstX = m_currentSelection . getLeft ( ) ; m_firstY = m_currentSelection . getTop ( ) + m_currentSelection . getHeight ( ) ; break ; default : } DOM . setCapture ( getElement ( ) ) ; break ; case DRAGGING : case RESIZE_HEIGHT : case RESIZE_WIDTH : case SELECTING : default : if ( m_currentSelection != null ) { m_state = State . SELECTED ; fireChangeEvent ( true ) ; } else { clearSelection ( ) ; } } event . preventDefault ( ) ; event . stopPropagation ( ) ; }
@see com.google.gwt.event.dom.client.MouseDownHandler#onMouseDown(com.google.gwt.event.dom.client.MouseDownEvent)