Java Code Examples for com.google.gwt.event.dom.client.MouseDownEvent

The following examples show how to use com.google.gwt.event.dom.client.MouseDownEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void onMouseDown(MouseDownEvent event) {
	// Test if Right Click
	if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
		return;
	}

	if (inEditionSelectableShapeToDrawConnection) {
		inDragBuildArrow = true;
		inEditionSelectableShapeToDrawConnection = false;
		drawBuildArrow(startFunctionWidget, mousePoint);
		return;
	}

	if (inEditionDragMovablePoint) {
		inDragMovablePoint = true;
		inEditionDragMovablePoint = false;
		movablePoint = highlightConnection.addMovablePoint(highlightPoint);
		highlightConnection.setSynchronized(false);
		highlightConnection.setAllowSynchronized(false);
		movablePoint.setTrackPoint(mousePoint);
		// Set canvas foreground to avoid dragging over a widget
		topCanvas.setForeground();
		return;
	}
}
 
Example 2
Source Project: EasyML   Source File: DiagramController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Show the context menu of the mouse position.(Position from mouse down event)
 * 
 * @param event  mouse down event.
 */
public void showContextualMenu(MouseDownEvent event){
	final int X = event.getRelativeX(widgetPanel.getElement());
	final int Y = event.getRelativeY(widgetPanel.getElement());
	getMousePoint().setLeft(X);
	getMousePoint().setTop(Y);

	final int offsetX = event.getClientX();
	final int offsetY = event.getClientY();
	mouseOffsetPoint.setLeft(offsetX);
	mouseOffsetPoint.setTop(offsetY);

	cmenu.hide();
	cmenu = new ContextMenu();
	Command command = new Command() {
		@Override
		public void execute() {
			cmenu.hide();
		}
	};
}
 
Example 3
Source Project: EasyML   Source File: Leaf.java    License: Apache License 2.0 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 4
@Override
public void onMouseDown(MouseDownEvent event) {
	debug("VComboBoxMultiselect.onMouseDown(): blocking mouseDown event to avoid blur");

	event.preventDefault();
	event.stopPropagation();

	/*
	 * In IE the above wont work, the blur event will still trigger. So, we
	 * set a flag here to prevent the next blur event from happening. This
	 * is not needed if do not already have focus, in that case there will
	 * not be any blur event and we should not cancel the next blur.
	 */
	if (BrowserInfo.get()
		.isIE() && this.focused) {
		this.preventNextBlurEventInIE = true;
		debug("VComboBoxMultiselect: Going to prevent next blur event on IE");
	}
}
 
Example 5
Source Project: cuba   Source File: VLayoutDragDropMouseHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Start listening to events
 */
private void attach() {
    if (handlers.isEmpty()) {
        if (attachTarget == null) {
            handlers.add(
                    root.addDomHandler(this, MouseDownEvent.getType()));
            handlers.add(
                    root.addDomHandler(this, TouchStartEvent.getType()));
        } else {
            handlers.add(attachTarget.addDomHandler(this,
                    MouseDownEvent.getType()));
            handlers.add(attachTarget.addDomHandler(this,
                    TouchStartEvent.getType()));
        }
    }
}
 
Example 6
@Override
public void onMouseDown(MouseDownEvent event) {
	debug("VComboBoxMultiselect.onMouseDown(): blocking mouseDown event to avoid blur");

	event.preventDefault();
	event.stopPropagation();

	/*
	 * In IE the above wont work, the blur event will still trigger. So, we
	 * set a flag here to prevent the next blur event from happening. This
	 * is not needed if do not already have focus, in that case there will
	 * not be any blur event and we should not cancel the next blur.
	 */
	if (BrowserInfo.get()
		.isIE() && this.focused) {
		this.preventNextBlurEventInIE = true;
		debug("VComboBoxMultiselect: Going to prevent next blur event on IE");
	}
}
 
Example 7
Source Project: unitime   Source File: RoomSharingWidget.java    License: Apache License 2.0 6 votes vote down vote up
Cell(int day, int slot) {
	super("cell", "item", isEditable(day, slot) ? "clickable" : null);
	iDay = day; iSlot = slot;
	RoomSharingOption option = iModel.getOption(day, slot);
	if (option == null) {
		getElement().getStyle().clearBackgroundColor();
		setHTML("");
		setTitle("");
	} else {
		getElement().getStyle().setBackgroundColor(option.getColor());
		setHTML(option.getCode() == null ? "" : option.getCode());
		setTitle(CONSTANTS.longDays()[day] + " " + slot2short(slot) + " - " + slot2short(slot + iMode.getStep()) + ": " + option.getName());
	}
	if (isEditable(day, slot))
		addMouseDownHandler(new MouseDownHandler() {
			@Override
			public void onMouseDown(MouseDownEvent event) {
				setOption(iOption);
			}
		});
}
 
