Example usage for com.google.gwt.core.client Duration Duration

List of usage examples for com.google.gwt.core.client Duration Duration

Introduction

In this page you can find the example usage for com.google.gwt.core.client Duration Duration.

Prototype

public Duration() 

Source Link

Document

Creates a new Duration whose start time is now.

Usage

From source file:ch.heftix.mailxel.client.OrgTextArea.java

License:Open Source License

public OrgTextArea() {

    KeyboardListener kl = new KeyboardListener() {

        Duration sinceEscapePressed = null;

        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_ESCAPE) {
                sinceEscapePressed = new Duration();
            }//from   w  ww  . j  av  a2s . c o m
        }

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
        }

        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if ('q' == keyCode) {
                // System.out.println(sinceEscapePressed.elapsedMillis());
                if (null != sinceEscapePressed && (sinceEscapePressed.elapsedMillis() < 300)) {
                    // format region
                    TextArea ta = (TextArea) sender;
                    String text = ta.getText();
                    int pos = ta.getCursorPos();
                    int len = ta.getSelectionLength();
                    String replacement = om.prefixSelection(text, "> ", pos, len);
                    ta.setText(replacement);
                    cancelKey();
                }
            }
        }

    };

    addKeyboardListener(kl);

}

From source file:com.cgxlib.xq.client.plugins.MousePlugin.java

License:Apache License

private void reset(XQEvent nativeEvent) {
    this.startEvent = nativeEvent;
    this.startX = getClientX(nativeEvent);
    this.startY = getClientY(nativeEvent);
    this.mouseUpDuration = new Duration();
}

From source file:com.google.appinventor.client.explorer.commands.ChainableCommand.java

License:Open Source License

/**
 * Resets the start time for the link duration timer
 *
 *///from ww w .j  a  va2  s. com
private final void resetLinkDuration() {
    // Note that each link in the chain has a unique linkDuration.
    linkDuration = new Duration();
}

From source file:com.google.appinventor.client.explorer.commands.ChainableCommand.java

License:Open Source License

/**
 * Kick off the chain of commands.// w  w w. j  ava2 s.com
 *
 * @param actionName the name of action this chain of commands represents
 * @param node the project node to which the chain of commands is applied
 * @param finallyCommand a command to execute after the chain is finished,
 *                       regardless of whether it succeeds
 */
public final void startExecuteChain(String actionName, ProjectNode node, Command finallyCommand) {
    // The node must not be null.
    // If you are calling startExecuteChain with null for the node parameter, maybe you should
    // question why you are using a ChainableCommand at all. ChainableCommands were designed to
    // perform an operation on a ProjectNode.
    Preconditions.checkNotNull(node);

    setFinallyCommand(finallyCommand);
    initTrackingInformation(actionName, new Duration());

    executeLink(node);
}

From source file:com.google.gwt.gen2.demo.scrolltable.client.option.log.LogOption.java

License:Apache License

