List of usage examples for com.google.gwt.user.client.ui Label addClickHandler
public HandlerRegistration addClickHandler(ClickHandler handler)
From source file:org.waveprotocol.wave.client.widget.button.icon.IconButtonTemplate.java
License:Apache License
@UiConstructor public IconButtonTemplate() { Label label = new Label(); initWidget(label);/*from w w w . j a v a2 s . c om*/ label.addClickHandler(this); label.addMouseOverHandler(this); label.addMouseOutHandler(this); label.addMouseUpHandler(this); label.addMouseDownHandler(this); }
From source file:org.wisepersist.gwt.uploader.client.Uploader.java
License:Apache License
@Override protected void onLoad() { if (loaded) { return;//from w ww . j ava2 s.c o m } loaded = true; // Make sure our entire panel fits the size that they wanted for the button if (this.buttonWidth >= 0) { this.setWidth(this.buttonWidth + "px"); } if (this.buttonHeight >= 0) { this.setHeight(this.buttonHeight + "px"); } if (ajaxUploadEnabled && isAjaxUploadWithProgressEventsSupported()) { // If the browser supports the XMLHttpRequest Level 2 type then we can avoid rendering the // flash component and just stick with a DOM/Ajax approach. // Use a hidden file input component to handle allowing the user to popup the file system // dialog (but keep it outside of the button itself so it doesn't interfere with the mouse // events) this.add(createFileUpload()); // Create the main element that will hold all of the inner workings of the uploader component Label button = new Label(); button.setWidth("100%"); button.setHeight("100%"); if (this.buttonCursor != null) { switch (this.buttonCursor) { case ARROW: button.getElement().getStyle().setCursor(Style.Cursor.DEFAULT); break; case HAND: button.getElement().getStyle().setCursor(Style.Cursor.POINTER); break; } } // Setup what we want to happen when someone clicks anywhere on the button button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (buttonDisabled) { return; } switch (buttonAction) { case START_UPLOAD: startUpload(); break; case SELECT_FILES: openFileDialog(fileUpload, true); break; case SELECT_FILE: default: openFileDialog(fileUpload, false); break; } } }); button.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px -" + buttonHeight + "px"); } } }); button.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px"); } } }); button.addMouseDownHandler(new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px -" + (buttonHeight * 2) + "px"); } } }); button.addMouseUpHandler(new MouseUpHandler() { public void onMouseUp(MouseUpEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px"); } } }); // Depending on the way they wanted the uploader button rendered, create the appropriate // elements in the DOM that the user will click on. if (this.buttonTextStyle != null) { buttonTextStyleElement = Document.get().createStyleElement(); buttonTextStyleElement.setInnerText(this.buttonTextStyle); button.getElement().appendChild(buttonTextStyleElement); } if (this.buttonText != null) { buttonTextElement = Document.get().createDivElement(); buttonTextElement.setInnerHTML(this.buttonText); buttonTextElement.getStyle().setWidth(100, Style.Unit.PCT); buttonTextElement.getStyle().setHeight(100, Style.Unit.PCT); if (this.buttonTextLeftPadding > Integer.MIN_VALUE) { buttonTextElement.getStyle().setPaddingLeft(this.buttonTextLeftPadding, Style.Unit.PX); } if (this.buttonTextTopPadding > Integer.MIN_VALUE) { buttonTextElement.getStyle().setPaddingTop(this.buttonTextTopPadding, Style.Unit.PX); } button.getElement().appendChild(buttonTextElement); } if (this.buttonImageURL != null) { buttonImageElement = Document.get().createDivElement(); buttonImageElement.getStyle().setBackgroundImage("url(\"" + this.buttonImageURL + "\")"); if (this.buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px -" + (buttonHeight * 3) + "px"); } else { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px"); } buttonImageElement.getStyle().setWidth(100, Style.Unit.PCT); buttonImageElement.getStyle().setHeight(100, Style.Unit.PCT); button.getElement().appendChild(buttonImageElement); } // Add the entire button to the DOM this.add(button); } else { // If the browser doesn't support the XMLHttpRequest Level 2 type, then our only option is // to use the Flash/SWFUpload component. // The SWFUpload JS code completely replaces the DOM element that you give it as a target, // so we're creating an inner component that it can replace - leaving the outer component // for the caller to use as the GWT Widget that they can manage and style within the // appropriate container within their GWT application DivElement swfUploadElement = Document.get().createDivElement(); swfUploadElement.setId(Document.get().createUniqueId()); this.getElement().appendChild(swfUploadElement); JavaScriptObject nativeOptions = createNativeOptions(swfUploadElement.getId()); // Build a map that we'll use during the native creation process to setup // the necessary JSNI bridges to our Java event handlers... JSONObject eventHandlers = new JSONObject(); eventHandlers.put("swfupload_loaded_handler", JSONBoolean.getInstance(swfUploadLoadedHandler != null)); eventHandlers.put("file_dialog_start_handler", JSONBoolean.getInstance(fileDialogStartHandler != null)); eventHandlers.put("file_queued_handler", JSONBoolean.getInstance(fileQueuedHandler != null)); eventHandlers.put("file_queue_error_handler", JSONBoolean.getInstance(fileQueueErrorHandler != null)); eventHandlers.put("file_dialog_complete_handler", JSONBoolean.getInstance(fileDialogCompleteHandler != null)); eventHandlers.put("upload_start_handler", JSONBoolean.getInstance(uploadStartHandler != null)); eventHandlers.put("upload_progress_handler", JSONBoolean.getInstance(uploadProgressHandler != null)); eventHandlers.put("upload_error_handler", JSONBoolean.getInstance(uploadErrorHandler != null)); eventHandlers.put("upload_success_handler", JSONBoolean.getInstance(uploadSuccessHandler != null)); eventHandlers.put("upload_complete_handler", JSONBoolean.getInstance(uploadCompleteHandler != null)); swfUpload = nativeCreateSWFUpload(nativeOptions, eventHandlers.getJavaScriptObject()); } }
From source file:ru.ksu.niimm.cll.mocassin.frontend.viewer.client.NodeExplorer.java
License:Open Source License
public void show() { titleLabel.setText(currentNode.getName()); uriLabel.setText(currentNode.getUri()); typeLabel.setText(SegmentTypes.getLabel(currentNode.getNodeType())); if (currentNode.getNumPage() == 0) { goLink.setVisible(false);/*from w ww.j a v a 2 s. com*/ } else { goLink.setVisible(true); goLink.setText(constants.goLink() + " " + currentNode.getNumPage()); } relationTable.clear(); relationTable.setWidget(0, 0, new HTML("<b>Domain</b>")); relationTable.setWidget(0, 1, new HTML("<b>Relation</b>")); relationTable.setWidget(0, 2, new HTML("<b>Range</b>")); int i = 1; for (final RelationMetadata rel : relations) { boolean isCurrentFirst = rel.getFrom() == currentNode; Label from = null; Label to = null; if (isCurrentFirst) { from = new Label("this"); from.setStyleName("thisNodeLabel"); to = new Label(rel.getTo().getName()); to.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { dialog.hide(); App.eventBus.fireEvent(new GraphEvent(rel.getTo())); } }); to.setStyleName("viewNodeLink"); } else { to = new Label("this"); to.setStyleName("thisNodeLabel"); from = new Label(rel.getFrom().getName()); from.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { dialog.hide(); App.eventBus.fireEvent(new GraphEvent(rel.getFrom())); } }); from.setStyleName("viewNodeLink"); } relationTable.setWidget(i, 0, from); relationTable.setWidget(i, 1, new Label(rel.getType().toString())); relationTable.setWidget(i, 2, to); i++; } dialog.center(); dialog.show(); }
From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.LeftNavigationViewImpl.java
License:Apache License
@Override public void setSections(List<? extends Section> sections) { indexMap.clear();// w ww. j a v a 2s . c o m for (final Section section : sections) { Label label = new Label(section.getTitle()); label.setStyleName(style.navigationItem()); label.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { onSectionClick(section); } }); indexMap.put(section.getKey(), indexMap.size()); panel.add(label); } }
From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.widget.EditorTabBar.java
License:Apache License
public void addTabs(EditorTab... tabs) { for (final EditorTab tab : tabs) { this.tabs.add(tab); final int index = this.tabs.size() - 1; Label tabItem = new Label(tab.getTitle()); tabItem.addStyleName("app-TabItem"); tabItem.addClickHandler(new ClickHandler() { @Override/*w w w .j a v a 2 s . c o m*/ public void onClick(ClickEvent event) { selectTab(index, true); } }); panel.add(tabItem); } }
From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.widget.SelectableLabel.java
License:Apache License
public SelectableLabel(String name, T value) { this.value = value; Label label = new Label(name); checkbox = new CheckBox(); checkbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override/* w ww . ja v a2 s .co m*/ public void onValueChange(ValueChangeEvent<Boolean> event) { setSelected(event.getValue(), true); } }); label.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { checkbox.setValue(!checkbox.getValue(), true); } }); //infoIcon = new SimplePanel(); //EDITOR_RESOURCES.editorStyles().ensureInjected(); //infoIcon.addStyleName(EDITOR_RESOURCES.editorStyles().infoIconClass()); panel = new HorizontalPanel(); panel.addStyleName("app-SelectableLabel"); panel.setWidth("100%"); panel.add(checkbox); panel.add(label); //panel.add(infoIcon); panel.setCellWidth(checkbox, "25px"); //panel.setCellWidth(infoIcon, "16px"); initWidget(panel); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.MealPanel.java
License:Apache License
private void addFoodRow(UnorderedList<FlowPanel> list, final WithIndex<FoodEntry> f) { String desc = f.value.description(); FlowPanel foodRow = new FlowPanel(); foodRow.addStyleName("intake24-food"); Label foodLabel = new Label(desc); foodLabel.addStyleName("intake24-food-name"); if (!f.value.link.linkedTo.isEmpty()) foodLabel.addStyleName("intake24-linked-food-name"); foodLabel.addClickHandler(new ClickHandler() { @Override// ww w. jav a2 s . c o m public void onClick(ClickEvent event) { requestSelectionChange .call(new Selection.SelectedFood(mealIndex, f.index, SelectionMode.MANUAL_SELECTION)); } }); FlowPanel encodingComplete = new FlowPanel(); FlowPanel portionSizeComplete = new FlowPanel(); if (!f.value.isTemplate()) { foodRow.add(portionSizeComplete); foodRow.add(encodingComplete); } foodRow.add(foodLabel); if (!f.value.isRaw()) { encodingComplete.addStyleName("intake24-checkbox-checked-icon"); encodingComplete.setTitle(messages.navPanelMatchedTooltip()); } else { encodingComplete.addStyleName("intake24-checkbox-unchecked-icon"); encodingComplete.setTitle(messages.navPanelNotMatchedTooltip()); } if (f.value.isPortionSizeComplete()) { portionSizeComplete.addStyleName("intake24-checkbox-checked-icon"); portionSizeComplete.setTitle(messages.navPanelPortionSizeComplete()); } else { portionSizeComplete.addStyleName("intake24-checkbox-unchecked-icon"); portionSizeComplete.setTitle(messages.navPanelPortionSizeIncomplete()); } boolean thisFoodSelected = selection.accept(new Selection.Visitor<Boolean>() { @Override public Boolean visitMeal(Selection.SelectedMeal meal) { return false; } @Override public Boolean visitFood(Selection.SelectedFood food) { return (food.mealIndex == mealIndex) && (food.foodIndex == f.index); } @Override public Boolean visitNothing(Selection.EmptySelection selection) { return false; } }); if (thisFoodSelected) foodRow.addStyleName("intake24-selected-food"); list.addItem(foodRow); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.MealPanel.java
License:Apache License
public MealPanel(final Meal meal, final int mealIndex, final Selection selection, final Callback1<Selection> requestSelectionChange) { this.mealIndex = mealIndex; this.selection = selection; this.requestSelectionChange = requestSelectionChange; FlowPanel contents = new FlowPanel(); initWidget(contents);/* w w w . j a v a 2 s. com*/ boolean thisMealSelected = selection.accept(new Selection.Visitor<Boolean>() { @Override public Boolean visitMeal(Selection.SelectedMeal meal) { return meal.mealIndex == mealIndex; } @Override public Boolean visitFood(Selection.SelectedFood food) { return false; } @Override public Boolean visitNothing(Selection.EmptySelection selection) { return false; } }); final FlowPanel mealRow = new FlowPanel(); mealRow.addStyleName("intake24-meal"); if (thisMealSelected) mealRow.addStyleName("intake24-selected-meal"); final Label label = new Label(meal.name); label.addStyleName("intake24-meal-name"); label.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { requestSelectionChange.call(new Selection.SelectedMeal(mealIndex, SelectionMode.MANUAL_SELECTION)); } }); meal.time.accept(new SideEffectVisitor<Time>() { @Override public void visitSome(Time item) { Label timeLabel = new Label(meal.time.getOrDie().toString()); timeLabel.addStyleName("intake24-meal-time"); mealRow.add(timeLabel); } @Override public void visitNone() { final FlowPanel questionIcon = new FlowPanel(); questionIcon.addStyleName("intake24-meal-question-icon"); questionIcon.setTitle(messages.navPanelSuggestedTooltip()); mealRow.add(questionIcon); } }); mealRow.add(label); contents.add(mealRow); if (!meal.foods.isEmpty()) { UnorderedList<FlowPanel> foodList = new UnorderedList<FlowPanel>(); foodList.addStyleName("intake24-food-list"); PVector<WithIndex<FoodEntry>> withIndex = zipWithIndex(meal.foods); PVector<WithIndex<FoodEntry>> topLevel = filter(withIndex, new Function1<WithIndex<FoodEntry>, Boolean>() { @Override public Boolean apply(WithIndex<FoodEntry> argument) { return argument.value.link.linkedTo.isEmpty(); } }); for (final WithIndex<FoodEntry> f : topLevel) { addFoodRow(foodList, f); PVector<WithIndex<FoodEntry>> linkedToThis = filter(withIndex, new Function1<WithIndex<FoodEntry>, Boolean>() { @Override public Boolean apply(WithIndex<FoodEntry> argument) { return argument.value.link.linkedTo.accept(new Option.Visitor<UUID, Boolean>() { @Override public Boolean visitSome(UUID item) { return item.equals(f.value.link.id); } @Override public Boolean visitNone() { return false; } }); } }); for (final WithIndex<FoodEntry> linked : linkedToThis) { addFoodRow(foodList, linked); } } contents.add(foodList); } }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.ChoosePortionSizeMethodPrompt.java
License:Apache License
@Override public SurveyStageInterface getInterface(final Callback1<FoodOperation> onComplete, Callback1<Function1<FoodEntry, FoodEntry>> updateIntermediateState) { final FlowPanel content = new FlowPanel(); content.addStyleName("intake24-choose-portion-method-prompt"); PromptUtil.addBackLink(content);// w w w . ja v a2s . co m final HTMLPanel header = new HTMLPanel("h2", food.description()); content.add(header); FlowPanel promptPanel = WidgetFactory.createPromptPanel( SafeHtmlUtils.fromSafeConstant(messages.choosePortionMethod_promptText(food.description())), ShepherdTour.createTourButton(tour, ChoosePortionSizeMethodPrompt.class.getSimpleName())); content.add(promptPanel); ShepherdTour.makeShepherdTarget(promptPanel); final FlowPanel methodPanel = new FlowPanel(); methodPanel.getElement().setId("intake24-choose-portion-panel"); ShepherdTour.makeShepherdTarget(methodPanel); int index = 0; for (final PortionSizeMethod m : food.data.portionSizeMethods) { Image img = new Image(m.imageUrl); final int indexClosure = index; index++; ClickHandler clickHandler = new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(FoodOperation.updateEncoded(new Function1<EncodedFood, EncodedFood>() { @Override public EncodedFood apply(EncodedFood argument) { return argument.withSelectedPortionSizeMethod(indexClosure); } })); } }; img.addClickHandler(clickHandler); img.addStyleName("intake24-choose-portion-image"); FlowPanel container = new FlowPanel(); container.addStyleName("intake24-choose-portion-container"); container.add(img); Label label = new Label(SafeHtmlUtils.htmlEscape(descriptions.getString(m.description))); label.addStyleName("intake24-choose-portion-label"); label.addClickHandler(clickHandler); container.add(label); methodPanel.add(container); } content.add(methodPanel); return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, ChoosePortionSizeMethodPrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.FoodBrowser.java
License:Apache License
private Widget createFoodButton(final FoodHeader foodHeader, final int index) { String description;//w w w. j a v a 2 s.c om if (foodHeader.code.equals(SpecialData.FOOD_CODE_SANDWICH)) description = messages.foodBrowser_homemadeSandwich(); else if (foodHeader.code.equals(SpecialData.FOOD_CODE_SALAD)) description = messages.foodBrowser_homemadeSalad(); else description = foodHeader.description(); Label item = new Label(description); item.addStyleName("intake24-food-browser-food"); if (foodHeader.code.equals(SpecialData.FOOD_CODE_SANDWICH)) item.addStyleName("intake24-food-browser-sandwich-wizard"); else if (foodHeader.code.equals(SpecialData.FOOD_CODE_SALAD)) item.addStyleName("intake24-food-browser-salad-wizard"); item.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { if (foodHeader.code.equals(SpecialData.FOOD_CODE_SANDWICH) || foodHeader.code.equals(SpecialData.FOOD_CODE_SALAD)) { onSpecialFoodChosen.call(foodHeader.code); } else { FoodDataService.INSTANCE.getFoodData(locale, foodHeader.code, new MethodCallback<FoodData>() { @Override public void onFailure(Method method, Throwable exception) { contents.clear(); contents.add(WidgetFactory.createDefaultErrorMessage()); } @Override public void onSuccess(Method method, FoodData foodData) { onFoodChosen.call(foodData, index); } }); } } }); return item; }