[Schmitzm-commits] r2237 - in trunk/schmitzm-core/src/main/java/de/schmitzm: lang swing

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 21 16:21:51 CET 2013


Author: mojays
Date: 2013-02-21 16:21:51 +0100 (Thu, 21 Feb 2013)
New Revision: 2237

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
LangUtil: new methods min(.)/max(.) for arrays
LangUtil: new methods getDigits(.) to determine number of digits for double value
SwingUtil: initializer methods createSelectableJTable(.)

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2013-02-21 15:20:16 UTC (rev 2236)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2013-02-21 15:21:51 UTC (rev 2237)
@@ -1916,7 +1916,19 @@
 		return max(0, collections);
 	}
 
-	/**
+    /**
+     * Returns the maximum value of some double values
+     */
+    public static double max(double... values) {
+      if ( values.length == 0 )
+        return 0;
+      double maxValue = values[0];
+      for (double v : values)
+        maxValue = Math.max(v, maxValue);
+      return maxValue;
+    }
+
+    /**
 	 * Returns the minimum value of some integer collections.
 	 * 
 	 * @param defMinValue
@@ -1945,7 +1957,45 @@
 		return min(0, collections);
 	}
 
+    /**
+     * Returns the minimum value of some double values
+     */
+    public static double min(double... values) {
+      if ( values.length == 0 )
+        return 0;
+      double minValue = values[0];
+      for (double v : values)
+        minValue = Math.min(v, minValue);
+      return minValue;
+    }
+	
 	/**
+	 * Determines the number of digits of a value.
+	 * @param value a decimal value
+	 * @param maxDigits maximum number of digits to test (to avoid infinite test!)
+	 * @return {@code maxDigits + 1} if value has more digits 
+	 */
+	public static int getDigits(double value, int maxDigits) {
+	  for (int dig=0; dig<=maxDigits; dig++) {
+	    if ( value == round(value, dig) )
+	      return dig;
+	  }
+	  return maxDigits + 1;
+	}
+
+	/**
+     * Determines the number of digits of a value and returns a corrisponding initialized
+     * double value (0.1, 0.01, 0.001, etc.).
+     * @param value a decimal value
+     * @param maxDigits maximum number of digits to test (to avoid infinite test!)
+     * @see #getDigits(double, int) 
+     */
+    public static double getDigitValue(double value, int maxDigits) {
+      int digits = getDigits(value, maxDigits);
+      return Math.pow(10, -digits);
+    }
+
+	/**
 	 * Rundet einen Wert auf Nach- oder Vorkommastellen.
 	 * 
 	 * @param value

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2013-02-21 15:20:16 UTC (rev 2236)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2013-02-21 15:21:51 UTC (rev 2237)
@@ -123,6 +123,7 @@
 import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.TableCellEditor;
 import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableModel;
 import javax.swing.text.JTextComponent;
 import javax.swing.text.View;
 import javax.swing.tree.TreeNode;
@@ -146,6 +147,7 @@
 import de.schmitzm.swing.input.ManualInputOption;
 import de.schmitzm.swing.input.MultipleOptionPane;
 import de.schmitzm.swing.table.ComponentRenderer;
+import de.schmitzm.swing.table.SelectionTableModel;
 
 /**
  * Diese Klasse beinhaltet statische Hilfsfunktionen fuer das Arbeiten mit
@@ -1017,6 +1019,30 @@
 		fixComponentSize(comp, comp.getPreferredSize());
 	}
 	
+    /**
+     * Pipes any kind of {@link TableModel} to a {@link SelectionTableModel} and
+     * creates a {@link SelectableJTable} with this {@link SelectionTableModel}.
+     * @param model table model to pipe
+     */
+    public static SelectableJTable createSelectableJTable(TableModel model) {
+      return initSelectableJTable(model, null);
+    }
+
+    /**
+	 * Pipes any kind of {@link TableModel} to a {@link SelectionTableModel} and
+	 * initializes a {@link SelectableJTable} with this {@link SelectionTableModel}.
+	 * @param model table model to pipe
+	 * @param table table to initialize (if {@code null} a new {@link SelectableJTable} is
+	 *              created)
+	 * @return {@code table} or the new created {@link SelectableJTable} instance 
+	 */
+	public static SelectableJTable initSelectableJTable(TableModel model, SelectableJTable table) {
+	  if ( table == null )
+	    table = new SelectableJTable();
+	  table.setModel( new SelectionTableModel(model, table) );
+	  return table;
+	}
+	
 	/**
 	 * Returns the preferred size to set a component at in order to render
 	 * an html string.



More information about the Schmitzm-commits mailing list