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

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

Introduction

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

Prototype

public DivElement createDivElement() 

Source Link

Usage

From source file:com.google.appinventor.client.editor.simple.components.MockForm.java

License:Open Source License

private static int getVerticalScrollbarWidth() {
    // We only calculate the vertical scroll bar width once, then we store it in the static field
    // verticalScrollbarWidth. If the field is non-zero, we don't need to calculate it again.
    if (verticalScrollbarWidth == 0) {
        // The following code will calculate (on the fly) the width of a vertical scroll bar.
        // We'll create two divs, one inside the other and add the outer div to the document body,
        // but off-screen where the user won't see it.
        // We'll measure the width of the inner div twice: (first) when the outer div's vertical
        // scrollbar is hidden and (second) when the outer div's vertical scrollbar is visible.
        // The width of inner div will be smaller when outer div's vertical scrollbar is visible.
        // By subtracting the two measurements, we can calculate the width of the vertical scrollbar.

        // I used code from the following websites as reference material:
        // http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php
        // http://www.fleegix.org/articles/2006-05-30-getting-the-scrollbar-width-in-pixels

        Document document = Document.get();

        // Create an outer div.
        DivElement outerDiv = document.createDivElement();
        Style outerDivStyle = outerDiv.getStyle();
        // Use absolute positioning and set the top/left so that it is off-screen.
        // We don't want the user to see anything while we do this calculation.
        outerDivStyle.setProperty("position", "absolute");
        outerDivStyle.setProperty("top", "-1000px");
        outerDivStyle.setProperty("left", "-1000px");
        // Set the width and height of the outer div to a fixed size in pixels.
        outerDivStyle.setProperty("width", "100px");
        outerDivStyle.setProperty("height", "50px");
        // Hide the outer div's scrollbar by setting the "overflow" property to "hidden".
        outerDivStyle.setProperty("overflow", "hidden");

        // Create an inner div and put it inside the outer div.
        DivElement innerDiv = document.createDivElement();
        Style innerDivStyle = innerDiv.getStyle();
        // Set the height of the inner div to be 4 times the height of the outer div so that a
        // vertical scrollbar will be necessary (but hidden for now) on the outer div.
        innerDivStyle.setProperty("height", "200px");
        outerDiv.appendChild(innerDiv);//ww w .  ja  va  2  s .c  o m

        // Temporarily add the outer div to the document body. It's off-screen so the user won't
        // actually see anything.
        Element bodyElement = document.getElementsByTagName("body").getItem(0);
        bodyElement.appendChild(outerDiv);

        // Get the width of the inner div while the outer div's vertical scrollbar is hidden.
        int widthWithoutScrollbar = innerDiv.getOffsetWidth();
        // Show the outer div's vertical scrollbar by setting the "overflow" property to "auto".
        outerDivStyle.setProperty("overflow", "auto");
        // Now, get the width of the inner div while the vertical scrollbar is visible.
        int widthWithScrollbar = innerDiv.getOffsetWidth();

        // Remove the outer div from the document body.
        bodyElement.removeChild(outerDiv);

        // Calculate the width of the vertical scrollbar by subtracting the two widths.
        verticalScrollbarWidth = widthWithoutScrollbar - widthWithScrollbar;
    }

    return verticalScrollbarWidth;
}

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);/*  ww  w .j  av  a  2 s  .c  o m*/

    Layout layout = new Layout(parent);
    layout.onAttach();

    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.livingstories.client.lsp.views.contentitems.BaseAssetPopupView.java

License:Apache License

protected Widget getContent(AssetContentItem contentItem) {
    // Add the content
    HTML contentHTML = new HTML(contentItem.getContent());
    // So that lightbox centering in firefox works, enclose each sized <object>
    // with a div styled to exactly that size.
    NodeList<Element> objectElements = contentHTML.getElement().getElementsByTagName("object");
    Document document = Document.get();
    for (int i = 0, len = objectElements.getLength(); i < len; i++) {
        Element objectElement = objectElements.getItem(i);
        String width = objectElement.getAttribute("width");
        String height = objectElement.getAttribute("height");
        if (width.matches("[0-9]+%?") && height.matches("[0-9]+%?")) {
            DivElement div = document.createDivElement();
            div.getStyle().setProperty("width", width + (width.endsWith("%") ? "" : "px"));
            div.getStyle().setProperty("height", height + (height.endsWith("%") ? "" : "px"));
            objectElement.getParentElement().replaceChild(div, objectElement);
            div.appendChild(objectElement);
        }// w w  w  .j  a va 2s  .  c o m
    }
    // In case there are images within the content, we should fire a PopupImageLoadedEvent
    // so that any popup window displaying this view has a chance to reposition itself.
    NodeList<Element> imageElements = contentHTML.getElement().getElementsByTagName("img");
    for (int i = 0; i < imageElements.getLength(); i++) {
        ImageElement image = imageElements.getItem(i).cast();
        addImageLoadHandler(image);
    }
    return contentHTML;
}

