com.google.gwt.user.client.Event Java Examples

The following examples show how to use com.google.gwt.user.client.Event. 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
Source File: ExtendedFlexTable.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example #2
Source File: DataStore.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
private CanvasElement prepareMissingTileImage() {
	int tileSize = DjvuContext.getTileSize();
	CanvasElement canvas = createImage(tileSize, tileSize);
	Context2d context2d = canvas.getContext2d();
	context2d.setFillStyle("white");
	context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
	Image image = new Image();
	final ImageElement imageElement = image.getElement().cast();
	imageElement.getStyle().setProperty("visibility", "hidden");
	Event.setEventListener(imageElement, event -> {
		if (Event.ONLOAD == event.getTypeInt()) {
			missingTileImage.getContext2d().drawImage(imageElement, 0, 0);
			RootPanel.get().getElement().removeChild(imageElement);
		}
	});
	RootPanel.get().getElement().appendChild(imageElement);
	image.setUrl(getBlankImageUrl());
	return canvas;
}
 
Example #3
Source File: CellBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBrowserEvent2(Event event) {
  super.onBrowserEvent2(event);

  // Handle keyboard navigation between lists.
  String eventType = event.getType();
  if (BrowserEvents.KEYDOWN.equals(eventType) && !isKeyboardNavigationSuppressed()) {
    int keyCode = event.getKeyCode();
    boolean isRtl = LocaleInfo.getCurrentLocale().isRTL();
    keyCode = KeyCodes.maybeSwapArrowKeysForRtl(keyCode, isRtl);
    switch (keyCode) {
      case KeyCodes.KEY_LEFT:
        keyboardNavigateShallow();
        return;
      case KeyCodes.KEY_RIGHT:
        keyboardNavigateDeep();
        return;
    }
  }
}
 
Example #4
Source File: TargetPerspectiveEditorView.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
private void addItem(UnorderedList unorderedList, String name, boolean selected, Command onSelect) {
    AnchorElement anchor = Document.get().createAnchorElement();
    anchor.setInnerText(name);

    LIElement li = Document.get().createLIElement();
    li.getStyle().setCursor(Style.Cursor.POINTER);
    li.appendChild(anchor);
    li.setClassName(selected ? "selected" : "");
    unorderedList.appendChild((Node) li);

    Event.sinkEvents(anchor, Event.ONCLICK);
    Event.setEventListener(anchor, event -> {
        if(Event.ONCLICK == event.getTypeInt()) {
            onSelect.execute();
        }
    });
}
 
Example #5
Source File: MockComponent.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the components widget representation and initializes its properties.
 *
 * <p>To be called from implementing constructor.
 *
 * @param widget  components visual representation in designer
 */
void initComponent(Widget widget) {
  // Widget needs to be initialized before the component itself so that the component properties
  // can be reflected by the widget
  initWidget(widget);

  // Capture mouse and click events in onBrowserEvent(Event)
  sinkEvents(Event.MOUSEEVENTS | Event.ONCLICK | Event.TOUCHEVENTS);

  // Add the special name property and set the tooltip
  String name = componentName();
  setTitle(name);
  addProperty(PROPERTY_NAME_NAME, name, null, new TextPropertyEditor());

  // TODO(user): Ensure this value is unique within the project using a list of
  // already used UUIDs
  // Set the component's UUID
  // The default value here can be anything except 0, because YoungAndroidProjectServce
  // creates forms with an initial Uuid of 0, and Properties.java doesn't encode
  // default values when it generates JSON for a component.
  addProperty(PROPERTY_NAME_UUID, "-1", null, new TextPropertyEditor());
  changeProperty(PROPERTY_NAME_UUID, "" + Random.nextInt());

  editor.getComponentPalettePanel().configureComponent(this);
}
 
