Java Code Examples for com.google.gwt.dom.client.NativeEvent

The following are top voted examples for showing how to use com.google.gwt.dom.client.NativeEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: empiria.player   File: AbstractConnectionView.java   Source Code and License 7 votes vote down vote up
@Override
public void onTouchEvent(TouchEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();

    JsArray<Touch> touches = nativeEvent.getTouches();
    boolean isMouseClick = isMouseClick(touches); // method is also called
    // when MouseEvents
    // occur
    boolean isOneFingerTouch = isOneFingerTouch(touches);

    switch (event.getType()) {
        case TOUCH_START:
            if (isMouseClick || isOneFingerTouch) {
                onTouchStart(nativeEvent);
            } else {
                onTouchCancel(nativeEvent);
            }
            break;
        case TOUCH_CANCEL:
        case TOUCH_END:
            onTouchEnd(nativeEvent);
            break;
        case TOUCH_MOVE:
            if (isMouseClick || isOneFingerTouch) {
                onTouchMove(nativeEvent);
            } else {
                onTouchCancel(nativeEvent);
            }
            break;
        default:
            break;
    }

}
 
Example 2
Project: EasyML   File: DatasetWidget.java   Source Code and License 6 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {

	super.onMouseDown(event);
	if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
		event.stopPropagation();
		event.preventDefault();
	}

	DiagramController con =this.getController();
	con.setPropTable(ptable);
}
 
Example 3
Project: empiria.player   File: ExplorableImgContentPresenter.java   Source Code and License 6 votes vote down vote up
private EventHandlerProxy createToolboxTouchStartHandler() {
    Command command = new Command() {
        @Override
        public void execute(NativeEvent event) {
            event.preventDefault();
        }

    };

    return handlerFactory.createUserTouchStartHandler(command);
}
 
Example 4
Project: empiria.player   File: ExplorableImgContentPresenter.java   Source Code and License 6 votes vote down vote up
private EventHandlerProxy createZoomOutButtonUserDownHandler() {
    Command command = new Command() {
        @Override
        public void execute(NativeEvent event) {
            zoomOut();
            zoomOutTicker.scheduleRepeating(200);
            event.preventDefault();
        }

    };

    return handlerFactory.createUserDownHandler(command);
}
 
Example 5
Project: empiria.player   File: MediaProgressBarAndroid.java   Source Code and License 6 votes vote down vote up
@Override
protected void setPosition(NativeEvent event) {
    if (isAttached()) {
        event.preventDefault();
        int positionX = getPositionX(event);
        moveScroll(positionX > 0 ? positionX : 0, true);
        if (!isPressed()) {// robimy seeka tylko gdy zakonczono dotyk
            seekInMedia(positionX > 0 ? positionX : 0);
        }
    }
}
 
Example 6
Project: empiria.player   File: AbstractConnectionView.java   Source Code and License 6 votes vote down vote up
public void onTouchMove(NativeEvent event) {
    if (getView() != null) {
        if (NOT_MOBILE_BROWSER) {
            event.preventDefault();
        }
        callOnMoveHandlers(new ConnectionMoveEvent(getPositionX(event), getPositionY(event), event));
    }
}
 
Example 7
Project: empiria.player   File: TouchController.java   Source Code and License 6 votes vote down vote up
public void updateOnTouchStart(NativeEvent onTouchStartEvent) {

        int y = touchEventReader.getScreenY(onTouchStartEvent);
        int x = touchEventReader.getX(onTouchStartEvent);
        boolean multiTouch = touchEventReader.isMoreThenOneFingerTouch(onTouchStartEvent);

        touchModel.setStartScrollTopPossition(windowDelegate.getScrollTop());
        touchModel.setStartY(y);
        touchModel.setStartX(x);
        touchModel.setLastEndX(x);
        touchModel.setEndX(-1);
        touchModel.setMultiTouch(multiTouch);
        touchModel.setSwipeStarted(false);
        touchModel.setTouchReservation(false);
        touchModel.setVerticalSwipeDetected(false);
    }
 
