View Javadoc

1   package org.lcsim.util.aida;
2   
3   import hep.aida.ref.plotter.Plotter;
4   import hep.aida.ref.plotter.PlotterUtilities;
5   
6   import java.awt.BorderLayout;
7   
8   import javax.swing.JFrame;
9   import javax.swing.JLabel;
10  import javax.swing.JPanel;
11  import javax.swing.JTabbedPane;
12  
13  /**
14   * This is an extension of <tt>Plotter</tt> that draws itself into a tab
15   * within a <tt>JTabbedPane</tt>.
16   * 
17   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
18   */
19  public class TabbedPlotter extends Plotter {
20      
21      JTabbedPane tabbedPane;
22      JFrame frame;
23      
24      /**
25       * Create an unnamed plotter.
26       */
27      public TabbedPlotter() {
28          super(null);
29      }
30      
31      /**
32       * Create a named plotter.
33       * @param name The plotter name.
34       */
35      public TabbedPlotter(String name) {
36          super(name);
37      }
38      
39      /**
40       * Set the target <tt>JTabbedPane</tt> into which this plotter's
41       * plots will be drawn.     
42       * @param tabbedPane The target JTabbedPane for the plots.
43       */
44      public void setTabbedPane(JTabbedPane tabbedPane) {
45          this.tabbedPane = tabbedPane;
46      }
47      
48      /**
49       * Set the parent <tt>JFrame</tt> for this plotter.
50       * @param frame The parent <tt>JFrame</tt>.
51       */
52      public void setFrame(JFrame frame) {
53          this.frame = frame;
54      }
55              
56      /**
57       * Show this plotter's graphics, setting the parent <tt>JFrame</tt>
58       * to visible, if necessary.
59       */
60      public void show() {
61          if (!isShowing()) {
62              // Add the tab if not already showing.
63              addPlotterTab();
64              if (!frame.isVisible()) {
65                  // Activate the JFrame if it is invisible.
66                  frame.setVisible(true);
67              }
68          }
69      }
70         
71      /**
72       * Add a tab for this plotter.
73       */
74      private void addPlotterTab() {
75          String title = title();
76          if (title == null)
77              title = "     ";
78          JPanel plotterPanel = new JPanel(new BorderLayout());
79          plotterPanel.add(PlotterUtilities.componentForPlotter(this), BorderLayout.CENTER);
80          tabbedPane.addTab(title, plotterPanel);
81          tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, new JLabel(title));
82      }
83  }