Example usage for com.google.gwt.user.client Timer Timer

List of usage examples for com.google.gwt.user.client Timer Timer

Introduction

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

Prototype

Timer

Source Link

Usage

From source file:client.richedit.RichTextToolbar.java

License:Apache License

public void setPanelColors(String tcolor, String bgcolor) {
    _tcolor = tcolor;//from ww w  .j  av a 2  s .com
    _bgcolor = bgcolor;

    // this may be called before we're added to the DOM, so we need to wait until our inner
    // iframe is created before trying to set its background color, etc.
    new Timer() {
        public void run() {
            if (richText.getElement() != null) {
                setPanelColorsImpl(richText.getElement(), StringUtil.getOr(_tcolor, ""),
                        StringUtil.getOr(_bgcolor, "none"));
            } else {
                schedule(100);
            }
        }
    }.schedule(100);
}

From source file:client.richedit.RichTextToolbar.java

License:Apache License

@Override // from Widget
protected void onAttach() {
    super.onAttach();
    // yes, we have to wait 100ms before we configure our iframe, no you don't want to know
    // why; just walk away and think happy thoughts
    new Timer() {
        public void run() {
            configureIFrame(richText.getElement(), CssUtil.GLOBAL_PATH);
        }/*from  www  . j a va 2 s. c o  m*/
    }.schedule(100);
}

From source file:client.ui.views.country.CountrySelector.java

License:Open Source License

/**
 * Initialize {@code CountrySelector}.// w w w  . j av  a  2s .  c  o  m
 */
public CountrySelector() {
    initWidget(uiBinder.createAndBindUi(this));

    searchInputTimer = new Timer() {
        @Override
        public void run() {
            if (searchInputText != null && !searchInputText.isEmpty()) {
                manager.search(searchInputText);
            }
        }
    };

    search.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            searchInputText = search.getText().trim();
            searchInputTimer.cancel();

            if (searchInputText.isEmpty()) {
                manager.clearSearch();

                panel.clear();
                map.clear();

                List<Country> selectedCountries = manager.getSelectedCountries();

                onSearch(selectedCountries, selectedCountries);

            } else {
                searchInputTimer.schedule(SEARCH_INPUT_DELAY);
            }
        }
    });
}

From source file:client.ui.views.indicator.IndicatorSelector.java

License:Open Source License

/**
 * Initialize {@code IndicatorSelector}.
 *//*w  ww. jav  a 2s .  com*/
public IndicatorSelector() {
    initWidget(uiBinder.createAndBindUi(this));

    searchInputTimer = new Timer() {
        @Override
        public void run() {
            if (searchInputText != null && !searchInputText.isEmpty()) {
                manager.search(searchInputText);
            }
        }
    };

    search.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            searchInputText = search.getText().trim();
            searchInputTimer.cancel();

            if (searchInputText.isEmpty()) {
                manager.clearSearch();

                panel.clear();
                map.clear();

                Indicator selectedIndicator = manager.getSelectedIndicator();

                if (selectedIndicator != null) {
                    onSearch(Arrays.asList(selectedIndicator), selectedIndicator);
                }
            } else {
                searchInputTimer.schedule(SEARCH_INPUT_DELAY);
            }
        }
    });
}

From source file:client.ui.views.series.ChartSeriesView.java

License:Open Source License

/**
 * Initialize {@code ChartSeriesView}.//  w w w .  ja v a2 s .c o m
 */
public ChartSeriesView() {
    super();
    initWidget(uiBinder.createAndBindUi(this));

    redrawTimer = new Timer() {
        @Override
        public void run() {
            if (map.isEmpty()) {
                label.setVisible(true);
                chart.setVisible(false);
            } else {
                label.setVisible(false);
                chart.setVisible(true);

                chart.setSeries(map.values());
            }
        }
    };
}

From source file:client.ui.views.series.SeriesView.java

License:Open Source License

/**
 * Set whether scrollbars are enabled.//from ww  w. jav a2 s.  c o m
 *
 * @param enabled Whether scrollbars are enabled.
 */
public void setScrollEnabled(final boolean enabled) {
    final Element element = (Element) getElement().getFirstChild();
    boolean scrollEnabled = element.hasClassName(CLASS_NAME_SCROLL);

    if ((scrollEnabled && !enabled) || (!scrollEnabled && enabled)) {
        if (enabled) {
            (new Timer() {
                @Override
                public void run() {
                    element.addClassName(CLASS_NAME_SCROLL);
                }
            }).schedule(SCROLL_DELAY);
        } else {
            element.removeClassName(CLASS_NAME_SCROLL);
        }
    }
}

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 va  2 s.com
 */
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.adamantium.speedchecker.client.application.ApplicationPresenter.java

License:Apache License

/**
 * ? ?  ? /*from w  w w . ja  v  a 2 s . c  o m*/
 */
@Override
public void start(final int size) {
    // First, we validate the input.
    getView().setError("");
    if (!FieldVerifier.isValidSize(size)) {
        getView().setError("Packet Size should be greater then 16 and less then 1024");
        return;
    }

    if (timer == null) {
        timer = new Timer() {
            @Override
            public void run() {
                // ? ? 
                String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                Random rnd = new Random();
                StringBuilder sb = new StringBuilder(size);
                for (int i = 0; i < size; i++) {
                    // ? ?
                    sb.append(chars.charAt(rnd.nextInt(chars.length())));
                }
                String text = sb.toString();
                sendTextToServer(text);
            }
        };

        //? 
        timer.scheduleRepeating(1000);
        getView().disableInterface();
    }
}

From source file:com.agnie.gwt.common.client.widget.FormFieldContainer.java

License:Open Source License

public FormFieldContainer(String label, Widget inputFieldContainer, boolean required) {
    container = (HTMLPanel) uiBinder.createAndBindUi(this);
    container.addStyleName(resource.css().formFieldContainer());
    initWidget(container);/*from  w ww  .j  a v a2 s. c  om*/
    setLabel(label);
    addInputFieldContainer(inputFieldContainer);
    setRequired(required);

    timer = new Timer() {

        @Override
        public void run() {
            errorFixed();
        }
    };
}

From source file:com.agnie.gwt.common.client.widget.MessagePanel.java

License:Open Source License

public MessagePanel() {
    container = (HTMLPanel) uiBinder.createAndBindUi(this);
    initWidget(container);//from w ww. j a v  a  2  s  .  co  m

    close.addStyleName(resource.css().closeBtn());
    close.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            container.setVisible(false);
        }
    });

    this.hide();

    timer = new Timer() {
        public void run() {
            MessagePanel.this.hide();
        }
    };
}