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 immediately when a widget's 023 * <code>show()</code> method is called. 024 * 025 * @author Dominik Mayer 026 * @author Danilo Reinert 027 * 028 * @see ShownEvent 029 * @see HideEvent 030 * @see HiddenEvent 031 * 032 * @since 2.0.4.0 033 */ 034public class ShownEvent extends GwtEvent<ShownHandler> { 035 036 private static final Type<ShownHandler> TYPE = new Type<ShownHandler>(); 037 private final NativeEvent nativeEvent; 038 private final boolean autoShown; 039 040 public static Type<ShownHandler> getType() { 041 return TYPE; 042 } 043 044 public ShownEvent() { 045 this(null); 046 } 047 048 public ShownEvent(NativeEvent nativeEvent) { 049 this(nativeEvent, false); 050 } 051 052 public ShownEvent(boolean autoShown) { 053 this(null, autoShown); 054 } 055 056 public ShownEvent(NativeEvent nativeEvent, boolean autoShown) { 057 this.nativeEvent = nativeEvent; 058 this.autoShown = autoShown; 059 } 060 061 @Override 062 public final Type<ShownHandler> getAssociatedType() { 063 return TYPE; 064 } 065 066 @Override 067 protected void dispatch(ShownHandler handler) { 068 handler.onShown(this); 069 } 070 071 /** 072 * Prevents the browser from taking its default action for the given event. 073 */ 074 public final void preventDefault() { 075 076 if (nativeEvent == null) return; 077 078 nativeEvent.preventDefault(); 079 } 080 081 /** 082 * Stops the event from being propagated to parent elements. 083 */ 084 public final void stopPropagation() { 085 086 if (nativeEvent == null) return; 087 088 nativeEvent.stopPropagation(); 089 } 090 091 public boolean isAutoShown() { 092 return autoShown; 093 } 094}