Example usage for com.google.gwt.layout.client Layout getUnitSize

List of usage examples for com.google.gwt.layout.client Layout getUnitSize

Introduction

In this page you can find the example usage for com.google.gwt.layout.client Layout getUnitSize.

Prototype

public double getUnitSize(Unit unit, boolean vertical) 

Source Link

Document

Returns the size of one unit, in pixels, in the context of this layout.

Usage

From source file:com.kk_electronic.kkportal.core.ui.GroupDisplay.java

License:Open Source License

public void setWidgets(List<List<T>> widgets) {
    if (canvas.isAttached() == false) {
        return;//from ww  w .j  a  v a2 s.c  om
    }
    if (widgets == null) {
        canvas.clear();
        displayed.clear();
        return;
    }
    HashSet<Widget> needRemoval = new HashSet<Widget>(displayed);

    Layout l = iHateJavaProtection(canvas);

    double x = margin * l.getUnitSize(marginunit, false) / l.getUnitSize(Unit.PCT, false);
    double y = margin * l.getUnitSize(marginunit, true);

    double left = x;
    for (List<T> column : widgets) {
        double top = y;
        //TODO: Support weighted column sizes
        double width = (100.0 - x) / widgets.size() - x;
        for (final T face : column) {
            final Widget widget = face.asWidget();
            int height = face.getDesiredHeight();
            if (!displayed.contains(widget)) {
                canvas.add(widget);
                canvas.getWidgetContainerElement(widget).getStyle().clearOverflow();
                displayed.add(widget);
                face.getDragHandle().addMouseDownHandler(new MouseDownHandler() {

                    @Override
                    public void onMouseDown(MouseDownEvent event) {
                        dnd.startDrag(event, face);
                    }
                });
            }
            canvas.setWidgetLeftWidth(widget, left, Unit.PCT, width, Unit.PCT);
            canvas.setWidgetTopHeight(widget, top, Unit.PX, height, Unit.PX);
            top += height + y;
            needRemoval.remove(face);
        }
        left += width + x;
    }
    for (Widget toRemove : needRemoval) {
        canvas.remove(toRemove);
        displayed.remove(toRemove);
        //TODO:remove handler
    }
    canvas.animate(150);
}