Example 8
Project: gwt-history   File: HistoryTest.java   Source Code and License 6 votes vote down vote up
@DoNotRunWith(Platform.HtmlUnitUnknown)
public void testClickLink() {
  AnchorElement anchorElement = Document.get().createAnchorElement();
  anchorElement.setHref("#href1");
  Document.get().getBody().appendChild(anchorElement);

  try {
    History.newItem("something_as_base");

    addHistoryListenerImpl(
        event -> {
          assertEquals("href1", event.getValue());
          finishTest();
        });

    delayTestFinish(5000);

    NativeEvent clickEvent =
        Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);

    anchorElement.dispatchEvent(clickEvent);

  } finally {
    Document.get().getBody().removeChild(anchorElement);
  }
}
 
Example 9
Project: empiria.player   File: MultiPageTouchHandler.java   Source Code and License 6 votes vote down vote up
private void onTouchMove(NativeEvent event) {
    touchEndTimer.cancel();

    if (!touchController.canMove(multiPageController)) {
        return;
    }

    // nie zawsze wystepuje event touchend na androidzie - emulacja
    // zachownaia
    touchController.updateEndPoint(event);

    if (touchController.isReadyToStartAnimation()) {
        startAnimation(event);
    } else {
        touchController.setVerticalSwipeDetected(true);
    }
}
 
Example 10
Project: empiria.player   File: MultiPageTouchHandler.java   Source Code and License 6 votes vote down vote up
private void onTouchEnd(NativeEvent event) {
    touchEndTimer.cancel();

    if (touchController.isSwipeStarted()) {
        touchEventReader.preventDefault(event);
        touchController.updateOnTouchEnd(event);

        if (touchController.canSwitchPage()) {
            multiPageController.switchPage();
        } else {
            multiPageController.animatePageSwitch();
        }
        touchController.setSwypeStarted(false);
    }

    touchController.resetTouchModel();
    multiPageController.resetFocusAndStyles();
}
 
Example 11
Project: empiria.player   File: MultiPageTouchHandlerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void onTouchEventTest_TOUCH_END_isNotSwipeStartedTest() {

    // when
    when(touchEvent.getType()).thenReturn(TouchTypes.TOUCH_END);

    NativeEvent nativeEvent = mock(NativeEvent.class);
    when(touchEvent.getNativeEvent()).thenReturn(nativeEvent);
    // given
    testObj.onTouchEvent(touchEvent);

    // then
    InOrder inOrder = inOrder(userAgentUtil, touchEventReader, touchController, touchEndTimerFactory, touchEndTimer, touchEvent, multiPageController);

    inOrder.verify(touchEvent).getType();
    inOrder.verify(touchEvent).getNativeEvent();
    inOrder.verify(touchEndTimer).cancel();
    inOrder.verify(touchController).isSwipeStarted();
    inOrder.verify(touchController).resetTouchModel();
    inOrder.verify(multiPageController).resetFocusAndStyles();
}
 
Example 12
Project: empiria.player   File: MultiPageTouchHandlerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void onTouchEventTest_TOUCH_MOVE_isNotHorizontalSwipeTest() {

    // when
    when(touchEvent.getType()).thenReturn(TouchTypes.TOUCH_MOVE);

    when(touchController.canMove(multiPageController)).thenReturn(true);
    when(touchController.isReadyToStartAnimation()).thenReturn(false);
    NativeEvent nativeEvent = mock(NativeEvent.class);
    when(touchEvent.getNativeEvent()).thenReturn(nativeEvent);
    // given
    testObj.onTouchEvent(touchEvent);

    // then
    InOrder inOrder = inOrder(userAgentUtil, touchEventReader, touchController, touchEndTimerFactory, touchEndTimer, touchEvent, multiPageController);

    inOrder.verify(touchEvent).getType();
    inOrder.verify(touchEvent).getNativeEvent();
    inOrder.verify(touchEndTimer).cancel();
    inOrder.verify(touchController).canMove(multiPageController);
    inOrder.verify(touchController).updateEndPoint(nativeEvent);
    inOrder.verify(touchController).isReadyToStartAnimation();
    inOrder.verify(touchController).setVerticalSwipeDetected(true);
}
 
