001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.client.ui; 029 030import org.opencms.gwt.client.util.CmsDomUtil; 031 032import com.google.gwt.dom.client.Element; 033import com.google.gwt.event.dom.client.HasAllMouseHandlers; 034import com.google.gwt.event.dom.client.MouseDownEvent; 035import com.google.gwt.event.dom.client.MouseDownHandler; 036import com.google.gwt.event.dom.client.MouseMoveEvent; 037import com.google.gwt.event.dom.client.MouseMoveHandler; 038import com.google.gwt.event.dom.client.MouseOutEvent; 039import com.google.gwt.event.dom.client.MouseOutHandler; 040import com.google.gwt.event.dom.client.MouseOverEvent; 041import com.google.gwt.event.dom.client.MouseOverHandler; 042import com.google.gwt.event.dom.client.MouseUpEvent; 043import com.google.gwt.event.dom.client.MouseUpHandler; 044import com.google.gwt.event.dom.client.MouseWheelEvent; 045import com.google.gwt.event.dom.client.MouseWheelHandler; 046import com.google.gwt.event.shared.HandlerRegistration; 047import com.google.gwt.uibinder.client.UiConstructor; 048import com.google.gwt.user.client.DOM; 049import com.google.gwt.user.client.ui.ComplexPanel; 050import com.google.gwt.user.client.ui.Widget; 051 052/** 053 * A basic panel which is like GWT's FlowPanel, except it allows you to choose the HTML tag 054 * to use.<p> 055 * Implements {@link com.google.gwt.event.dom.client.HasAllMouseHandlers}.<p> 056 * 057 * @since 8.0.0 058 */ 059public class CmsFlowPanel extends ComplexPanel implements HasAllMouseHandlers { 060 061 /** 062 * Default constructor.<p> 063 */ 064 public CmsFlowPanel() { 065 066 this(CmsDomUtil.Tag.div.name()); 067 } 068 069 /** 070 * Wrapping constructor.<p> 071 * 072 * @param element the element to wrap 073 */ 074 public CmsFlowPanel(Element element) { 075 076 element.removeFromParent(); 077 setElement(element); 078 } 079 080 /** 081 * Creates an empty flow panel with a given tag name. 082 * 083 * @param tag the HTML tag name to use 084 */ 085 @UiConstructor 086 public CmsFlowPanel(String tag) { 087 088 setElement((Element)DOM.createElement(tag)); 089 } 090 091 /** 092 * Adds a new child widget to the panel. 093 * 094 * @param w the widget to be added 095 */ 096 @Override 097 public void add(Widget w) { 098 099 super.add(w, (Element)getElement()); 100 } 101 102 /** 103 * @see com.google.gwt.event.dom.client.HasMouseDownHandlers#addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler) 104 */ 105 public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) { 106 107 return addDomHandler(handler, MouseDownEvent.getType()); 108 } 109 110 /** 111 * @see com.google.gwt.event.dom.client.HasMouseMoveHandlers#addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler) 112 */ 113 public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) { 114 115 return addDomHandler(handler, MouseMoveEvent.getType()); 116 } 117 118 /** 119 * @see com.google.gwt.event.dom.client.HasMouseOutHandlers#addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) 120 */ 121 public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) { 122 123 return addDomHandler(handler, MouseOutEvent.getType()); 124 } 125 126 /** 127 * @see com.google.gwt.event.dom.client.HasMouseOverHandlers#addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler) 128 */ 129 public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) { 130 131 return addDomHandler(handler, MouseOverEvent.getType()); 132 } 133 134 /** 135 * @see com.google.gwt.event.dom.client.HasMouseUpHandlers#addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) 136 */ 137 public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) { 138 139 return addDomHandler(handler, MouseUpEvent.getType()); 140 } 141 142 /** 143 * @see com.google.gwt.event.dom.client.HasMouseWheelHandlers#addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) 144 */ 145 public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) { 146 147 return addDomHandler(handler, MouseWheelEvent.getType()); 148 } 149 150 /** 151 * Inserts a widget at a given position.<p> 152 * 153 * @param w the widget to insert 154 * @param beforeIndex the position before which the widget should be inserted 155 */ 156 public void insert(Widget w, int beforeIndex) { 157 158 insert(w, (Element)getElement(), beforeIndex, true); 159 } 160 161}