From source file:com.google.speedtracer.client.SourceViewer.java

License:Apache License

/**
 * Creates an instance of the SourceViewer and invokes the passed in callback
 * when the iFrame is loaded with the target source.
 * /*w w w .j a v a2s.c  o m*/
 * We first load the proxy html page. This proxy page uses cross site XHR
 * enabled by Chrome extensions to fetch and format the target source. Once
 * the target source is loaded, we consider the viewer initialized.
 * 
 * @param parent the parent container element we will attach the SourceViewer
 *          to.
 * @param resources the ClientBundle instance for this class.
 * @param initializedCallback the {@link SourceViewerInitializedCallback} that
 *          we pass the loaded SourceViewer to.
 */
public static void create(Element parent, final Resources resources,
        final SourceViewerInitializedCallback initializedCallback) {
    Document document = parent.getOwnerDocument();
    // Create the iframe within which we will load the source.
    final IFrameElement sourceFrame = document.createIFrameElement();
    Element frameWrapper = document.createDivElement();
    frameWrapper.setClassName(resources.sourceViewerCss().frameWrapper());
    frameWrapper.appendChild(sourceFrame);

    final Element baseElement = document.createDivElement();
    final Element headerElem = document.createDivElement();
    headerElem.setClassName(resources.sourceViewerCss().header());
    baseElement.appendChild(headerElem);

    // IFrame must be attached to fire onload.
    baseElement.appendChild(frameWrapper);
    parent.appendChild(baseElement);
    Event.addEventListener("load", sourceFrame, new EventListener() {
        public void handleEvent(Event event) {
            // The source fetcher should be loaded. Lets now point it at the source
            // we want to load.
            SourceViewer sourceViewer = new SourceViewer(baseElement, headerElem, sourceFrame, resources);
            initializedCallback.onSourceViewerInitialized(sourceViewer);
        }
    });

    sourceFrame.setSrc(Chrome.getExtension().getUrl("monitor/SourceFetcher.html"));
}

From source file:com.google.speedtracer.client.SourceViewer.java

License:Apache License

protected SourceViewer(Element myElement, Element headerElem, IFrameElement sourceFrame, Resources resources) {
    this.element = myElement;
    this.sourceFrame = sourceFrame;
    this.styles = resources.sourceViewerCodeCss();
    this.element.setClassName(resources.sourceViewerCss().base());

    // Create the title element and the close link.
    Document document = myElement.getOwnerDocument();
    this.titleElement = document.createDivElement();
    titleElement.setClassName(resources.sourceViewerCss().titleText());
    AnchorElement closeLink = document.createAnchorElement();
    closeLink.setClassName(resources.sourceViewerCss().closeLink());
    closeLink.setHref("javascript:;");
    closeLink.setInnerText("Close");
    headerElem.appendChild(titleElement);
    headerElem.appendChild(closeLink);/*www.j  a va  2s  . c  o  m*/

    this.columnMarker = document.createSpanElement();

    // TODO(jaimeyap): I guess this listener is going to leak.
    ClickEvent.addClickListener(closeLink, closeLink, new ClickListener() {
        public void onClick(ClickEvent event) {
            hide();
        }
    });

    injectStyles(sourceFrame, this.styles.getText());
}

From source file:com.google.speedtracer.client.visualizations.view.RequestDetails.java

License:Apache License

private static Element createSectionHeader(Css css, Document document, String text) {
    final DivElement header = document.createDivElement();
    header.setClassName(css.sectionHeader());
    header.setInnerHTML(text);/*from   ww w  .  j  a v a2 s  .c o m*/
    return header;
}