Example 13
Project: EasyML   File: BaseWidget.java   Source Code and License 6 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
	if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
		event.stopPropagation();
		event.preventDefault();
		controller.showMenu(this);
		this.setFocus();
	}
}
 
Example 14
Project: EasyML   File: Leaf.java   Source Code and License 6 votes vote down vote up
/**
 * Create a leaf node for the Tree
 *
 * @param name   name of the TreeItem
 * @param module Attached moduleId for the TreeItem
 */
public Leaf(String name,
		T module,
		String style) {
	// add context menu
	this.menu = new ContextMenu();
	label = new Label(name);
	this.setWidget(label);

	label.addMouseDownHandler(new MouseDownHandler() {
		@Override
		public void onMouseDown(MouseDownEvent event) {
			// display the context menu when right click
			if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
				menu.setPopupPosition(event.getClientX(), event.getClientY());
				menu.show();
			}
		}
	});

	// set moduleId
	this.module = module;
	this.addStyleName("bda-treeleaf");
	if (!style.equals(""))
		this.addStyleName(style);
}
 
Example 15
Project: empiria.player   File: MultiPageTouchHandlerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void onTouchEventTest_TOUCH_START_complete_test() {

    // when
    when(touchEvent.getType()).thenReturn(TouchTypes.TOUCH_START);

    when(touchController.canSwype(multiPageController)).thenReturn(true);
    when(touchController.isSwypeStarted()).thenReturn(false);
    NativeEvent nativeEvent = mock(NativeEvent.class);
    when(touchEvent.getNativeEvent()).thenReturn(nativeEvent);
    // given
    testObj.onTouchEvent(touchEvent);

    // then
    InOrder inOrder = inOrder(userAgentUtil, touchEventReader, touchController, touchEndTimerFactory, touchEndTimer, touchEvent, multiPageController);

    inOrder.verify(touchEvent).getType();
    inOrder.verify(touchEvent).getNativeEvent();
    inOrder.verify(touchController).canSwype(multiPageController);
    inOrder.verify(touchController).isSwypeStarted();

    inOrder.verify(touchController).updateOnTouchStart(nativeEvent);

    inOrder.verify(touchEndTimer).cancel();
    inOrder.verify(multiPageController).resetFocusAndStyles();
}
 
Example 16
Project: empiria.player   File: SlideshowPagerPresenterTest.java   Source Code and License 6 votes vote down vote up
@Test
public void shouldExecuteClickCommand() {
    // given
    int slidesSize = 1;
    testObj.createPager(slidesSize);

    NativeEvent event = mock(NativeEvent.class);
    verify(pagerButton).setClickCommand(commandCaptor.capture());
    Command command = commandCaptor.getValue();

    // when
    command.execute(event);

    // then
    verify(pagerButton).deactivatePagerButton();
    verify(pagerButton).activatePagerButton();
    verify(slideshowController).showSlide(0);
}
 
Example 17
Project: empiria.player   File: MultiPageTouchHandlerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void onTouchEventTest_TOUCH_MOVE_canMoveTest() {

    // when
    when(touchEvent.getType()).thenReturn(TouchTypes.TOUCH_MOVE);

    when(touchController.canMove(multiPageController)).thenReturn(false);
    NativeEvent nativeEvent = mock(NativeEvent.class);
    when(touchEvent.getNativeEvent()).thenReturn(nativeEvent);
    // given
    testObj.onTouchEvent(touchEvent);

    // then
    InOrder inOrder = inOrder(userAgentUtil, touchEventReader, touchController, touchEndTimerFactory, touchEndTimer, touchEvent, multiPageController);

    inOrder.verify(touchEvent).getType();
    inOrder.verify(touchEvent).getNativeEvent();
    inOrder.verify(touchEndTimer).cancel();
    inOrder.verify(touchController).canMove(multiPageController);
}
 