@Override
protected Widget onInitialize() {
    layout = new FlexTable();

    // Create the log area
    logLabel = new HTML();
    logLabel.setHeight("200px");
    DOM.setStyleAttribute(logLabel.getElement(), "font", "8pt/10pt courier");
    ScrollPanel scrollPanel = new ScrollPanel(logLabel);
    scrollPanel.setPixelSize(500, 200);//from   w  ww .ja  v a2s. c  o m
    DOM.setStyleAttribute(scrollPanel.getElement(), "border", "1px solid black");
    layout.setWidget(0, 0, scrollPanel);
    layout.getFlexCellFormatter().setColSpan(0, 0, 2);

    // Add a clear button
    Button clearButton = new Button("Clear Log", new ClickHandler() {
        public void onClick(ClickEvent event) {
            logLabel.setHTML("");
            lineCount = 0;
        }
    });
    layout.setWidget(1, 0, clearButton);
    layout.getFlexCellFormatter().setColSpan(1, 0, 2);

    // Add labels for highlighting
    final Label highlightedCellLabel = new Label("Highlighted cell:");
    final Label highlightedRowLabel = new Label("Highlighted row:");
    final Label unhighlightedCellLabel = new Label("Last unhighlighted cell:");
    final Label unhighlightedRowLabel = new Label("Last unhighlighted row:");
    layout.setWidget(2, 0, highlightedCellLabel);
    layout.setWidget(3, 0, highlightedRowLabel);
    layout.setWidget(2, 1, unhighlightedRowLabel);
    layout.setWidget(3, 1, unhighlightedCellLabel);

    // Add all of the listeners
    FixedWidthGrid dataTable = ScrollTableDemo.get().getDataTable();
    dataTable.addTableListener(new TableListener() {
        public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
            addLogEntry("cell clicked: (" + row + "," + cell + ")", "#ff00ff");
        }
    });
    dataTable.addColumnSortHandler(new ColumnSortHandler() {
        public void onColumnSorted(ColumnSortEvent event) {
            ColumnSortList sortList = event.getColumnSortList();
            int column = -1;
            boolean ascending = true;
            if (sortList != null) {
                column = sortList.getPrimaryColumn();
                ascending = sortList.isPrimaryAscending();
            }
            if (ascending) {
                addLogEntry("sorted column: " + column + " (ascending)", "black");
            } else {
                addLogEntry("sorted column: " + column, "black");
            }
        }
    });
    dataTable.addCellHighlightHandler(new CellHighlightHandler() {
        public void onCellHighlight(CellHighlightEvent event) {
            Cell cell = event.getValue();
            highlightedCellLabel
                    .setText("Highlighted cell: (" + cell.getRowIndex() + "," + cell.getCellIndex() + ")");
        }
    });
    dataTable.addCellUnhighlightHandler(new CellUnhighlightHandler() {
        public void onCellUnhighlight(CellUnhighlightEvent event) {
            Cell cell = event.getValue();
            unhighlightedCellLabel.setText(
                    "Last unhighlighted cell: (" + cell.getRowIndex() + "," + cell.getCellIndex() + ")");
        }
    });
    dataTable.addRowHighlightHandler(new RowHighlightHandler() {
        public void onRowHighlight(RowHighlightEvent event) {
            Row cell = event.getValue();
            highlightedRowLabel.setText("Highlighted row: (" + cell.getRowIndex() + ")");
        }
    });
    dataTable.addRowUnhighlightHandler(new RowUnhighlightHandler() {
        public void onRowUnhighlight(RowUnhighlightEvent event) {
            Row cell = event.getValue();
            unhighlightedRowLabel.setText("Last unhighlighted row: (" + cell.getRowIndex() + ")");
        }
    });
    dataTable.addRowSelectionHandler(new RowSelectionHandler() {
        public void onRowSelection(RowSelectionEvent event) {
            // Show the previously selected rows
            Set<Row> deselectedRows = event.getDeselectedRows();
            String previous = "Previously selected rows: ";
            for (Row row : event.getOldValue()) {
                if (deselectedRows.contains(row)) {
                    previous += "-";
                }
                previous += row.getRowIndex() + ", ";
            }
            addLogEntry(previous, "green");

            // Show the currently selected rows
            Set<Row> selectedRows = event.getSelectedRows();
            String current = "Currently selected rows: ";
            for (Row row : event.getNewValue()) {
                if (selectedRows.contains(row)) {
                    current += "+";
                }
                current += row.getRowIndex() + ", ";
            }

            addLogEntry(current, "green");
        }
    });

    // Paging specific options
    if (PagingScrollTableDemo.get() != null) {
        PagingScrollTable<Student> pagingScrollTable = PagingScrollTableDemo.get().getPagingScrollTable();
        if (pagingScrollTable != null) {
            pagingScrollTable.addPageChangeHandler(new PageChangeHandler() {
                public void onPageChange(PageChangeEvent event) {
                    pageLoadDuration = new Duration();
                }
            });

            pagingScrollTable.addPageLoadHandler(new PageLoadHandler() {
                public void onPageLoad(PageLoadEvent event) {
                    // Convert to 1 based index
                    int page = event.getPage() + 1;
                    int duration = -1;
                    if (pageLoadDuration != null) {
                        duration = pageLoadDuration.elapsedMillis();
                        pageLoadDuration = null;
                    }
                    String text = "Page " + page + " loaded in " + duration + "ms";
                    addLogEntry(text, "black");
                }
            });
        }
    }

    return layout;
}

