コード例 #1
0
ファイル: TabMenu.java プロジェクト: papperwing/perun
  /**
   * Return defined button with own click handler
   *
   * @param type selected button type
   * @param title text displayed on button hover
   * @param clickAction ClickHandler / if null it's not added
   * @return create button
   */
  public static CustomButton getPredefinedButton(
      ButtonType type, String title, ClickHandler clickAction) {

    CustomButton b = new CustomButton();

    // icon first
    b.setIcon(getButtonIconByType(type));
    // then text

    b.setText(getButtonTextByType(type));

    if (title != null && !title.isEmpty()) {
      b.setTitle(title);
    }

    if (clickAction != null) {
      b.addClickHandler(clickAction);
    }

    if (ButtonType.CONTINUE.equals(type)) {
      b.setImageAlign(true);
    }

    return b;
  }
コード例 #2
0
ファイル: FastButton.java プロジェクト: geogebra/geogebra
  @Override
  public void onBrowserEvent(Event event) {

    if (!this.isEnabled()) {
      event.stopPropagation();
      return;
    }
    switch (DOM.eventGetType(event)) {
      case Event.ONTOUCHSTART:
        {
          onTouchStart(event);
          event.stopPropagation();
          break;
        }
      case Event.ONTOUCHEND:
        {
          onTouchEnd(event);
          event.stopPropagation();
          break;
        }
      case Event.ONTOUCHMOVE:
        {
          onTouchMove(event);
          event.stopPropagation();
          break;
        }
      case Event.ONMOUSEUP:
        {
          Log.debug("touch up");
          // because Event.ONCLICK always came twice on desktop browsers oO
          onClick(event);
          event.stopPropagation();
          break;
        }
      case Event.ONMOUSEDOWN:
        {
          event.stopPropagation();
          break;
        }
      default:
        {
          // Let parent handle event if not one of the above (?)
          try {
            super.onBrowserEvent(event);
          } catch (Throwable t) {
            Log.debug(DOM.eventGetType(event) + "event failed");
          }
        }
    }
  }
コード例 #3
0
ファイル: FastButton.java プロジェクト: geogebra/geogebra
  private void onClick(Event event) {
    event.stopPropagation();
    event.preventDefault();

    if (touchHandled) {
      // if the touch is already handled, we are on a device that supports
      // touch (so you aren't in the desktop browser)

      touchHandled = false; // reset for next press
      clickHandled = true; // ignore future ClickEvents
    } else if (!clickHandled) {
      // Press not handled yet
      fireFastClickEvent();
    }

    super.onBrowserEvent(event);
  }
コード例 #4
0
ファイル: TabMenu.java プロジェクト: papperwing/perun
  /**
   * Add search widget to tab menu
   *
   * @param searchEvent event triggered when user click on search button
   * @param title displayed on button hover
   * @return ExtendedTextBox textbox widget
   */
  public ExtendedTextBox addSearchWidget(final PerunSearchEvent searchEvent, final String title) {

    final ExtendedTextBox textBox = new ExtendedTextBox();

    final CustomButton button = getPredefinedButton(ButtonType.SEARCH, title);

    // trigger search on ENTER
    textBox
        .getTextBox()
        .addKeyUpHandler(
            new KeyUpHandler() {
              public void onKeyUp(KeyUpEvent event) {
                if (!textBox.getTextBox().getText().trim().isEmpty()) {
                  button.setEnabled(true);
                  if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                    searchEvent.searchFor(textBox.getTextBox().getText().trim());
                  }
                } else {
                  button.setEnabled(false);
                }
              }
            });
    textBox
        .getTextBox()
        .addBlurHandler(
            new BlurHandler() {
              @Override
              public void onBlur(BlurEvent event) {
                // fake some meaningless KeyUpEvent
                DomEvent.fireNativeEvent(
                    Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN),
                    textBox.getTextBox());
              }
            });
    textBox
        .getTextBox()
        .addValueChangeHandler(
            new ValueChangeHandler<String>() {
              @Override
              public void onValueChange(ValueChangeEvent<String> event) {
                // fake some meaningless KeyUpEvent
                DomEvent.fireNativeEvent(
                    Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN),
                    textBox.getTextBox());
              }
            });

    // button click triggers action
    button.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent clickEvent) {
            if (UiElements.searchStingCantBeEmpty(textBox.getTextBox().getText().trim())) {
              searchEvent.searchFor(textBox.getTextBox().getText().trim());
            }
          }
        });

    // button is active only if there is "search string"
    button.setEnabled(false);

    this.addWidget(textBox);
    this.addWidget(button);

    // always focus search widget
    Scheduler.get()
        .scheduleDeferred(
            new Command() {
              @Override
              public void execute() {
                textBox.getTextBox().setFocus(true);
              }
            });

    return textBox;
  }