Example 18
Project: empiria.player   File: TestResetButtonPresenterTest.java   Source Code and License 6 votes vote down vote up
@Test
public void shouldNavigateToFirstItem_ifLockUnlockWasCalled() {
    // given
    NativeEvent event = mock(NativeEvent.class);
    testObj.lock();

    verify(testResetButtonView).addHandler(commandCaptor.capture());
    Command command = commandCaptor.getValue();

    testObj.unlock();

    // when
    command.execute(event);

    // then
    verifyActionsOnResetClick();
}
 
Example 19
Project: EasyML   File: DiagramController.java   Source Code and License 6 votes vote down vote up
/**
 * Trigger action when mouse up event fired
 * 
 * @param event
 */
protected void onMouseUp(MouseUpEvent event) {
	// Test if Right Click
	if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
		logger.info( "Handle NativeEvent.BUTTON_RIGHT begin >");
		event.stopPropagation();
		event.preventDefault();
		logger.info("Handle NativeEvent.BUTTON_RIGHT end <");
		return;
	}

	if ( !lockDrawConnection && inDragBuildConnection ) {
		logger.info( "draw connection lock: " +  lockDrawConnection );
		NodeShape shape = (NodeShape) getShapeUnderMouse();
		if (shape != null && shape instanceof InNodeShape) {
			Connection c = connfactory.buildConnection(this, startShape, shape);
			if (c == null) {
				Window.alert("Connection can't be build");
			} else {
				c.draw();
				connDrawSet.add(c);
				((NodeShape) startShape).onConnectionEnd(c);
				shape.onConnectionEnd(c);
			}
		}else {
			((NodeShape) startShape).onConnectionCancel();
		}
		deleteConnection(buildConnection);
		inDragBuildConnection = false;
		buildConnection = null;
	}
}
 
Example 20
Project: EasyML   File: DiagramController.java   Source Code and License 6 votes vote down vote up
/**
 * Trigger action when mouse down event fired
 * 
 * @param event
 */
public void onMouseDown(MouseDownEvent event) {
	logger.info("diagram left mouse down");
	this.getWidgetPanel().getElement().focus();
	if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
		NodeShape shape = (NodeShape) getShapeUnderMouse();
		if (shape instanceof OutNodeShape) {
			OutNodeShape outShape = (OutNodeShape)shape;
			int x = outShape.getOffsetLeft() + 2*outShape.getRadius();
			int y = outShape.getOffsetTop() + 2*outShape.getRadius();
			outShape.getContextMenu().setPopupPosition(x,y);
			outShape.getContextMenu().show();
		}
		if(isvacancy){
			event.stopPropagation();
			event.preventDefault();
			//Popup connection menu
			if( !this.inShapeArea ){
				final Connection c = getConnectionNearMouse();
				if (c != null) {
					showMenu(c);
				}else{
					showContextualMenu(event);
				}
			}

		}

		return;
	}

	if (!lockDrawConnection && inEditionToDrawConnection) {
		logger.info( "draw connection lock: " +  lockDrawConnection );
		inDragBuildConnection = true;
		inEditionToDrawConnection = false;
		((NodeShape) startShape).onConnectionStart();
		drawBuildArrow(startShape, getMousePoint());
	}
	if(!isvacancy){
		event.stopPropagation();
		event.preventDefault();
		focusTimer.scheduleRepeating(50);
	}
	else {
		this.clearSelectedWidgets();
		selectedWidget = null;
		focusTimer.scheduleRepeating(50);
	}
	this.setIsVacancy(true);
}
 
Example 21
Project: empiria.player   File: AccordionPresenterTest.java   Source Code and License 6 votes vote down vote up
@Test
public void shouldInitializeSection() {
    // given
    NativeEvent nativeEvent = mock(NativeEvent.class);

    // when
    testObj.initialize(bean, generator);

    // then
    verify(section).init(transition);
    verify(section).addClickCommand(commandCaptor.capture());
    verify(view).addSection(section);

    Command clickCommand = commandCaptor.getValue();
    clickCommand.execute(nativeEvent);
    verify(accordionController).onClick(section);
}
 
