All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gwt.advanced.client.util.GWTUtil Maven / Gradle / Ivy

There is a newer version: 2.0.9
Show newest version
/*
 * Copyright 2008-2012 Sergey Skladchikov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gwt.advanced.client.util;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.impl.DOMImpl;
import com.google.gwt.user.client.ui.Widget;

/**
 * This class contains helper methods for GWT framework.
 *
 * @author Sergey Skladchikov
 * @since 1.1.0
 */
public class GWTUtil {
    /**
     * This method checks whether the current browser is IE.
     *
     * @return true if the browser is IE.
     */
    public static boolean isIE() {
        return GWT.create(DOMImpl.class).getClass().getName().equals(
            "com.google.gwt.user.client.impl.DOMImplIE6"
        );
    }

    /**
     * This method checks whether the current browser is FF.
     *
     * @return true if the browser is FF.
     */
    public static boolean isFF() {
        String name = GWT.create(DOMImpl.class).getClass().getName();
        return name.equals("com.google.gwt.user.client.impl.DOMImplMozilla")
                || name.equals("com.google.gwt.user.client.impl.DOMImplMozillaOld");
    }

    /**
     * This method adjusts widget size to make it smaller then the parent element.

* Note that this element can be a value returne by widget.getParent().getElement() or * another container element like {@link org.gwt.advanced.client.ui.widget.AdvancedFlexTable#getBodyElement()}. * This method doesn't check whether it's really a parent. * * @param widget is a widget to be adjusted. * @param parent is a parent container element. * @param adjustHeight is a flag that specifies whether widget height must be adjusted. */ public static void adjustWidgetSize(Widget widget, Element parent, boolean adjustHeight) { adjustElementSize(widget.getElement(), parent, adjustHeight); } /** * This method adjusts widget size to make it smaller then the parent element.

* Note that this element can be a value returned by widget.getParent().getElement() or * another container element like {@link org.gwt.advanced.client.ui.widget.AdvancedFlexTable#getBodyElement()}. * This method doesn't check whether it's really a parent. * * @param element is an element which size must be adjusted. * @param parent is a parent container element. * @param adjustHeight is a flag that specifies whether widget height must be adjusted. */ public static void adjustElementSize(Element element, Element parent, boolean adjustHeight) { int originalHeight = DOM.getElementPropertyInt(parent, "clientHeight"); int originalWidth = DOM.getElementPropertyInt(parent, "clientWidth"); int height = originalHeight; int width = originalWidth; boolean completed; do { DOM.setStyleAttribute(element, "width", width + "px"); int widthNow = DOM.getElementPropertyInt(parent, "clientWidth"); completed = widthNow <= originalWidth; if (!completed) width = width + originalWidth - widthNow; if (adjustHeight) { DOM.setStyleAttribute(element, "height", height + "px"); int heightNow = DOM.getElementPropertyInt(parent, "clientHeight"); completed = completed && heightNow <= originalHeight; if (heightNow > originalHeight) height = height + originalHeight - heightNow; } } while (!completed); } /** * Prevents the event for all browsers. * * @param event is an event to prevent. */ public static void preventEvent(Event event) { event.preventDefault(); event.stopPropagation(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy