|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * SciJava Common shared library for SciJava software. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2009 - 2017 Board of Regents of the University of |
| 6 | + * Wisconsin-Madison, Broad Institute of MIT and Harvard, Max Planck |
| 7 | + * Institute of Molecular Cell Biology and Genetics, University of |
| 8 | + * Konstanz, and KNIME GmbH. |
| 9 | + * %% |
| 10 | + * Redistribution and use in source and binary forms, with or without |
| 11 | + * modification, are permitted provided that the following conditions are met: |
| 12 | + * |
| 13 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 14 | + * this list of conditions and the following disclaimer. |
| 15 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 16 | + * this list of conditions and the following disclaimer in the documentation |
| 17 | + * and/or other materials provided with the distribution. |
| 18 | + * |
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 23 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. |
| 30 | + * #L% |
| 31 | + */ |
| 32 | + |
| 33 | +package org.scijava.plugin; |
| 34 | + |
| 35 | +import java.lang.annotation.ElementType; |
| 36 | +import java.lang.annotation.Retention; |
| 37 | +import java.lang.annotation.RetentionPolicy; |
| 38 | +import java.lang.annotation.Target; |
| 39 | + |
| 40 | +import org.scijava.Priority; |
| 41 | +import org.scijava.UIDetails; |
| 42 | +import org.scijava.annotations.Indexable; |
| 43 | + |
| 44 | +/** |
| 45 | + * Annotation identifying a plugin, which gets loaded by SciJava's dynamic |
| 46 | + * discovery mechanism. |
| 47 | + * |
| 48 | + * @author Curtis Rueden |
| 49 | + * @see SciJavaPlugin |
| 50 | + * @see PluginService |
| 51 | + */ |
| 52 | +@Retention(RetentionPolicy.RUNTIME) |
| 53 | +@Target(ElementType.TYPE) |
| 54 | +@Indexable |
| 55 | +public @interface Plugin { |
| 56 | + |
| 57 | + /** @deprecated Use {@link UIDetails#APPLICATION_MENU_ROOT} instead. */ |
| 58 | + @Deprecated |
| 59 | + String APPLICATION_MENU_ROOT = "app"; |
| 60 | + |
| 61 | + /** |
| 62 | + * @deprecated Use a context-specific menu root string instead. This one is |
| 63 | + * too general. There is no such thing as a "default context menu" |
| 64 | + * since such a thing wouldn't be a context menu! |
| 65 | + */ |
| 66 | + @Deprecated |
| 67 | + String CONTEXT_MENU_ROOT = "context"; |
| 68 | + |
| 69 | + /** The type of plugin; e.g., {@link org.scijava.service.Service}. */ |
| 70 | + Class<? extends SciJavaPlugin> type(); |
| 71 | + |
| 72 | + /** The name of the plugin. */ |
| 73 | + String name() default ""; |
| 74 | + |
| 75 | + /** The human-readable label to use (e.g., in the menu structure). */ |
| 76 | + String label() default ""; |
| 77 | + |
| 78 | + /** A longer description of the plugin (e.g., for use as a tool tip). */ |
| 79 | + String description() default ""; |
| 80 | + |
| 81 | + /** |
| 82 | + * Abbreviated menu path defining where the plugin is shown in the menu |
| 83 | + * structure. Uses greater than signs ({@code >}) as a separator; e.g.: "Image |
| 84 | + * > Overlay > Properties..." defines a "Properties..." menu item within |
| 85 | + * the "Overlay" submenu of the "Image" menu. Use either {@link #menuPath} or |
| 86 | + * {@link #menu} but not both. |
| 87 | + */ |
| 88 | + String menuPath() default ""; |
| 89 | + |
| 90 | + /** |
| 91 | + * Full menu path defining where the plugin is shown in the menu structure. |
| 92 | + * This construction allows menus to be fully specified including mnemonics, |
| 93 | + * accelerators and icons. Use either {@link #menuPath} or {@link #menu} but |
| 94 | + * not both. |
| 95 | + */ |
| 96 | + Menu[] menu() default {}; |
| 97 | + |
| 98 | + /** |
| 99 | + * String identifier naming the menu to which this plugin belongs, or in the |
| 100 | + * case of a tool, the context menu that should be displayed while the tool is |
| 101 | + * active. The default value of {@link UIDetails#APPLICATION_MENU_ROOT} |
| 102 | + * references the menu structure of the primary application window. |
| 103 | + */ |
| 104 | + String menuRoot() default UIDetails.APPLICATION_MENU_ROOT; |
| 105 | + |
| 106 | + /** Path to the plugin's icon (e.g., shown in the menu structure). */ |
| 107 | + String iconPath() default ""; |
| 108 | + |
| 109 | + /** |
| 110 | + * The plugin index returns plugins sorted by priority. For example, this is |
| 111 | + * useful for {@link org.scijava.service.Service}s to control which service |
| 112 | + * implementation is chosen when multiple implementations are present in the |
| 113 | + * classpath, as well as to force instantiation of one service over another |
| 114 | + * when the dependency hierarchy does not dictate otherwise. |
| 115 | + * <p> |
| 116 | + * Any double value is allowed, but for convenience, there are some presets: |
| 117 | + * </p> |
| 118 | + * <ul> |
| 119 | + * <li>{@link Priority#FIRST}</li> |
| 120 | + * <li>{@link Priority#VERY_HIGH}</li> |
| 121 | + * <li>{@link Priority#HIGH}</li> |
| 122 | + * <li>{@link Priority#NORMAL}</li> |
| 123 | + * <li>{@link Priority#LOW}</li> |
| 124 | + * <li>{@link Priority#VERY_LOW}</li> |
| 125 | + * <li>{@link Priority#LAST}</li> |
| 126 | + * </ul> |
| 127 | + * |
| 128 | + * @see org.scijava.service.Service |
| 129 | + */ |
| 130 | + double priority() default Priority.NORMAL; |
| 131 | + |
| 132 | + /** |
| 133 | + * Whether the plugin can be selected in the user interface. A plugin's |
| 134 | + * selection state (if any) is typically rendered in the menu structure using |
| 135 | + * a checkbox or radio button menu item (see {@link #selectionGroup}). |
| 136 | + */ |
| 137 | + boolean selectable() default false; |
| 138 | + |
| 139 | + /** |
| 140 | + * For selectable plugins, specifies a name defining a group of linked |
| 141 | + * plugins, only one of which is selected at any given time. Typically this is |
| 142 | + * rendered in the menu structure as a group of radio button menu items. If no |
| 143 | + * group is given, the plugin is assumed to be a standalone toggle, and |
| 144 | + * typically rendered as a checkbox menu item. |
| 145 | + */ |
| 146 | + String selectionGroup() default ""; |
| 147 | + |
| 148 | + /** |
| 149 | + * When false, the plugin is grayed out in the user interface, if applicable. |
| 150 | + */ |
| 151 | + boolean enabled() default true; |
| 152 | + |
| 153 | + /** When false, the plugin is not displayed in the user interface. */ |
| 154 | + boolean visible() default true; |
| 155 | + |
| 156 | + /** |
| 157 | + * Provides a "hint" as to whether the plugin would behave correctly in a |
| 158 | + * headless context. |
| 159 | + * <p> |
| 160 | + * Plugin developers should not specify {@code headless = true} unless the |
| 161 | + * plugin refrains from using any UI-specific features (e.g., AWT or Swing |
| 162 | + * calls). |
| 163 | + * </p> |
| 164 | + * <p> |
| 165 | + * Of course, merely setting this flag does not guarantee that the plugin will |
| 166 | + * not invoke any headless-incompatible functionality, but it provides an |
| 167 | + * extra safety net for downstream headless code that wishes to be |
| 168 | + * conservative in which plugins it allows to execute. |
| 169 | + * </p> |
| 170 | + */ |
| 171 | + boolean headless() default false; |
| 172 | + |
| 173 | + /** Defines a function that is called to initialize the plugin in some way. */ |
| 174 | + String initializer() default ""; |
| 175 | + |
| 176 | + /** |
| 177 | + * A list of additional attributes which can be used to extend this annotation |
| 178 | + * beyond its built-in capabilities. |
| 179 | + * <p> |
| 180 | + * Note to developers: when designing new plugin types, it is tempting to use |
| 181 | + * this attribute to store additional information about each plugin. However, |
| 182 | + * we suggest doing so only if you need that additional information before |
| 183 | + * creating an instance of the plugin: e.g., to decide whether to instantiate |
| 184 | + * one, or even whether to load the annotated plugin class at all. If you are |
| 185 | + * going to create a plugin instance anyway, it is cleaner and more type-safe |
| 186 | + * to add proper API methods to the plugin type's interface reporting the same |
| 187 | + * information. |
| 188 | + * </p> |
| 189 | + */ |
| 190 | + Attr[] attrs() default {}; |
| 191 | + |
| 192 | +} |
0 commit comments