Example 22
Project: empiria.player   File: ColorfillCanvasImplJUnitTest.java   Source Code and License 6 votes vote down vote up
@Test
public void onAreaClick() throws Exception {
    // before
    ColorfillAreaClickListener colorfillAreaClickListener = mock(ColorfillAreaClickListener.class);
    instance.setAreaClickListener(colorfillAreaClickListener);
    when(canvasImageDataProvider.getCanvasImageData(canvasStubView)).thenReturn(imageData);

    ArgumentCaptor<LoadHandler> loadHandlerCaptor = ArgumentCaptor.forClass(LoadHandler.class);
    verify(canvasStubView).setImageLoadHandler(loadHandlerCaptor.capture());
    loadHandlerCaptor.getValue()
                     .onLoad(null);

    ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    verify(userInteractionHandlerFactory).applyUserClickHandler(commandCaptor.capture(), eq(canvas));

    NativeEvent nativeEvent = mock(NativeEvent.class);
    commandCaptor.getValue()
                 .execute(nativeEvent);

    ArgumentCaptor<Area> areaCaptor = ArgumentCaptor.forClass(Area.class);
    verify(colorfillAreaClickListener).onAreaClick(areaCaptor.capture());
    verify(nativeEvent).preventDefault();
    Area area = areaCaptor.getValue();
    assertThat(area.getX()).isEqualTo(POSITION_X);
    assertThat(area.getY()).isEqualTo(POSITION_Y);
}
 
Example 23
Project: empiria.player   File: ColorfillCanvasImplJUnitTest.java   Source Code and License 6 votes vote down vote up
@Test
public void onAreaClickWrongCoordinates() throws Exception {
    ColorfillAreaClickListener colorfillAreaClickListener = mock(ColorfillAreaClickListener.class);
    instance.setAreaClickListener(colorfillAreaClickListener);
    when(canvasImageDataProvider.getCanvasImageData(canvasStubView)).thenReturn(imageData);

    doReturn(-10).when(positionHelper)
                 .getXPositionRelativeToTarget(any(NativeEvent.class), Matchers.any(Element.class));
    doReturn(-15).when(positionHelper)
                 .getYPositionRelativeToTarget(any(NativeEvent.class), Matchers.any(Element.class));

    ArgumentCaptor<LoadHandler> loadHandlerCaptor = ArgumentCaptor.forClass(LoadHandler.class);
    verify(canvasStubView).setImageLoadHandler(loadHandlerCaptor.capture());
    loadHandlerCaptor.getValue()
                     .onLoad(null);

    ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    verify(userInteractionHandlerFactory).applyUserClickHandler(commandCaptor.capture(), eq(canvas));

    NativeEvent nativeEvent = mock(NativeEvent.class);
    commandCaptor.getValue()
                 .execute(nativeEvent);

    verify(colorfillAreaClickListener, times(0)).onAreaClick(any(Area.class));
}
 
Example 24
Project: empiria.player   File: TouchControllerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void updateEndPointTest() {
    NativeEvent onTouchMoveEvent = mock(NativeEvent.class);
    int y = 100;
    when(touchEventReader.getScreenY(onTouchMoveEvent)).thenReturn(y);
    int x = 200;
    when(touchEventReader.getX(onTouchMoveEvent)).thenReturn(x);
    testObj.updateEndPoint(onTouchMoveEvent);

    assertEquals(touchModel.getEndX(), x);
    assertEquals(touchModel.getEndY(), y);

    InOrder inOrder = inOrder(windowDelegate, touchEventReader, eventsBus);
    inOrder.verify(touchEventReader)
            .getScreenY(onTouchMoveEvent);
    inOrder.verify(touchEventReader)
            .getX(onTouchMoveEvent);
}
 
