Print

Print


Commit in java/trunk/monitoring-app/src/main/java/org/hps/monitoring/ecal on MAIN
EcalPanel.java+133-208141 -> 142
More documentation changes.

java/trunk/monitoring-app/src/main/java/org/hps/monitoring/ecal
EcalPanel.java 141 -> 142
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/ecal/EcalPanel.java	2014-01-30 23:38:45 UTC (rev 141)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/ecal/EcalPanel.java	2014-01-30 23:54:41 UTC (rev 142)
@@ -25,8 +25,7 @@
     // The color used for rendering seed hits.
     private Color clusterColor = Color.GREEN;
     // The color-mapping scale used by to color calorimeter crystals.
-    private MultiGradientScale scale = MultiGradientScale.makeRainbowScale(0.0,
-            1.0);
+    private MultiGradientScale scale = MultiGradientScale.makeRainbowScale(0.0, 1.0);
     // The number of boxes in the x-direction.
     private int xBoxes = 1;
     // The number of boxes in the y-direction.
@@ -47,139 +46,107 @@
     private boolean sizeChanged = true;
     // The panel on which the scale is rendered.
     ScalePanel scalePanel = new ScalePanel();
-
+    
     // Efficiency variables for crystal placement.
     int boxWidth = 0;
     int widthRem = 0;
     int boxHeight = 0;
     int heightRem = 0;
-
+    
     /**
-     * <b>EcalPanel</b><br/>
-     * <br/>
+     * <b>EcalPanel</b><br/><br/>
      * Initializes the calorimeter panel.
-     * 
-     * @param numXBoxes
-     *            - The number of crystals in the x-direction.
-     * @param numYBoxes
-     *            - The number of crystals in the y-direction.
+     * @param numXBoxes - The number of crystals in the x-direction.
+     * @param numYBoxes - The number of crystals in the y-direction.
      **/
     public EcalPanel(int numXBoxes, int numYBoxes) {
         // Initialize the base component.
         super();
-
+        
         // Set the number of calorimeter crystals.
         xBoxes = numXBoxes;
         yBoxes = numYBoxes;
-
+        
         // Initialize the arrays.
         disabled = new boolean[xBoxes][yBoxes];
         hit = new double[xBoxes][yBoxes];
         cluster = new boolean[xBoxes][yBoxes];
         changed = new boolean[xBoxes][yBoxes];
-
+        
         // Add the scale panel.
         setLayout(null);
         add(scalePanel);
         sizeChanged = true;
         scaleChanged = true;
     }
-
+    
     /**
-     * <b>setCrystalEnabled</b><br/>
-     * <br/>
-     * <code>public void <b>setCrystalEnabled</b>(int xIndex, int yIndex, boolean active)</code>
-     * <br/>
-     * <br/>
+     * <b>setCrystalEnabled</b><br/><br/>
+     * <code>public void <b>setCrystalEnabled</b>(int xIndex, int yIndex, boolean active)</code><br/><br/>
      * Sets whether the indicated crystal is enabled or not. Invalid indices
      * will be ignored.
-     * 
-     * @param xIndex
-     *            - The x-coordinate of the crystal.
-     * @param yIndex
-     *            - The y-coordinate of the crystal.
-     * @param active
-     *            - This should be <code>true</code> if the crystal is active
-     *            and <code>false</code> if it is not.
-     * @throws IndexOutOfBoundsException
-     *             Occurs when the given xy crystal coordinate does not point to
-     *             a crystal.
+     * @param xIndex - The x-coordinate of the crystal.
+     * @param yIndex - The y-coordinate of the crystal.
+     * @param active - This should be <code>true</code> if the crystal is
+     * active and <code>false</code> if it is not.
+     * @throws IndexOutOfBoundsException Occurs when the given xy crystal
+     * coordinate does not point to a crystal.
      **/
