Example usage for com.google.gwt.dom.client Document getBody

List of usage examples for com.google.gwt.dom.client Document getBody

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Document getBody.

Prototype

public BodyElement getBody() 

Source Link

Usage

From source file:burrito.client.crud.widgets.FormattedRichTextArea.java

License:Apache License

@Override
protected void onAttach() {
    super.onAttach();

    Timer cssTimer = new Timer() {
        @Override// ww w  . j  a v a2 s .  c o m
        public void run() {
            Document doc = IFrameElement.as(getElement()).getContentDocument();
            StyleElement style = doc.createStyleElement();
            style.setInnerText(CSS);
            HeadElement.as(Element.as(doc.getBody().getPreviousSibling())).appendChild(style);
        }
    };

    cssTimer.schedule(100);
}

From source file:ch.unifr.pai.twice.widgets.mpbrowser.client.MPBrowser.java

License:Apache License

private void updateScrollBar() {
    Document d = IFrameElement.as(frame.getElement()).getContentDocument();
    boolean scrollVertical = d.getBody().getScrollHeight() > frame.getOffsetHeight();
    boolean scrollHorizontal = d.getBody().getScrollWidth() > frame.getOffsetWidth();
    scrollDown.setEnabled(scrollVertical);
    scrollUp.setEnabled(scrollVertical);
    scrollBar.getElement().getStyle().setBackgroundColor(scrollVertical ? "lightgrey" : "lightgrey");
}

From source file:ch.unifr.pai.twice.widgets.mpbrowser.client.MPBrowser.java

License:Apache License

private void updateScrollBar2() {
    Document d = IFrameElement.as(frame2.getElement()).getContentDocument();
    boolean scrollVertical = d.getBody().getScrollHeight() > frame2.getOffsetHeight();
    boolean scrollHorizontal = d.getBody().getScrollWidth() > frame2.getOffsetWidth();
    scrollDown2.setEnabled(scrollVertical);
    scrollUp2.setEnabled(scrollVertical);
    scrollBar2.getElement().getStyle().setBackgroundColor(scrollVertical ? "lightgrey" : "lightgrey");
}

From source file:com.bfr.client.selection.RangeEndPoint.java

License:Apache License

public static RangeEndPoint findLocation(Element element, int absX, int absY) {
    // Convert to document-relative coordinates
    Document doc = element.getOwnerDocument();
    int relX = absX - doc.getBodyOffsetLeft();
    int offY = getTotalOffsetY(doc);
    int relY = absY + offY;

    if (spn == null) {
        spn = doc.createSpanElement();/*from   w  ww.j  av  a  2  s. c o m*/
        spn.setInnerText("X");
    }
    Element body = doc.getBody();
    body.appendChild(spn);
    spn.getStyle().setPosition(Position.ABSOLUTE);
    spn.getStyle().setTop(relY, Unit.PX);
    spn.getStyle().setLeft(relX, Unit.PX);

    FindLocRes locRes = findLocation(doc, element, relX, relY);

    return (locRes == null) ? null : locRes.ep;
}

From source file:com.denormans.googleanalyticsgwt.api.GoogleAnalytics.java

License:Apache License

private static boolean injectAnalytics(@Nullable final String defaultTrackerID) {
    if (defaultTrackerID != null) {
        setupDefaultTrackerID(defaultTrackerID);
    }/* w  w w .j a v  a  2 s .  c o  m*/

    if (IsAlreadyInjected) {
        return true;
    }

    IsAlreadyInjected = true;

    boolean isAlreadyLoaded = get() != null;
    if (isAlreadyLoaded) {
        return true;
    }

    String src;
    if (isSSL()) {
        src = "https://ssl.google-analytics.com/ga.js";
    } else {
        src = "http://www.google-analytics.com/ga.js";
    }

    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc(src);
    script.setType("text/javascript");
    script.setAttribute("async", "true");

    doc.getBody().appendChild(script);

    return false;
}

From source file:com.github.gwtbootstrap.showcase.client.NonResShowcase.java

License:Apache License