Example 8
Source Project: unitime   Source File: PeriodPreferencesWidget.java    License: Apache License 2.0 6 votes vote down vote up
Cell(int day, int slot, Date date, PeriodInterface period) {
	super("cell", "item", isEditable() && period != null ? "clickable" : null, period == null ? "disabled" : null, period != null && iModel.isAssigned(period) ? "highlight" : null);
	iDay = day;
	iSlot = slot;
	iDate = date;
	iPeriod = period;
	if (period != null) {
		PreferenceInterface preference = iModel.getPreference(day, slot);
		if (preference == null) {
			getElement().getStyle().clearBackgroundColor();
			setHTML("");
			setTitle("");
		} else {
			getElement().getStyle().setBackgroundColor(preference.getColor());
			setTitle(DateTimeFormat.getFormat(CONSTANTS.examPeriodDateFormat()).format(date) + " " + slot2short(slot) + (period == null ? "" : " - " + slot2short(slot + period.getLength())) + ": " + preference.getName());
		}
		if (isEditable())
			addMouseDownHandler(new MouseDownHandler() {
				@Override
				public void onMouseDown(MouseDownEvent event) {
					setOption(iPreference);
				}
			});				
	}
}
 
Example 9
Source Project: unitime   Source File: PeriodPreferencesWidget.java    License: Apache License 2.0 6 votes vote down vote up
private D(int day, int slot, Date date, PeriodInterface period) {
	super("cell", "day", isEditable() && period != null ? "clickable" : null, period == null ? "unavailable" : null);
	iDay = day;
	iSlot = slot;
	iDate = date;
	iPeriod = period;
	setText(DateTimeFormat.getFormat("d").format(date));
	if (period != null) {
		PreferenceInterface preference = iModel.getPreference(day, slot);
		if (preference == null) {
			getElement().getStyle().clearBackgroundColor();
			setTitle("");
		} else {
			getElement().getStyle().setBackgroundColor(preference.getColor());
			setTitle(DateTimeFormat.getFormat(CONSTANTS.examPeriodDateFormat()).format(date) + " " + slot2short(slot) + (period == null ? "" : " - " + slot2short(slot + period.getLength())) + ": " + preference.getName());
		}
		if (isEditable())
			addMouseDownHandler(new MouseDownHandler() {
				@Override
				public void onMouseDown(MouseDownEvent event) {
					setOption(iPreference);
				}
			});				
	}
}
 
Example 10
@Override
public void onMouseDown(MouseDownEvent event) {
	this.onMouseUp(null);

	Icon dragIcon = (Icon) event.getSource();
	this.selectedRow = (TableRow<T>) dragIcon.getParent().getParent();
	this.body = (TableEditorBody<T>) this.selectedRow.getParent();

	this.overRegistration = new HandlerRegistrationCollection();
	this.upRegistration = RootPanel.get().addDomHandler(this, MouseUpEvent.getType());
	this.rows = Lists.newArrayList(this.body.getRows());
	for (TableRow<T> row : this.rows) {
		this.overRegistration.add(row.addDomHandler(this, MouseOverEvent.getType()));
	}
	TableOrder.this.disableTextSelection(true);
	RootPanel.get().getElement().getStyle().setCursor(Style.Cursor.MOVE);
	StyleUtils.addStyle(this.selectedRow, TableOrder.STYLE_ROW_DRAGING);
}
 
Example 11
Source Project: gantt   Source File: GanttWidget.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    GWT.log("onMouseDown(MouseDownEvent)");
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        GanttWidget.this.onTouchOrMouseDown(event.getNativeEvent());
    } else {
        secondaryClickOnNextMouseUp = true;
        new Timer() {

            @Override
            public void run() {
                secondaryClickOnNextMouseUp = false;
            }
        }.schedule(CLICK_INTERVAL);
        event.stopPropagation();
    }
}
 
