List of usage examples for com.google.gwt.i18n.shared DateTimeFormat format
public String format(Date date)
From source file:com.achow101.bctalkaccountpricer.client.Bitcointalk_Account_Pricer.java
License:Open Source License
/** * This is the entry point method.// w w w . ja v a 2 s .c o m */ public void onModuleLoad() { // Add Gui stuff final Button sendButton = new Button("Estimate Price"); final TextBox nameField = new TextBox(); nameField.setText("User ID/Token"); final Label errorLabel = new Label(); final Label uidLabel = new Label(); final Label usernameLabel = new Label(); final Label postsLabel = new Label(); final Label activityLabel = new Label(); final Label potActivityLabel = new Label(); final Label postQualityLabel = new Label(); final Label trustLabel = new Label(); final Label priceLabel = new Label(); final Label loadingLabel = new Label(); final Label tokenLabel = new Label(); final InlineHTML estimateShareLabel = new InlineHTML(); final InlineHTML reportTimeStamp = new InlineHTML(); final RadioButton radioNormal = new RadioButton("merch", "Normal"); final RadioButton radioMerchant = new RadioButton("merch", "Merchant"); // We can add style names to widgets sendButton.addStyleName("sendButton"); radioNormal.setValue(true); radioMerchant.setValue(false); // Add the nameField and sendButton to the RootPanel // Use RootPanel.get() to get the entire body element RootPanel.get("nameFieldContainer").add(nameField); RootPanel.get("sendButtonContainer").add(sendButton); RootPanel.get("errorLabelContainer").add(errorLabel); RootPanel.get("uidLabelContainer").add(uidLabel); RootPanel.get("usernameLabelContainer").add(usernameLabel); RootPanel.get("postsLabelContainer").add(postsLabel); RootPanel.get("activityLabelContainer").add(activityLabel); RootPanel.get("potActivityLabelContainer").add(potActivityLabel); RootPanel.get("postQualityLabelContainer").add(postQualityLabel); RootPanel.get("trustLabelContainer").add(trustLabel); RootPanel.get("priceLabelContainer").add(priceLabel); RootPanel.get("loadingLabelContainer").add(loadingLabel); RootPanel.get("tokenLabelContainer").add(tokenLabel); RootPanel.get("tokenShareLabelContainer").add(estimateShareLabel); RootPanel.get("radioNormalContainer").add(radioNormal); RootPanel.get("radioMerchantContainer").add(radioMerchant); RootPanel.get("reportTimeStamp").add(reportTimeStamp); // Create activity breakdown panel final VerticalPanel actPanel = new VerticalPanel(); final FlexTable actTable = new FlexTable(); actPanel.add(actTable); RootPanel.get("activityBreakdown").add(actPanel); // Create posts breakdown panel final VerticalPanel postsPanel = new VerticalPanel(); final FlexTable postsTable = new FlexTable(); postsPanel.add(postsTable); RootPanel.get("postsBreakdown").add(postsPanel); // Create addresses breakdown panel final VerticalPanel addrPanel = new VerticalPanel(); final FlexTable addrTable = new FlexTable(); postsPanel.add(addrTable); RootPanel.get("addrBreakdown").add(addrTable); // Focus the cursor on the name field when the app loads nameField.setFocus(true); nameField.selectAll(); // 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) { // Add request to queue addToQueue(); } /** * Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { addToQueue(); } } // Adds the request to server queue private void addToQueue() { // Clear previous output uidLabel.setText(""); usernameLabel.setText(""); postsLabel.setText(""); activityLabel.setText(""); potActivityLabel.setText(""); postQualityLabel.setText(""); trustLabel.setText(""); priceLabel.setText(""); sendButton.setEnabled(false); errorLabel.setText(""); loadingLabel.setText(""); tokenLabel.setText(""); estimateShareLabel.setText(""); reportTimeStamp.setText(""); actTable.removeAllRows(); postsTable.removeAllRows(); addrTable.removeAllRows(); // Create and add request request = new QueueRequest(); request.setMerchant(radioMerchant.getValue()); if (nameField.getText().matches("^[0-9]+$")) request.setUid(Integer.parseInt(escapeHtml(nameField.getText()))); else { request.setToken(escapeHtml(nameField.getText())); request.setOldReq(); } final String urlPath = com.google.gwt.user.client.Window.Location.getPath(); final String host = com.google.gwt.user.client.Window.Location.getHost(); final String protocol = com.google.gwt.user.client.Window.Location.getProtocol(); final String url = protocol + "//" + host + urlPath + "?token="; // Request check loop Timer requestTimer = new Timer() { public void run() { // send request to server pricingService.queueServer(request, new AsyncCallback<QueueRequest>() { @Override public void onFailure(Throwable caught) { errorLabel.setText("Request Queuing failed. Please try again."); sendButton.setEnabled(true); pricingService.removeRequest(request, null); cancel(); } @Override public void onSuccess(QueueRequest result) { if (result.getQueuePos() == -3) { loadingLabel.setText( "Please wait for your previous request to finish and try again"); sendButton.setEnabled(true); cancel(); } else if (result.getQueuePos() == -2) { loadingLabel.setText("Please wait 2 minutes before requesting again."); sendButton.setEnabled(true); cancel(); } else if (result.getQueuePos() == -4) { loadingLabel.setText("Invalid token"); sendButton.setEnabled(true); cancel(); } else { tokenLabel.setText("Your token is " + result.getToken()); estimateShareLabel.setHTML("Share this estimate: <a href=\"" + url + result.getToken() + "\">" + url + result.getToken() + "</a>"); if (!result.isProcessing() && !result.isDone()) { loadingLabel.setText("Please wait. You are number " + result.getQueuePos() + " in the queue."); } if (result.isProcessing()) { loadingLabel.setText("Request is processing. Please wait."); } if (result.isDone()) { // Clear other messages errorLabel.setText(""); loadingLabel.setText(""); // Output results uidLabel.setText(result.getResult()[0]); usernameLabel.setText(result.getResult()[1]); postsLabel.setText(result.getResult()[2]); activityLabel.setText(result.getResult()[3]); potActivityLabel.setText(result.getResult()[4]); postQualityLabel.setText(result.getResult()[5]); trustLabel.setText(result.getResult()[6]); priceLabel.setText(result.getResult()[7]); int indexOfLastAct = 0; int startAddrIndex = 0; for (int i = 8; i < result.getResult().length; i++) { if (result.getResult()[i].equals("<b>Post Sections Breakdown</b>")) { indexOfLastAct = i; break; } actTable.setHTML(i - 8, 0, result.getResult()[i]); } for (int i = indexOfLastAct; i < result.getResult().length; i++) { if (result.getResult()[i] .contains("<b>Addresses posted in non-quoted text</b>")) { startAddrIndex = i; break; } postsTable.setHTML(i - indexOfLastAct, 0, result.getResult()[i]); } if (!result.isMerchant()) { for (int i = startAddrIndex; i < result.getResult().length; i++) { addrTable.setHTML(i - startAddrIndex, 0, result.getResult()[i]); } } // Set the right radio radioMerchant.setValue(result.isMerchant()); radioNormal.setValue(!result.isMerchant()); // Report the time stamp DateTimeFormat fmt = DateTimeFormat.getFormat("MMMM dd, yyyy, hh:mm:ss a"); Date completedDate = new Date(1000L * result.getCompletedTime()); Date expireDate = new Date( 1000L * (result.getCompletedTime() + result.getExpirationTime())); reportTimeStamp .setHTML("<i>Report generated at " + fmt.format(completedDate) + " and expires at " + fmt.format(expireDate) + "</i>"); // Kill the timer after everything is done cancel(); } request = result; request.setPoll(true); sendButton.setEnabled(true); } } }); } }; requestTimer.scheduleRepeating(2000); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); sendButton.addClickHandler(handler); nameField.addKeyUpHandler(handler); // Check the URL for URL parameters String urlTokenParam = com.google.gwt.user.client.Window.Location.getParameter("token"); if (!urlTokenParam.isEmpty()) { nameField.setText(urlTokenParam); handler.addToQueue(); } }
From source file:com.google.gwt.sample.stockwatcher.server.CurrencyServiceImpl.java
private String calculateRatesUrl() { String pattern = "yyyy-MM-dd"; DefaultDateTimeFormatInfo info = new DefaultDateTimeFormatInfo(); DateTimeFormat dtf = new DateTimeFormat(pattern, info) { };/*from w w w. ja v a2s . com*/ Date d = new Date(); CalendarUtil.addMonthsToDate(d, -1); return "http://api.fixer.io/" + dtf.format(d) + "?base=HKD"; }
From source file:com.vaadin.client.DateTimeService.java
License:Apache License
/** * Check if format contains the month name. If it does we manually convert * it to the month name since DateTimeFormat.format always uses the current * locale and will replace the month name wrong if current locale is * different from the locale set for the DateField. * * MMMM is converted into long month name, MMM is converted into short month * name. '' are added around the name to avoid that DateTimeFormat parses * the month name as a pattern./*from w w w .jav a2 s .c om*/ * * z is converted into the time zone name, using the specified * {@code timeZoneJSON} * * @param date * The date to convert * @param formatStr * The format string that might contain {@code MMM} or * {@code MMMM} * @param timeZone * The {@link TimeZone} used to replace {@code z}, can be * {@code null} * * @return the formatted date string * @since 8.2 */ public String formatDate(Date date, String formatStr, TimeZone timeZone) { /* * Format month and day names separately when locale for the * com.vaadin.client.DateTimeService is not the same as the browser locale */ formatStr = formatTimeZone(date, formatStr, timeZone); formatStr = formatMonthNames(date, formatStr); formatStr = formatDayNames(date, formatStr); // Format uses the browser locale DateTimeFormat format = DateTimeFormat.getFormat(formatStr); String result = format.format(date); return result; }
From source file:gwt.material.design.addins.client.ui.MaterialTimePicker.java
License:Apache License
@Override public void setValue(Date time, boolean fireEvents) { if (this.time != null) { if (this.time.equals(time)) { return; }/*from w ww.jav a2 s .com*/ } if (this.time == time) { return; } this.time = time; String timeString = null; if (this.hour24 == true) { DateTimeFormat hour24DateTimeFormat = DateTimeFormat.getFormat("HH:mm"); timeString = hour24DateTimeFormat.format(time); } else { DateTimeFormat hour12DateTimeFormat = DateTimeFormat.getFormat("hh:mm aa"); timeString = hour12DateTimeFormat.format(time); } this.setValue(this.input.getElement(), timeString); if (fireEvents == true) { this.fireValueChangeEvent(); } }
From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractColourReportPresenter.java
License:Open Source License
public void submitTestResults(final MetadataField emailAddressMetadataField, final TimedStimulusListener onError, final TimedStimulusListener onSuccess) { StringBuilder stringBuilder = new StringBuilder(); final DateTimeFormat format = DateTimeFormat.getFormat(messages.reportDateFormat()); final ScoreCalculator scoreCalculator = new ScoreCalculator(userResults); for (final StimulusResponseGroup stimuliGroup : userResults.getStimulusResponseGroups()) { final GroupScoreData calculatedScores = scoreCalculator.calculateScores(stimuliGroup); stringBuilder.append("\t"); stringBuilder.append(stimuliGroup.getPostName()); stringBuilder.append("\t"); stringBuilder.append(format.format(new Date())); stringBuilder.append("\t"); stringBuilder.append(calculatedScores.getScore()); stringBuilder.append("\t"); stringBuilder.append(calculatedScores.getMeanReactionTime()); stringBuilder.append("\t"); stringBuilder.append(calculatedScores.getReactionTimeDeviation()); stringBuilder.append("\n"); }//w w w. j a va 2 s. c o m final String scoreLog = stringBuilder.toString(); // submissionService.submitTagValue(userResults.getUserData().getUserId(), "ScoreLog", scoreLog.replaceAll("\t", ","), 0); new RegistrationService().submitRegistration(userResults, new RegistrationListener() { @Override public void registrationFailed(RegistrationException exception) { onError.postLoadTimerFired(); ((ReportView) simpleView).addText("Could not connect to the server."); ((ReportView) simpleView).addOptionButton(new PresenterEventListner() { @Override public String getLabel() { return "Retry"; } @Override public void eventFired(ButtonBase button, SingleShotEventListner shotEventListner) { Timer timer = new Timer() { @Override public void run() { ((ReportView) simpleView).clearPageAndTimers(null); submitTestResults(emailAddressMetadataField, onError, onSuccess); } }; timer.schedule(1000); } @Override public String getStyleName() { return null; } @Override public int getHotKey() { return -1; } }); } @Override public void registrationComplete() { onSuccess.postLoadTimerFired(); } }, messages.reportDateFormat(), emailAddressMetadataField, scoreLog); }
From source file:nl.ru.languageininteraction.synaesthesia.client.presenter.ReportPresenter.java
License:Open Source License
@Override protected void setContent(AppEventListner appEventListner) { StringBuilder stringBuilder = new StringBuilder(); final DateTimeFormat format = DateTimeFormat.getFormat(messages.reportDateFormat()); final NumberFormat numberFormat2 = NumberFormat.getFormat("0.00"); final NumberFormat numberFormat3 = NumberFormat.getFormat("0.000"); final ScoreCalculator scoreCalculator = new ScoreCalculator(userResults); for (final StimuliGroup stimuliGroup : scoreCalculator.getStimuliGroups()) { final GroupScoreData calculatedScores = scoreCalculator.calculateScores(stimuliGroup); ((ReportView) simpleView).showResults(stimuliGroup, calculatedScores); ((ReportView) simpleView)/*from w ww. j a v a 2 s .com*/ .addText(messages.reportScreenScore(numberFormat2.format(calculatedScores.getScore()))); ((ReportView) simpleView).addText(messages.userfeedbackscreentext()); // userResults.updateBestScore(calculatedScores.getScore()); // ((ReportView) simpleView).addText(messages.reportScreenSCT()); // ((ReportView) simpleView).addText(messages.reportScreenSCTaccuracy(numberFormat2.format(calculatedScores.getAccuracy()))); // ((ReportView) simpleView).addText(messages.reportScreenSCTmeanreactionTime(numberFormat3.format(calculatedScores.getMeanReactionTime() / 1000), numberFormat3.format(calculatedScores.getReactionTimeDeviation() / 1000))); stringBuilder.append(userResults.getMetadataValue(mateadataFields.postName_firstname())); stringBuilder.append("\t"); stringBuilder.append(format.format(new Date())); stringBuilder.append("\t"); stringBuilder.append(calculatedScores.getScore()); stringBuilder.append("\t"); stringBuilder.append(calculatedScores.getMeanReactionTime()); stringBuilder.append("\t"); stringBuilder.append(calculatedScores.getReactionTimeDeviation()); stringBuilder.append("\n"); ((ReportView) simpleView).addOptionButton(new PresenterEventListner() { @Override public String getLabel() { return messages.socialPostButtonText(); } @Override public void eventFired(Button button) { new SocialMediaPost().postImageAndLink( messages.socialMediaPostText(numberFormat2.format(calculatedScores.getScore()), "(this precentage is not calculated yet) 100", stimuliGroup.getGroupLabel()), messages.socialMediaPostSubject(), messages.socialMediaPostImage(), messages.socialMediaPostUrl()); //stimuliGroup.getGroupLabel(), numberFormat2.format(calculatedScores.getScore()) } }); } userResults.setScoreLog(stringBuilder.toString()); ((ReportView) simpleView).addText(messages.reportScreenPostSCTtext()); if (userResults.getBestScore() <= Float.parseFloat(messages.positiveresultsThreshold())) { // ((ReportView) simpleView).addHighlightedText(messages.positiveresultscreentext1()); // ((ReportView) simpleView).addHighlightedText(messages.positiveresultscreentext2()); // ((ReportView) simpleView).addHighlightedText(messages.positiveresultscreentext3()); } else { // ((ReportView) simpleView).addHighlightedText(messages.negativeresultscreentext1()); // ((ReportView) simpleView).addHighlightedText(messages.negativeresultscreentext2()); // ((ReportView) simpleView).addHighlightedText(messages.negativeresultscreentext3()); } ((ReportView) simpleView).addPadding(); }
From source file:nz.org.winters.appspot.acrareporter.store.DailyCounts.java
License:Apache License
public String dateString() { DateTimeFormat fmt = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT); return fmt.format(date); }
From source file:org.bonitasoft.web.toolkit.client.common.json.JSonSerializer.java
License:Open Source License
public static String serialize(final Object object) { if (object == null) { return "null"; } else if (object instanceof JsonSerializable) { return ((JsonSerializable) object).toJson(); } else if (object instanceof Collection<?>) { return serializeCollection((Collection<?>) object); } else if (object instanceof Map<?, ?>) { return serializeMap((Map<?, ?>) object); } else if (object instanceof Number) { return object.toString(); } else if (object instanceof Boolean) { return (Boolean) object ? "true" : "false"; } else if (object instanceof Date) { final DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss.SSS"); return quote(sdf.format((Date) object)); } else if (object instanceof Throwable) { return serializeException((Throwable) object); }// w w w . ja va2 s .co m return quote(object.toString()); }
From source file:org.bonitasoft.web.toolkit.client.ui.ClientDateFormater.java
License:Open Source License
@Override public String _toString(final Date value, final String format) { final DateTimeFormat formatter = DateTimeFormat.getFormat(format); return formatter.format(value); }
From source file:org.greatlogic.glgwt.client.widget.GLGridWidget.java
License:Apache License
private int resizeColumnGetWidth(final Object value, final DateTimeFormat dateTimeFormat) { if (value == null) { return 0; }// ww w . j av a2s . c o m final String valueAsString = dateTimeFormat == null ? value.toString() // : dateTimeFormat.format((Date) value); return _textMetrics.getWidth(valueAsString); }