-    public void setCrystalEnabled(int xIndex, int yIndex, boolean active)
-            throws IndexOutOfBoundsException {
+    public void setCrystalEnabled(int xIndex, int yIndex, boolean active) throws IndexOutOfBoundsException {
         if (xIndex >= 0 && xIndex < xBoxes && yIndex >= 0 && yIndex < yBoxes) {
             disabled[xIndex][yIndex] = !active;
             changed[xIndex][yIndex] = true;
-        } else {
-            throw new IndexOutOfBoundsException(String.format(
-                    "Invalid crystal address (%2d, %2d).", xIndex, yIndex));
         }
+        else {
+            throw new IndexOutOfBoundsException(String.format("Invalid crystal address (%2d, %2d).", xIndex, yIndex));
+        }
     }
-
+    
     /**
-     * <b>addCrystalEnergy</b><br/>
-     * <br/>
-     * <code>public void <b>addCrystalEnergy</b>(int xIndex, int yIndex, double energy)</code>
-     * <br/>
-     * <br/>
+     * <b>addCrystalEnergy</b><br/><br/>
+     * <code>public void <b>addCrystalEnergy</b>(int xIndex, int yIndex, double energy)</code><br/><br/>
      * Adds the indicated quantity of energy to the crystal at the given
      * coordinates.
-     * 
-     * @param xIndex
-     *            - The x-coordinate of the crystal.
-     * @param yIndex
-     *            - The y-coordinate of the crystal.
-     * @param energy
-     *            - The energy to add.
-     * @throws IndexOutOfBoundsException
-     *             Occurs when the given xy crystal coordinate does not point to
-     *             a crystal.
+     * @param xIndex - The x-coordinate of the crystal.
+     * @param yIndex - The y-coordinate of the crystal.
+     * @param energy - The energy to add.
+     * @throws IndexOutOfBoundsException Occurs when the given xy crystal
+     * coordinate does not point to a crystal.
      **/
-    public void addCrystalEnergy(int xIndex, int yIndex, double energy)
-            throws IndexOutOfBoundsException {
+    public void addCrystalEnergy(int xIndex, int yIndex, double energy) throws IndexOutOfBoundsException {
         if (xIndex >= 0 && xIndex < xBoxes && yIndex >= 0 && yIndex < yBoxes) {
             this.hit[xIndex][yIndex] += energy;
             changed[xIndex][yIndex] = true;
-        } else {
-            throw new IndexOutOfBoundsException(String.format(
-                    "Invalid crystal address (%2d, %2d).", xIndex, yIndex));
         }
+        else {
+            throw new IndexOutOfBoundsException(String.format("Invalid crystal address (%2d, %2d).", xIndex, yIndex));
+        }
     }
-
+    
     /**
-     * <b>setCrystalCluster</b>
-     * <code>public void <b>setCrystalCluster</b>(int xIndex, int yIndex, boolean cluster)</code>
-     * <br/>
-     * <br/>
+     * <b>setCrystalCluster</b><br/><br/>
+     * <code>public void <b>setCrystalCluster</b>(int xIndex, int yIndex, boolean cluster)</code><br/><br/>
      * Sets whether a crystal is also the location of a seed hit.
-     * 
-     * @param xIndex
-     *            - The x-coordinate of the crystal.
-     * @param yIndex
-     *            - The y-coordinate of the crystal.
-     * @param cluster
-     *            - This should be <code>true</code> if there is a seed hit and
-     *            <code>false</code> if there is not.
-     * @throws IndexOutOfBoundsException
-     *             Occurs when the given xy crystal coordinate does not point to
-     *             a crystal.
+     * @param xIndex - The x-coordinate of the crystal.
+     * @param yIndex - The y-coordinate of the crystal.
+     * @param cluster - This should be <code>true</code> if there
+     * is a seed hit and <code>false</code> if there is not.
+     * @throws IndexOutOfBoundsException Occurs when the given xy
+     * crystal coordinate does not point to a crystal.
      **/
-    public void setCrystalCluster(int xIndex, int yIndex, boolean cluster)
-            throws IndexOutOfBoundsException {
+    public void setCrystalCluster(int xIndex, int yIndex, boolean cluster) throws IndexOutOfBoundsException {
         if (xIndex >= 0 && xIndex < xBoxes && yIndex >= 0 && yIndex < yBoxes) {
             this.cluster[xIndex][yIndex] = cluster;
             changed[xIndex][yIndex] = true;
-        } else {
-            throw new IndexOutOfBoundsException(String.format(
-                    "Invalid crystal address (%2d, %2d).", xIndex, yIndex));
         }
+        else {
+            throw new IndexOutOfBoundsException(String.format("Invalid crystal address (%2d, %2d).", xIndex, yIndex));
+        }
     }
-
+    
     /**
-     * <b>clearCrystals</b><br/>
-     * <br/>
-     * <code>public void <b>clearCrystals</b>()</code><br/>
-     * <br/>
+     * <b>clearCrystals</b><br/><br/>
+     * <code>public void <b>clearCrystals</b>()</code><br/><br/>
      * Sets all crystal energies to zero and removes all clusters. This <b>does
      * not</b> enable any disabled crystals.
      **/
@@ -197,58 +164,43 @@
             }
         }
     }