Example #6
Source File: PerspectivesExplorerView.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
@Override
public void addPerspective(String name, Command onClicked) {
    AnchorElement anchor = Document.get().createAnchorElement();
    anchor.getStyle().setCursor(Style.Cursor.POINTER);
    anchor.getStyle().setColor("black");
    anchor.getStyle().setProperty("fontSize", "larger");
    anchor.setInnerText(name);

    Event.sinkEvents(anchor, Event.ONCLICK);
    Event.setEventListener(anchor, event -> {
        if(Event.ONCLICK == event.getTypeInt()) {
            onClicked.execute();
        }
    });

    SpanElement icon = Document.get().createSpanElement();
    icon.getStyle().setMarginRight(10, Style.Unit.PX);
    icon.setClassName("pficon-virtual-machine");
    icon.getStyle().setProperty("fontSize", "larger");

    DivElement gi = createItemDiv(new Element[] {icon, anchor});
    perspectivesDiv.appendChild((Node) gi);
}
 
Example #7
Source File: ExtendedFlexTable.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method originally copied from HTMLTable superclass where it was defined private
 * Now implemented differently to only return target cell if it'spart of 'this' table
 */
private Element getMouseEventTargetCell(Event event) {
	Element td = DOM.eventGetTarget(event);
	//locate enclosing td element
	while (!DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
		// If we run out of elements, or run into the table itself, then give up.
		if ((td == null) || td == getElement())
			return null;
		td = DOM.getParent(td);
	}
	//test if the td is actually from this table
	Element tr = DOM.getParent(td);
	Element body = DOM.getParent(tr);
	if (body == this.getBodyElement()) {
		return td;
	}
	//Didn't find appropriate cell
	return null;
}
 
Example #8
Source File: InputSelect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	if (DOM.eventGetType(event) == Event.ONKEYDOWN) {
		switch (event.getKeyCode()) {
			case KeyCodes.KEY_TAB:
			case KeyCodes.KEY_ESCAPE:
				this.getDropdown().close();
				break;
			default:
				break;
		}
	}
	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #9
Source File: ForumScrollTable.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ForumScrollTable
 */
public ForumScrollTable(FixedWidthGrid dataTable, FixedWidthFlexTable headerTable,
                        ScrollTableImages scrollTableImages, ForumController controller) {
	super(dataTable, headerTable, scrollTableImages);
	this.dataTable = dataTable;
	this.controller = controller;

	setResizePolicy(ResizePolicy.UNCONSTRAINED);
	setScrollPolicy(ScrollPolicy.BOTH);
	dataTable.setSelectionEnabled(false); // Disables selection

	dataTable.setColumnSorter(new ExtendedColumnSorter());

	// Sets some events
	DOM.sinkEvents(getDataWrapper(), Event.ONDBLCLICK | Event.ONMOUSEDOWN);
}
 
Example #10
Source File: KeyBindingRegistryIntegrationGwtTest.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that new keybindings are used after changing them in the editor.
 */
public void testReregistrationKeyBinding() {
  KeyBindingRegistry bindings = new KeyBindingRegistry();
  callTracker = 0;
  EditorAction testAction = new EditorAction() {
    public void execute(EditorContext context) {
      callTracker++;
    }
  };
  bindings.registerAction(KeyCombo.ORDER_G, testAction);

  EditorImpl editor = createEditor(bindings);
  Event rawEvent = Document.get().createKeyPressEvent(
      true, false, false, false, G_CODE, G_CODE).cast();
  editor.onJavaScriptEvent("keypress", rawEvent);
  // callTracker should be 1 assuming the test above passes

  bindings.removeAction(KeyCombo.ORDER_G);
  initEditor(editor, Editor.ROOT_REGISTRIES, bindings);
  editor.onJavaScriptEvent("keypress", rawEvent);
  assertEquals("Callback action called on deregistered keypress", callTracker, 1);
}
 
Example #11
Source File: InputSlider.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void endConstruct() {
	this.getElement().appendChild(this.backgroundBar);
	StyleUtils.addStyle(this.backgroundBar, InputSlider.STYLE_BACKGROUNG);
	this.contentPanel.setWidget(this.handleWidget);

	this.popover.add(this.handleWidget);
	this.popover.setTrigger(Trigger.FOCUS);

	this.handleWidget.addKeyDownHandler(this.keyHandler);

	this.addValueChangeHandler(this);

	this.sinkEvents(Event.MOUSEEVENTS | Event.ONMOUSEWHEEL | Event.TOUCHEVENTS);

	super.endConstruct();
}
 
