001/* 002 * Copyright 2012 GWT-Bootstrap 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.github.gwtbootstrap.client.ui.event; 017 018import com.google.gwt.dom.client.NativeEvent; 019import com.google.gwt.event.shared.GwtEvent; 020 021/** 022 * Represents an event that is fired when a widget is completely hidden. 023 * 024 * @author Dominik Mayer 025 * @author Danilo Reinert 026 * 027 * @see HideEvent 028 * @see ShowEvent 029 * @see ShownEvent 030 * 031 * @since 2.0.4.0 032 */ 033public class HiddenEvent extends GwtEvent<HiddenHandler> { 034 035 private static final Type<HiddenHandler> TYPE = new Type<HiddenHandler>(); 036 private final NativeEvent nativeEvent; 037 private final boolean autoHidden; 038 039 public static Type<HiddenHandler> getType() { 040 return TYPE; 041 } 042 043 public HiddenEvent() { 044 this(null, false); 045 } 046 047 public HiddenEvent(boolean autoHidden) { 048 this(null, autoHidden); 049 } 050 051 public HiddenEvent(NativeEvent nativeEvent) { 052 this(nativeEvent, false); 053 } 054 055 public HiddenEvent(NativeEvent nativeEvent, boolean autoHidden) { 056 this.nativeEvent = nativeEvent; 057 this.autoHidden = autoHidden; 058 } 059 060 @Override 061 public final Type<HiddenHandler> getAssociatedType() { 062 return TYPE; 063 } 064 065 @Override 066 protected void dispatch(HiddenHandler handler) { 067 handler.onHidden(this); 068 } 069 070 /** 071 * Prevents the browser from taking its default action for the given event. 072 */ 073 public final void preventDefault() { 074 075 if (nativeEvent == null) return; 076 077 nativeEvent.preventDefault(); 078 } 079 080 /** 081 * Stops the event from being propagated to parent elements. 082 */ 083 public final void stopPropagation() { 084 085 if (nativeEvent == null) return; 086 087 nativeEvent.stopPropagation(); 088 } 089 090 public boolean isAutoHidden() { 091 return autoHidden; 092 } 093}