Example usage for com.google.gwt.user.client.ui Label setText

List of usage examples for com.google.gwt.user.client.ui Label setText

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Label setText.

Prototype

public void setText(String text) 

Source Link

Document

Sets the label's content to the given text.

Usage

From source file:com.google.gwt.sample.stockwatcher.client.StockWatcher2.java

private void updateTable(StockPrice price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;/*from ww w.  j  ava2  s .c o  m*/
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");
    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.sample.stockwatcher.client.StockWatcherT.java

/**
 * Update a single row in the stock table.
 *
 * @param price Stock data for a single row.
 *///from ww w  .  j  av  a2 s .  c  o  m
private void updateTable(StockPrice price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);

}

From source file:com.google.gwt.sample.stockwatcher.client.TemperatureWatcher.java

/**
 * Update a single row in the stock table.
 *
 * @param price Stock data for a single row.
 *//*from   ww w.  j  a  v  a2 s  .c  o m*/
private void updateTable(Temperature temperature) {
    // Make sure the stock is still in the stock table.
    Boolean boo = false;
    int row = 0;
    for (row = 0; row < listOfTemperatures.size() && !boo; row++) {
        if (listOfTemperatures.get(row).getCity().toUpperCase().equals(temperature.getCity().toUpperCase()))
            boo = true; //can be improved, only compares the city, i.e two cities with the same name in defferent countries/region can't be added
    }
    if (!boo)
        return;

    // Format the data in the Price and Change fields.
    String tempText = NumberFormat.getFormat("#,##0.00").format(temperature.getTemperature());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(temperature.getChange());
    String changePercentText = changeFormat.format(temperature.getChangePercent());

    // Populate the Price and Change fields with new data.
    temperatureFlextable.setText(row, 3, tempText);
    Label changeWidget = (Label) temperatureFlextable.getWidget(row, 4);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");
    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (temperature.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (temperature.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.sample.stockwatcher.client.ui.StockWatcherViewImpl.java

/**
 * Update a single row in the stock table.
 * /*from  w ww . j av  a 2s .  c  om*/
 * @param price Stock data for a single row.
 */
private void updateTable(StockData price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    // stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText
    // + "%)");
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }
    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.sample.stockwatcher.uibinder.client.StockWatcherWidget.java

private void updateTable(final StockPrice price) {
    if (!stocks.contains(price.getSymbol())) {
        return;//  w  w  w. j a  va 2  s. c om
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    stockFlexTable.setText(row, 1, priceText);
    // stockFlexTable.setText(row, 2, changeText + " (" + changePercentText + "%)");
    Label changeWidget = (Label) stockFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";

    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }
    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.sample.stockwatcher_json.client.StockWatcherJSON.java

private void updateTable(StockData price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;/*  w ww  . ja  va  2  s . c o  m*/
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.sample.stockwatcher_rpc.client.StockWatcherRPC.java

/**
 * Update a single row in the stock table.
 * /* w  w  w .  jav a2s  .  c  om*/
 * @param price
 *            Stock data for a single row.
 */
private void updateTable(StockPrice price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.sample.temp_conv.client.GWT_Temp_Conv.java

public void updateOutputTable(Temperature temp) {
    double ftemp = Double.parseDouble(temp.getFahrenheit());
    double ctemp = Double.parseDouble(temp.getCelcius());
    String changeStyleName = "comfortable";

    // Set css styling
    if (ftemp >= 212) {
        changeStyleName = "boiling";
    } else if (ftemp <= 32) {
        changeStyleName = "freezing";
    }//from   w  ww  . ja v a 2 s  . c  o  m

    // Format the output
    Label flabel = (Label) outputTable.getWidget(1, 0);
    Label clabel = (Label) outputTable.getWidget(1, 1);
    String fahr = NumberFormat.getFormat("#,##0.00").format(ftemp);
    String celc = NumberFormat.getFormat("#,##0.00").format(ctemp);
    flabel.setText(fahr);
    clabel.setText(celc);
    flabel.setStyleName(changeStyleName);
    clabel.setStyleName(changeStyleName);

    // Display the output
    outputTable.setWidget(1, 0, flabel);
    outputTable.setWidget(1, 1, clabel);

}

From source file:com.google.gwt.sample.vanfood.client.VanFood.java

private void addTimeStamp() {
    Label lastUpdatedLabel = new Label();
    lastUpdatedLabel.setText("Last update : "
            + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM).format(new Date()));

    mainPanel.add(lastUpdatedLabel);/*from w  w w  . ja  v  a2  s  .c  o  m*/
}

From source file:com.google.livingstories.client.contentmanager.ContentItemManager.java

License:Apache License

/**
 * Make an RPC call to the server to persist a new content entity or a change to an existing
 * content entity to the datastore. The timestamp is updated once the change is done if no
 * value had been entered for it before.
 *///from   w ww  .j a  v a 2s. c  o  m
private void createOrChangeContentItem(final BaseContentItem sentContentItem, final boolean publish,
        final Label statusLabel) {

    AsyncCallback<BaseContentItem> callback = new AsyncCallback<BaseContentItem>() {
        public void onFailure(Throwable caught) {
            if (statusLabel != null) {
                statusLabel.setText("Save not successful. Try again.");
                statusLabel.setStyleName("serverResponseLabelError");
            }
        }

        public void onSuccess(BaseContentItem returnedContentItem) {
            if (statusLabel != null) {
                statusLabel.setText(publish ? "Published!" : "Saved as draft");
                statusLabel.setStyleName("serverResponseLabelSuccess");
            }
            timestamp.setText(DateUtil.formatDateTime(returnedContentItem.getTimestamp()));
            updateDisplayedPublishStatus(returnedContentItem);
            if (returnedContentItem.getContentItemType() == ContentItemType.PLAYER
                    && returnedContentItem.getLivingStoryId() == null) {
                addUnassignedPlayer((PlayerContentItem) returnedContentItem);
            }

            // Set the content editor items to what was returned from the server. This is needed
            // because some changes are made to the content as entered by the user, such as adding
            // target="_blank" in links and adding player tags.
            contentEditor.setContent(returnedContentItem.getContent());
            if (returnedContentItem.getContentItemType() == ContentItemType.EVENT) {
                summaryEditor.setContent(((EventContentItem) returnedContentItem).getEventSummary());
            }
            if (returnedContentItem.getContentItemType() == ContentItemType.NARRATIVE) {
                narrativeSummaryTextArea
                        .setContent(((NarrativeContentItem) returnedContentItem).getNarrativeSummary());
            }

            // remember which linked content items were suggested, but fix up the returned content
            // item so that nothing incorrect gets cached locally.
            Set<Long> suggestionIds = GlobalUtil.copySet(returnedContentItem.getLinkedContentItemIds());
            suggestionIds.removeAll(sentContentItem.getLinkedContentItemIds());
            returnedContentItem.setLinkedContentItemIds(sentContentItem.getLinkedContentItemIds());

            contentItemListBox.addOrUpdateContentItem(returnedContentItem);
            linkedContentItemSelector.addOrUpdateContentItem(returnedContentItem);
            updatePreview();

            if (!suggestionIds.isEmpty()) {
                linkedContentItemSelector.setSuggestedContentItemIds(suggestionIds);
                linkedContentItemSelector.selectSuggested();
                advisoryLabel.setVisible(true);

                // scroll the picker panel into view. This should assure that both the
                // linkedContentItemSelector and advisoryLabel are fully visible (if indeed both can fit
                // onscreen at once).
                pickerPanel.getElement().scrollIntoView();
                // and, in case it doesn't fit all onscreen, prioritize display of the
                // advisory label:
                advisoryLabel.getElement().scrollIntoView();
            } else {
                hideSuggestions();
            }
        }
    };

    contentRpcService.createOrChangeContentItem(sentContentItem, callback);
}