-
+    
     /**
-     * <b>setClusterColor</b><br/>
-     * <br/>
-     * <code>public void <b>setClusterColor</b>(Color c)</code><br/>
-     * <br/>
+     * <b>setClusterColor</b><br/><br/>
+     * <code>public void <b>setClusterColor</b>(Color c)</code><br/><br/>
      * Sets the color of the seed hit marker.
-     * 
-     * @param c
-     *            - The color to be used for seed hit markers. A value of
-     *            <code>null</code> will result in seed hit markers being the
-     *            inverse color of the crystal in which they appear.
+     * @param c - The color to be used for seed hit markers. A value of <code>null
+     * </code> will result in seed hit markers being the inverse color of the crystal
+     * in which they appear.
      **/
-    public void setClusterColor(Color c) {
-        clusterColor = c;
-    }
-
+    public void setClusterColor(Color c) { clusterColor = c; }
+    
     /**
-     * <b>setMinimum</b><br/>
-     * <br>
-     * <code>public void <b>setMinimum</b>(double minimum)</code><br/>
-     * <br/>
+     * <b>setMinimum</b><br/><br>
+     * <code>public void <b>setMinimum</b>(double minimum)</code><br/><br/>
      * Sets the minimum value of the color mapping scale. Energies below this
      * value will all be the same minimum color.
-     * 
-     * @param minimum
-     *            - The minimum energy to be mapped.
+     * @param minimum - The minimum energy to be mapped.
      **/
     public void setMinimum(double minimum) {
         scale.setMinimum(minimum);
         scaleChanged = true;
     }
-
+    
     /**
-     * <b>setMaximum</b><br/>
-     * <br/>
-     * <code>public void <b>setMaximum</b>(double maximum)</code><br/>
-     * <br/>
+     * <b>setMaximum</b><br/><br/>
+     * <code>public void <b>setMaximum</b>(double maximum)</code><br/><br/>
      * Sets the maximum value of the color mapping scale. Energies above this
      * value will all be the same maximum color.
-     * 
-     * @param maximum
-     *            - The maximum energy to be mapped.
+     * @param maximum - The maximum energy to be mapped.
      **/
     public void setMaximum(double maximum) {
         scale.setMaximum(maximum);
         scaleChanged = true;
     }
-
+    
     /**
-     * <b>setScalingLinear</b><br/>
-     * <br/>
+     * <b>setScalingLinear</b><br/><br/>
      * <code>public void <b>setScalingLinear</b>()<br/><br/>
      * Sets the color mapping scale behavior to linear mapping.
      **/
@@ -256,29 +208,23 @@
         scale.setScalingLinear();
         scaleChanged = true;
     }
-
+    
     /**
-     * <b>setScalingLogarithmic</b><br/>
-     * <br/>
-     * <code>public void <b>setScalingLogarithmic</b></code><br/>
-     * <br/>
+     * <b>setScalingLogarithmic</b><br/><br/>
+     * <code>public void <b>setScalingLogarithmic</b></code><br/><br/>
      * Sets the color mapping scale behavior to logarithmic mapping.
      **/
     public void setScalingLogarithmic() {
         scale.setScalingLogarithmic();
         scaleChanged = true;
     }
-
+    
     /**
-     * <b>setScaleEnabled</b><br/>
-     * <br/>
-     * <code>public void <b>setScaleEnabled</b>(boolean enabled)</code><br/>
-     * <br/>
+     * <b>setScaleEnabled</b><br/><br/>
+     * <code>public void <b>setScaleEnabled</b>(boolean enabled)</code><br/><br/>
      * Sets whether the scale should be visible or not.
-     * 
-     * @param enabled
-     *            - <code>true</code> indicates that the scale should be visible
-     *            and <code>false</code> that it should be hidden.
+     * @param enabled - <code>true</code> indicates that the scale should
+     * be visible and <code>false</code> that it should be hidden.
      **/
     public void setScaleEnabled(boolean enabled) {
         if (scalePanel.isVisible() != enabled) {
@@ -287,39 +233,31 @@
             sizeChanged = true;
         }
     }
-
+    
     /**
-     * <b>redraw</b><br/>
-     * <br/>
+     * <b>redraw</b><br/><br/>
      * <code>public void <b>redraw</b>()</code> Re-renders the calorimeter
      * panel.
      **/
-    public void redraw() {
-        super.repaint();
-    }
-
-    public void setSize(Dimension d) {
-        setSize(d.width, d.height);
-    }
-
+    public void redraw() { super.repaint(); }
+    
+    public void setSize(Dimension d) { setSize(d.width, d.height); }
+    
     public void setSize(int width, int height) {
         super.setSize(width, height);
         scalePanel.setLocation(width - scaleWidth, 0);
         scalePanel.setSize(scaleWidth, height);
         sizeChanged = true;
     }
