Author: [log in to unmask] Date: Sat Mar 14 12:26:02 2015 New Revision: 2450 Log: Add global plotter registry for use in monitoring app. Added: java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/PlotterRegistry.java Modified: java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/MonitoringPlotFactory.java Modified: java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/MonitoringPlotFactory.java ============================================================================= --- java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/MonitoringPlotFactory.java (original) +++ java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/MonitoringPlotFactory.java Sat Mar 14 12:26:02 2015 @@ -22,7 +22,9 @@ * by the MonitoringApplication before any calls to AIDA are made from Drivers. */ public class MonitoringPlotFactory extends PlotterFactory { - + + static PlotterRegistry plotters = new PlotterRegistry(); + // The name of the factory which will be used in naming tabs in the monitoring app. String name = null; @@ -33,6 +35,8 @@ private static JTabbedPane rootPane = null; private static PlotterRegionListener regionListener; + + int tabIndex; public static void setPlotterRegionListener(PlotterRegionListener regionListener) { MonitoringPlotFactory.regionListener = regionListener; @@ -66,7 +70,8 @@ // FIXME: Hack to disregard call from an AIDA related class. if (!(new RuntimeException()).getStackTrace()[2].getClassName().equals("hep.aida.ref.plotter.style.registry.StyleStoreXMLReader")) { rootPane.addTab(name, tabs); - rootPane.setTabComponentAt(rootPane.getTabCount() - 1, new JLabel(name)); + tabIndex = rootPane.getTabCount() - 1; + rootPane.setTabComponentAt(tabIndex, new JLabel(name)); } } @@ -98,10 +103,16 @@ } private void setupPlotterTab(String plotterName, IPlotter plotter) { + + // Setup the plotter's GUI pane and tab. JPanel plotterPanel = new JPanel(new BorderLayout()); plotterPanel.add(PlotterUtilities.componentForPlotter(plotter), BorderLayout.CENTER); tabs.addTab(plotterName, plotterPanel); - tabs.setTabComponentAt(tabs.getTabCount() - 1, new JLabel(plotterName)); + int plotterIndex = tabs.getTabCount() - 1; + tabs.setTabComponentAt(plotterIndex, new JLabel(plotterName)); + + // Register plotter globally with its tab indices. + plotters.register(plotter, tabIndex, plotterIndex); } private void addChart(JFreeChart chart) { @@ -143,5 +154,13 @@ stripChart.getLegend().setVisible(false); /* Legend turned off for now. */ addChart(stripChart); return stripChart; + } + + /** + * + * @return + */ + public static PlotterRegistry getPlotterRegistry() { + return plotters; } -} +} Added: java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/PlotterRegistry.java ============================================================================= --- java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/PlotterRegistry.java (added) +++ java/trunk/monitoring-util/src/main/java/org/hps/monitoring/plotting/PlotterRegistry.java Sat Mar 14 12:26:02 2015 @@ -0,0 +1,51 @@ +/** + * + */ +package org.hps.monitoring.plotting; + +import hep.aida.IPlotter; +import hep.aida.IPlotterRegion; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Set; + +/** + * @author Jeremy McCormick <[log in to unmask]> + * + */ +public class PlotterRegistry { + + Set<IPlotter> plotters = new HashSet<IPlotter>(); + HashMap<IPlotter, int[]> tabMap = new HashMap<IPlotter, int[]>(); + + public void clear() { + plotters.clear(); + } + + public IPlotter find(IPlotterRegion region) { + for (IPlotter plotter : plotters) { + for (int i = 0; i < plotter.numberOfRegions(); i++) { + if (plotter.region(i) == region) { + return plotter; + } + } + } + return null; + } + + public void register(IPlotter plotter, int index1, int index2) { + tabMap.put(plotter, new int[] { index1, index2 }); + } + + public IPlotter find(int index1, int index2) { + for (Entry<IPlotter, int[]> entry : tabMap.entrySet()) { + int[] indices = entry.getValue(); + if (indices[0] == index1 && indices[1] == index2) { + return entry.getKey(); + } + } + return null; + } +}