View Javadoc

1   package org.lsst.ccs.plugin.jas3.tutorial;
2   
3   import java.io.IOException;
4   import java.net.URL;
5   import java.util.logging.Logger;
6   import javax.swing.JToolBar;
7   import org.freehep.application.studio.Plugin;
8   import org.freehep.application.studio.Studio;
9   import org.freehep.xml.menus.XMLMenuBuilder;
10  import org.xml.sax.SAXException;
11  
12  /**
13   * This is the main entry point of the tutorial plugin.
14   * @author tonyj
15   */
16  public class TutorialPlugin extends Plugin {
17  
18      private static final Logger logger = Logger.getLogger(TutorialPlugin.class.getName());
19  
20      /*
21       * The init method of the plugin will be called during JAS startup. This is the place
22       * where you should register any functionality that your plugin provides.
23       * 
24       * Note that the order in which plugins are initialized is unpredictable, so in this method you
25       * should not assume that other plugins have or have not been initialized. There
26       * is a postInit method which is called after all plugins have been initialized.
27       */
28      @Override
29      protected void init() throws SAXException, IOException {
30          logger.info("Initializing tutorial plugin");
31          // Get the top level "Studio" application.
32          Studio studio = (Studio) Studio.getApplication();
33          addMenuItemsAndToolbar(studio);
34          registerCommandHandler(studio);
35      }
36  
37      @Override
38      protected void postInit() {
39          logger.info("Post init tutorial plugin");
40      }
41  
42      private void addMenuItemsAndToolbar(Studio studio) throws SAXException, IOException {
43          // Get the menu builder corresponding to the studio
44          XMLMenuBuilder builder = studio.getXMLMenuBuilder();
45          // Read the definition of the tutorial menus (stored in the maven resources directory)
46          URL xml = getClass().getResource("Tutorial.menus");
47          // Merge these menus into the application's menus
48          builder.build(xml);
49          // Find the newly registered toolbar
50          JToolBar toolbar = builder.getToolBar("tutorialToolbar");
51          // Add it to the toolbar area
52          studio.addToolBar(toolbar, toolbar.getName());
53      }
54  
55      private void registerCommandHandler(Studio studio) {
56         studio.getCommandTargetManager().add(new TutorialCommands(studio));
57      }
58  }