コード例 #1
0
 public void setFocus(boolean focused) {
   if (focused) {
     focusImpl.focus(getElement());
   } else {
     focusImpl.blur(getElement());
   }
 }
コード例 #2
0
ファイル: IconAnchor.java プロジェクト: schollD/gwt-bootstrap
 @Override
 public void setFocus(boolean focused) {
   if (focused) {
     impl.focus(getElement());
   } else {
     impl.blur(getElement());
   }
 }
コード例 #3
0
 public int getTabIndex() {
   return focusImpl.getTabIndex(getElement());
 }
コード例 #4
0
/**
 * @author Thiago da Rosa de Bustamante
 *     <p>- EXPERIMENTAL - THIS CLASS IS NOT READY TO BE USED IN PRODUCTION. IT CAN CHANGE FOR NEXT
 *     RELEASES
 */
@Experimental
public class SelectableFlowPanel extends SelectableWidget
    implements HasAllFocusHandlers,
        IndexedPanel.ForIsWidget,
        InsertPanel.ForIsWidget,
        HasEnabled,
        Focusable {
  private static final String DEFAULT_STYLE_NAME = "faces-SelectableFlowPanel";
  private static FocusImpl focusImpl = FocusImpl.getFocusImplForPanel();
  private InternalFlowPanel panel;

  public SelectableFlowPanel() {
    this(new InternalFlowPanel());
  }

  public SelectableFlowPanel(SelectHandler buttonSelectHandler) {
    this();
    addSelectHandler(buttonSelectHandler);
  }

  protected SelectableFlowPanel(InternalFlowPanel panel) {
    this.panel = panel;
    makeFocusable(panel.getElement());
    initWidget(this.panel);
    setStyleName(DEFAULT_STYLE_NAME);
  }

  public void add(IsWidget w) {
    panel.add(w);
  }

  @Override
  public void add(Widget w) {
    panel.add(w);
  }

  @Override
  public HandlerRegistration addBlurHandler(BlurHandler handler) {
    return addDomHandler(handler, BlurEvent.getType());
  }

  @Override
  public HandlerRegistration addFocusHandler(FocusHandler handler) {
    return addDomHandler(handler, FocusEvent.getType());
  }

  public int getTabIndex() {
    return focusImpl.getTabIndex(getElement());
  }

  @Override
  public Widget getWidget(int index) {
    return panel.getWidget(index);
  }

  @Override
  public int getWidgetCount() {
    return panel.getWidgetCount();
  }

  @Override
  public int getWidgetIndex(IsWidget child) {
    return panel.getWidgetIndex(child);
  }

  @Override
  public int getWidgetIndex(Widget child) {
    return panel.getWidgetIndex(child);
  }

  @Override
  public void insert(IsWidget w, int beforeIndex) {
    panel.insert(w, beforeIndex);
  }

  @Override
  public void insert(Widget w, int beforeIndex) {
    panel.insert(w, beforeIndex);
  }

  @Override
  public boolean isEnabled() {
    return getSelectEventsHandler().isEnabled();
  }

  @Override
  public boolean remove(int index) {
    return panel.remove(index);
  }

  public boolean remove(IsWidget w) {
    return panel.remove(w);
  }

  public void select() {
    setFocus(true);
    super.select();
  }

  public void setAccessKey(char key) {
    focusImpl.setAccessKey(getElement(), key);
  }

  @Override
  public void setEnabled(boolean enabled) {
    getSelectEventsHandler().setEnabled(enabled);
    if (enabled) {
      removeStyleDependentName("disabled");
    } else {
      addStyleDependentName("disabled");
    }
  }

  public void setFocus(boolean focused) {
    if (focused) {
      focusImpl.focus(getElement());
    } else {
      focusImpl.blur(getElement());
    }
  }

  public void setTabIndex(int index) {
    focusImpl.setTabIndex(getElement(), index);
  }

  /** @return */
  protected WidgetCollection getChildren() {
    return panel.getChildren();
  }

  protected void makeFocusable(Element e) {
    e.setTabIndex(0);
  }

  private static class InternalFlowPanel extends FlowPanel {
    @Override
    protected WidgetCollection getChildren() {
      return super.getChildren();
    }
  }
}
コード例 #5
0
 public void setTabIndex(int index) {
   focusImpl.setTabIndex(getElement(), index);
 }
