LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  February 2015

HPS-SVN February 2015

Subject:

r2029 - /java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/PlotInfoWindow.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Tue, 3 Feb 2015 03:06:05 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (215 lines)

Author: [log in to unmask]
Date: Mon Feb  2 19:06:00 2015
New Revision: 2029

Log:
Add IFunction support to plot info window.  HPSJAVA-334

Modified:
    java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/PlotInfoWindow.java

Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/PlotInfoWindow.java
 =============================================================================
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/PlotInfoWindow.java	(original)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/PlotInfoWindow.java	Mon Feb  2 19:06:00 2015
@@ -8,10 +8,12 @@
 import hep.aida.IFunction;
 import hep.aida.IHistogram1D;
 import hep.aida.IHistogram2D;
-import hep.aida.jfree.plotter.ObjectStyle;
 import hep.aida.jfree.plotter.PlotterRegion;
 import hep.aida.ref.event.AIDAListener;
 import hep.aida.ref.event.AIDAObservable;
+import hep.aida.ref.function.FunctionChangedEvent;
+import hep.aida.ref.function.FunctionDispatcher;
+import hep.aida.ref.function.FunctionListener;
 
 import java.awt.Component;
 import java.awt.Dimension;
@@ -37,16 +39,12 @@
 
 /**
  * <p>
- * This is a GUI component for showing the statistics and other information about an AIDA plot.
+ * This is a GUI component for showing the statistics and other information about an AIDA plot
+ * when it is clicked on in the monitoring app.
  * <p>
- * This information is updated dynamically via the <code>AIDAObserver</code> API on the AIDA object.
+ * The information is updated dynamically via the <code>AIDAObserver</code> API on the AIDA object.
  */
-// FIXME: Add addRows for all types of AIDA objects (only Histogram1D implemented so far).
-// FIXME: Columns disappear when rebuilding table.
-// TODO: Add sorting of info table.
-// TODO: Probably this should be moved out of monitoring application as it is generically applicable
-// to AIDA objects.
-public class PlotInfoWindow extends JFrame implements AIDAListener, ActionListener {
+public class PlotInfoWindow extends JFrame implements AIDAListener, ActionListener, FunctionListener {
 
     JComboBox<Object> plotComboBox;
     JTable infoTable = new JTable();
@@ -59,7 +57,7 @@
 
     static final String[] COLUMN_NAMES = { "Field", "Value" };
 
-    static final String PLOT_SELECTED = "PLOT_SELECTED";
+    static final String PLOT_SELECTED = "PlotSelected";
 
     Timer timer = new Timer();
 
@@ -125,12 +123,13 @@
      */
     @Override
     public void stateChanged(final EventObject evt) {
-
+               
         // Make a timer task for running the update.
         TimerTask task = new TimerTask() {
             public void run() {
+                                
                 // Is the state change from the current AIDAObservable?
-                if (evt.getSource() != PlotInfoWindow.this.currentObject) {
+                if (evt.getSource() != currentObject) {
                     // Assume this means that a different AIDAObservable was selected in the GUI.
                     return;
                 }
@@ -157,17 +156,18 @@
      */
     @Override
     public void actionPerformed(ActionEvent e) {
-        // Was a new item selected in the combo box?
+        // Is there a new item selected in the combo box?
         if (PLOT_SELECTED.equals(e.getActionCommand())) {
             if (plotComboBox.getSelectedItem() != null) {
-                // Set the current object from the combo box to update the GUI state.
+                // Set the current object from the combo box value, to update the GUI state.
                 setCurrentObject(plotComboBox.getSelectedItem());
             }
         }
     }
 
     /**
-     * Get the title of an AIDA object. Unfortunately there is not base type with this information.
+     * Get the title of an AIDA object.  Unfortunately there is no base type with this information,
+     * so it is gotten manually from each possible type.
      * @param object The AIDA object.
      * @return The title of the object from its title method or value of its toString method, if
      *         none exists.
@@ -230,6 +230,8 @@
             if (((ICloud1D) currentObject).isConverted()) {
                 addRows(((ICloud1D) currentObject).histogram());
             }
+        } else if (currentObject instanceof IFunction) {
+            addRows((IFunction) currentObject);
         }
     }
 
@@ -252,7 +254,7 @@
         List<Object> objects = currentRegion.getPlottedObjects();
         for (Object object : objects) {
             if (isValidObject(object)) {
-                this.plotComboBox.addItem(object);
+                plotComboBox.addItem(object);
             }
         }
     }
@@ -262,9 +264,8 @@
             return false;
         if (object instanceof IBaseHistogram || object instanceof IFunction || object instanceof IDataPointSet) {
             return true;
-        } else {
-            return false;
-        }
+        } 
+        return false;
     }
 
     /**
@@ -321,7 +322,20 @@
         addRow("x rms", String.format("%.10f%n", cloud.rmsX()));
         addRow("y rms", String.format("%.10f%n", cloud.rmsY()));
     }
-
+    
+    /**
+     * Add rows to the info table from the state of a 2D cloud.
+     * @param cloud The AIDA object.
+     */
+    void addRows(IFunction function) {
+        addRow("title", function.title());
+        
+        // Add generically the values of all function parameters.
+        for (String parameter : function.parameterNames()) {
+            addRow(parameter, function.parameter(parameter));
+        }
+    }
+    
     /**
      * Add a row to the info table.
      * @param field The field name.
@@ -336,10 +350,10 @@
      * @param object The backing AIDA object.
      */
     synchronized void setCurrentObject(Object object) {
-
+        
         if (object == null)
             throw new IllegalArgumentException("The object arg is null!");
-
+        
         if (object == currentObject)
             return;
 
@@ -359,13 +373,17 @@
     }
 
     /**
-     * Remove this object as an <code>AIDAListener</code> on the current <code>AIDAObservable</code>
-     * .
+     * Remove this as a listener on the current AIDA object.
      */
     void removeListener() {
         if (currentObject != null) {
-            // Remove this object as a listener on the current observable.
-            ((AIDAObservable) currentObject).removeListener(this);
+            if (currentObject instanceof AIDAObservable && !(currentObject instanceof IFunction)) {
+                // Remove this object as an listener on the AIDA observable.
+                ((AIDAObservable) currentObject).removeListener(this);
+            } else if (currentObject instanceof FunctionDispatcher) {
+                // Remove this object as function listener.
+                ((FunctionDispatcher)currentObject).removeFunctionListener(this);
+            }
         }
     }
 
@@ -373,12 +391,29 @@
      * Add this object as an <code>AIDAListener</code> on the current <code>AIDAObservable</code>.
      */
     void addListener() {
-        if (currentObject instanceof AIDAObservable) {
+        if (currentObject instanceof AIDAObservable && !(currentObject instanceof FunctionDispatcher)) {
             // Setup a listener on the current AIDA object.
             AIDAObservable observable = (AIDAObservable) currentObject;
             observable.addListener(this);
             observable.setValid(this);
             observable.setConnected(true);
+        } else if (currentObject instanceof IFunction) {
+            if (currentObject instanceof FunctionDispatcher) {
+                ((FunctionDispatcher)currentObject).addFunctionListener(this);
+            }
+        }
+    }
+
+    /**
+     * Callback for updating from changed to <code>IFunction</code> object.
+     * @param event The change event (unused in this method).
+     */
+    @Override
+    public void functionChanged(FunctionChangedEvent event) {
+        try {
+            runUpdateTable();
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use