From source file:com.google.speedtracer.client.visualizations.view.RequestDetails.java

License:Apache License

private static void maybeAddSpringInsightLinks(ServerEvent event, Css css, Element parent) {
    final ServerEvent.Data data = event.getServerEventData();
    final String applicationUrl = data.getApplicationUrl();
    final String endPointUrl = data.getEndPointUrl();
    final String traceViewUrl = data.getTraceViewUrl();
    if (applicationUrl == null && endPointUrl == null && traceViewUrl == null) {
        return;//  w w  w.  j  ava 2 s .c om
    }

    final Document document = parent.getOwnerDocument();
    final DivElement element = document.createDivElement();
    element.setClassName(css.springInsightViews());
    element.setInnerText("Spring Insight Views: ");

    element.appendChild(document.createTextNode("("));

    // Add Trace URL
    if (traceViewUrl != null) {
        element.appendChild(createNewTabLink(document, css.springInsightLink(), traceViewUrl, "Trace"));
    }

    // Add EndPoint URL
    if (endPointUrl != null) {
        // Is there a previous item?
        if (traceViewUrl != null) {
            element.appendChild(document.createTextNode(", "));
        }
        element.appendChild(createNewTabLink(document, css.springInsightLink(), endPointUrl, "EndPoint"));
    }

    // Add Application URL
    if (applicationUrl != null) {
        // Is there a previous item?
        if (traceViewUrl != null || endPointUrl != null) {
            element.appendChild(document.createTextNode(", "));
        }
        element.appendChild(createNewTabLink(document, css.springInsightLink(), applicationUrl, "Application"));
    }

    element.appendChild(document.createTextNode(") "));
    parent.appendChild(element);
}

From source file:com.google.speedtracer.client.visualizations.view.RequestDetails.java

License:Apache License

private void maybeShowServerEvents(final Element parent, final Element insertAfter, final Css css,
        final Document document) {
    if (!info.hasServerTraceUrl()) {
        return;/*from  ww w  .  j av a2s . c  o m*/
    }

    final String traceUrl = info.getServerTraceUrl();

    // TODO(knorton): When playing back from a dump, we do not want to try to
    // fetch the server-side trace.
    serverEventController.requestTraceFor(info, new ServerEventController.RequestTraceCallback() {
        public void onFailure() {
            if (ClientConfig.isDebugMode()) {
                Logging.getLogger().logText("Failed to fetch server trace: " + traceUrl);
            }
        }

        public void onSuccess(ServerEvent event) {
            // insertBefore may be null, in which case Element.insertBefore will
            // append.
            final Element insertBefore = insertAfter.getNextSiblingElement();

            parent.insertBefore(createSectionHeader(css, document, "Server Trace"), insertBefore);

            final DivElement container = document.createDivElement();
            container.setClassName(css.serverTraceTree());
            parent.insertBefore(container, insertBefore);

            // TODO(knorton): Spring Insight specific functionality that needs
            // to be better generalized.
            maybeAddSpringInsightLinks(event, css, container);

            final LazyEventTree.Resources treeResources = GWT.create(LazyEventTree.Resources.class);
            final ServerEventTreeController controller = new ServerEventTreeController();

            final LazyEventTree tree = new LazyEventTree(new DefaultContainerImpl(container), controller, event,
                    new EventTraceBreakdown(event, controller, treeResources), treeResources);
            tree.addSelectionChangeListener(controller);
            tree.addExpansionChangeListener(controller);
            fixHeightOfParentRow();
        }
    });
}

From source file:com.googlecode.gwtquake.client.GwtQuake.java

License:Open Source License