Example 12
Source Project: gantt   Source File: SvgArrowWidget.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setUpEventHandlers(boolean touchSupported,
        boolean msTouchSupported) {
    this.touchSupported = touchSupported;
    this.msTouchSupported = msTouchSupported;
    if (msTouchSupported) {
        addDomHandler(pointerDownHandler, PointerDownEvent.getType());
        addDomHandler(pointerUpHandler, PointerUpEvent.getType());
    } else if (touchSupported) {
        addDomHandler(touchStartHandler, TouchStartEvent.getType());
    } else {
        addHandler(mouseDownHandler, MouseDownEvent.getType());
    }
    registerMouseDownAndTouchDownEventListener(startingPoint);
    registerMouseDownAndTouchDownEventListener(endingPoint);
}
 
Example 13
Source Project: calendar-component   Source File: DateCell.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttach() {
    super.onAttach();

    handlers.add(addHandler(this, MouseDownEvent.getType()));
    handlers.add(addHandler(this, MouseUpEvent.getType()));
    handlers.add(addHandler(this, MouseMoveEvent.getType()));
    handlers.add(addDomHandler(this, ContextMenuEvent.getType()));
    handlers.add(addKeyDownHandler(this));
}
 
Example 14
Source Project: calendar-component   Source File: DateCell.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        Element e = Element.as(event.getNativeEvent().getEventTarget());
        if (e.getClassName().contains("reserved") || isDisabled()
                || !weekgrid.getParentCalendar().isRangeSelectAllowed()) {
            eventRangeStart = -1;
        } else {
            eventRangeStart = event.getY();
            eventRangeStop = eventRangeStart;
            Event.setCapture(getElement());
            setFocus(true);
        }
    }
}
 
Example 15
Source Project: appinventor-extensions   Source File: SimplePaletteItem.java    License: Apache License 2.0 5 votes vote down vote up
private void addHandlers() {
  addMouseDownHandler(new MouseDownHandler() {
    @Override
    public void onMouseDown(MouseDownEvent arg0) {
      select(getWidget());
    }
  });
  addTouchStartHandler(new TouchStartHandler() {
    @Override
    public void onTouchStart(TouchStartEvent event) {
      select(getWidget());
    }
  });
}
 
Example 16
Source Project: cuba   Source File: VLayoutDragDropMouseHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if (isElementNode(nativeEvent) && isChildOfRoot(nativeEvent)) {
        if (startDragOnMove) {
            initiateDragOnMove(event.getNativeEvent());
        } else {
            initiateDrag(event.getNativeEvent());
        }
    }
}
 
Example 17
Source Project: gwt-material   Source File: MaterialTabTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testDynamicTab() {
    // given
    MaterialTab tab = getWidget();

    // when / then
    // This will dynamically add new Tab Item
    MaterialTabItem item = newTabItem(tab, row, 1);

    boolean[] selectionEventFired = new boolean[]{false};
    tab.addSelectionHandler(selectionEvent -> selectionEventFired[0] = true);

    // This will trigger the selection event of the tab once tab item fired MouseDownEvent
    item.fireEvent(new GwtEvent<MouseDownHandler>() {
        @Override
        public Type<MouseDownHandler> getAssociatedType() {
            return MouseDownEvent.getType();
        }

        @Override
        protected void dispatch(MouseDownHandler eventHandler) {
            eventHandler.onMouseDown(null);
        }
    });

    // Expected : true
    assertTrue(selectionEventFired[0]);
}
 
Example 18
Source Project: unitime   Source File: TravelTimes.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEDOWN:
    	MouseDownEvent.fireNativeEvent(event, this);
    	event.stopPropagation();
    	event.preventDefault();
    	break;
	}
}
 
Example 19
Source Project: unitime   Source File: IntervalSelector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEDOWN:
    	MouseDownEvent.fireNativeEvent(event, this);
    	event.stopPropagation();
    	event.preventDefault();
    	break;
	}
}
 