From source file:com.google.gwt.modernizr.client.runtimesample.RuntimeSample.java

License:MIT License

public void onModuleLoad() {
    Resources.css().ensureInjected();

    testCounter = 0;// w ww  .j a  va  2  s.  c om
    subTestCounter = 0;
    time = new Duration();
    labelCreationTime = 0;

    // Loading time !
    HTML duration = new HTML();
    RootPanel.get().add(duration);

    // flexbox
    createAndAddLabel("Flexbox", Modernizr.flexbox(), false);

    // Canvas
    createAndAddLabel("Canvas", Modernizr.canvas(), false);

    createAndAddLabel("Canvas text", Modernizr.canvasText(), false);
    createAndAddLabel("webgl", Modernizr.webgl(), false);

    // Touch
    createAndAddLabel("Touch events", Modernizr.touch(), false);

    // geolocation
    createAndAddLabel("Geolocation API", Modernizr.geolocation(), false);

    // Postmessage
    createAndAddLabel("Postmessage", Modernizr.postMessage(), false);

    // webSqlDatabase
    createAndAddLabel("Web SQL Database", Modernizr.webSqlDatabase(), false);

    // indexedDB
    createAndAddLabel("IndexedDB", Modernizr.indexedDB(), false);

    // hashChange
    createAndAddLabel("HashChange", Modernizr.hashChange(), false);

    // history
    createAndAddLabel("History management", Modernizr.history(), false);

    // DragAndDrop
    createAndAddLabel("Drag and Drop", Modernizr.dragAndDrop(), false);

    // WebSockets
    createAndAddLabel("Web Sockets", Modernizr.webSockets(), false);

    // Rgba
    createAndAddLabel("rgba", Modernizr.rgba(), false);

    // Hsla
    createAndAddLabel("hsla", Modernizr.hsla(), false);

    // Multiple background
    createAndAddLabel("Multiple background", Modernizr.multipleBackgroung(), false);

    // Background size
    createAndAddLabel("Background size", Modernizr.backgroundSize(), false);

    // Border Image
    createAndAddLabel("Border image", Modernizr.borderImage(), false);

    // Border Radius
    createAndAddLabel("Border radius", Modernizr.borderRadius(), false);

    // Box Shadow
    createAndAddLabel("Box shadow", Modernizr.boxShadow(), false);

    // Text Shadow
    createAndAddLabel("Text shadow", Modernizr.textShadow(), false);

    // Opacity
    createAndAddLabel("Opacity", Modernizr.opacity(), false);

    // Css animations

    createAndAddLabel("CSS animations", Modernizr.cssAnimations(), false);

    // Css columns

    createAndAddLabel("CSS columns", Modernizr.cssColumns(), false);

    // Css gradient

    createAndAddLabel("CSS gradient", Modernizr.cssGradients(), false);

    // Css reflections
    createAndAddLabel("CSS reflections", Modernizr.cssReflections(), false);

    // Css transforms
    createAndAddLabel("CSS transforms", Modernizr.cssTransforms(), false);

    // Css transforms 3d
    createAndAddLabel("CSS transforms 3d", Modernizr.cssTransforms3d(), false);

    // Css transitions
    createAndAddLabel("CSS transitions", Modernizr.cssTransitions(), false);

    // Audio
    createAndAddLabel("Font face", Modernizr.fontFace(), false);

    // Audio
    createAndAddLabel("HTML5 audio", Modernizr.audio(), false);

    // Audio format
    for (AudioFormat format : AudioFormat.values()) {

        createAndAddLabel("audio format " + format.name(), Modernizr.audio(format), true);
    }

    // Video
    createAndAddLabel("HTML5 video", Modernizr.video(), false);

    // Video format
    for (VideoFormat format : VideoFormat.values()) {

        createAndAddLabel("video format " + format.name(), Modernizr.video(format), true);
    }

    // Local storage
    createAndAddLabel("Local storage", Modernizr.localStorage(), false);

    // Session storage
    createAndAddLabel("Session storage", Modernizr.sessionStorage(), false);

    // Web worker
    createAndAddLabel("Web workers", Modernizr.webWorkers(), false);

    // Application cache
    createAndAddLabel("Application cache", Modernizr.applicationCache(), false);

    // Svg
    createAndAddLabel("SVG", Modernizr.svg(), false);

    // Inline svg
    createAndAddLabel("Inline SVG", Modernizr.inlineSvg(), false);

    // Smil
    createAndAddLabel("SMIL", Modernizr.smil(), false);

    // Svg clip paths
    createAndAddLabel("SVG Clipping", Modernizr.svgClipPaths(), false);

    // Input attributes
    createAndAddLabel("Input attributes", null, false);

    for (InputAttribute attr : InputAttribute.values()) {
        createAndAddLabel(attr.name().toLowerCase(), Modernizr.inputAttribute(attr), true);
    }

    // Input types
    createAndAddLabel("Input types", null, false);

    for (InputType type : InputType.values()) {
        createAndAddLabel(type.toString(), Modernizr.inputType(type), true);
    }

    // set durationTime
    int gwtModernizrTime = time.elapsedMillis() - labelCreationTime;
    duration.setHTML("<p>GWTModernizr took: " + gwtModernizrTime + "ms</p>");

}