Example #12
Source File: TableEmptyState.java    From cuba with Apache License 2.0 6 votes vote down vote up
public TableEmptyState() {
    container = Document.get().createDivElement();
    container.setClassName("c-table-empty-state");

    messageBox = Document.get().createDivElement();
    messageBox.setClassName("c-table-empty-state-message-box");

    messageLabel = Document.get().createDivElement();
    messageLabel.setClassName("c-table-empty-state-message");

    linkMessageLabel = Document.get().createSpanElement();
    linkMessageLabel.setClassName("c-table-empty-state-link-message v-button-link");

    container.appendChild(messageBox);

    Event.sinkEvents(container, Event.ONCLICK);
    Event.setEventListener(container, this);
}
 
Example #13
Source File: CellContainerToDomMapper.java    From jetpad-projectional-open-source with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDetach() {
  super.onDetach();

  enablePopup(getTarget());
  getSource().resetContainerPeer();
  getTarget().removeClassName(CSS.rootContainer());

  myContent.removeFromParent();
  myLineHighlight1.removeFromParent();
  myLineHighlight2.removeFromParent();

  $(getTarget()).unbind(Event.KEYEVENTS | Event.MOUSEEVENTS);

  myWindowReg.removeHandler();
}
 
Example #14
Source File: InputBoolean.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean eventTargetsLabelOrChild(DomEvent<?> event) {
	Event nativeEvent = Event.as(event.getNativeEvent());
	EventTarget target = nativeEvent.getEventTarget();
	if (Element.is(target)) {
		return this.labelElement.isOrHasChild(Element.as(target));
	}
	return false;
}
 
Example #15
Source File: OffPageSelector.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example #16
Source File: AriaToggleButton.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	if (event.getTypeInt() == Event.ONKEYUP && event.getKeyCode() == KeyCodes.KEY_SPACE) {
		onClick();
	}
	if (event.getTypeInt() == Event.ONCLICK) {
		setValue(!getValue());
	}
	super.onBrowserEvent(event);
}
 
Example #17
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 */
public VComboBoxMultiselect() {
	this.tb = createTextBox();
	this.suggestionPopup = createSuggestionPopup();

	this.popupOpener.addMouseDownHandler(VComboBoxMultiselect.this);
	Roles.getButtonRole()
		.setAriaHiddenState(this.popupOpener.getElement(), true);
	Roles.getButtonRole()
		.set(this.popupOpener.getElement());

	this.panel.add(this.tb);
	this.panel.add(this.popupOpener);
	initWidget(this.panel);
	Roles.getComboboxRole()
		.set(this.panel.getElement());

	this.tb.addKeyDownHandler(this);
	this.tb.addKeyUpHandler(this);

	this.tb.addFocusHandler(this);
	this.tb.addBlurHandler(this);

	this.panel.addDomHandler(this, ClickEvent.getType());

	setStyleName(CLASSNAME);

	sinkEvents(Event.ONPASTE);
}
 
Example #18
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);

	if (event.getTypeInt() == Event.ONPASTE) {
		if (this.textInputEnabled) {
			filterOptions(this.currentPage);
		}
	}
}
 
Example #19
Source File: CubaScrollTableWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    final int type = DOM.eventGetType(event);
    if (type == Event.ONKEYDOWN && _delegate.shortcutHandler != null) {
        _delegate.shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example #20
Source File: CubaSourceCodeEditorWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    int type = DOM.eventGetType(event);
    if (type == Event.ONKEYDOWN
            && event.getKeyCode() == KeyCodes.KEY_ENTER
            && !event.getAltKey()
            && !event.getShiftKey()
            && !event.getCtrlKey()) {
        event.stopPropagation();
        return;
    }

    super.onBrowserEvent(event);
}
 