-
+    
     protected void paintComponent(Graphics g) {
         if (sizeChanged) {
             // Determine the width and heights of the calorimeter crystals.
             int width;
-            if (scalePanel.isVisible()) {
-                width = getWidth() - scaleWidth;
-            } else {
-                width = getWidth();
-            }
+            if (scalePanel.isVisible()) { width = getWidth() - scaleWidth; }
+            else { width = getWidth(); }
             int height = getHeight();
-
+            
             boxWidth = width / xBoxes;
             widthRem = width % xBoxes;
             boxHeight = height / yBoxes;
@@ -327,7 +265,7 @@
         }
         int heightRemReset = heightRem;
         int widthRemReset = widthRem;
-
+        
         // Start drawing the calorimeter crystals. To avoid having empty
         // space, we distribute the extra widthRem pixels to the boxes at
         // a rate of one pixel for box until we run out. We do the same thing
@@ -348,22 +286,19 @@
                     th++;
                     heightRem--;
                 }
-
+                
                 if (sizeChanged || scaleChanged || changed[x][y]) {
                     // Determine the appropriate color for the box.
                     Color crystalColor;
-                    if (disabled[x][y]) {
-                        crystalColor = Color.BLACK;
-                    } else {
-                        crystalColor = scale.getColor(hit[x][y]);
-                    }
+                    if (disabled[x][y]) { crystalColor = Color.BLACK; }
+                    else { crystalColor = scale.getColor(hit[x][y]); }
                     g.setColor(crystalColor);
-
+                    
                     // Draw the box.
                     g.fillRect(curX, curY, tw, th);
                     g.setColor(Color.BLACK);
                     g.drawRect(curX, curY, tw, th);
-
+                    
                     // If there is a cluster, draw an x.
                     if (cluster[x][y]) {
                         // Get the correct coordinates.
@@ -371,7 +306,7 @@
                         double lth = (0.5 * th) / 2;
                         double[] lx = { curX + ltw, curX + tw - ltw };
                         double[] ly = { curY + lth, curY + th - lth };
-
+                        
                         // Get the appropriate cluster color.
                         Color c;
                         if (clusterColor == null) {
@@ -379,10 +314,9 @@
                             int blue = Math.abs(255 - crystalColor.getBlue());
                             int green = Math.abs(255 - crystalColor.getGreen());
                             c = new Color(red, green, blue);
-                        } else {
-                            c = clusterColor;
                         }
-
+                        else { c = clusterColor; }
+                        
                         // Draw an x on the cluster crystal.
                         Graphics2D g2 = (Graphics2D) g;
                         g2.setColor(c);
@@ -394,69 +328,66 @@
                         // g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         // RenderingHints.VALUE_ANTIALIAS_OFF);
                     }
-
+                    
                     // Note that this crystals has been updated.
                     changed[x][y] = false;
                 }
-
+                
                 // Increment the current y position.
                 curY += th;
             }
-
+            
             // Increment the current x position.
             curX += tw;
-
+            
             // Reset the current y position and heightRem.
             curY = 0;
             heightRem = heightRemReset;
         }
-
+        
         // If the scale has changed, redraw the scale panel as well.
         if (scaleChanged && scalePanel.isVisible()) {
             scalePanel.redraw();
         }
-
+        
         // Indicate that the any size changes have been handled.
         scaleChanged = false;
         sizeChanged = false;
-
+        
         // Reset the height and width remainder variables.
         heightRem = heightRemReset;
         widthRem = widthRemReset;
     }