Example 25
Project: empiria.player   File: TouchControllerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void updateOnTouchEndTest() {
    NativeEvent event = mock(NativeEvent.class);
    int y = 100;
    when(touchEventReader.getFromChangedTouchesScreenY(event)).thenReturn(y);
    int x = 200;
    when(touchEventReader.getFromChangedTouchesX(event)).thenReturn(x);
    testObj.updateOnTouchEnd(event);

    assertEquals(touchModel.getEndX(), x);
    assertEquals(touchModel.getEndY(), y);

    InOrder inOrder = inOrder(windowDelegate, touchEventReader, eventsBus);
    inOrder.verify(touchEventReader)
            .getFromChangedTouchesScreenY(event);
    inOrder.verify(touchEventReader)
            .getFromChangedTouchesX(event);
}
 
Example 26
Project: empiria.player   File: MultiPageTouchHandlerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void onTouchEventTest_TOUCH_START_isSecondFingerAdd_test() {

    // when
    when(touchEvent.getType()).thenReturn(TouchTypes.TOUCH_START);
    when(touchController.canSwype(multiPageController)).thenReturn(true);
    when(touchController.isSwypeStarted()).thenReturn(true);
    NativeEvent nativeEvent = mock(NativeEvent.class);
    when(touchEvent.getNativeEvent()).thenReturn(nativeEvent);
    // given
    testObj.onTouchEvent(touchEvent);

    // then
    InOrder inOrder = inOrder(userAgentUtil, touchEventReader, touchController, touchEndTimerFactory, touchEndTimer, touchEvent, multiPageController);

    inOrder.verify(touchEvent).getType();
    inOrder.verify(touchEvent).getNativeEvent();
    inOrder.verify(touchController).canSwype(multiPageController);
    inOrder.verify(touchController).isSwypeStarted();
}
 
Example 27
Project: empiria.player   File: FeedbackBlend.java   Source Code and License 5 votes vote down vote up
private Command createClickCommand() {
    return new Command() {
        @Override
        public void execute(NativeEvent event) {
            if (textFeedback.isPresent()) {
                textFeedback.get().hideFeedback();
            }
            hide();
        }
    };
}
 
Example 28
Project: empiria.player   File: SlideshowPagerPresenter.java   Source Code and License 5 votes vote down vote up
private Command createClickCommand(final SlideshowPagerButtonPresenter pagerButton) {
    final int indexToShow = pagerButtonsList.size();

    return new Command() {

        @Override
        public void execute(NativeEvent event) {
            deactivateAllPagerButtons();
            pagerButton.activatePagerButton();
            slideshowController.showSlide(indexToShow);
        }
    };
}
 
Example 29
Project: empiria.player   File: LinkModule.java   Source Code and License 5 votes vote down vote up
private Command createClickCommand() {
    return new Command() {
        @Override
        public void execute(NativeEvent event) {
            processLink();
        }
    };
}
 
Example 30
Project: empiria.player   File: TutorPresenterImpl.java   Source Code and License 5 votes vote down vote up
@Override
public void init() {
    tutorView.bindUi();
    tutorView.addClickHandler(new Command() {
        @Override
        public void execute(NativeEvent event) {
            clicked();
        }
    });
}
 
Example 31
Project: calendar-component   File: DateCellDayItem.java   Source Code and License 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {

    startX = event.getClientX();
    startY = event.getClientY();

    if (isDisabled() || event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        return;
    }

    clickTarget = Element.as(event.getNativeEvent().getEventTarget());
    mouseMoveCanceled = false;

    if ((weekGrid.getCalendar().isItemMoveAllowed() && getCalendarItem().isMoveable())
            || (clickTargetsResize() && getCalendarItem().isResizeable())) {

        moveRegistration = addMouseMoveHandler(this);
        setFocus(true);
        try {
            startYrelative = (int) ((double) event.getRelativeY(caption) % slotHeight);
            startXrelative = (event.getRelativeX(weekGrid.getElement())
                    - weekGrid.timebar.getOffsetWidth())
                    % getDateCellWidth();
        } catch (Exception e) {
            GWT.log("Exception calculating relative start position", e);
        }
        mouseMoveStarted = false;
        Style s = getElement().getStyle();
        s.setZIndex(1000);
        startDatetimeFrom = (Date) calendarItem.getStartTime().clone();
        startDatetimeTo = (Date) calendarItem.getEndTime().clone();
        Event.setCapture(getElement());
    }

    // make sure the right cursor is always displayed
    if (clickTargetsResize() && getCalendarItem().isResizeable()) {
        addGlobalResizeStyle();
    }

    /*
     * We need to stop the event propagation or else the WeekGrid range
     * select will kick in
     */
    event.stopPropagation();
    event.preventDefault();
}
 
