List of usage examples for com.google.gwt.user.client.ui Label setText
public void setText(String text)
From source file:org.roda.wui.client.process.CreateDefaultJob.java
private Widget addPluginItemWidgetToWorkflowList(PluginInfo pluginInfo) { FlowPanel panel = new FlowPanel(); panel.addStyleName("plugin-list-item"); panel.getElement().setAttribute("data-id", pluginInfo.getId()); panel.addDomHandler(new ClickHandler() { @Override/*from w w w . jav a 2 s . com*/ public void onClick(ClickEvent event) { FlowPanel panel = (FlowPanel) event.getSource(); String selectedPluginId = panel.getElement().getAttribute("data-id"); for (int i = 0; i < workflowList.getWidgetCount(); i++) { Widget panelWidget = workflowList.getWidget(i); panelWidget.removeStyleName("plugin-list-item-selected"); } if (selectedPluginId != null) { CreateDefaultJob.this.selectedPlugin = lookupPlugin(selectedPluginId); panel.addStyleName("plugin-list-item-selected"); } updateWorkflowOptions(); } }, ClickEvent.getType()); FlowPanel itemImage = new FlowPanel(); itemImage.addStyleName("fa"); itemImage.addStyleName("plugin-list-item-icon"); if (pluginInfo.getCategories().isEmpty()) { itemImage.addStyleName("plugin-list-item-icon-default"); } else { itemImage.addStyleName("plugin-list-item-icon-" + pluginInfo.getCategories().get(0)); itemImage.setTitle(pluginInfo.getCategories().get(0)); } Label label = new Label(); String labelContent = messages.pluginLabelWithVersion(pluginInfo.getName(), pluginInfo.getVersion()); label.setText(labelContent); label.setTitle(labelContent); label.addStyleName("plugin-list-item-label"); panel.add(itemImage); panel.add(label); workflowList.add(panel); return panel; }
From source file:org.roda.wui.client.process.CreateSelectedJob.java
private Widget addPluginItemWidgetToWorkflowList(PluginInfo pluginInfo) { FlowPanel panel = new FlowPanel(); panel.addStyleName("plugin-list-item"); panel.getElement().setAttribute("data-id", pluginInfo.getId()); panel.addDomHandler(new ClickHandler() { @Override/*from ww w .j a v a2s. c o m*/ public void onClick(ClickEvent event) { FlowPanel panel = (FlowPanel) event.getSource(); String selectedPluginId = panel.getElement().getAttribute("data-id"); for (int i = 0; i < workflowList.getWidgetCount(); i++) { Widget panelWidget = workflowList.getWidget(i); panelWidget.removeStyleName("plugin-list-item-selected"); } if (selectedPluginId != null) { CreateSelectedJob.this.selectedPlugin = lookupPlugin(selectedPluginId); panel.addStyleName("plugin-list-item-selected"); } updateWorkflowOptions(); } }, ClickEvent.getType()); FlowPanel itemImage = new FlowPanel(); itemImage.addStyleName("fa"); itemImage.addStyleName("plugin-list-item-icon"); if (pluginInfo.getCategories().isEmpty()) { itemImage.addStyleName("plugin-list-item-icon-default"); } else { itemImage.addStyleName("plugin-list-item-icon-" + pluginInfo.getCategories().get(0)); itemImage.setTitle(pluginInfo.getCategories().get(0)); } Label label = new Label(); String labelContent = messages.pluginLabelWithVersion(pluginInfo.getName(), pluginInfo.getVersion()); label.setText(labelContent); label.setTitle(labelContent); label.addStyleName("plugin-list-item-label"); panel.add(itemImage); panel.add(label); workflowList.add(panel); return panel; }
From source file:org.rstudio.studio.client.application.ui.appended.ApplicationEndedPopupPanel.java
License:Open Source License
private ApplicationEndedPopupPanel(int mode, String description) { super(false, false); setStylePrimaryName(RESOURCES.styles().applicationEndedPopupPanel()); setGlassEnabled(true);//from w w w . j a v a 2s . co m setGlassStyleName(RESOURCES.styles().glass()); // main panel HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.setSpacing(10); // create widgets and make mode dependent customizations Image image; Label captionLabel = new Label(); captionLabel.setStylePrimaryName(RESOURCES.styles().captionLabel()); final FancyButton button = new FancyButton(); button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { reloadApplication(); } }); FocusHelper.setFocusDeferred(button); switch (mode) { case QUIT: image = new Image(RESOURCES.applicationQuit()); captionLabel.setText("R Session Ended"); button.setText("Start New Session"); break; case SUICIDE: image = new Image(RESOURCES.applicationSuicide()); captionLabel.setText("R Session Aborted"); button.setText("Start New Session"); break; case DISCONNECTED: image = new Image(RESOURCES.applicationDisconnected()); captionLabel.setText("R Session Disconnected"); button.setText("Reconnect"); break; case OFFLINE: image = new Image(RESOURCES.applicationOffline()); captionLabel.setText("RStudio Temporarily Offline"); button.setText("Reconnect"); break; default: throw new IllegalArgumentException("Unknown mode " + mode); } // add image horizontalPanel.add(image); // captions and button VerticalPanel contentPanel = new VerticalPanel(); contentPanel.setStylePrimaryName(RESOURCES.styles().contentPanel()); contentPanel.add(captionLabel); HTML descriptionLabel = new HTML(description); descriptionLabel.setStylePrimaryName(RESOURCES.styles().descriptionLabel()); contentPanel.add(descriptionLabel); contentPanel.add(button); horizontalPanel.add(contentPanel); // center the horizontal panel within the popup CenterPanel mainPanel = new CenterPanel(horizontalPanel); mainPanel.setStylePrimaryName(RESOURCES.styles().mainPanel()); setWidget(((MyUiBinder) GWT.create(MyUiBinder.class)).createAndBindUi(this)); content_.setWidget(mainPanel); }
From source file:org.rstudio.studio.client.application.ui.impl.WebApplicationHeader.java
License:Open Source License
private void initCommandsPanel(final SessionInfo sessionInfo) { // add username Label usernameLabel = new Label(); usernameLabel.setText(sessionInfo.getUserIdentity()); headerBarCommandsPanel_.add(usernameLabel); headerBarCommandsPanel_.add(createCommandSeparator()); // signout link Widget signoutLink = createCommandLink("Sign Out", new ClickHandler() { public void onClick(ClickEvent event) { eventBus_.fireEvent(new LogoutRequestedEvent()); }//from w ww. ja v a 2 s. c o m }); headerBarCommandsPanel_.add(signoutLink); }
From source file:org.rstudio.studio.client.common.shell.ShellWidget.java
License:Open Source License
public int getCharacterWidth() { // create width checker label and add it to the root panel Label widthChecker = new Label(); widthChecker.setStylePrimaryName(styles_.console()); FontSizer.applyNormalFontSize(widthChecker); RootPanel.get().add(widthChecker, -1000, -1000); // put the text into the label, measure it, and remove it String text = new String("abcdefghijklmnopqrstuvwzyz0123456789"); widthChecker.setText(text); int labelWidth = widthChecker.getOffsetWidth(); RootPanel.get().remove(widthChecker); // compute the points per character int pointsPerCharacter = labelWidth / text.length(); // compute client width int clientWidth = getElement().getClientWidth(); int offsetWidth = getOffsetWidth(); if (clientWidth == offsetWidth) { // if the two widths are the same then there are no scrollbars. // however, we know there will eventually be a scrollbar so we // should offset by an estimated amount // (is there a more accurate way to estimate this?) final int ESTIMATED_SCROLLBAR_WIDTH = 19; clientWidth -= ESTIMATED_SCROLLBAR_WIDTH; }//from www .j a v a2 s . com // compute character width (add pad so characters aren't flush to right) final int RIGHT_CHARACTER_PAD = 2; int width = (clientWidth / pointsPerCharacter) - RIGHT_CHARACTER_PAD; // enforce a minimum width final int MINIMUM_WIDTH = 30; return Math.max(width, MINIMUM_WIDTH); }
From source file:org.rstudio.studio.client.workbench.exportplot.clipboard.CopyPlotToClipboardDesktopMetafileDialog.java
License:Open Source License
public CopyPlotToClipboardDesktopMetafileDialog(ExportPlotPreviewer previewer, ExportPlotClipboard clipboard, ExportPlotOptions options, OperationWithInput<ExportPlotOptions> onClose) { super(previewer, clipboard, options, onClose); ExportPlotResources.Styles styles = ExportPlotResources.INSTANCE.styles(); Label label = new Label(); label.setStylePrimaryName(styles.copyFormatLabel()); label.setText("Copy as:"); addLeftWidget(label);// w w w .j a va 2s.c o m copyAsBitmapRadioButton_ = new RadioButton("Format", SafeHtmlUtils.fromString("Bitmap")); copyAsBitmapRadioButton_.setStylePrimaryName(styles.copyFormatBitmap()); addLeftWidget(copyAsBitmapRadioButton_); copyAsMetafileRadioButton_ = new RadioButton("Format", SafeHtmlUtils.fromString("Metafile")); copyAsMetafileRadioButton_.setStylePrimaryName(styles.copyFormatMetafile()); addLeftWidget(copyAsMetafileRadioButton_); if (options.getCopyAsMetafile()) copyAsMetafileRadioButton_.setValue(true); else copyAsBitmapRadioButton_.setValue(true); }
From source file:org.rstudio.studio.client.workbench.views.plots.ui.export.impl.CopyPlotToClipboardDesktopMetafileDialog.java
License:Open Source License
public CopyPlotToClipboardDesktopMetafileDialog(PlotsServerOperations server, ExportPlotOptions options, OperationWithInput<ExportPlotOptions> onClose) { super(server, options, onClose); ExportPlotResources.Styles styles = ExportPlotResources.INSTANCE.styles(); Label label = new Label(); label.setStylePrimaryName(styles.copyFormatLabel()); label.setText("Copy as:"); addLeftWidget(label);//from w w w . j a va2 s. c om copyAsBitmapRadioButton_ = new RadioButton("Format", SafeHtmlUtils.fromString("Bitmap")); copyAsBitmapRadioButton_.setStylePrimaryName(styles.copyFormatBitmap()); addLeftWidget(copyAsBitmapRadioButton_); copyAsMetafileRadioButton_ = new RadioButton("Format", SafeHtmlUtils.fromString("Metafile")); copyAsMetafileRadioButton_.setStylePrimaryName(styles.copyFormatMetafile()); addLeftWidget(copyAsMetafileRadioButton_); if (options.getCopyAsMetafile()) copyAsMetafileRadioButton_.setValue(true); else copyAsBitmapRadioButton_.setValue(true); }
From source file:org.rstudio.studio.client.workbench.views.plots.ui.manipulator.ManipulatorControlPicker.java
License:Open Source License
public ManipulatorControlPicker(String variable, String value, Manipulator.Picker picker, final ManipulatorChangedHandler changedHandler) { super(variable, picker, changedHandler); // get manipulator styles ManipulatorStyles styles = ManipulatorResources.INSTANCE.manipulatorStyles(); // main control HorizontalPanel panel = new HorizontalPanel(); panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); // caption/*from w w w .j av a 2 s . c o m*/ Label captionLabel = new Label(); captionLabel.setStyleName(styles.captionLabel()); captionLabel.setText(getLabel() + ":"); panel.add(captionLabel); // picker listBox_ = new ListBox(); listBox_.setVisibleItemCount(1); JsArrayString choices = picker.getChoices(); int selectedIndex = 0; for (int i = 0; i < choices.length(); i++) { String choice = choices.get(i); listBox_.addItem(choice); if (choice.equals(value)) selectedIndex = i; } listBox_.setSelectedIndex(selectedIndex); listBox_.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { ManipulatorControlPicker.this .onValueChanged(new JSONString(listBox_.getItemText(listBox_.getSelectedIndex()))); } }); panel.add(listBox_); initWidget(panel); addControlStyle(styles.picker()); }
From source file:org.rstudio.studio.client.workbench.views.plots.ui.manipulator.ManipulatorControlSlider.java
License:Open Source License
public ManipulatorControlSlider(String variable, double value, Manipulator.Slider slider, ManipulatorChangedHandler changedHandler) { super(variable, slider, changedHandler); // get manipulator styles ManipulatorStyles styles = ManipulatorResources.INSTANCE.manipulatorStyles(); // containing panel VerticalPanel panel = new VerticalPanel(); // setup caption panel and add it HorizontalPanel captionPanel = new HorizontalPanel(); Label captionLabel = new Label(); captionLabel.setStyleName(styles.captionLabel()); captionLabel.setText(getLabel() + ":"); captionPanel.add(captionLabel);/*from w w w. ja v a 2 s . co m*/ final Label valueLabel = new Label(); valueLabel.setStyleName(styles.sliderValueLabel()); captionPanel.add(valueLabel); panel.add(captionPanel); // create with range and custom formatter final double min = slider.getMin(); final double max = slider.getMax(); final double range = max - min; sliderBar_ = new SliderBar(min, max, this); // show labels only at the beginning and end sliderBar_.setNumLabels(1); // set step size (default to 1 or continuous decimal as appropriate) double step = slider.getStep(); if (step == -1) { // short range or decimals means continous decimal if (range < 2 || hasDecimals(max) || hasDecimals(min)) step = range / 250; // ~ one step per pixel else step = 1; } sliderBar_.setStepSize(step); // optional tick marks if (slider.getTicks()) { double numTicks = range / step; if (numTicks <= 25) // no more than 25 ticks sliderBar_.setNumTicks(new Double(numTicks).intValue()); else sliderBar_.setNumTicks(1); } else { // always at beginning and end sliderBar_.setNumTicks(1); } // update label on change sliderBar_.addChangeListener(new ChangeListener() { @Override public void onChange(Widget sender) { valueLabel.setText(formatLabel(sliderBar_, sliderBar_.getCurrentValue())); } }); sliderBar_.setCurrentValue(value); // fire changed even on slide completed sliderBar_.addSlideCompletedListener(new ChangeListener() { @Override public void onChange(Widget sender) { ManipulatorControlSlider.this.onValueChanged(new JSONNumber(sliderBar_.getCurrentValue())); } }); // add slider bar and fully initialize widget panel.add(sliderBar_); initWidget(panel); addControlStyle(styles.slider()); }
From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ImagePreviewer.java
License:Open Source License
private static void onPreviewImageLineWidget(final DocDisplay display, final DocUpdateSentinel sentinel, final String href, final String attributes, final Position position, final Range tokenRange) { // if we already have a line widget for this row, bail LineWidget lineWidget = display.getLineWidgetForRow(position.getRow()); if (lineWidget != null) return;//from w w w . j a va 2s .c o m // shared mutable state that we hide in this closure final Mutable<PinnedLineWidget> plw = new Mutable<PinnedLineWidget>(); final Mutable<ChunkOutputWidget> cow = new Mutable<ChunkOutputWidget>(); final Mutable<HandlerRegistration> docChangedHandler = new Mutable<HandlerRegistration>(); final Mutable<HandlerRegistration> renderHandler = new Mutable<HandlerRegistration>(); // command that ensures state is cleaned up when widget hidden final Command onDetach = new Command() { private void detach() { // detach chunk output widget cow.set(null); // detach pinned line widget if (plw.get() != null) plw.get().detach(); plw.set(null); // detach render handler if (renderHandler.get() != null) renderHandler.get().removeHandler(); renderHandler.set(null); // detach doc changed handler if (docChangedHandler.get() != null) docChangedHandler.get().removeHandler(); docChangedHandler.set(null); } @Override public void execute() { // if the associated chunk output widget has been cleaned up, // make a last-ditch detach effort anyhow ChunkOutputWidget widget = cow.get(); if (widget == null) { detach(); return; } // fade out and then detach FadeOutAnimation anim = new FadeOutAnimation(widget, new Command() { @Override public void execute() { detach(); } }); anim.run(400); } }; // construct placeholder for image final SimplePanel container = new SimplePanel(); container.addStyleName(RES.styles().container()); final Label noImageLabel = new Label("(No image at path " + href + ")"); // resize command (used by various routines that need to respond // to width / height change events) final CommandWithArg<Integer> onResize = new CommandWithArg<Integer>() { private int state_ = -1; @Override public void execute(Integer height) { // defend against missing chunk output widget (can happen if a widget // is closed / dismissed before image finishes loading) ChunkOutputWidget widget = cow.get(); if (widget == null) return; // don't resize if the chunk widget if we were already collapsed int state = widget.getExpansionState(); if (state == state_ && state == ChunkOutputWidget.COLLAPSED) return; state_ = state; widget.getFrame().setHeight(height + "px"); LineWidget lw = plw.get().getLineWidget(); lw.setPixelHeight(height); display.onLineWidgetChanged(lw); } }; // construct our image String srcPath = imgSrcPathFromHref(sentinel, href); final Image image = new Image(srcPath); image.addStyleName(RES.styles().image()); // parse and inject attributes Map<String, String> parsedAttributes = HTMLAttributesParser.parseAttributes(attributes); final Element imgEl = image.getElement(); for (Map.Entry<String, String> entry : parsedAttributes.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); if (StringUtil.isNullOrEmpty(key) || StringUtil.isNullOrEmpty(val)) continue; imgEl.setAttribute(key, val); } // add load handlers to image DOM.sinkEvents(imgEl, Event.ONLOAD | Event.ONERROR); DOM.setEventListener(imgEl, new EventListener() { @Override public void onBrowserEvent(Event event) { if (DOM.eventGetType(event) == Event.ONLOAD) { final ImageElementEx imgEl = image.getElement().cast(); int minWidth = Math.min(imgEl.naturalWidth(), 100); int maxWidth = Math.min(imgEl.naturalWidth(), 650); Style style = imgEl.getStyle(); boolean hasWidth = imgEl.hasAttribute("width") || style.getProperty("width") != null; if (!hasWidth) { style.setProperty("width", "100%"); style.setProperty("minWidth", minWidth + "px"); style.setProperty("maxWidth", maxWidth + "px"); } // attach to container container.setWidget(image); // update widget int height = image.getOffsetHeight() + 10; onResize.execute(height); } else if (DOM.eventGetType(event) == Event.ONERROR) { container.setWidget(noImageLabel); onResize.execute(50); } } }); // handle editor resize events final Timer renderTimer = new Timer() { @Override public void run() { int height = image.getOffsetHeight() + 30; onResize.execute(height); } }; // initialize render handler renderHandler.set(display.addRenderFinishedHandler(new RenderFinishedEvent.Handler() { private int width_; @Override public void onRenderFinished(RenderFinishedEvent event) { int width = display.getBounds().getWidth(); if (width == width_) return; width_ = width; renderTimer.schedule(100); } })); // initialize doc changed handler docChangedHandler.set(display.addDocumentChangedHandler(new DocumentChangedEvent.Handler() { private String href_ = href; private String attributes_ = StringUtil.notNull(attributes); private final Timer refreshImageTimer = new Timer() { @Override public void run() { // if the discovered href isn't an image link, just bail if (!ImagePreviewer.isImageHref(href_)) return; // set new src location (load handler will replace label as needed) container.setWidget(new SimplePanel()); noImageLabel.setText("(No image at path " + href_ + ")"); image.getElement().setAttribute("src", imgSrcPathFromHref(sentinel, href_)); // parse and inject attributes Map<String, String> parsedAttributes = HTMLAttributesParser.parseAttributes(attributes_); final Element imgEl = image.getElement(); for (Map.Entry<String, String> entry : parsedAttributes.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); if (StringUtil.isNullOrEmpty(key) || StringUtil.isNullOrEmpty(val)) continue; imgEl.setAttribute(key, val); } } }; private void onDocumentChangedImpl(DocumentChangedEvent event) { int row = plw.get().getRow(); Range range = event.getEvent().getRange(); if (range.getStart().getRow() <= row && row <= range.getEnd().getRow()) { String line = display.getLine(row); if (ImagePreviewer.isStandaloneMarkdownLink(line)) { // check to see if the URL text has been updated Token hrefToken = null; JsArray<Token> tokens = display.getTokens(row); for (Token token : JsUtil.asIterable(tokens)) { if (token.hasType("href")) { hrefToken = token; break; } } if (hrefToken == null) return; String attributes = ""; int startBraceIdx = line.indexOf("){"); int endBraceIdx = line.lastIndexOf("}"); if (startBraceIdx != -1 && endBraceIdx != -1 && endBraceIdx > startBraceIdx) { attributes = line.substring(startBraceIdx + 2, endBraceIdx).trim(); } // if we have the same href as before, don't update // (avoid flickering + re-requests of same URL) if (hrefToken.getValue().equals(href_) && attributes.equals(attributes_)) return; // cache href and schedule refresh of image href_ = hrefToken.getValue(); attributes_ = attributes; refreshImageTimer.schedule(700); } else { onDetach.execute(); } } } @Override public void onDocumentChanged(final DocumentChangedEvent event) { // ignore 'removeLines' events as they won't mutate the actual // line containing the markdown link String action = event.getEvent().getAction(); if (action.equals("removeLines")) return; Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { onDocumentChangedImpl(event); } }); } })); ChunkOutputHost host = new ChunkOutputHost() { @Override public void onOutputRemoved(final ChunkOutputWidget widget) { onDetach.execute(); } @Override public void onOutputHeightChanged(ChunkOutputWidget widget, int height, boolean ensureVisible) { onResize.execute(height); } }; cow.set(new ChunkOutputWidget(sentinel.getId(), "md-image-preview-" + StringUtil.makeRandomId(8), RmdChunkOptions.create(), ChunkOutputWidget.EXPANDED, false, // can close host, ChunkOutputSize.Bare)); ChunkOutputWidget outputWidget = cow.get(); outputWidget.setRootWidget(container); outputWidget.hideSatellitePopup(); outputWidget.getElement().getStyle().setMarginTop(4, Unit.PX); plw.set(new PinnedLineWidget(LINE_WIDGET_TYPE, display, outputWidget, position.getRow(), null, null)); }