1 /* 2 * PanmirrorOutlineVisibleEvent.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 package org.rstudio.studio.client.panmirror.events; 17 18 import com.google.gwt.event.shared.EventHandler; 19 import com.google.gwt.event.shared.GwtEvent; 20 import com.google.gwt.event.shared.HandlerRegistration; 21 import com.google.gwt.event.shared.HasHandlers; 22 23 /** 24 * Represents an outline visible event 25 */ 26 public class PanmirrorOutlineVisibleEvent extends 27 GwtEvent<PanmirrorOutlineVisibleEvent.Handler> { 28 29 /** 30 * Handler interface for {@link PanmirrorOutlineVisibleEvent} events. 31 */ 32 public static interface Handler extends EventHandler { 33 34 /** 35 * Called when a {@link PanmirrorOutlineVisibleEvent} is fired. 36 * 37 * @param event the {@link PanmirrorOutlineVisibleEvent} that was fired 38 */ onPanmirrorOutlineVisible(PanmirrorOutlineVisibleEvent event)39 void onPanmirrorOutlineVisible(PanmirrorOutlineVisibleEvent event); 40 } 41 42 /** 43 * Interface specifying that a class can add 44 * {@code PanmirrorOutlineVisibleEvent.Handler}s. 45 */ 46 public interface HasPanmirrorOutlineVisibleHandlers extends HasHandlers { 47 /** 48 * Adds a {@link PanmirrorOutlineVisibleEvent} handler. 49 * 50 * @param handler the handler 51 * @return {@link HandlerRegistration} used to remove this handler 52 */ addPanmirrorOutlineVisibleHandler(Handler handler)53 HandlerRegistration addPanmirrorOutlineVisibleHandler(Handler handler); 54 } 55 56 /** 57 * Handler type. 58 */ 59 private static Type<PanmirrorOutlineVisibleEvent.Handler> TYPE; 60 61 /** 62 * Fires an navigation event on all registered handlers in the handler 63 * manager. If no such handlers exist, this method will do nothing. 64 * 65 * @param source the source of the handlers 66 */ fire(HasPanmirrorOutlineVisibleHandlers source, boolean visible)67 public static void fire(HasPanmirrorOutlineVisibleHandlers source, boolean visible) { 68 if (TYPE != null) { 69 PanmirrorOutlineVisibleEvent event = new PanmirrorOutlineVisibleEvent(visible); 70 source.fireEvent(event); 71 } 72 } 73 74 /** 75 * Gets the type associated with this event. 76 * 77 * @return returns the handler type 78 */ getType()79 public static Type<PanmirrorOutlineVisibleEvent.Handler> getType() { 80 if (TYPE == null) { 81 TYPE = new Type<>(); 82 } 83 return TYPE; 84 } 85 86 /** 87 * Creates an navigation event. 88 */ PanmirrorOutlineVisibleEvent(boolean visible)89 PanmirrorOutlineVisibleEvent(boolean visible) { 90 visible_ = visible; 91 } 92 getVisible()93 public Boolean getVisible() 94 { 95 return visible_; 96 } 97 98 @Override getAssociatedType()99 public final Type<PanmirrorOutlineVisibleEvent.Handler> getAssociatedType() { 100 return TYPE; 101 } 102 103 @Override dispatch(PanmirrorOutlineVisibleEvent.Handler handler)104 protected void dispatch(PanmirrorOutlineVisibleEvent.Handler handler) { 105 handler.onPanmirrorOutlineVisible(this); 106 } 107 108 private final boolean visible_; 109 } 110