Example #21
Source File: DesktopUniversalPopup.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
  super.onBrowserEvent(event);

  // We don't want anything outside the popup to receive events
  event.stopPropagation();
}
 
Example #22
Source File: CubaDateFieldWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    final int type = DOM.eventGetType(event);

    if (type == Event.ONKEYDOWN && shortcutHandler != null) {
        shortcutHandler.handleKeyboardEvent(event);
    }
}
 
Example #23
Source File: DefaultPopup.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (Event.ONKEYDOWN == event.getTypeInt()) {
        if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
            // Dismiss when escape is pressed
            hide();
        }
    }
}
 
Example #24
Source File: FocusManager.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void dispatch(KeyEvent<?> event) {
     if (checkStatDialogCondition(event)) {
       StatDialog.show();
     } else {
Timer timer = null;
       if (Timing.isEnabled()) {
         Timing.enterScope();
         Timing.setScopeValue(ExecutionTree.class, new ExecutionTree());
         timer = Timing.start("Key event dispatch");
       }
       try {
         // Only respond to key events on the body element. Otherwise, the key
         // event was probably targeted to some editable input element, and that
         // should own the events.
         NativeEvent realEvent = event.getNativeEvent();
         Element target = realEvent.getEventTarget().cast();
         if (!"body".equals(target.getTagName().toLowerCase())) {
           return;
         }
         // Test that the event is meaningful (and stop bubbling if it is not).
         SignalEvent signal = SignalEventImpl.create(realEvent.<Event>cast(), true);
         if (signal != null) {
           KeyCombo key = EventWrapper.getKeyCombo(signal);
           if (globalHandler.onKeySignal(key)) {
             event.preventDefault();
           }
         }
       } finally {
         Timing.stop(timer);
         Timing.exitScope();
       }
     }
   }
 
Example #25
Source File: TextButton.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setUiListener(MouseListener mouseListener) {
  sinkEvents(Event.MOUSEEVENTS);
  sinkEvents(Event.ONCLICK);

  this.mouseListener = mouseListener;
}
 
Example #26
Source File: SingleDateSelector.java    From unitime with 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 #27
Source File: AbstractInputSelect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	switch (DOM.eventGetType(event)) {
		case Event.ONKEYDOWN:
			switch (event.getKeyCode()) {
				case KeyCodes.KEY_HOME:
					this.selectionHandler.onHomeKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_END:
					this.selectionHandler.onEndKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_UP:
					this.selectionHandler.onUpKeyDown();
					mustKillEvent = true;
					break;
				case KeyCodes.KEY_DOWN:
					this.selectionHandler.onDownKeyDown();
					mustKillEvent = true;
					break;
				default:
					break;
			}
			break;
		case Event.ONKEYPRESS:
			this.keyPressHandler.handleKeyPress(event.getCharCode());
			break;
		default:
			break;
	}

	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example #28
Source File: UniTimeTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public TableEvent(Event sourceEvent, int row, int col, Element tr, Element td, T data) {
	iRow = row;
	iCol = col;
	iTR = tr;
	iTD = td;
	iData = data;
	iSourceEvent = sourceEvent;
}
 
Example #29
Source File: MobileUniversalPopup.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
  if (event.getTypeInt() == Event.ONCLICK && event.getTarget() == shadow) {
    hideCommand.execute();
  } else {
    super.onBrowserEvent(event);
  }
}
 
Example #30
Source File: StudentSchedule.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void checkAccessKeys(NativePreviewEvent event) {
	if (event.getTypeInt() == Event.ONKEYUP && (event.getNativeEvent().getAltKey() || event.getNativeEvent().getCtrlKey())) {
		for (Map.Entry<Character, Integer> entry: iTabAccessKeys.entrySet())
			if (event.getNativeEvent().getKeyCode() == Character.toLowerCase(entry.getKey()) || event.getNativeEvent().getKeyCode()  == Character.toUpperCase(entry.getKey())) {
				iTabs.selectTab(entry.getValue());
			}
	}
}