List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler
FocusHandler
From source file:asquare.gwt.tests.buttonblur.client.Demo.java
License:Apache License
private Widget createDemoPanel() { Button result = new Button("gwtButton"); result.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { Debug.println("gwtButton.onFocus()"); }/*from w w w . j ava 2s. co m*/ }); result.addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { Debug.println("gwtButton.onLostFocus()"); } }); return result; }
From source file:cc.kune.gspace.client.share.ShareToOthersPanel.java
License:Open Source License
@Inject public ShareToOthersPanel(final I18nUITranslationService i18n, final ShareToOthersDropController dropController) { this.dropController = dropController; final FlowPanel flow = new FlowPanel(); flow.addStyleName("k-share-others"); multivalueSBox = SearchBoxFactory.create(i18n, false, true, SEARCH_TEXTBOX_ID, new OnEntitySelectedInSearch() { @Override//from w w w .ja v a 2 s. c om public void onSeleted(final String shortName) { if (addListener != null) { addListener.onAdd(shortName); } } }); final SuggestBox suggestBox = multivalueSBox.getSuggestBox(); final ValueBoxBase<String> searchTextBox = suggestBox.getValueBox(); final Label suggestBoxIntro = new Label(I18n.t("drag and drop to add people or")); final Label suggestTextWhenEmpty = new Label(I18n.t("search to add")); flow.add(suggestBoxIntro); flow.add(multivalueSBox); flow.add(suggestTextWhenEmpty); multivalueSBox.addStyleName("k-share-searchbox"); suggestTextWhenEmpty.addStyleName("k-share-searchbox-text"); suggestTextWhenEmpty.addStyleName("k-clean"); initWidget(flow); // Search box settings suggestTextWhenEmpty.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { suggestBox.setFocus(true); } }); searchTextBox.addFocusHandler(new FocusHandler() { @Override public void onFocus(final FocusEvent event) { // searchLabel.setVisible(false); suggestTextWhenEmpty.getElement().getStyle().setVisibility(Visibility.HIDDEN); } }); searchTextBox.addBlurHandler(new BlurHandler() { @Override public void onBlur(final BlurEvent event) { if (searchTextBox.getValue().isEmpty()) { suggestTextWhenEmpty.getElement().getStyle().setVisibility(Visibility.VISIBLE); } } }); // Tooltips Tooltip.to(suggestBox, I18n.t(NOT_LIST_TOOLTIP)); Tooltip.to(suggestTextWhenEmpty, I18n.t(NOT_LIST_TOOLTIP)); Tooltip.to(suggestBoxIntro, I18n.t(NOT_LIST_TOOLTIP)); // D&D dropController.init(flow); }
From source file:ch.unifr.pai.twice.layout.client.mobile.MobileInterface.java
License:Apache License
/** * Initializes the main components/*w w w .j ava 2 s. c o m*/ */ public MobileInterface() { RESOURCES.mobileLayoutStyle().ensureInjected(); controlbar.setStyleName("controlbar"); others.setStyleName(RESOURCES.mobileLayoutStyle().menuButton()); others.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { menu.show(); } }); others.getElement().getStyle().setDisplay(Display.INLINE); others.setWidth("auto"); others.getElement().getStyle().setFloat(Float.LEFT); keyboardPanel.getElement().getStyle().setFloat(Float.RIGHT); keyboardButton.addStyleName("mobileKeyboard"); hideKeyboard.addStyleName("mobileKeyboard"); keyboardPanel.add(hideKeyboard); keyboardPanel.add(keyboardButton); // hideKeyboard.setWidth("50px"); // hideKeyboard.setHeight("100%"); // keyboardButton.setWidth("50px"); // keyboardButton.setHeight("50px"); // keyboardPanel.setWidgetPosition(hideKeyboard, 0, 0); // keyboardPanel.setWidgetPosition(keyboardButton, 0, 0); hideKeyboard.getElement().getStyle().setDisplay(Display.NONE); keyboardButton.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { hideKeyboard.getElement().getStyle().setDisplay(Display.BLOCK); keyboardButton.getElement().getStyle().setDisplay(Display.NONE); } }); keyboardButton.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { hideKeyboard.getElement().getStyle().setDisplay(Display.NONE); keyboardButton.setValue(null); keyboardButton.getElement().getStyle().setDisplay(Display.BLOCK); } }); hideKeyboard.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { hideKeyboard.getElement().getStyle().setDisplay(Display.NONE); keyboardButton.setValue(null); keyboardButton.getElement().getStyle().setDisplay(Display.BLOCK); } }); controlbar.add(others); controlbar.add(keyboardPanel); }
From source file:ch.unifr.pai.twice.mousecontrol.client.MobileKeyboard.java
License:Apache License
/** * The mobile keyboard widget/* www . j ava2 s . c om*/ * * @param openKeyboardText * - the text for the open keyboard button * @param closeKeyboardText * - the text for the close keyboard button */ public MobileKeyboard(String openKeyboardText, String closeKeyboardText) { super(); // Prevent IPhone and IPad to write everything in upper case getElement().setAttribute("autocapitalize", "off"); setWidth("100%"); setHeight("100%"); getElement().getStyle().setFontSize(200, Unit.PCT); setAlignment(TextAlignment.CENTER); getElement().getStyle().setVerticalAlign(VerticalAlign.TOP); addFocusHandler(new FocusHandler() { /** * If the text box gets focus, add the handler * * @see com.google.gwt.event.dom.client.FocusHandler#onFocus(com.google.gwt.event.dom.client.FocusEvent) */ @Override public void onFocus(FocusEvent event) { getElement().getStyle().setZIndex(-1); registration = Event.addNativePreviewHandler(handler); // Scheduler.get().scheduleDeferred(new ScheduledCommand() { // // @Override // public void execute() { // Window.scrollTo(0, 1); // Document.get().setScrollTop(0); // RootLayoutPanel.get().onResize(); // } // }); } }); addBlurHandler(new BlurHandler() { /** * If the text box looses focus, hide the keyboard * * @see com.google.gwt.event.dom.client.BlurHandler#onBlur(com.google.gwt.event.dom.client.BlurEvent) */ @Override public void onBlur(BlurEvent event) { hide(); } }); setValue(openKeyboardText); getElement().getStyle().setZIndex(2); }
From source file:ch.unifr.pai.twice.widgets.client.MyNewTextBox.java
License:Apache License
public MyNewTextBox(ServerPushEventBus eventBus, String source) { this.eventBus = eventBus; this.source = source; l2.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); l2.getElement().getStyle().setBorderWidth(1, Unit.PX); l2.getElement().getStyle().setWidth(100, Unit.PCT); measurement.getElement().getStyle().setVisibility(Visibility.HIDDEN); cursor.setHeight("15px"); cursor.getElement().getStyle().setBackgroundColor("black"); // cursor.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); cursor.setWidth("1px"); cursorBlink = new Timer() { @Override//ww w . java2s .c o m public void run() { if (cursor.getElement().getStyle().getVisibility().equals(Visibility.VISIBLE.getCssName())) { cursor.getElement().getStyle().setVisibility(Visibility.HIDDEN); } else { cursor.getElement().getStyle().setVisibility(Visibility.VISIBLE); } } }; cursor.getElement().getStyle().setVisibility(Visibility.HIDDEN); this.setWidth("100px"); this.setHeight("120px"); this.add(measurement, 0, 0); this.add(cursor, 0, 0); this.add(l2, 0, 0); this.add(t, 0, 0); this.interpreter = new RemoteTextInputInterpreter(new Command() { @Override public void execute() { measurement.setText(interpreter.getValue().substring(0, interpreter.getThisCursorPos())); t.setText(interpreter.getValue()); l2.setText(interpreter.getValue()); MyNewTextBox.this.setWidgetPosition(cursor, measurement.getOffsetWidth(), measurement.getOffsetHeight() - 15); } }, eventBus, source); t.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { previewRegistration = Event.addNativePreviewHandler(previewHandler); t.getElement().getStyle().setVisibility(Visibility.HIDDEN); cursorBlink.scheduleRepeating(600); } }); t.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { if (previewRegistration != null) { previewRegistration.removeHandler(); previewRegistration = null; } t.getElement().getStyle().setVisibility(Visibility.VISIBLE); cursor.getElement().getStyle().setVisibility(Visibility.HIDDEN); cursorBlink.cancel(); } }); }
From source file:ch.unifr.pai.twice.widgets.client.RemoteKeyRecorder.java
License:Apache License
/** * Define a static, unique identifier for this text box. This is needed for * the linkage between the different clients. Make sure that this value is * not composed dynamically - the best is a usage of a simple string not * coming from any other method.//from w w w .ja va2 s . co m * * @param uniqueIdentifier */ public RemoteKeyRecorder(String uniqueIdentifier, ServerPushEventBus eventBus) { super(); this.uniqueIdentifier = uniqueIdentifier; this.eventBus = eventBus; addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { keyRegistration = Event.addNativePreviewHandler(new NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { switch (event.getTypeInt()) { case Event.ONKEYUP: switch (event.getNativeEvent().getKeyCode()) { case KeyCodes.KEY_DELETE: case KeyCodes.KEY_BACKSPACE: send(event.getNativeEvent().getKeyCode(), null, null); break; case KeyCodes.KEY_LEFT: send(null, null, -1); break; case KeyCodes.KEY_RIGHT: send(null, null, 1); } event.cancel(); break; case Event.ONKEYPRESS: send(null, String.valueOf((char) event.getNativeEvent().getCharCode()), null); event.cancel(); break; } } }); } }); addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { if (keyRegistration != null) keyRegistration.removeHandler(); keyRegistration = null; } }); }
From source file:com.agnie.gwt.common.client.widget.LabelPasswordBox.java
License:Open Source License
public LabelPasswordBox(String label) { super.setLabel(label); /*// ww w .j a va 2s .c om * NOTE: Below code to detect firefox browser and make use of focus event to change type of input field to * password. Is a temporary fix, ideal way to handle the browser specific handling is to make use of deferred * binding. The issue is when we make use of key press handler to change the type first key is not getting * recognised on firefox because of some reason. And if we think of using focus handler for all browsers. Focus * handler fails to convert it to password box on chrome. */ String userAgent = Navigator.getUserAgent(); if (userAgent.contains("Firefox")) { super.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent arg0) { changeTypeToPass(); removeStyle(); } }); } else { super.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (!passwordmode) { Scheduler.get().scheduleDeferred(new Command() { public void execute() { changeTypeToPass(); removeStyle(); } }); passwordmode = true; } } }); } super.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent arg0) { String value = getValue(); if (value.isEmpty()) { changeTypeToText(); addStyle(); passwordmode = false; } else { changeTypeToPass(); removeStyle(); } } }); }
From source file:com.akanoo.client.views.CanvasView.java
License:Apache License
@Inject public CanvasView(final Binder binder, Resources resources, Languages messages) { this.resources = resources; resources.canvasStyle().ensureInjected(); this.messages = messages; representations = new ArrayList<CanvasView.NoteRepresentation>(); widget = binder.createAndBindUi(this); scrollPanel.addAttachHandler(new AttachEvent.Handler() { @Override/* ww w . j a v a 2 s.co m*/ public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { updateCanvasSize(); } } }); Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { updateCanvasSize(); } }); // create drag controller dragController = new PickupDragController(boundaryPanel, true); dragController.setBehaviorDragStartSensitivity(resources.canvasStyle().pixelSensitivity()); dragController.setBehaviorBoundaryPanelDrop(false); dragController.addDragHandler(new DragHandlerAdapter() { @Override public void onDragStart(DragStartEvent event) { Widget note = event.getContext().draggable; startPosition = new Point(canvas.getWidgetLeft(note), canvas.getWidgetTop(note)); GWT.log("Starting at: " + startPosition); ignoreClick = true; } }); dropController = new AbsolutePositionDropController(canvas) { @Override public void onDrop(DragContext context) { super.onDrop(context); final Widget notePanel = context.draggable; Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { Point newPosition = new Point(canvas.getWidgetLeft(notePanel), canvas.getWidgetTop(notePanel)); if (!newPosition.equals(startPosition)) { GWT.log("Now got: " + newPosition); Note note = findByNotePanel(notePanel).note; getUiHandlers().moveNote(note, newPosition); } ignoreClick = false; } }); } }; dragController.registerDropController(dropController); canvasFocus.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { GWT.log("Canvas focussed!"); } }); canvasFocus.addMouseDownHandler(new MouseDownHandler() { @Override public void onMouseDown(MouseDownEvent event) { GWT.log("Canvas mouse down!"); if (editing) ignoreNext = true; } }); canvasFocus.addTouchStartHandler(new TouchStartHandler() { @Override public void onTouchStart(TouchStartEvent event) { GWT.log("Canvas touch down!"); if (editing) ignoreNext = true; } }); canvasFocus.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { canvasClick(event); } }); }
From source file:com.alkacon.acacia.client.ui.AttributeValueView.java
License:Open Source License
/** * Sets the value widget.<p>// w w w . j a v a2 s. c o m * * @param widget the widget * @param value the value * @param defaultValue the default attribute value * @param active <code>true</code> if the widget should be activated */ public void setValueWidget(I_FormEditWidget widget, String value, String defaultValue, boolean active) { if (m_hasValue) { throw new RuntimeException("Value has already been set"); } m_defaultValue = defaultValue; m_hasValue = true; m_isSimpleValue = true; m_widget = widget; if (AttributeHandler.hasResizeHandler() && (m_widget instanceof HasResizeHandlers)) { ((HasResizeHandlers) m_widget).addResizeHandler(AttributeHandler.getResizeHandler()); } m_widgetHolder.clear(); m_widget.setWidgetInfo(m_label, m_help); if (active) { m_widget.setValue(value, false); } else { m_widget.setValue("", false); } m_widgetHolder.add(m_widget); m_widget.setName(getHandler().getAttributeName()); m_widget.addValueChangeHandler(new ChangeHandler()); m_widget.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { ValueFocusHandler.getInstance().setFocus(AttributeValueView.this); activateWidget(); } }); m_widget.setActive(active); if (!active) { addActivationHandler(); } else { removeStyleName(formCss().emptyValue()); } addStyleName(formCss().simpleValue()); }
From source file:com.alkacon.opencms.v8.calendar.client.input.CmsSerialDate.java
License:Open Source License
/** * Private function to set all the end selections.<p> * *///from w ww . ja v a 2 s . com private void setLowPanel() { FlexTable table = new FlexTable(); table.insertRow(0); FlowPanel cell1 = new FlowPanel(); Label startDate = new Label(m_labels.get("GUI_SERIALDATE_TIME_STARTDATE_0").isString().stringValue()); startDate.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDateLable()); cell1.add(startDate); cell1.getElement().getStyle().setWidth(100, Unit.PCT); cell1.add(m_dateboxbegin); m_dateboxbegin.setDateOnly(true); m_dateboxbegin.getElement().getStyle().setWidth(108, Unit.PX); m_dateboxbegin.getElement().getStyle().setFloat(Float.RIGHT); m_dateboxbegin.addValueChangeHandler(new ValueChangeHandler<Date>() { public void onValueChange(ValueChangeEvent<Date> event) { fireValueChange(); } }); table.setWidget(0, 0, cell1); table.getCellFormatter().getElement(0, 0).getStyle().setWidth(185, Unit.PX); table.getCellFormatter().getElement(0, 0).getStyle().setVerticalAlign(VerticalAlign.TOP); FlowPanel cell2 = new FlowPanel(); CmsRadioButton sel1 = new CmsRadioButton("1", m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_NEVER_0").isString().stringValue()); m_lowRadioButton[0] = sel1; sel1.setGroup(m_groupDuration); sel1.setChecked(true); sel1.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanelSelection()); sel1.addStyleName( org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().radioButtonlabel()); sel1.getElement().getStyle().setMarginLeft(13, Unit.PX); sel1.getElement().getStyle().setMarginTop(0, Unit.PX); sel1.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { fireValueChange(); } }); CmsRadioButton sel2 = new CmsRadioButton("2", m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_OCC_0").isString().stringValue()); m_lowRadioButton[1] = sel2; sel2.setGroup(m_groupDuration); sel2.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanelSelection()); sel2.addStyleName( org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().radioButtonlabel()); sel2.getElement().setAttribute("style", "clear:left"); sel2.getElement().getStyle().setMarginLeft(13, Unit.PX); sel2.getElement().getStyle().setMarginTop(6, Unit.PX); sel2.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (m_times.getText().isEmpty()) { m_times.setValue("1"); } fireValueChange(); } }); CmsRadioButton sel3 = new CmsRadioButton("3", m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_DATE_0").isString().stringValue()); m_lowRadioButton[2] = sel3; sel3.setGroup(m_groupDuration); sel3.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanelSelection()); sel3.addStyleName( org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().radioButtonlabel()); sel3.getElement().setAttribute("style", "clear:left"); sel3.getElement().getStyle().setMarginLeft(13, Unit.PX); sel3.getElement().getStyle().setMarginTop(6, Unit.PX); sel3.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { m_dateboxend.setValue(new Date()); fireValueChange(); } }); cell2.add(sel1); cell2.add(sel2); m_times.setStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().textBoxSerialDate()); m_times.getElement().getStyle().setMarginTop(5, Unit.PX); m_times.getElement().getStyle().setWidth(82, Unit.PX); cell2.add(m_times); m_times.addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { fireValueChange(); } }); m_times.addValueChangeHandler(new ValueChangeHandler<String>() { public void onValueChange(ValueChangeEvent<String> event) { fireValueChange(); } }); m_times.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { selectEnding(1); } }); Label times = new Label( m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_OCC_TIMES_0").isString().stringValue()); times.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDateLable()); times.getElement().getStyle().setMarginTop(7, Unit.PX); times.getElement().getStyle().setMarginLeft(2, Unit.PX); cell2.add(times); cell2.add(sel3); cell2.add(m_dateboxend); m_dateboxend.setDateOnly(true); m_dateboxend.getElement().getStyle().setWidth(90, Unit.PX); m_dateboxend.getElement().getStyle().setMarginTop(5, Unit.PX); m_dateboxend.getElement().getStyle().setMarginLeft(22, Unit.PX); m_dateboxend.addValueChangeHandler(new ValueChangeHandler<Date>() { public void onValueChange(ValueChangeEvent<Date> event) { fireValueChange(); } }); m_dateboxend.addDomHandler(new ClickHandler() { public void onClick(ClickEvent event) { selectEnding(2); } }, ClickEvent.getType()); table.setWidget(0, 1, cell2); m_lowPanel.add(table); m_lowPanel.setStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanel()); }