/******************************************************************************* * This file is part of OpenNMS(R). * * Copyright (C) 2010-2011 The OpenNMS Group, Inc. * OpenNMS(R) is Copyright (C) 1999-2011 The OpenNMS Group, Inc. * * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. * * OpenNMS(R) is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * OpenNMS(R) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with OpenNMS(R). If not, see: * http://www.gnu.org/licenses/ * * For more information contact: * OpenNMS(R) Licensing <license@opennms.org> * http://www.opennms.org/ * http://www.opennms.com/ *******************************************************************************/ package org.opennms.features.dashboard.client.dnd; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.allen_sauer.gwt.dnd.client.DragContext; import com.allen_sauer.gwt.dnd.client.drop.AbstractInsertPanelDropController; import com.allen_sauer.gwt.dnd.client.util.DOMUtil; import com.allen_sauer.gwt.dnd.client.util.DragClientBundle; import com.allen_sauer.gwt.dnd.client.util.LocationWidgetComparator; /** * A {@link DropController} for instances of {@link HorizontalPanel}. * author: Tharindu Munasinghe (tharindumunasinghe@gmail.com) * org.opennms.features.dashboard */ public class HorizontalPanelDropController extends AbstractInsertPanelDropController { /** * Label for IE quirks mode workaround. */ private static final Label DUMMY_LABEL_IE_QUIRKS_MODE_OFFSET_HEIGHT = new Label("x"); /** * Construct an {@link HorizontalPanelDropController}. * * @param dropTarget the {@link HorizontalPanel} drop target */ public HorizontalPanelDropController(HorizontalPanel dropTarget) { super(dropTarget); } @Override protected LocationWidgetComparator getLocationWidgetComparator() { return LocationWidgetComparator.RIGHT_HALF_COMPARATOR; } @Override protected Widget newPositioner(DragContext context) { // Use two widgets so that setPixelSize() consistently affects dimensions // excluding positioner border in quirks and strict modes SimplePanel outer = new SimplePanel(); outer.addStyleName(DragClientBundle.INSTANCE.css().positioner()); // place off screen for border calculation RootPanel.get().add(outer, -500, -500); // Ensure IE quirks mode returns valid outer.offsetHeight, and thus valid // DOMUtil.getVerticalBorders(outer) outer.setWidget(DUMMY_LABEL_IE_QUIRKS_MODE_OFFSET_HEIGHT); int width = 0; int height = 0; for (Widget widget : context.selectedWidgets) { width += widget.getOffsetWidth(); height = Math.max(height, widget.getOffsetHeight()); } SimplePanel inner = new SimplePanel(); inner.setPixelSize(width - DOMUtil.getHorizontalBorders(outer), height - DOMUtil.getVerticalBorders(outer)); outer.setWidget(inner); return outer; } }