Example 32
Project: empiria.player   File: DisableDefaultBehaviorCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(NativeEvent event) {
    event.preventDefault();
}
 
Example 33
Project: empiria.player   File: MultiPageTouchHandlerTest.java   Source Code and License 5 votes vote down vote up
@Test
public void onTouchEventTest_TOUCH_MOVE_isReadyToStartAnnimationTest() {

    // when
    when(touchEvent.getType()).thenReturn(TouchTypes.TOUCH_MOVE);

    when(touchController.canMove(multiPageController)).thenReturn(true);
    when(touchController.isReadyToStartAnimation()).thenReturn(true);
    NativeEvent nativeEvent = mock(NativeEvent.class);
    when(touchEvent.getNativeEvent()).thenReturn(nativeEvent);
    float swypeLength = 200f;
    when(touchController.getSwypePercentLength()).thenReturn(swypeLength);
    // given
    testObj.onTouchEvent(touchEvent);

    // then
    InOrder inOrder = inOrder(userAgentUtil, touchEventReader, touchController, touchEndTimerFactory, touchEndTimer, touchEvent, multiPageController);

    inOrder.verify(touchEvent).getType();
    inOrder.verify(touchEvent).getNativeEvent();
    inOrder.verify(touchEndTimer).cancel();
    inOrder.verify(touchController).canMove(multiPageController);
    inOrder.verify(touchController).updateEndPoint(nativeEvent);
    inOrder.verify(touchController).isReadyToStartAnimation();
    inOrder.verify(touchEventReader).preventDefault(nativeEvent);
    inOrder.verify(touchEndTimer).schedule(MultiPageController.TOUCH_END_TIMER_TIME);
    inOrder.verify(touchController).isSwipeRight();
    inOrder.verify(touchController).getSwypePercentLength();
    inOrder.verify(multiPageController).move(false, swypeLength);
    inOrder.verify(touchController).updateAfterSwypeDetected();
}
 
Example 34
Project: Charba   File: Animation.java   Source Code and License 5 votes vote down vote up
/**
 * Callback called on each step of an animation.
 * 
 * @param item animation item info.
 */
protected void onProgress(AnimationItem item) {
	// creates a native event by GWT (change)
	NativeEvent event = Document.get().createChangeEvent();
	// fires the event
	getChart().fireEvent(new AnimationProgressEvent(event, item));
}
 
Example 35
Project: empiria.player   File: MediaProgressBarImpl.java   Source Code and License 5 votes vote down vote up
@Override
protected void setPosition(NativeEvent event) {
    if (isPressed() && isAttached()) {
        int positionX = getPositionX(event);
        int positionNonNegative = Math.max(positionX, 0);
        positionNonNegative -= getHalfOfProgressButtonWidth();
        seekInMedia(positionNonNegative);
        progressBarEventHandler.resetCurrentTime();
    }
}
 