Example 20
Source Project: unitime   Source File: TimeGrid.java    License: Apache License 2.0 5 votes vote down vote up
public SelectionPanel(boolean fixed) {
	setStyleName(fixed ? "selection" : "active-selection");
	if (fixed) {
		iRemove = new P("x"); iRemove.setHTML("&times;");
		iRemove.addMouseDownHandler(new MouseDownHandler() {
			@Override
			public void onMouseDown(MouseDownEvent event) {
				iSelections.remove(SelectionPanel.this);
				if (iSelection != null)
					iAllSelections.remove(iSelection);
			}
		});
		if (iRTL) {
			iRemove.getElement().getStyle().setLeft(2, Unit.PX);
		} else {
			iRemove.getElement().getStyle().setRight(2, Unit.PX);
		}
		iRemove.getElement().getStyle().setTop(2, Unit.PX);
		iRemove.getElement().getStyle().setPosition(Position.ABSOLUTE);
		add(iRemove);
		iText = new P("text");
		add(iText, 0, 0);
	}
	
	sinkEvents(Event.ONMOUSEDOWN);
	sinkEvents(Event.ONMOUSEUP);
	sinkEvents(Event.ONMOUSEMOVE);
}
 
Example 21
Source Project: unitime   Source File: SingleDateSelector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEDOWN:
    	MouseDownEvent.fireNativeEvent(event, this);
    	event.stopPropagation();
    	event.preventDefault();
    	break;
	}
}
 
Example 22
Source Project: unitime   Source File: SingleDateSelector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEDOWN:
    	MouseDownEvent.fireNativeEvent(event, this);
    	event.stopPropagation();
    	event.preventDefault();
    	break;
	}
}
 
Example 23
Source Project: djvu-html5   Source File: PanListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
public PanListener(Widget widget) {
	this.widget = widget;
	widget.addDomHandler(this, MouseDownEvent.getType());
	widget.addDomHandler(this, MouseUpEvent.getType());
	widget.addDomHandler(this, MouseMoveEvent.getType());
	widget.addDomHandler(this, TouchStartEvent.getType());
	widget.addDomHandler(this, TouchEndEvent.getType());
	widget.addDomHandler(this, TouchMoveEvent.getType());
}
 
Example 24
Source Project: djvu-html5   Source File: PanListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
	int button = event.getNativeButton();
	if ((button == NativeEvent.BUTTON_LEFT || button == NativeEvent.BUTTON_MIDDLE) && touchId == null) {
		isMouseDown = true;
		x = event.getX();
		y = event.getY();
		event.preventDefault();
		Event.setCapture(widget.getElement());
	}
}
 
Example 25
Source Project: swellrt   Source File: FocusFrameController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMouseDown(MouseDownEvent event, Element source) {
  if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
    return false;
  }
  focus.focusWithoutScroll(panel.asBlip(source));
  // Cancel bubbling, so that other blips do not grab focus.
  return true;
}
 
Example 26
Source Project: swellrt   Source File: MenuController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMouseDown(MouseDownEvent event, Element context) {
  if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
    return false;
  }
  BlipMenuItemView item = panel.asBlipMenuItem(context);
  switch (item.getOption()) {
    case EDIT:
      actions.startEditing(item.getParent().getParent());
      break;
    case EDIT_DONE:
      actions.stopEditing();
      break;
    case REPLY:
      actions.reply(item.getParent().getParent());
      break;
    case DELETE:
      // We delete the blip without confirmation if shift key is pressed
      if (event.getNativeEvent().getShiftKey() || Window.confirm(messages.confirmDeletion())) {
        actions.delete(item.getParent().getParent());
      }
      break;
    case LINK:
      actions.popupLink(item.getParent().getParent());
      break;
    default:
      throw new AssertionError();
  }
  event.preventDefault();
  return true;
}
 
Example 27
Source Project: swellrt   Source File: CollapseController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMouseDown(MouseDownEvent event, Element source) {
  if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
    return false;
  }
  handleClick(panel.fromToggle(source));
  return false;
}
 
Example 28
TDHandle() {
	super(TableCellElement.TAG_TD);
	this.dragIcon = new Icon();
	this.dragIcon.setType(IconFont.ICON_DRAG);
	this.dragIcon.addDomHandler(TableOrder.this.mouseHandler, MouseDownEvent.getType());
	this.dragIcon.addDomHandler(TableOrder.this.mouseHandler, ClickEvent.getType());
	this.append(this.dragIcon);
}
 
Example 29
Source Project: gantt   Source File: SvgArrowWidget.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        GWT.log("Starting point Clicked!");

        handleDownEvent(event.getNativeEvent());
    }
}
 
Example 30
@Override
public boolean onMouseDown(MouseDownEvent event, Element source) {
  if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
    return false;
  }
  focus.focusWithoutScroll(panel.asBlip(source));
  // Cancel bubbling, so that other blips do not grab focus.
  return true;
}