View Javadoc

1   package org.lcsim.util.aida;
2   
3   import hep.aida.IPlotter;
4   import hep.aida.ref.plotter.PlotterFactory;
5   
6   import java.awt.BorderLayout;
7   
8   import javax.swing.JFrame;
9   import javax.swing.JTabbedPane;
10  
11  /**
12   * This is an extension of <tt>PlotterFactory</tt> that puts the output
13   * from each <tt>IPlotter</tt> in a separate tab.  Each of these factory
14   * objects has an associated <tt>JFrame</tt> with a set of tabs.
15   * 
16   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
17   */
18  public class TabbedPlotterFactory extends PlotterFactory {
19      
20      private String name;
21      private JTabbedPane tabbedPane = new JTabbedPane();
22      private JFrame frame; 
23      
24      /**
25       * Create a named factory.
26       * @param name The name of the factory.
27       */
28      public TabbedPlotterFactory(String name) {
29          this.name = name;
30          createFrame();
31      }
32      
33      /**
34       * Create an un-named factory.
35       */
36      public TabbedPlotterFactory() {
37          if (!(new RuntimeException()).getStackTrace()[2].getClassName()
38                  .equals("hep.aida.ref.plotter.style.registry.StyleStoreXMLReader")) {
39              createFrame();
40          }
41      }
42      
43      /**
44       * This method initializes a <tt>JFrame</tt> for this <tt>TabbedPlotterFactory</tt>.
45       * It is initially set to invisible.  When the method {@link IPlotter#show()} on an
46       * associated <tt>TabbedPlotter</tt> is called, the frame will be set to visible
47       * if it isn't already showing.
48       */
49      private void createFrame() {
50          frame = new JFrame();
51          frame.add(tabbedPane, BorderLayout.CENTER);
52          if (name != null)
53              frame.setTitle(name);
54          frame.setContentPane(tabbedPane);
55          frame.pack();
56          frame.setSize(800, 600);        
57      }
58          
59      /**
60       * Create a named plotter which will plot its graphics onto a tabbed pane.
61       * @param plotterName The name of the plotter.
62       * @return The plotter.
63       */
64      public IPlotter create(String plotterName) {
65          TabbedPlotter plotter = new TabbedPlotter(plotterName);
66          plotter.setTabbedPane(tabbedPane);
67          plotter.setFrame(frame);
68          plotter.setTitle(plotterName);
69          return plotter;
70      }
71  
72      /**
73       * Create an unnamed plotter.
74       * @return The plotter.
75       */
76      public IPlotter create() {
77          return create((String) null);
78      }    
79  }