[Schmitzm-commits] r742 - in trunk/src/schmitzm/jfree: feature feature/style resource/locales

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Mar 3 12:31:17 CET 2010


Author: alfonx
Date: 2010-03-03 12:31:16 +0100 (Wed, 03 Mar 2010)
New Revision: 742

Added:
   trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java
Modified:
   trunk/src/schmitzm/jfree/feature/AggregationFunction.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
   trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties
Log:
null is available in AggregationFunctionJCOmboBox

Modified: trunk/src/schmitzm/jfree/feature/AggregationFunction.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/AggregationFunction.java	2010-03-03 10:49:28 UTC (rev 741)
+++ trunk/src/schmitzm/jfree/feature/AggregationFunction.java	2010-03-03 11:31:16 UTC (rev 742)
@@ -1,6 +1,6 @@
 package schmitzm.jfree.feature;
 
-import hep.aida.bin.StaticBin1D;
+import hep.aida.bin.QuantileBin1D;
 
 import java.awt.Component;
 
@@ -18,6 +18,8 @@
  * 
  * @see FeatureChartStyle#setAttributeAggregation(int, AggregationFunction)
  * @see FeatureChartStyle#getAttributeAggregation(int)
+ * @see optionally FeatureChartStyle#setNoDataWeightValues(int, java.util.Set))
+ * @see optionally FeatureChartStyle#getAttributeAggregationWeightAttributeName(int)
  */
 public enum AggregationFunction {
 
@@ -34,8 +36,8 @@
 	 * weighting
 	 **/
 	AVG_WEIGHTED(true),
-	// /** Median of the attribute values. */
-	// MEDIAN,
+	 /** Median of the attribute values. */
+	 MEDIAN(false),
 	/** Minimum attribute value. */
 	MIN(false),
 	/** Maximum attribute value. */
@@ -47,13 +49,17 @@
 
 	private final boolean weighted;
 
+	/**
+	 * Constructed for this {@link Enum}, defining whether it uses a weight. 
+	 * @param weighted
+	 */
 	AggregationFunction(boolean weighted) {
 		this.weighted = weighted;
 	}
 
 	/**
-	 * Returns true, if this aggreation method is used a second attribute for
-	 * weighting
+	 * Returns <code>true</code>, if this aggregation method is used a second attribute for
+	 * weighting.
 	 **/
 	public boolean isWeighted() {
 		return weighted;
@@ -75,11 +81,13 @@
 	 * @param statistics
 	 *            Statistic to take the result from.
 	 */
-	public Double getResult(StaticBin1D statistics) {
+	public Double getResult(QuantileBin1D statistics) {
 		switch (this) {
 		case AVG:
 		case AVG_WEIGHTED:
 			return statistics.mean();
+		case MEDIAN:
+			return statistics.median();
 		case MAX:
 			return statistics.max();
 		case MIN:
@@ -126,37 +134,4 @@
 		return resource;
 	}
 
-	/**
-	 * A static {@link DefaultListCellRenderer} that will render instances of
-	 * {@link AggregationFunction} with the title and description field as a
-	 * tooltip.
-	 */
-	static ListCellRenderer listCellRenderer = new DefaultListCellRenderer() {
-
-		@Override
-		public Component getListCellRendererComponent(JList list, Object value,
-				int index, boolean isSelected, boolean cellHasFocus) {
-
-			Component proto = super.getListCellRendererComponent(list, value,
-					index, isSelected, cellHasFocus);
-
-			if (proto instanceof JLabel && value instanceof AggregationFunction) {
-				((JLabel) proto).setText(((AggregationFunction) value)
-						.getTitle());
-				((JLabel) proto).setToolTipText(((AggregationFunction) value)
-						.getDescription());
-			}
-
-			return proto;
-		}
-	};
-
-	/**
-	 * Returns a {@link ListCellRenderer} that will render elemnts of type
-	 * {@link AggregationFunction} with their title and description as tooltip
-	 **/
-	public static ListCellRenderer getListCellRenderer() {
-		return listCellRenderer;
-	}
-
 }

Added: trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java	2010-03-03 10:49:28 UTC (rev 741)
+++ trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java	2010-03-03 11:31:16 UTC (rev 742)
@@ -0,0 +1,76 @@
+package schmitzm.jfree.feature;
+
+import java.awt.Component;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+import schmitzm.jfree.JFreeChartUtil;
+import schmitzm.lang.LangUtil;
+
+/**
+ * A {@link JComboBox} to select one {@link AggregationFunction}s. Can be
+ * initialized to also support a <code>null</code>.
+ * 
+ * @author SK
+ */
+public class AggregationFunctionJComboBox extends JComboBox {
+
+	/**
+	 * @param nullAlso
+	 *            if <code>true</code>, <code>null</code> will be the first item
+	 *            in the list.
+	 */
+	public AggregationFunctionJComboBox(boolean nullAlso) {
+		super(nullAlso ? LangUtil.extendArray(
+				new AggregationFunction[] { null }, AggregationFunction
+						.values()) : AggregationFunction.values());
+		setRenderer(listCellRenderer);
+//		ASUtil.addMouseWheelForCombobox(this, false);
+	}
+
+	/**
+	 * By default the <code>null</code> value is added.
+	 */
+	public AggregationFunctionJComboBox() {
+		this(true);
+	}
+
+	/**
+	 * A static {@link DefaultListCellRenderer} that will render instances of
+	 * {@link AggregationFunction} with the title and description field as a
+	 * tooltip.<br/>
+	 * Any <code>null</code> value will also be rendered correctly.
+	 */
+	static ListCellRenderer listCellRenderer = new DefaultListCellRenderer() {
+
+		@Override
+		public Component getListCellRendererComponent(JList list, Object value,
+				int index, boolean isSelected, boolean cellHasFocus) {
+
+			Component proto = super.getListCellRendererComponent(list, value,
+					index, isSelected, cellHasFocus);
+
+			if (proto instanceof JLabel) {
+				JLabel jLabel = (JLabel) proto;
+
+				if (value instanceof AggregationFunction) {
+					jLabel.setText(((AggregationFunction) value).getTitle());
+					jLabel.setToolTipText(((AggregationFunction) value)
+							.getDescription());
+				} else if (value == null) {
+					jLabel.setText(JFreeChartUtil
+							.R("AggregationFunction.NONE.Title"));
+					jLabel.setToolTipText(JFreeChartUtil
+							.R("AggregationFunction.NONE.Desc"));
+				}
+			}
+
+			return proto;
+		}
+	};
+
+}


Property changes on: trunk/src/schmitzm/jfree/feature/AggregationFunctionJComboBox.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2010-03-03 10:49:28 UTC (rev 741)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2010-03-03 11:31:16 UTC (rev 742)
@@ -30,6 +30,7 @@
 package schmitzm.jfree.feature.style;
 
 import hep.aida.bin.DynamicBin1D;
+import hep.aida.bin.QuantileBin1D;
 import hep.aida.bin.StaticBin1D;
 
 import java.util.ArrayList;
@@ -252,14 +253,14 @@
 			dataset.addSeries(xySeries[i]);
 
 		// Calculate any statistics needed for normalization.
-		HashMap<String, StaticBin1D> statisticsForNormalization = calcStatisticsForNormalization(
+		HashMap<String, QuantileBin1D> statisticsForNormalization = calcStatisticsForNormalization(
 				fc, chartStyle);
 		// Prepare set for statistics to calculate aggregation
 		// functions (one statistic for each range attribute of
 		// each domain value)
-		HashMap<Number, StaticBin1D>[] statisticsForAggregation = new HashMap[attrCount];
+		HashMap<Number, QuantileBin1D>[] statisticsForAggregation = new HashMap[attrCount];
 		for (int i = 1; i < attrCount; i++)
-			statisticsForAggregation[i] = new HashMap<Number, StaticBin1D>();
+			statisticsForAggregation[i] = new HashMap<Number, QuantileBin1D>();
 
 		// If dataset should be sorted, the features must be sorted first
 		// according to the domain attribute. The "autoSort" functionality
@@ -379,7 +380,7 @@
 	 *            {@link ChartStyle} to determine which attributes shall be
 	 *            normalized.
 	 */
-	public static HashMap<String, StaticBin1D> calcStatisticsForNormalization(
+	public static HashMap<String, QuantileBin1D> calcStatisticsForNormalization(
 			FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
 			FeatureChartStyle chartStyle) {
 		// NORMALIZATION:
@@ -390,7 +391,7 @@
 		 * Holds the statistics needed to normalize the attribute values. Key =
 		 * attributeName
 		 */
-		HashMap<String, StaticBin1D> attribStats = new HashMap<String, StaticBin1D>();
+		HashMap<String, QuantileBin1D> attribStats = new HashMap<String, QuantileBin1D>();
 
 		// First check if any attribute needs normalization. If not we can
 		// skip the whole iteration
@@ -432,7 +433,7 @@
 
 							// Look for a cached version of the Statistics or
 							// create a new one
-							StaticBin1D stat = attribStats.get(attrName);
+							QuantileBin1D stat = attribStats.get(attrName);
 							if (stat == null) {
 								stat = new DynamicBin1D();
 								attribStats.put(attrName, stat);
@@ -470,7 +471,7 @@
 	 *      FeatureChartStyle, int)
 	 */
 	private static Number normalize(Number yValue, String attrName,
-			HashMap<String, StaticBin1D> statisticsForNormalization) {
+			HashMap<String, QuantileBin1D> statisticsForNormalization) {
 		Number zValue;
 
 		if (statisticsForNormalization.get(attrName) == null) {
@@ -520,14 +521,14 @@
 					Number.class, "Range attribute", "CategoryDataset");
 
 		// Calculate any statistics needed for normalization.
-		HashMap<String, StaticBin1D> statisticsForNormalization = calcStatisticsForNormalization(
+		HashMap<String, QuantileBin1D> statisticsForNormalization = calcStatisticsForNormalization(
 				fc, chartStyle);
 		// Prepare set for statistics to calculate aggregation
 		// functions (one statistic for each range attribute of
 		// each domain value)
-		HashMap<Comparable<?>, StaticBin1D>[] statisticsForAggregation = new HashMap[attrCount];
+		HashMap<Comparable<?>, QuantileBin1D>[] statisticsForAggregation = new HashMap[attrCount];
 		for (int i = 1; i < attrCount; i++)
-			statisticsForAggregation[i] = new HashMap<Comparable<?>, StaticBin1D>();
+			statisticsForAggregation[i] = new HashMap<Comparable<?>, QuantileBin1D>();
 
 		// Create a new dataset and insert the series
 		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
@@ -664,7 +665,7 @@
 						// Mapping between FID and data index in series
 						mapping.setMapping(f.getID(), yAttrName, catValue);
 					} else {
-						StaticBin1D aggrStat = statisticsForAggregation[attrIdx]
+						QuantileBin1D aggrStat = statisticsForAggregation[attrIdx]
 								.get(catValue);
 						if (aggrStat == null) {
 							aggrStat = new DynamicBin1D();
@@ -710,7 +711,7 @@
 					continue;
 				for (Comparable<?> catValue : statisticsForAggregation[attrIdx]
 						.keySet()) {
-					StaticBin1D aggrStat = statisticsForAggregation[attrIdx]
+					QuantileBin1D aggrStat = statisticsForAggregation[attrIdx]
 							.get(catValue);
 					Number yValue = aggrFunc.getResult(aggrStat);
 					// Fill series

Modified: trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties
===================================================================
--- trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties	2010-03-03 10:49:28 UTC (rev 741)
+++ trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties	2010-03-03 11:31:16 UTC (rev 742)
@@ -53,6 +53,8 @@
 
 FeatureChartAxisStyle.normalized=normalized
 
+AggregationFunction.NONE.Title=---
+AggregationFunction.NONE.Desc=<html>If multiple features fall into one category, only the <i>last</i> value is used.</html>  
 AggregationFunction.COUNT.Title=Count
 AggregationFunction.COUNT.Desc=Count of features
 AggregationFunction.SUM.Title=Sum



More information about the Schmitzm-commits mailing list