Example 36
Project: calendar-component   File: DateCellDayItem.java   Source Code and License 5 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
    if (mouseMoveCanceled
            || event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        return;
    }

    Event.releaseCapture(getElement());
    setFocus(false);
    if (moveRegistration != null) {
        moveRegistration.removeHandler();
        moveRegistration = null;
    }

    int endX = event.getClientX();
    int endY = event.getClientY();
    int xDiff = 0, yDiff = 0;
    if (startX != -1 && startY != -1) {
        // Drag started
        xDiff = startX - endX;
        yDiff = startY - endY;
    }

    startX = -1;
    startY = -1;
    mouseMoveStarted = false;
    Style s = getElement().getStyle();
    s.setZIndex(1);

    if (!clickTargetsResize()) {

        // check if mouse has moved over threshold of 3 pixels
        boolean mouseMoved = (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3);

        if (!weekGrid.getCalendar().isDisabled() && mouseMoved) {
            // Item Move:
            // - calendar must be enabled
            // - calendar must not be in read-only mode
            weekGrid.itemMoved(this);

        } else if (!weekGrid.getCalendar().isDisabled() && getCalendarItem().isClickable()) {
            // Item Click:
            // - calendar must be enabled (read-only is allowed)
            EventTarget et = event.getNativeEvent().getEventTarget();
            Element e = Element.as(et);
            if (e == caption || e == eventContent
                    || e.getParentElement() == caption) {
                if (weekGrid.getCalendar().getItemClickListener() != null) {
                    weekGrid.getCalendar().getItemClickListener().itemClick(calendarItem);
                }
            }
        }

    } else {
        // click targeted resize bar
        removeGlobalResizeStyle();
        if (weekGrid.getCalendar().getItemResizeListener() != null) {
            weekGrid.getCalendar().getItemResizeListener().itemResized(calendarItem);
        }
        dateCell.recalculateItemWidths();
    }
}
 
Example 37
Project: Charba   File: Animation.java   Source Code and License 5 votes vote down vote up
/**
 * Callback called at the end of an animation.
 * 
 * @param item animation item info.
 */
protected void onComplete(AnimationItem item) {
	// creates a native event by GWT (change)
	NativeEvent event = Document.get().createChangeEvent();
	// fires the event
	getChart().fireEvent(new AnimationCompleteEvent(event, item));
}
 
Example 38
Project: empiria.player   File: ConnectionModuleViewImplHandlers.java   Source Code and License 5 votes vote down vote up
@Override
public void onConnectionStart(ConnectionMoveStartEvent event) {
    if (view.isLocked())
        return;

    Optional<ConnectionItem> itemOptional = connectionsFinder.findConnectionItemForEventOnWidget(event, view, view.getConnectionItems());

    if (itemOptional.isPresent()) {
        ConnectionItem item = itemOptional.get();
        eventsBus.fireEvent(new PlayerEvent(PlayerEventTypes.TOUCH_EVENT_RESERVATION));
        event.preventDefault();
        view.getSurfaceForLineDrawing(item, NORMAL);
        view.startDrawLine(item);
        item.setConnected(true, NORMAL);

        ConnectionItem source = view.getConnectionItemPair().getSource();
        if (source != null && !item.equals(source)) {
            view.resetIfNotConnected(source.getBean().getIdentifier());
        }

        view.getConnectionItemPair().setSource(item);

    } else {
        NativeEvent nativeEvent = event.getNativeEvent();
        Point clickPoint = getClickPoint(nativeEvent);
        ConnectionPairEntry<String, String> pointOnPath = surfacesManager.findPointOnPath(view.getConnectedSurfaces(), clickPoint);

        if (pointOnPath != null) {
            surfacesManager.removeSurfaceFromParent(view.getConnectedSurfaces(), pointOnPath);
            view.disconnect(pointOnPath.getSource(), pointOnPath.getTarget(), true);
            event.preventDefault();
        }
    }
}
 
Example 39
Project: empiria.player   File: TestResetButtonPresenter.java   Source Code and License 5 votes vote down vote up
private void attachHandler() {
    testResetButtonView.addHandler(new Command() {
        @Override
        public void execute(NativeEvent event) {
            if (!locked) {
                changeWorkModeToTest();
                navigateToFirstItem();
                resetLesson();
            }
        }

    });
}
 
Example 40
Project: empiria.player   File: AccordionPresenter.java   Source Code and License 5 votes vote down vote up
private Command createClickEvent(final AccordionController controller, final AccordionSectionPresenter section) {
    return new Command() {
        @Override
        public void execute(NativeEvent event) {
            controller.onClick(section);
        }
    };
}