001package org.gwtbootstrap3.extras.summernote.client.event; 002 003/* 004 * #%L 005 * GwtBootstrap3 006 * %% 007 * Copyright (C) 2015 GwtBootstrap3 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import com.google.gwt.dom.client.NativeEvent; 024import com.google.gwt.event.shared.GwtEvent; 025 026/** 027 * The {@link SummernoteKeyUpEvent} is fired when a key is released within 028 * the summernote editor. 029 * 030 * @author Xiaodong Sun 031 */ 032public class SummernoteKeyUpEvent extends GwtEvent<SummernoteKeyUpHandler> { 033 034 private static Type<SummernoteKeyUpHandler> TYPE; 035 036 private final NativeEvent nativeEvent; 037 038 /** 039 * Fires a summernote key up event on all registered handlers in the handler 040 * manager. If no such handlers exist, this method will do nothing. 041 * 042 * @param source the source of the handlers 043 * @param keyUpEvent native key up event 044 */ 045 public static void fire(final HasSummernoteKeyUpHandlers source, NativeEvent nativeEvent) { 046 if (TYPE != null) { 047 SummernoteKeyUpEvent event = new SummernoteKeyUpEvent(nativeEvent); 048 source.fireEvent(event); 049 } 050 } 051 052 /** 053 * Gets the type associated with this event. 054 * 055 * @return returns the handler type 056 */ 057 public static Type<SummernoteKeyUpHandler> getType() { 058 if (TYPE == null) { 059 TYPE = new Type<SummernoteKeyUpHandler>(); 060 } 061 return TYPE; 062 } 063 064 @Override 065 public Type<SummernoteKeyUpHandler> getAssociatedType() { 066 return TYPE; 067 } 068 069 @Override 070 public String toDebugString() { 071 return super.toDebugString() + " key code is: " + nativeEvent.getKeyCode(); 072 } 073 074 /** 075 * Returns the native key up event. 076 * 077 * @return native key up event 078 */ 079 public NativeEvent getNativeEvent() { 080 return nativeEvent; 081 } 082 083 @Override 084 protected void dispatch(final SummernoteKeyUpHandler handler) { 085 handler.onSummernoteKeyUp(this); 086 } 087 088 /** 089 * Creates a summernote key up event. 090 * 091 * @param nativeEvent native key up event 092 */ 093 protected SummernoteKeyUpEvent(NativeEvent nativeEvent) { 094 this.nativeEvent = nativeEvent; 095 } 096}