public void onModuleLoad() {
    initWidget(uiBinder.createAndBindUi(this));
    // addSectionToContainer("Get Started", "setup", new Setup());
    // addSectionToContainer("Get Support", "support", new Support());
    addSectionToContainer("Buttons", "buttons", new Buttons());
    addSectionToContainer("Grid System", "gridSystem", new GridSystem());
    addSectionToContainer("Navigation", "navigation", new Navigation());
    addSectionToContainer("Hero Unit", "hero", new HeroUnit());
    addSectionToContainer("Forms", "forms", new Forms());
    addSectionToContainer("Page Header", "pageheader", new PageHeader());
    addSectionToContainer("Progress Bar", "progressbar", new ProgressBar());
    addSectionToContainer("Alerts", "alerts", new Alerts());
    addSectionToContainer("Pagination", "pagination", new Pagination());
    addSectionToContainer("Dropdown", "dropdown", new Dropdown());
    addSectionToContainer("Modal", "modal", new Modal());
    addSectionToContainer("Datepicker", "datepicker", new Datepicker());
    addSectionToContainer("Datetimepicker", "datetimepicker", new Datetimepicker());
    addSectionToContainer("Tooltip", "tooltip", new Tooltips());
    addSectionToContainer("Popover", "popover", new Popovers());
    addSectionToContainer("Icons", "icons", new Icons());

    RootPanel.get("content").add(this);
    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("https://apis.google.com/js/plusone.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);

    github_buttons.getElement().setInnerHTML(
            "<iframe src=\"http://markdotto.github.com/github-buttons/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=watch&count=true\"\n"
                    + "                                allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"110px\" height=\"20px\"></iframe>"
                    + "<br /><iframe src=\"http://markdotto.github.com/github-buttons/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=fork&count=true\"\n"
                    + "  allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"95px\" height=\"20px\"></iframe>");

    JavaScriptInjector.inject(/*from w w w.j  a v a  2s.  c o  m*/
            "!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");");
    JavaScriptInjector.inject(
            "(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1\";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));");

    Scheduler.get().scheduleFinally(new ScheduledCommand() {

        @Override
        public void execute() {
            History.fireCurrentHistoryState();
        }
    });
}

From source file:com.github.gwtbootstrap.showcase.client.Showcase.java

License:Apache License

public void onModuleLoad() {

    CustomResources res = GWT.create(CustomResources.class);
    res.showcase().ensureInjected();// w  ww.  j a v a  2s  .  com
    ClientFactory factory = GWT.create(ClientFactory.class);

    subnav = factory.getSubnav();

    initWidget(uiBinder.createAndBindUi(this));

    ActivityMapper activityMapper = new AppActivityMapper(factory);

    ActivityManager activityManager = new ActivityManager(activityMapper, factory.getEventBus());

    activityManager.setDisplay(main);
    PlaceHistoryMapper mapper = factory.getPlaceHistoryMapper();
    final PlaceHistoryHandler handler = new PlaceHistoryHandler(mapper);
    handler.register(factory.getPlaceController(), factory.getEventBus(), new OverviewPlace(""));

    final Map<Menus, NavLink> map = new EnumMap<Menus, NavLink>(Menus.class);
    for (Menus menu : Menus.values()) {
        NavLink link = new NavLink(menu.getDisplay());
        link.setHref("#" + menu.getName() + ":");

        if (menu == Menus.GWT) {
            nav.add(new Divider());
        }
        nav.add(link);

        map.put(menu, link);
    }

    factory.getEventBus().addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {

        @Override
        public void onPlaceChange(PlaceChangeEvent event) {
            Place place = event.getNewPlace();

            if (place instanceof HasMenuPlace) {
                HasMenuPlace menuPlace = (HasMenuPlace) place;

                for (Map.Entry<Menus, NavLink> entry : map.entrySet()) {
                    if (entry.getKey().equals(menuPlace.getMenu())) {
                        entry.getValue().setActive(true);
                    } else {
                        entry.getValue().setActive(false);
                    }
                }

            }
        }
    });

    // addSectionToContainer("Get Started", "setup", new Setup());
    // addSectionToContainer("Get Support", "support", new Support());
    // addSectionToContainer("Buttons", "buttons", new Buttons());
    // addSectionToContainer("Grid System", "gridSystem", new GridSystem());
    // addSectionToContainer("Navigation", "navigation", new Navigation());
    // addSectionToContainer("Hero Unit", "hero", new HeroUnit());
    // addSectionToContainer("Forms", "forms", new Forms());
    // addSectionToContainer("Page Header", "pageheader", new PageHeader());
    // addSectionToContainer("Progress Bar", "progressbar", new
    // ProgressBar());
    // addSectionToContainer("Alerts", "alerts", new Alerts());
    // addSectionToContainer("Pagination", "pagination", new Pagination());
    // addSectionToContainer("Dropdown", "dropdown", new Dropdown());
    // addSectionToContainer("Modal", "modal", new Modal());
    // addSectionToContainer("Datepicker", "datepicker", new Datepicker());
    // addSectionToContainer("Tooltip", "tooltip", new Tooltips());
    // addSectionToContainer("Popover", "popover", new Popovers());
    // addSectionToContainer("Icons", "icons", new Icons());

    RootPanel.get("content").add(this);
    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("https://apis.google.com/js/plusone.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);

    //        github_buttons
    //                .getElement()
    //                .setInnerHTML(
    //                        "<iframe src=\"http://ghbtns.com/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=watch&count=true\"\n"
    //                                + "                                allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"110px\" height=\"20px\"></iframe>"
    //                                + "<br /><iframe src=\"http://ghbtns.com/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=fork&count=true\"\n"
    //                                + "  allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"95px\" height=\"20px\"></iframe>");

    JavaScriptInjector.inject(
            "!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");");
    JavaScriptInjector.inject(
            "(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1\";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));");

    String token = History.getToken();
    if (!token.equals("")) {
        History.newItem("");
        History.newItem(token);
    }
}

From source file:com.google.gwt.examples.LayoutExample.java

License:Apache License

public void onModuleLoad() {
    // The following is a very simple example, which constructs a layout around
    // a parent element, and attaches two child elements that split their
    // parent's space vertically. It then goes on to animate from the first
    // state to a horizontal stacking that uses EM units rather than
    // percentages.
    Document doc = Document.get();
    Element parent = doc.createDivElement();
    doc.getBody().appendChild(parent);

    Layout layout = new Layout(parent);
    layout.onAttach();/*from   www .j a  v a  2 s.c  o m*/

    Element topChild = doc.createDivElement(), bottomChild = doc.createDivElement();
    Layer topLayer = layout.attachChild(topChild);
    Layer bottomLayer = layout.attachChild(bottomChild);

    // Stack the two children vertically, meeting at 50%.
    topLayer.setLeftRight(0, PX, 0, PX);
    bottomLayer.setLeftRight(0, PX, 0, PX);
    topLayer.setTopHeight(0, PCT, 50, PCT);
    bottomLayer.setBottomHeight(0, PCT, 50, PCT);
    layout.layout();

    // Update the two children to stack horizontally, meeting at 10em.
    // Also have them animate for 500ms.
    topLayer.setTopBottom(0, PX, 0, PX);
    bottomLayer.setTopBottom(0, PX, 0, PX);
    topLayer.setLeftWidth(0, EM, 10, EM);
    bottomLayer.setLeftRight(10, EM, 0, EM);
    layout.layout(500);
}

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

public TwitterPopup(Vendor vendor) {

    super(true);//  ww w .  j  av a 2s.c o m
    this.setStyleName("PopupPanel");

    int left = (Window.getClientWidth()) / 3;
    int top = (Window.getClientHeight()) / 2;
    this.setPopupPosition(left, top);

    String vendorName = null;
    try {
        vendorName = vendor.getName();
    } catch (Exception e) {

    }
    if ((vendorName == null) || (vendorName.equalsIgnoreCase("Name not available")))
        vendorName = "a street vendor";
    Label desc = new Label("You've added " + vendorName + " to your favourites list." + "\n"
            + "(Click outside the box to close)");
    mainPanel.add(desc);

    String url = "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-text=\"I just added "
            + vendorName + " to my list of favourite street vendors\" target=\"_blank\">Tweet</a>";
    HTML html = new HTML(url);

    mainPanel.add(html);

    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("http://platform.twitter.com/widgets.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);

    this.add(mainPanel);

}

From source file:com.google.speedtracer.client.view.HotKeyPanel.java

License:Apache License

private void show(Document document) {
    Element elem = createContentElement(document);
    populateContent(elem);/*from   w ww .  ja va 2  s .c  o m*/
    element = document.getBody().appendChild(elem);
}