View Javadoc

1   // Copyright 2003-2005, FreeHEP.
2   package hep.wired.plugin;
3   
4   import java.io.*;
5   import java.net.*;
6   import java.util.*;
7   
8   import org.xml.sax.SAXException;
9   
10  import org.freehep.application.studio.Plugin;
11  import org.freehep.application.studio.Studio;
12  
13  import org.freehep.xml.io.XMLIORegistry;
14  import org.freehep.xml.menus.XMLMenuBuilder;
15  
16  import hep.wired.plot.WiredPlot;
17  import hep.wired.services.InteractionHandler;
18  import hep.wired.services.ViewPort;
19  import hep.wired.util.Matrix2D;
20  import hep.wired.util.Matrix3D;
21  import hep.wired.util.WiredRegistry;
22  
23  /***
24   * Defines the Library plugin for use in JAS3.
25   *
26   * @author Mark Donszelmann
27   * @version $Id: WiredBase.java 2089 2005-07-21 23:38:57Z duns $
28   */
29  public class WiredBase extends Plugin {
30  
31  // See below
32  //    private WiredBaseCommandHandler baseHandler;
33  
34      public WiredBase() {
35  // See below
36  //        baseHandler = new WiredBaseCommandHandler(this);
37      }
38  
39      protected void init() throws SAXException, IOException {
40          Studio application = getApplication();
41          WiredRegistry.add(this);
42      
43  //        user = application.getUserProperties();
44  
45          // NOTE, should just be done in save/restore but that seems too late.
46          addXMLIOFactories(null);
47  
48          XMLMenuBuilder builder = application.getXMLMenuBuilder();
49          URL xml = getClass().getResource("WiredBase.menus");
50          try {
51              builder.build(xml);
52          } catch (org.xml.sax.SAXParseException e) {
53              System.out.println(e);
54              System.out.println("at line: "+e.getLineNumber()+" column: "+e.getColumnNumber());
55              throw e;
56          }
57  
58          application.addToolBar(builder.getToolBar("interactionToolBar"), "Interaction Toolbar");
59          application.addToolBar(builder.getToolBar("actionToolBar"), "Action Toolbar");
60          application.addToolBar(builder.getToolBar("qualityToolBar"), "Quality Toolbar");
61  
62  // Do not enable, since WIRED4 needs to handle commands differently. For JSky add the handler in the app itself.
63  //        application.getCommandTargetManager().add(baseHandler);
64      }
65  
66  // FIXME WIRED-391 maybe move to registry...
67      private void addXMLIOFactories(XMLIORegistry registry) {
68          addXMLIOFactory(registry, WiredPage.class);
69          addXMLIOFactory(registry, WiredPlot.class);
70  
71          addXMLIOFactory(registry, Matrix3D.class);
72          addXMLIOFactory(registry, Matrix2D.class);
73          
74          addXMLIOFactoryForService(registry, InteractionHandler.class);
75          addXMLIOFactoryForService(registry, ViewPort.class);
76      }
77  
78  // FIXME WIRED-391
79      private void addXMLIOFactory(XMLIORegistry registry, Class cls) {
80          if ((registry == null) || (registry.getXMLIOFactory(cls) == null)) {
81              WiredRegistry.add(new WiredXMLIOFactory(cls));
82          } 
83      }
84  
85      private void addXMLIOFactoryForService(XMLIORegistry registry, Class service) {
86          Set allClasses = WiredRegistry.allClasses(service);
87          for (Iterator i = allClasses.iterator(); i.hasNext(); ) {
88              addXMLIOFactory(registry, (Class)i.next());
89          }
90      }
91  }
92