4 added files
projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida
--- projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/LCSimAnalysisFactory.java (rev 0)
+++ projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/LCSimAnalysisFactory.java 2014-05-23 01:16:56 UTC (rev 3140)
@@ -0,0 +1,36 @@
+package org.lcsim.util.aida;
+
+import hep.aida.IPlotterFactory;
+import hep.aida.ref.AnalysisFactory;
+
+/**
+ * This is an extension of <tt>AnalysisFactory</tt> which currently
+ * just provides some additional organization of plots into tabs
+ * via an <tt>IPlotterFactory</tt> implementation.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class LCSimAnalysisFactory extends AnalysisFactory {
+
+ /**
+ * Register this class as the default AnalysisFactory for AIDA by setting
+ * the magic property string.
+ */
+ final static void register() {
+ System.setProperty("hep.aida.IAnalysisFactory", LCSimAnalysisFactory.class.getName());
+ }
+
+ /**
+ * Create an unnamed <tt>TabbedPlotterFactory</tt>.
+ */
+ public IPlotterFactory createPlotterFactory() {
+ return new TabbedPlotterFactory();
+ }
+
+ /**
+ * Create a named <tt>TabbedPlotterFactory</tt>.
+ */
+ public IPlotterFactory createPlotterFactory(String name) {
+ return new TabbedPlotterFactory(name);
+ }
+}
projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida
--- projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/TabbedPlotter.java (rev 0)
+++ projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/TabbedPlotter.java 2014-05-23 01:16:56 UTC (rev 3140)
@@ -0,0 +1,83 @@
+package org.lcsim.util.aida;
+
+import hep.aida.ref.plotter.Plotter;
+import hep.aida.ref.plotter.PlotterUtilities;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+
+/**
+ * This is an extension of <tt>Plotter</tt> that draws itself into a tab
+ * within a <tt>JTabbedPane</tt>.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class TabbedPlotter extends Plotter {
+
+ JTabbedPane tabbedPane;
+ JFrame frame;
+
+ /**
+ * Create an unnamed plotter.
+ */
+ public TabbedPlotter() {
+ super(null);
+ }
+
+ /**
+ * Create a named plotter.
+ * @param name The plotter name.
+ */
+ public TabbedPlotter(String name) {
+ super(name);
+ }
+
+ /**
+ * Set the target <tt>JTabbedPane</tt> into which this plotter's
+ * plots will be drawn.
+ * @param tabbedPane The target JTabbedPane for the plots.
+ */
+ public void setTabbedPane(JTabbedPane tabbedPane) {
+ this.tabbedPane = tabbedPane;
+ }
+
+ /**
+ * Set the parent <tt>JFrame</tt> for this plotter.
+ * @param frame The parent <tt>JFrame</tt>.
+ */
+ public void setFrame(JFrame frame) {
+ this.frame = frame;
+ }
+
+ /**
+ * Show this plotter's graphics, setting the parent <tt>JFrame</tt>
+ * to visible, if necessary.
+ */
+ public void show() {
+ if (!isShowing()) {
+ // Add the tab if not already showing.
+ addPlotterTab();
+ if (!frame.isVisible()) {
+ // Activate the JFrame if it is invisible.
+ frame.setVisible(true);
+ }
+ }
+ }
+
+ /**
+ * Add a tab for this plotter.
+ */
+ private void addPlotterTab() {
+ String title = title();
+ if (title == null)
+ title = " ";
+ JPanel plotterPanel = new JPanel(new BorderLayout());
+ plotterPanel.add(PlotterUtilities.componentForPlotter(this), BorderLayout.CENTER);
+ tabbedPane.addTab(title, plotterPanel);
+ tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, new JLabel(title));
+ }
+}
projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida
--- projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/TabbedPlotterFactory.java (rev 0)
+++ projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/TabbedPlotterFactory.java 2014-05-23 01:16:56 UTC (rev 3140)
@@ -0,0 +1,79 @@
+package org.lcsim.util.aida;
+
+import hep.aida.IPlotter;
+import hep.aida.ref.plotter.PlotterFactory;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JFrame;
+import javax.swing.JTabbedPane;
+
+/**
+ * This is an extension of <tt>PlotterFactory</tt> that puts the output
+ * from each <tt>IPlotter</tt> in a separate tab. Each of these factory
+ * objects has an associated <tt>JFrame</tt> with a set of tabs.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class TabbedPlotterFactory extends PlotterFactory {
+
+ private String name;
+ private JTabbedPane tabbedPane = new JTabbedPane();
+ private JFrame frame;
+
+ /**
+ * Create a named factory.
+ * @param name The name of the factory.
+ */
+ public TabbedPlotterFactory(String name) {
+ this.name = name;
+ createFrame();
+ }
+
+ /**
+ * Create an un-named factory.
+ */
+ public TabbedPlotterFactory() {
+ if (!(new RuntimeException()).getStackTrace()[2].getClassName()
+ .equals("hep.aida.ref.plotter.style.registry.StyleStoreXMLReader")) {
+ createFrame();
+ }
+ }
+
+ /**
+ * This method initializes a <tt>JFrame</tt> for this <tt>TabbedPlotterFactory</tt>.
+ * It is initially set to invisible. When the method {@link IPlotter#show()} on an
+ * associated <tt>TabbedPlotter</tt> is called, the frame will be set to visible
+ * if it isn't already showing.
+ */
+ private void createFrame() {
+ frame = new JFrame();
+ frame.add(tabbedPane, BorderLayout.CENTER);
+ if (name != null)
+ frame.setTitle(name);
+ frame.setContentPane(tabbedPane);
+ frame.pack();
+ frame.setSize(800, 600);
+ }
+
+ /**
+ * Create a named plotter which will plot its graphics onto a tabbed pane.
+ * @param plotterName The name of the plotter.
+ * @return The plotter.
+ */
+ public IPlotter create(String plotterName) {
+ TabbedPlotter plotter = new TabbedPlotter(plotterName);
+ plotter.setTabbedPane(tabbedPane);
+ plotter.setFrame(frame);
+ plotter.setTitle(plotterName);
+ return plotter;
+ }
+
+ /**
+ * Create an unnamed plotter.
+ * @return The plotter.
+ */
+ public IPlotter create() {
+ return create((String) null);
+ }
+}
projects/lcsim/trunk/aida/src/test/java/org/lcsim/util/aida
--- projects/lcsim/trunk/aida/src/test/java/org/lcsim/util/aida/TabbedPlotterFactoryTest.java (rev 0)
+++ projects/lcsim/trunk/aida/src/test/java/org/lcsim/util/aida/TabbedPlotterFactoryTest.java 2014-05-23 01:16:56 UTC (rev 3140)
@@ -0,0 +1,61 @@
+package org.lcsim.util.aida;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IHistogram1D;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterFactory;
+
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+/**
+ * This is a basic test of the {@link TabbedPlotterFactory} class.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class TabbedPlotterFactoryTest extends TestCase {
+
+ static {
+ // Register the default analysis factory.
+ LCSimAnalysisFactory.register();
+ }
+
+ /**
+ * Test the <tt>TabbedPlotterFactory</tt>.
+ */
+ public void testTabbedPlotterFactory() {
+ AIDA aida = AIDA.defaultInstance();
+ IAnalysisFactory analysisFactory = aida.analysisFactory();
+ IPlotterFactory plotterFactory = analysisFactory.createPlotterFactory(this.getClass().getSimpleName());
+
+ IHistogram1D histogram = aida.histogram1D("Fancy Histogram", 100, 0., 10.);
+ Random random = new Random();
+ for (int i=0; i<1000; i++) {
+ histogram.fill(random.nextDouble() * 10);
+ }
+
+ IPlotter plotter = plotterFactory.create("Test Plot");
+ plotter.createRegions();
+ plotter.region(0).plot(histogram);
+ plotter.show();
+
+ IPlotter plotter2 = plotterFactory.create("Test Plot 2");
+ plotter.createRegion();
+ plotter2.region(0).plot(histogram);
+ plotter2.show();
+
+ IPlotter plotter3 = plotterFactory.create();
+ plotter.createRegion();
+ plotter3.region(0).plot(histogram);
+ plotter3.show();
+
+ synchronized(this) {
+ try {
+ wait(10000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
SVNspam 0.1