List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler
FocusHandler
From source file:org.openelis.ui.widget.CheckLabel.java
License:Open Source License
protected void init() { grid = new Grid(1, 2); grid.setCellSpacing(0);// www .ja v a 2 s . c o m grid.setBorderWidth(0); grid.setCellPadding(0); grid.setHeight("16px"); check = new Check(); check.addValueChangeHandler(new ValueChangeHandler<Boolean>() { public void onValueChange(ValueChangeEvent<Boolean> event) { if (!queryMode) { String check; if (event.getValue() == null || !event.getValue()) check = "N"; else check = "Y"; setValue(new CheckLabelValue(check, value != null ? value.getLabel() : "")); //fireValueChange(event.getValue() != null ? (event.getValue() ? "Y" : "N") : null); } } }); drawWidget(); super.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { check.setFocus(true); } }); super.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { check.setFocus(false); } }); setWidget(grid); exceptions = new Exceptions(); }
From source file:org.openelis.ui.widget.Dropdown.java
License:Open Source License
/** * Creates the display for the Dropdown and sets it as the Composite widget. * Sets all handlers for user interaction. *///from w w w. j a va 2s . c o m public void init() { initWidget(uiBinder.createAndBindUi(this)); /* * Image must be in a div instead of adding the style to cell itself to * display correctly */ // image = new AbsolutePanel(); // button.setWidget(image); /* * Set the focus style when the Focus event is fired Externally */ addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { if (isEnabled()) { display.addStyleName(css.Focus()); Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { @Override public void execute() { textbox.selectAll(); } }); } } }); /* * Removes the focus style when the Blue event is fires externally */ addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { display.removeStyleName(css.Focus()); if (!queryMode) finishEditing(); } }); keyHandler = new KeyboardHandler(); addHandler(keyHandler, KeyDownEvent.getType()); addHandler(keyHandler, KeyPressEvent.getType()); exceptions = new Exceptions(); setCSS(UIResources.INSTANCE.dropdown()); table = GWT.create(Table.class); table.addColumn(new Column.Builder(10).renderer(new SelectionCell()).build()); setPopupContext(table); setWidth("150px"); setHelper((WidgetHelper) new StringHelper()); }
From source file:org.openelis.ui.widget.EditBox.java
License:Open Source License
public void init() { display = new Grid(1, 2); display.setCellSpacing(0);/*from w ww . java 2 s. c o m*/ display.setCellPadding(0); textbox = new TextBase(); button = new Button(null, "..."); display.setWidget(0, 0, textbox); display.setWidget(0, 1, button); initWidget(display); display.setStyleName("SelectBox"); textbox.setStyleName("TextboxUnselected"); /* * Set the focus style when the Focus event is fired Externally */ addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { if (isEnabled()) { display.addStyleName("Focus"); selectAll(); } } }); /* * Removes the focus style when the Blue event is fires externally */ addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { display.removeStyleName("Focus"); unselectAll(); finishEditing(); } }); /* * Since HorizontalPanel is not a Focusable widget we need to listen to * the textbox focus and blur events and pass them through to the * handlers registered to source. */ textbox.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { FocusEvent.fireNativeEvent(event.getNativeEvent(), source); } }); textbox.addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { if (!showing && isEnabled()) BlurEvent.fireNativeEvent(event.getNativeEvent(), source); } }); button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { showPopup(); } }); button.addMouseDownHandler(new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { showing = true; } }); exceptions = new Exceptions(); }
From source file:org.openelis.ui.widget.MultiDropdown.java
License:Open Source License
/** * Default no-arg constructor// w ww . j av a 2s.c om */ public MultiDropdown() { /* * Final instance of the private class KeyboardHandler */ final KeyboardHandler keyHandler = new KeyboardHandler(); initWidget(uiBinder.createAndBindUi(this)); /* Image must be in a div instead of adding the style to cell itself to display correctly */ //image = new AbsolutePanel(); //button.setWidget(image); /* * Set the focus style when the Focus event is fired Externally */ addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { if (isEnabled()) display.addStyleName(css.Focus()); } }); /* * Removes the focus style when the Blue event is fires externally */ addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { display.removeStyleName(css.Focus()); finishEditing(); } }); /* * Registers the keyboard handling this widget */ addHandler(keyHandler, KeyDownEvent.getType()); addHandler(keyHandler, KeyPressEvent.getType()); exceptions = new Exceptions(); setCSS(UIResources.INSTANCE.dropdown()); setPopupContext(new Table.Builder(10).column(new Column.Builder(100).renderer(new SelectionCell()).build()) .build()); setHelper((WidgetHelper) new IntegerHelper()); textbox.setReadOnly(true); }
From source file:org.openelis.ui.widget.richtext.RichTextWidget.java
License:Open Source License
public void init(boolean tools) { this.tools = tools; initWidget(vp);//from w w w . j a v a 2 s. c o m DOM.setStyleAttribute(vp.getElement(), "background", "white"); vp.setSpacing(0); if (tools) { vp.add(toolbar); vp.add(area); vp.setCellWidth(toolbar, "100%"); } else { vp.add(area); } area.setSize("100%", "100%"); area.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { if (!area.isEnabled()) area.setFocus(false); } }); //Font and Font size can not be set until the area recieves focus. We set up this handler to //set the font and size that we want to default then remove the handler so we don't repeat it. focReg = area.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { area.getFormatter().setFontName("Verdana"); area.getFormatter().setFontSize(RichTextArea.FontSize.X_SMALL); focReg.removeHandler(); } }); }
From source file:org.openelis.ui.widget.table.Table.java
License:Open Source License
private void setKeyHandling() { /*//from w ww . j av a2 s.c om * This Handler takes care of all key events on the table when editing * and when only selection is on */ addDomHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { int row, col, keyCode; if (!isEnabled()) return; keyCode = event.getNativeEvent().getKeyCode(); row = editingRow; col = editingCol; if (isEditing() && getColumnAt(col).getCellEditor().ignoreKey(keyCode)) return; switch (keyCode) { case (KeyCodes.KEY_TAB): // Ignore if no cell is currently being edited if (!editing) break; // Tab backwards if shift pressed otherwise tab forward if (!event.isShiftKeyDown()) { while (true) { col++; if (col >= getColumnCount()) { col = 0; row++; if (row >= getRowCount()) { setFocus(true); break; } } if (startEditing(row, col, event.getNativeEvent())) { event.preventDefault(); event.stopPropagation(); break; } } } else { while (true) { col--; if (col < 0) { col = getColumnCount() - 1; row--; if (row < 0) { setFocus(true); break; } } if (startEditing(row, col, event.getNativeEvent())) { event.preventDefault(); event.stopPropagation(); break; } } } break; case (KeyCodes.KEY_DOWN): // If Not editing select the next row below the current // selection if (!isEditing()) { if (isAnyRowSelected()) { row = getSelectedRow(); while (true) { row++; if (row >= getRowCount()) break; selectRowAt(row, event.getNativeEvent()); if (isRowSelected(row)) break; } } break; } // If editing set focus to the same col cell in the next // selectable row below while (true) { row++; if (row >= getRowCount()) break; if (startEditing(row, col, event.getNativeEvent())) { event.stopPropagation(); event.preventDefault(); break; } } break; case (KeyCodes.KEY_UP): // If Not editing select the next row above the current // selection if (!isEditing()) { if (isAnyRowSelected()) { row = getSelectedRow(); while (true) { row--; if (row < 0) break; selectRowAt(row, event.getNativeEvent()); if (isRowSelected(row)) break; } } break; } // If editing set focus to the same col cell in the next // selectable row above while (true) { row--; if (row < 0) break; if (startEditing(row, col, event.getNativeEvent())) { event.stopPropagation(); event.preventDefault(); break; } } break; case (KeyCodes.KEY_ENTER): // If editing just finish and return if (isEditing()) { finishEditing(); return; } if (getRowCount() == 0) return; // If not editing and a row is selected, focus on first // editable cell if (!isAnyRowSelected()) row = 0; else row = getSelectedRow(); col = 0; while (col < getColumnCount()) { if (startEditing(row, col, event.getNativeEvent())) break; col++; } break; } } }, KeyDownEvent.getType()); addDomHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { //removeStyleName(UIResources.INSTANCE.text().Focus()); } }, BlurEvent.getType()); addDomHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { //addStyleName(UIResources.INSTANCE.text().Focus()); } }, FocusEvent.getType()); }
From source file:org.openxdata.designer.client.view.WidgetPropertiesView.java
/** * Sets up event listeners./*from ww w. java2 s. co m*/ */ private void setupEvents() { txtText.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateText(); } }); txtText.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateText(); } }); txtHelpText.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateHelpText(); } }); txtHelpText.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateHelpText(); } }); txtWidth.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateWidth(); } }); txtWidth.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateWidth(); } }); txtHeight.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateHeight(); } }); txtHeight.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateHeight(); } }); txtLeft.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateLeft(); } }); txtLeft.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateLeft(); } }); txtTop.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateTop(); } }); txtTop.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateTop(); } }); txtBinding.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateBinding(widget, null); } }); txtChildBinding.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (txtChildBinding.getText().trim().length() == 0) updateChildBinding(); } }); txtChildBinding.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { txtChildBinding.selectAll(); } }); txtBinding.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { txtBinding.selectAll(); } }); sgstBinding.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) { updateBinding(); } }); sgstChildBinding.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) { updateChildBinding(); } }); txtTabIndex.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateTabIndex(); } }); txtTabIndex.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateTabIndex(); } }); txtExternalSource.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateExternalSource(); } }); cbRepeat.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateIsRepeat(); } }); txtExternalSource.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateExternalSource(); } }); txtDisplayField.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateDisplayField(); } }); txtDisplayField.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateDisplayField(); } }); txtValueField.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateValueField(); } }); txtValueField.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateValueField(); } }); txtFilterField.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateFilterField(); } }); txtFilterField.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateFilterField(); } }); txtId.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { updateId(); } }); txtId.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { updateId(); } }); txtForeColor.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setForeColor(txtForeColor.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FORE_COLOR, txtForeColor.getText()); } }); sgstForeColor.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) { if (widget != null) widget.setForeColor(txtForeColor.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FORE_COLOR, txtForeColor.getText()); } }); txtBackgroundColor.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setBackgroundColor(txtBackgroundColor.getText()); else if (viewWidget != null) viewWidget.setBackgroundColor(txtBackgroundColor.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_BACKGROUND_COLOR, txtBackgroundColor.getText()); } }); sgstBackgroundColor.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) { if (widget != null) widget.setBackgroundColor(txtBackgroundColor.getText()); else if (viewWidget != null) viewWidget.setBackgroundColor(txtBackgroundColor.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_BACKGROUND_COLOR, txtBackgroundColor.getText()); } }); txtBorderColor.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setBorderColor(txtBorderColor.getText()); else if (viewWidget != null && viewWidget instanceof DesignGroupWidget) ((DesignWidgetWrapper) viewWidget.getParent().getParent()) .setBorderColor(txtBorderColor.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_BORDER_COLOR, txtBorderColor.getText()); } }); sgstBorderColor.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) { if (widget != null) widget.setBorderColor(txtBorderColor.getText()); else if (viewWidget != null && viewWidget instanceof DesignGroupWidget) ((DesignWidgetWrapper) viewWidget.getParent().getParent()) .setBorderColor(txtBorderColor.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_BORDER_COLOR, txtBorderColor.getText()); } }); txtFontSize.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setFontSize(txtFontSize.getText() + OpenXdataConstants.UNITS); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FONT_SIZE, txtFontSize.getText() + OpenXdataConstants.UNITS); } }); txtFontSize.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { if (widget != null) widget.setFontSize(txtFontSize.getText() + OpenXdataConstants.UNITS); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FONT_SIZE, txtFontSize.getText() + OpenXdataConstants.UNITS); } }); txtFontFamily.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setFontFamily(txtFontFamily.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FONT_FAMILY, txtFontFamily.getText()); } }); txtFontFamily.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { if (widget != null) widget.setFontFamily(txtFontFamily.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FONT_FAMILY, txtFontFamily.getText()); } }); txtBorderWidth.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setBorderWidth(txtBorderWidth.getText()); else if (viewWidget != null && viewWidget instanceof DesignGroupWidget) ((DesignWidgetWrapper) viewWidget.getParent().getParent()) .setBorderWidth(txtBorderWidth.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_BORDER_WIDTH, txtBorderWidth.getText()); } }); txtBorderWidth.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { if (widget != null) widget.setBorderWidth(txtBorderWidth.getText()); else if (viewWidget != null && viewWidget instanceof DesignGroupWidget) ((DesignWidgetWrapper) viewWidget.getParent().getParent()) .setBorderWidth(txtBorderWidth.getText()); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_BORDER_WIDTH, txtBorderWidth.getText()); } }); lbTextDecoration.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setTextDecoration(lbTextDecoration.getItemText(lbTextDecoration.getSelectedIndex())); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_TEXT_DECORATION, lbTextDecoration.getItemText(lbTextDecoration.getSelectedIndex())); } }); lbTextAlign.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setTextAlign(lbTextAlign.getItemText(lbTextAlign.getSelectedIndex())); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_TEXT_ALIGN, lbTextAlign.getItemText(lbTextAlign.getSelectedIndex())); } }); lbFontStyle.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setFontStyle(lbFontStyle.getItemText(lbFontStyle.getSelectedIndex())); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FONT_STYLE, lbFontStyle.getItemText(lbFontStyle.getSelectedIndex())); } }); lbFontWeight.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setFontWeight(lbFontWeight.getItemText(lbFontWeight.getSelectedIndex())); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_FONT_WEIGHT, lbFontWeight.getItemText(lbFontWeight.getSelectedIndex())); } }); lbBorderStyle.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { if (widget != null) widget.setBorderStyle(lbBorderStyle.getItemText(lbBorderStyle.getSelectedIndex())); else if (viewWidget != null && viewWidget instanceof DesignGroupWidget) ((DesignWidgetWrapper) viewWidget.getParent().getParent()) .setBorderStyle(lbBorderStyle.getItemText(lbBorderStyle.getSelectedIndex())); else widgetPropertyChangeListener.onWidgetPropertyChanged(WidgetPropertySetter.PROP_BORDER_STYLE, lbBorderStyle.getItemText(lbBorderStyle.getSelectedIndex())); } }); }
From source file:org.oscim.web.client.SearchBox.java
License:Open Source License
public SearchBox(final Map map) { final Button searchButton = new Button("Search"); final TextBox searchField = new TextBox(); //searchField.setText("Bremen"); final PathLayer mOverlay = new PathLayer(map, 0xCC0000FF); map.layers().add(mOverlay);//w w w . j a v a 2s .c o m // We can add style names to widgets searchButton.addStyleName("sendButton"); RootPanel.get("nameFieldContainer").add(searchField); RootPanel.get("sendButtonContainer").add(searchButton); // Focus the cursor on the name field when the app loads searchField.setFocus(true); searchField.selectAll(); // Create a cell to render each value in the list. PoiCell poiCell = new PoiCell(); // Create a CellList that uses the cell. final CellList<PoiData> cellList = new CellList<PoiData>(poiCell, PoiData.KEY_PROVIDER); final SingleSelectionModel<PoiData> selectionModel = new SingleSelectionModel<PoiData>( PoiData.KEY_PROVIDER); cellList.setSelectionModel(selectionModel); final ScrollPanel scroller = new ScrollPanel(cellList); RootPanel.get("listContainer").add(scroller); scroller.setSize("350px", "300px"); RootPanel.get("search").getElement().getStyle().setVisibility(Visibility.VISIBLE); scroller.setVisible(false); searchField.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { scroller.setVisible(true); } }); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { final PoiData d = selectionModel.getSelectedObject(); mOverlay.clearPath(); //log.debug("selected " + d.getName() + " " + d.getLatitude() + " " // + d.getLongitude()); BoundingBox b = d.getBoundingBox(); if (b != null) { if (b.maxLatitudeE6 - b.minLatitudeE6 < 100 && b.maxLongitudeE6 - b.minLongitudeE6 < 100) // for small bbox use zoom=16 to get an overview map.animator().animateTo(500, b.getCenterPoint(), 1 << 16, false); else map.animator().animateTo(b); if (d instanceof NominatimData && ((NominatimData) d).getWkt() != null) { String wkt = ((NominatimData) d).getWkt(); WKTReader r = new WKTReader(); GeometryBuffer g = new GeometryBuffer(1024, 10); try { r.parse(wkt, g); } catch (Exception e) { log.debug(wkt); } //FIXME mOverlay.setGeom(g); //log.debug("add polygon " + p.length()); } else { mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6); mOverlay.addPoint(b.maxLatitudeE6, b.maxLongitudeE6); mOverlay.addPoint(b.minLatitudeE6, b.maxLongitudeE6); mOverlay.addPoint(b.minLatitudeE6, b.minLongitudeE6); mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6); } // hide overlay after 5 seconds map.postDelayed(new Runnable() { @Override public void run() { mOverlay.clearPath(); } }, 5000); } else { MapPosition pos = new MapPosition(); map.viewport().setTilt(0); map.viewport().setRotation(0); pos.setZoomLevel(13); pos.setPosition(d.getLatitude(), d.getLongitude()); map.setMapPosition(pos); } scroller.setVisible(false); } }); // Create a handler for the sendButton and nameField class MyHandler implements ClickHandler, KeyUpHandler { /** * Fired when the user clicks on the sendButton. */ public void onClick(ClickEvent event) { sendRequest(); } /** * Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { sendRequest(); } } /** * Send the name from the nameField to the server and wait for a * response. */ private void sendRequest() { String textToServer = searchField.getText(); searchButton.setEnabled(false); String url = URL.encode(NOMINATIM_GLOBAL + textToServer); JsonpRequestBuilder builder = new JsonpRequestBuilder(); builder.setCallbackParam("json_callback"); builder.requestObject(url, new AsyncCallback<JsArray<NominatimData>>() { public void onFailure(Throwable caught) { log.debug("request failed"); searchButton.setEnabled(true); } public void onSuccess(JsArray<NominatimData> data) { List<PoiData> items = new ArrayList<PoiData>(); for (int i = 0, n = data.length(); i < n; i++) { NominatimData d = data.get(i); items.add(d); } cellList.setRowCount(items.size(), true); cellList.setRowData(0, items); scroller.setVisible(true); searchButton.setEnabled(true); } }); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); searchButton.addClickHandler(handler); searchField.addKeyUpHandler(handler); }
From source file:org.pepstock.jem.gwt.client.commons.SearcherHistoryTextBox.java
License:Open Source License
/** * Constructs object/*w ww . java2 s . co m*/ */ public SearcherHistoryTextBox() { addStyleName(Styles.INSTANCE.common().searcher()); textBox.setStyleName(Styles.INSTANCE.common().searcherTextBox()); // listen blur to change style, removing outline textBox.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { if (focus) { removeStyleName(Styles.INSTANCE.common().searcherFocus()); focus = false; } } }); // listen focus to change style, adding outline textBox.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { if (!focus) { addStyleName(Styles.INSTANCE.common().searcherFocus()); focus = true; } } }); setCellPadding(2); setCellSpacing(0); setWidget(0, 0, textBox); // adds HISTORY image historyImage.getElement().getStyle().setVerticalAlign(Style.VerticalAlign.MIDDLE); // activates change cursor handlers historyImage.addMouseOverHandler(new MouseOverHandler() { @Override public void onMouseOver(MouseOverEvent event) { historyImage.getElement().getStyle().setCursor(Cursor.POINTER); } }); // activates change cursor handlers historyImage.addMouseOutHandler(new MouseOutHandler() { @Override public void onMouseOut(MouseOutEvent event) { historyImage.getElement().getStyle().setCursor(Cursor.AUTO); } }); setWidget(0, 1, historyImage); historyImage.addClickHandler(new HistoryImageClickHandler()); FlexCellFormatter formatter = getFlexCellFormatter(); formatter.setWidth(0, 0, Sizes.HUNDRED_PERCENT); formatter.setWidth(0, 1, Sizes.toString(historyImage.getWidth() + 1)); formatter.setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE); }
From source file:org.rstudio.core.client.widget.FocusTracker.java
License:Open Source License
public FocusTracker(final HasAllFocusHandlers widget) { isFocused_ = false;// ww w. ja v a2 s. c o m widget.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { isFocused_ = true; } }); widget.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { isFocused_ = false; } }); }