From source file:com.google.gwt.modernizr.client.runtimesample.RuntimeSample.java

License:MIT License

private void createAndAddLabel(String test, Boolean testResult, boolean subTest) {
    Duration creationLabelDuration = new Duration();

    computeCounters(subTest);/* w  w w  .  jav a2  s . c  o  m*/

    String s = "" + testCounter + "." + (subTest ? "" + subTestCounter + " " : " ") + test + ": "
            + (testResult != null ? testResult : "");

    Label l = new Label(s);

    if (subTest) {
        l.addStyleName(Resources.css().subTest());
    }
    if (testResult == null) {
        l.addStyleName(Resources.css().black());
    } else if (testResult) {
        l.addStyleName(Resources.css().yes());
    }

    RootPanel.get().add(l);

    labelCreationTime += creationLabelDuration.elapsedMillis();

}

From source file:com.pronoiahealth.olhie.client.widgets.booklist3d.errai.BookList3D_3.java

License:Open Source License

/**
 * Create the list of books//from   ww w.j  a va2 s .  c om
 * 
 * @param books
 * @param appendToCurrent
 *            - If true append to the current books which will cause the
 *            jQuery attached events to be removed first, the books added to
 *            the current list and then the events attached again. If false,
 *            a new list will be created and the old one will be destroyed
 *            first.
 */
public void build(List<BookDisplay> books, boolean appendToCurrent) {
    Duration d = new Duration();
    consoleLog("************************ Start Book3d");
    if (books != null && books.size() > 0) {
        removeEventsFromLst();
        if (appendToCurrent == false) {
            detroyInstanceCreatedObjects();
            bliwMap.clear();
            clearPhysicalBookList();
        }

        // Add the list for books
        for (BookDisplay book : books) {
            BookListItemWidget bliw = bookListItemInst.get();
            String bookId = bliw.build(book);
            bookList.appendChild(bliw.getElement());
            bliwMap.put(bookId, bliw);
        }
        attachEventsToLst();
    }
    NumberFormat.getDecimalFormat().format(d.elapsedMillis());
    consoleLog("************************ Finished Book3d"
            + (NumberFormat.getDecimalFormat().format(d.elapsedMillis())));
}

From source file:com.ricbit.gibit.client.Gibit.java

License:Apache License

private void performQuery(final String query, final int page) {
    sendButton.setEnabled(false);//from ww w.j  a v a 2 s . c o m
    seriesPagination.setVisible(false);
    loadingPanel.setVisible(true);
    debug.setVisible(false);
    noMatchPanel.setVisible(false);
    duration = new Duration();
    searchService.searchServer(query, new AsyncCallback<SearchResponse>() {
        @Override
        public void onFailure(Throwable caught) {
            queryNotFound();
        }

        @Override
        public void onSuccess(SearchResponse results) {
            displayResults(results, query, page);
        }
    });
}

From source file:com.ui.gwt.performance.client.PerfTimer.java

License:Apache License

private PerfTimer(Object o, String methodName) {
    record = new PerfRecord(o.getClass().getName(), methodName);
    SpeedTracer.mark(record.toString() + ": start");
    duration = new Duration();
}