-
+    
     /**
      * The local class <b>ScalePanel</b> renders the scale for the calorimeter
      * color map.
      **/
     private class ScalePanel extends JPanel {
         /**
-         * <b>redraw</b><br/>
-         * <br/>
-         * <code>public void <b>redraw</b>()</code><br/>
-         * <br/>
+         * <b>redraw</b><br/><br/>
+         * <code>public void <b>redraw</b>()</code><br/><br/>
          * Orders the scale to re-render itself.
          **/
-        public void redraw() {
-            super.repaint();
-        }
-
+        public void redraw() { super.repaint(); }
+        
         protected void paintComponent(Graphics g) {
             // Set the text region width.
             int textWidth = 45;
             boolean useText;
-
+            
             // Store height and width.
             int height = getHeight();
             int width;
             if (getWidth() > textWidth) {
                 width = getWidth() - textWidth;
                 useText = true;
-            } else {
+            }
+            else {
                 width = getWidth();
                 useText = false;
             }
-
+            
             // Define the step size for the scale. This will differ depending
             // on whether we employ a linear or logarithmic scale.
             double step;
@@ -465,40 +396,38 @@
             if (linear) {
                 step = (scale.getMaximum() - scale.getMinimum()) / height;
                 curValue = scale.getMinimum();
-            } else {
+            }
+            else {
                 double max = Math.log10(scale.getMaximum());
                 double min = Math.log10(scale.getMinimum());
                 step = (max - min) / height;
                 curValue = min;
             }
-
+            
             // Color the text area.
             g.setColor(Color.BLACK);
             g.drawRect(0, 0, width, height);
             g.drawRect(1, 1, width - 1, height - 1);
             g.fillRect(width, 0, textWidth, height);
-
+            
             // Render the scale.
             int sy = height;
             int[] sx = { 0, width };
             for (int i = 0; i <= height; i++) {
                 // Get the appropriate value for the current pixel.
                 double scaledValue;
-                if (linear) {
-                    scaledValue = curValue;
-                } else {
-                    scaledValue = Math.pow(10, curValue);
-                }
+                if (linear) { scaledValue = curValue; }
+                else { scaledValue = Math.pow(10, curValue); }
                 g.setColor(scale.getColor(scaledValue));
-
+                
                 // Draw a line.
                 g.drawLine(sx[0], sy, sx[1], sy);
-
+                
                 // Update the spacing variables.
                 curValue += step;
                 sy--;
             }
-
+            
             // Generate the scale text.
             if (useText) {
                 // Determine the spacing of the text.
@@ -506,33 +435,30 @@
                 int fontHeight = fm.getHeight();
                 double fStep = (height - 2.0 * fontHeight) / fontHeight;
                 double halfStep = fStep / 2.0;
-
+                
                 // Get the scaling value.
                 double fScale;
                 double fMin;
                 if (linear) {
                     fScale = scale.getMaximum() - scale.getMinimum();
                     fMin = scale.getMinimum();
-                } else {
-                    fScale = Math.log10(scale.getMaximum())
-                            - Math.log10(scale.getMinimum());
+                }
+                else {
+                    fScale = Math.log10(scale.getMaximum() - Math.log10(scale.getMinimum()));
                     fMin = Math.log10(scale.getMinimum());
                 }
-
+                
                 // Populate the first and last values.
                 NumberFormat nf = new DecimalFormat("0.#E0");
                 g.setColor(Color.WHITE);
-                g.drawString(nf.format(scale.getMaximum()), width + 5,
-                        fontHeight);
-                g.drawString(nf.format(scale.getMinimum()), width + 5,
-                        height - 3);
-
+                g.drawString(nf.format(scale.getMaximum()), width + 5, fontHeight);
+                g.drawString(nf.format(scale.getMinimum()), width + 5, height - 3);
+                
                 // Calculate text placement variables.
                 double heightAvailable = height - 2.0 * fontHeight;
                 double heightDefault = heightAvailable / (1.5 * fontHeight);
                 int num = (int) Math.floor(heightAvailable / heightDefault);
-                double heightRemainder = heightAvailable
-                        - (num * heightDefault);
+                double heightRemainder = heightAvailable - (num * heightDefault);
                 double heightExtra = heightRemainder / num;
                 double lSpacing = heightDefault + heightExtra;
                 double lHalfSpacing = lSpacing / 2.0;
@@ -540,20 +466,21 @@
                 int[] lX = { width - 4, width, width + 5 };
                 int lShift = (int) (fontHeight * 0.25 + lHalfSpacing);
                 double lTemp = 0.0;
-
+                
                 // Calculate value conversion variables.
                 double lMin = scale.getMinimum();
                 double lScale;
                 if (linear) {
                     lMin = scale.getMinimum();
                     lScale = scale.getMaximum() - scale.getMinimum();
-                } else {
+                }
+                else {
                     double min = Math.log10(scale.getMinimum());
                     double max = Math.log10(scale.getMaximum());
                     lMin = min;
                     lScale = max - min;
                 }
-
+                
                 // Write the labels.
                 for (int i = 0; i < num; i++) {
                     g.setColor(Color.BLACK);
@@ -561,9 +488,7 @@
                     g.drawLine(lX[0], h, lX[1], h);
                     g.setColor(Color.WHITE);
                     double lVal = lMin + (1.0 - ((double) h / height)) * lScale;
-                    if (!linear) {
-                        lVal = Math.pow(10, lVal);
-                    }
+                    if (!linear) { lVal = Math.pow(10, lVal); }
                     g.drawString(nf.format(lVal), lX[2], lHeight + lShift);
                     lTemp += lSpacing;
                     lHeight = (int) (fontHeight + lTemp);
SVNspam 0.1