コード例 #6
0
 public void setAccessKey(char key) {
   focusImpl.setAccessKey(getElement(), key);
 }
コード例 #7
0
ファイル: IconAnchor.java プロジェクト: schollD/gwt-bootstrap
/**
 * An Anchor with optional image and caret.
 *
 * <p>It uses a HTML {@code <a>} tag and can contain text and child widgets. But not both at the
 * same time.
 *
 * <p>
 *
 * <h3>UiBinder Usage:</h3>
 *
 * {@code <b:IconAnchor icon="plane" href="www.twitter.com">Some Text</b:IconAnchor>}
 *
 * <p>Here we add a second Icon:
 *
 * <pre>
 * {@code <b:IconAnchor icon="STAR" text="There is a widget so the text goes here">
 *     <b:Icon type="STAR" />
 * </b:IconAnchor>}
 * </pre>
 *
 * All parameter are optional. All setters can be used as parameters.
 *
 * @since 2.0.4.0
 * @author Dominik Mayer
 * @author ohashi keisuke
 */
public class IconAnchor extends ComplexWidget
    implements HasText,
        HasIcon,
        HasHref,
        HasClickHandlers,
        HasEnabled,
        Focusable,
        HasName,
        HasMouseDownHandlers {

  private static final FocusImpl impl = FocusImpl.getFocusImplForWidget();

  protected Icon icon = new Icon();

  private TextNode text = new TextNode("");

  private Caret caret = new Caret();

  private IconPosition iconPosition;

  /**
   * Creates the widget and sets the {@code href} property to {@code javascript:;} in order to avoid
   * problems when clicking on it.
   */
  public IconAnchor() {
    super("a");
    setIconPosition(IconPosition.LEFT);
    setEmptyHref();
  }

  /** {@inheritDoc} */
  @Override
  public void setIconPosition(IconPosition position) {

    this.iconPosition = position;
    icon.removeFromParent();
    text.removeFromParent();

    if (IconPosition.RIGHT == position) {
      this.insert(text, 0);
      this.insert(icon, 1);
      return;

    } else if (IconPosition.LEFT == position) {
      this.insert(icon, 0);
      this.insert(text, 1);
      return;
    }
  }

  /** {@inheritDoc} */
  @Override
  public void setIcon(IconType type) {
    setBaseIcon(type);
  }

  /** {@inheritDoc} */
  @Override
  public void setBaseIcon(BaseIconType type) {
    this.icon.setBaseType(type);
  }

  /** {@inheritDoc} */
  @Override
  public void setIconSize(IconSize size) {
    icon.setIconSize(size);
  }

  /** {@inheritDoc} */
  public void setText(String text) {
    this.text.removeFromParent();
    this.text = new TextNode(" " + text + " ");
    setIconPosition(iconPosition);
  }

  /** {@inheritDoc} */
  public String getText() {
    return text.getText();
  }

  /** {@inheritDoc} */
  public void setHref(String href) {
    getElement().setAttribute("href", href);
  }

  /** {@inheritDoc} */
  public String getHref() {
    return getElement().getAttribute("href");
  }

  /**
   * Shows or hides the caret.
   *
   * @param visible <code>true</code> if the caret should be shown.
   */
  public void setCaret(boolean visible) {
    if (visible) super.add(caret);
    else super.remove(caret);
  }

  /** {@inheritDoc} */
  public void setTargetHistoryToken(String targetHistoryToken) {
    setHref("#" + targetHistoryToken);
  }

  /** {@inheritDoc} */
  public String getTargetHistoryToken() {
    String[] hrefs = getHref().split("#");
    return hrefs[1];
  }

  /**
   * Sets the <code>href</code>property of this element to "javascript:;" in order to get another
   * cursor (hand).
   */
  public void setEmptyHref() {
    setHref(Constants.EMPTY_HREF);
  }

  /** {@inheritDoc} */
  @Override
  public HandlerRegistration addClickHandler(ClickHandler handler) {
    return addDomHandler(handler, ClickEvent.getType());
  }

  /** {@inheritDoc} */
  @Override
  public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
    return addDomHandler(handler, MouseDownEvent.getType());
  }

  /** {@inheritDoc} */
  @Override
  public boolean isEnabled() {
    return !DOM.getElementPropertyBoolean(getElement(), "disabled");
  }

  /** {@inheritDoc} */
  @Override
  public void setEnabled(boolean enabled) {
    DOM.setElementPropertyBoolean(getElement(), "disabled", !enabled);
  }

  /** {@inheritDoc} */
  @Override
  public void onBrowserEvent(Event event) {
    switch (DOM.eventGetType(event)) {
      case Event.ONCLICK:
        if (isEnabled()) {
          super.onBrowserEvent(event);
        }
        break;
      default:
        super.onBrowserEvent(event);
        break;
    }
  }

  @Override
  public int getTabIndex() {
    return impl.getTabIndex(getElement());
  }

  @Override
  public void setAccessKey(char key) {
    DOM.setElementProperty(getElement(), "accessKey", "" + key);
  }

  @Override
  public void setFocus(boolean focused) {
    if (focused) {
      impl.focus(getElement());
    } else {
      impl.blur(getElement());
    }
  }

  @Override
  public void setTabIndex(int index) {
    impl.setTabIndex(getElement(), index);
  }

  @Override
  protected void onAttach() {
    super.onAttach();

    // Accessibility: setting tab index to be 0 by default, ensuring element
    // appears in tab sequence. We must ensure that the element doesn't already
    // have a tabIndex set. This is not a problem for normal widgets, but when
    // a widget is used to wrap an existing static element, it can already have
    // a tabIndex.
    int tabIndex = getTabIndex();
    if (-1 == tabIndex) {
      setTabIndex(0);
    }
  }

  /**
   * Set active style name.
   *
   * @param active <code>true</code> : set active <code>false</code> : unset active
   */
  public void setActive(boolean active) {
    setStyleName(Constants.ACTIVE, active);
  }

  /**
   * Has the active css style name?
   *
   * @return <code>true</code>: has <code>false</code> : none.
   */
  public boolean isActive() {
    return getStyleName().contains(Constants.ACTIVE);
  }

  /** {@inheritDoc} */
  @Override
  public void setName(String name) {
    getAnchorElement().setName(name);
  }

  /** {@inheritDoc} */
  @Override
  public String getName() {
    return getAnchorElement().getName();
  }

  /**
   * Set target attribute
   *
   * @param target target name
   */
  public void setTarget(String target) {
    getAnchorElement().setTarget(target);
  }

  /**
   * Get target attribute value
   *
   * @return target attribute value
   */
  public String getTarget() {
    return getAnchorElement().getTarget();
  }

  protected AnchorElement getAnchorElement() {
    return AnchorElement.as(getElement());
  }

  /** {@inheritDoc} */
  @Override
  public void setCustomIconStyle(String customIconStyle) {
    icon.addStyleName(customIconStyle);
  }
}
コード例 #8
0
ファイル: IconAnchor.java プロジェクト: schollD/gwt-bootstrap
 @Override
 public void setTabIndex(int index) {
   impl.setTabIndex(getElement(), index);
 }
コード例 #9
0
ファイル: IconAnchor.java プロジェクト: schollD/gwt-bootstrap
 @Override
 public int getTabIndex() {
   return impl.getTabIndex(getElement());
 }