Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/asaph/samplegui/SampleGuiPlugin.java


1   /*
2   ================================================================================
3   
4     FILE:  SampleGuiPlugin.java
5     
6     PROJECT:
7     
8       Asaph
9     
10    CONTENTS:
11    
12      A sample plugin
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.asaph.samplegui;
43  
44  
45  import javax.swing.JOptionPane;
46  
47  import com.virtuosotechnologies.lib.command.CommandNode;
48  import com.virtuosotechnologies.lib.command.CommandEvent;
49  import com.virtuosotechnologies.lib.basiccommand.BasicCommandNode;
50  import com.virtuosotechnologies.lib.basiccommand.BasicItemCommandNode;
51  import com.virtuosotechnologies.lib.plugin.PluginInitializer;
52  import com.virtuosotechnologies.lib.plugin.PluginInitializerException;
53  import com.virtuosotechnologies.lib.plugin.PluginLinker;
54  
55  import com.virtuosotechnologies.asaph.maingui.CommandManager;
56  import com.virtuosotechnologies.asaph.maingui.GuiEnvironmentManager;
57  
58  
59  /**
60   * A sample GuiPlugin
61   */
62  public class SampleGuiPlugin
63  implements PluginInitializer
64  {
65    private GuiEnvironmentManager guiEnvironmentManager_;
66    
67    
68    /**
69     * Perform first initialization of the plugin. This is called after the plugin
70     * is instantiated, but before it is asked to provide any of its API implementations.
71     * Any APIs the plugin declared it needed for initialization will be available
72     * through the linker when this method is called.
73     * <p>
74     * Plugins should perform any time-consuming initialization in this method, rather
75     * than in the constructor or static initializers, and should use this method to
76     * report any fatal errors during initialization.
77     *
78     * @param linker the linker for this plugin.
79     * @exception PluginInitializerException thrown if the plugin could not
80     *    initialize itself.
81     */
82    public void initialize(
83      PluginLinker linker)
84    throws
85      PluginInitializerException
86    {
87      CommandManager commandManager = (CommandManager)
88        linker.getAPI(CommandManager.API_NAME).getImplementation();
89      guiEnvironmentManager_ = (GuiEnvironmentManager)
90        linker.getAPI(GuiEnvironmentManager.API_NAME).getImplementation();
91      
92      CommandNode group;
93      BasicCommandNode command;
94      
95      command = new BasicItemCommandNode()
96      {
97        public void commandInvoked(
98          CommandEvent ev)
99        {
100         doSampleSongCommand();
101       }
102     };
103     command.setNameProperty("Sample Song Command");
104     
105     group = commandManager.createCommandGroup(CommandManager.SONG_COMMANDS);
106     group.addChild(command);
107     
108     command = new BasicItemCommandNode()
109     {
110       public void commandInvoked(
111         CommandEvent ev)
112       {
113         doSampleToolCommand();
114       }
115     };
116     command.setNameProperty("Sample Tool Command");
117     
118     group = commandManager.createCommandGroup(CommandManager.TOOL_COMMANDS);
119     group.addChild(command);
120   }
121   
122   
123   private void doSampleSongCommand()
124   {
125     JOptionPane.showMessageDialog(guiEnvironmentManager_.getDialogParent(),
126       "You selected the sample song command.");
127   }
128   
129   
130   private void doSampleToolCommand()
131   {
132     JOptionPane.showMessageDialog(guiEnvironmentManager_.getDialogParent(),
133       "You selected the sample tool command.");
134   }
135   
136   
137   /**
138    * A plugin must implement this method to provide the implementations of the APIs
139    * that it provides. This method is called after the initialize() method.
140    * Any APIs the plugin declared it needed in to implement this API will be available
141    * through the linker when this method is called.
142    * <p>
143    * Plugins should perform any time-consuming initialization in this method, rather
144    * than in the constructor or static initializers, and should use this method to
145    * report any fatal errors during initialization.
146    *
147    * @param apiName the name of the API to implement
148    * @param linker the linker for this plugin.
149    * @return an object implementing the API.
150    * @exception PluginInitializerException thrown if the plugin could not implement the API.
151    */
152   public Object getAPIImplementation(
153     String apiName,
154     PluginLinker linker)
155   throws
156     PluginInitializerException
157   {
158     if (apiName.equals(SampleGuiAPI.API_NAME))
159     {
160       return new SampleGuiAPI()
161       {
162         public void performSongCommand()
163         {
164           doSampleSongCommand();
165         }
166         
167         public void performToolCommand()
168         {
169           doSampleToolCommand();
170         }
171       };
172     }
173     throw new PluginInitializerException();
174   }
175 }