public void onModuleLoad() {
    // Initialize drivers.
    Document doc = Document.get();
    doc.setTitle("GWT Quake II");
    BodyElement body = doc.getBody();//from  www.  ja  va2s . co m
    Style style = body.getStyle();
    style.setPadding(0, Unit.PX);
    style.setMargin(0, Unit.PX);
    style.setBorderWidth(0, Unit.PX);
    style.setProperty("height", "100%");
    style.setBackgroundColor("#000");
    style.setColor("#888");

    //   Window.alert("UA: " + userAgent+ " type: " + browserType);

    boolean wireframe = ("" + Window.Location.getHash()).indexOf("wireframe") != -1;

    canvas = (CanvasElement) doc.createElement("canvas");
    video = doc.createElement("video");

    w = Window.getClientWidth();
    h = Window.getClientHeight();
    canvas.setWidth(w);
    canvas.setHeight(h);
    style = canvas.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");

    style = video.getStyle();
    style.setProperty("height", "100%");
    style.setProperty("width", "100%");
    style.setProperty("display", "none");

    body.appendChild(canvas);
    body.appendChild(video);

    try {
        Globals.autojoin.value = Window.Location.getHash().indexOf("autojoin") != -1 ? 1.0f : 0.0f;
        final Renderer renderer = wireframe ? new GwtWireframeGLRenderer(canvas)
                : new GwtWebGLRenderer(canvas, video);
        Globals.re = renderer;

        ResourceLoader.impl = new GwtResourceLoaderImpl();
        Compatibility.impl = new CompatibilityImpl();

        Sound.impl = new GwtSound();
        NET.socketFactory = new WebSocketFactoryImpl();
        //      Sys.impl = new Sys.SysImpl() {
        //        public void exit(int status) {
        //          Window.alert("Something's rotten in Denmark");
        //          Window.Location.assign("gameover.html");
        //        }
        //      };

        // Flags.
        QuakeCommon.Init(new String[] { "GQuake" });

        // Enable stdout.
        Globals.nostdout = ConsoleVariables.Get("nostdout", "0", 0);

        Window.addResizeHandler(new ResizeHandler() {

            public void onResize(ResizeEvent event) {
                if (Window.getClientWidth() == w && Window.getClientHeight() == h) {
                    return;
                }

                w = Window.getClientWidth();
                h = Window.getClientHeight();

                renderer.GLimp_SetMode(new Dimension(w, h), 0, false);
            }
        });

        //      QuakeServer.main(new String[0], new DummySNetImpl(), false);

        timer = new Timer() {
            double startTime = Duration.currentTimeMillis();

            @Override
            public void run() {
                try {
                    double curTime = Duration.currentTimeMillis();
                    boolean pumping = ResourceLoader.Pump();
                    if (pumping) {
                        Screen.UpdateScreen2();
                    } else {
                        int dt = (int) (curTime - startTime);
                        GwtKBD.Frame(dt);
                        QuakeCommon.Frame(dt);
                    }
                    startTime = curTime;
                    timer.schedule(ResourceLoader.Pump() ? LOADING_DELAY : INTER_FRAME_DELAY);
                } catch (Exception e) {
                    Compatibility.printStackTrace(e);
                }
            }
        };
        timer.schedule(INTER_FRAME_DELAY);
    } catch (Exception e) {
        Compatibility.printStackTrace(e);
        DivElement div = doc.createDivElement();
        div.setInnerHTML(NO_WEBGL_MESSAGE);
        body.appendChild(div);
    }
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.VDragCaptionProvider.java

License:Apache License

public Element getDragCaptionElement(Widget w) {
    ComponentConnector component = Util.findConnectorFor(w);
    DDLayoutState state = ((DragAndDropAwareState) root.getState()).getDragAndDropState();
    DragCaptionInfo dci = state.dragCaptions.get(component);

    Document document = Document.get();

    Element dragCaptionImage = document.createDivElement();
    Element dragCaption = document.createSpanElement();

    String dragCaptionText = dci.caption;
    if (dragCaptionText != null) {
        if (dci.contentMode == ContentMode.TEXT) {
            dragCaption.setInnerText(dragCaptionText);
        } else if (dci.contentMode == ContentMode.HTML) {
            dragCaption.setInnerHTML(dragCaptionText);
        } else if (dci.contentMode == ContentMode.PREFORMATTED) {
            PreElement preElement = document.createPreElement();
            preElement.setInnerText(dragCaptionText);
            dragCaption.appendChild(preElement);
        }/*from  w  ww  . ja  v  a  2 s .co  m*/
    }

    String dragIconKey = state.dragCaptions.get(component).iconKey;
    if (dragIconKey != null) {
        String resourceUrl = root.getResourceUrl(dragIconKey);
        Icon icon = component.getConnection().getIcon(resourceUrl);
        dragCaptionImage.appendChild(icon.getElement());
    }

    dragCaptionImage.appendChild(dragCaption);

    return dragCaptionImage;
}