001/* 002 * Copyright 2010, 2011 Institut Pasteur. 003 * 004 * This file is part of ICY. 005 * 006 * ICY is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * ICY is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with ICY. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package plugins.tutorial; 020 021import icy.plugin.PluginDescriptor; 022import icy.plugin.PluginLauncher; 023import icy.plugin.PluginLoader; 024import icy.plugin.abstract_.PluginActionable; 025import icy.system.thread.ThreadUtil; 026import plugins.tutorial.gui.GuiBuildExample01; 027 028/** 029 * This tutorial shows how to start a plugin from a plugin. <br> 030 * We use an invoke later to create the plugin in the graphic thread. Plugin which support starting 031 * as thread don't need this. 032 * 033 * @author Fabrice de Chaumont 034 */ 035public class StartAPluginFromAPlugin extends PluginActionable 036{ 037 @Override 038 public void run() 039 { 040 041 System.out.println("Plugin list:"); 042 System.out.println("============"); 043 044 // we get all the PluginDescriptor from the PluginManager 045 for (final PluginDescriptor pluginDescriptor : PluginLoader.getPlugins()) 046 { 047 System.out.print(pluginDescriptor.getSimpleClassName()); // output the name of the 048 // class. 049 050 // This part of the example check for a match in the name of the class 051 if (pluginDescriptor.getSimpleClassName().compareToIgnoreCase("PluginWithPanel") == 0) 052 { 053 System.out.print(" ==> Starting by looking at the name...."); 054 055 // Create a new Runnable which contain the proper launcher 056 ThreadUtil.invokeLater(new Runnable() 057 { 058 @Override 059 public void run() 060 { 061 PluginLauncher.start(pluginDescriptor); 062 } 063 }); 064 } 065 066 // This part of the example check for a match in the name of the class 067 if (pluginDescriptor.isInstanceOf(GuiBuildExample01.class)) 068 { 069 System.out.print(" ==> Starting using instance of...."); 070 071 // Create a new Runnable which contain the proper launcher 072 ThreadUtil.invokeLater(new Runnable() 073 { 074 @Override 075 public void run() 076 { 077 PluginLauncher.start(pluginDescriptor); 078 } 079 }); 080 } 081 082 System.out.println(); 083 } 084 } 085}