[Schmitzm-commits] r697 - in trunk/src/schmitzm: geotools/gui geotools/io swing/table

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Feb 13 15:46:44 CET 2010


Author: mojays
Date: 2010-02-13 15:46:42 +0100 (Sat, 13 Feb 2010)
New Revision: 697

Added:
   trunk/src/schmitzm/swing/table/DoubleRenderer.java
Modified:
   trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java
   trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
   trunk/src/schmitzm/geotools/io/GeoImportUtil.java
Log:
- GeoImportUtil: use of CRS.parseWKT(.) replaced by GTUtil.createCRS(.) to provide use of EPSG-Codes
- new DoubleRenderer: format Double table cells with tooltip
- FeatureTablePane: double attributes are formatted with 3 digits and tooltip with all digits

Modified: trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java	2010-02-13 11:54:14 UTC (rev 696)
+++ trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java	2010-02-13 14:46:42 UTC (rev 697)
@@ -254,7 +254,8 @@
           featureArray = FeatureUtil.featuresToArray(featureTable);
       if (featureArray[row] == null)
         return null;
-      return featureArray[row].getAttribute( attrIdxForCol[col] );
+      Object value = featureArray[row].getAttribute( attrIdxForCol[col] ); 
+      return value;
   }
   
   /**

Modified: trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2010-02-13 11:54:14 UTC (rev 696)
+++ trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2010-02-13 14:46:42 UTC (rev 697)
@@ -32,6 +32,7 @@
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
+import java.text.NumberFormat;
 
 import javax.swing.BorderFactory;
 import javax.swing.JScrollPane;
@@ -55,6 +56,7 @@
 import schmitzm.swing.JPanel;
 import schmitzm.swing.SortableJTable;
 import schmitzm.swing.SwingUtil;
+import schmitzm.swing.table.DoubleRenderer;
 
 /**
  * Diese Komponente stellt eine Tabelle dar, in der die Attribute einer
@@ -239,9 +241,7 @@
 			// }
 			// };
 			mapPane.setToolTipText(GeotoolsGUIUtil.R(PREVIEW_MAPPANE_TOOLTIP));
-
 //			mapPane.setState(SelectableXMapPane.NONE);
-			
 			mapPane.setMinimumSize(new Dimension(100, 100));
 			SwingUtil.setPreferredWidth(mapPane, 200);
 			mapPane.setBorder(BorderFactory.createLoweredBevelBorder());
@@ -254,8 +254,7 @@
 		featuresTable.setModel(featuresTableModel);
 		featuresTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 		featuresTable.setColumnSelectionAllowed(false);
-		featuresTable
-				.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+		featuresTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 		// Wenn Auswahl in Tabelle sich aendert, Vorschau anpassen
 		featuresTable.getSelectionModel().addListSelectionListener(
 				new ListSelectionListener() {
@@ -282,7 +281,12 @@
 				showFeaturesInMap();
 			}
 		});
-
+		// Format fuer Double auf 3 Nachkommastellen setzen
+		NumberFormat formatter = NumberFormat.getNumberInstance();
+		formatter.setMinimumFractionDigits(3);
+		formatter.setMaximumFractionDigits(3);
+		DoubleRenderer doubleRenderer = new DoubleRenderer(formatter,null);
+		featuresTable.setDefaultRenderer(Double.class, doubleRenderer);
 	}
 
 	/**

Modified: trunk/src/schmitzm/geotools/io/GeoImportUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-02-13 11:54:14 UTC (rev 696)
+++ trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-02-13 14:46:42 UTC (rev 697)
@@ -246,7 +246,8 @@
 			// Standard-CRS
 			// zu setzen
 			LOGGER.debug("  parseWKT on " + prjUrl);
-			CRS.parseWKT(readProjectionString(prjUrl));
+//            CRS.parseWKT(readProjectionString(prjUrl));
+            GTUtil.createCRS(readProjectionString(prjUrl));
 		} catch (Exception err) {
 			LOGGER.warn(" CRS.parseWKT mit Ex\n: ", err);
 			LOGGER.warn(" No projection found for file. Default is used.");
@@ -304,7 +305,8 @@
 			if (prjString == null || prjString.trim().equals(""))
 				throw new FileNotFoundException("No proper prj-File exists: "
 						+ file.getName());
-			CRS.parseWKT(prjString);
+//			CRS.parseWKT(prjString);
+            GTUtil.createCRS(prjString);
 		} catch (FileNotFoundException err) {
 			store.forceSchemaCRS(getDefaultCRS());
 			LOGGER.warn("No projection found for file " + file.getName()

Added: trunk/src/schmitzm/swing/table/DoubleRenderer.java
===================================================================
--- trunk/src/schmitzm/swing/table/DoubleRenderer.java	2010-02-13 11:54:14 UTC (rev 696)
+++ trunk/src/schmitzm/swing/table/DoubleRenderer.java	2010-02-13 14:46:42 UTC (rev 697)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+package schmitzm.swing.table;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.text.NumberFormat;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.border.Border;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableCellRenderer;
+
+/**
+ * Diese Klasse stellt einen Renderer fuer Tabellenzellen dar, in denen
+ * eine {@link Double}-Wert dargestellt werden soll.<br>
+ * Das {@linkplain NumberFormat Format} kann individuell gesetzt werden.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * @version 1.0
+ */
+public class DoubleRenderer extends DefaultTableCellRenderer.UIResource {
+  /** Speichert das Format, in dem der {@link Double}-Wert <b>in der Zelle</b>
+   *  dargestellt wird. */
+  protected NumberFormat cellFormatter = null;
+
+  /** Speichert das Format, in dem der {@link Double}-Wert <b>im Tooltip</b>
+   *  dargestellt wird. */
+  protected NumberFormat tooltipFormatter = null;
+  
+  /** Speichert, ob ein Tooltip angezeigt wird. */
+  protected boolean tooltipEnabled = true;
+
+  /**
+   * Erzeugt einen neuen Zellen-Renderer. Wird {@code null} als Format uebergeben,
+   * wird der {@link Double}-Wert unformatiert mittels {@link Double#toString()}
+   * dargestellt.
+   * @param cellFormatter bestimmt das Format, in dem der {@link Double}-Wert
+   *                      <b>in der Zelle</b> dargestellt wird.
+   * @param tooltipFormatter bestimmt das Format, in dem der {@link Double}-Wert
+   *                         <b>im Tooltip</b> dargestellt wird.
+   */
+  public DoubleRenderer(NumberFormat cellFormatter, NumberFormat tooltipFormatter) {
+    super();
+    setHorizontalAlignment(JLabel.RIGHT);
+    setCellFormat(cellFormatter);
+  }
+
+  /**
+   * Setzt das Format, in dem der {@link Double}-Wert in der Zelle dargestellt wird.
+   * @param formatter Format, in dem der {@link Double}-Wert in der Zelle
+   *                  dargestellt wird (wenn {@code null}, wird der Tooltip
+   *                  unformatiert mittels {@link Double#toString()} dargestellt).
+   */
+  public void setCellFormat(NumberFormat formatter) {
+    this.cellFormatter = formatter;
+  }
+
+  /**
+   * Liefert das Format, in dem der {@link Double}-Wert in der Zelle dargestellt wird.
+   */
+  public NumberFormat getCellFormat() {
+    return this.cellFormatter;
+  }
+
+  /**
+   * Setzt das Format, in dem der {@link Double}-Wert im Tooltip dargestellt wird.
+   * @param formatter Format, in dem der {@link Double}-Wert im Tooltip
+   *                  dargestellt wird (wenn {@code null}, wird der Tooltip
+   *                  unformatiert mittels {@link Double#toString()} dargestellt).
+   */
+  public void setTooltipFormat(NumberFormat formatter) {
+    this.tooltipFormatter = formatter;
+  }
+
+  /**
+   * Liefert das Format, in dem der {@link Double}-Wert im Tooltip dargestellt wird.
+   */
+  public NumberFormat getTooltipFormat() {
+    return this.tooltipFormatter;
+  }
+
+  /**
+   * Setzt, ob der Tooltip fuer die Zelle angezeigt wird.
+   */
+  public void setTooltipEnabled(boolean enabled) {
+    this.tooltipEnabled = enabled;
+  }
+  
+  /**
+   * Prueft, ob der Tooltip fuer die Zelle angezeigt wird.
+   */
+  public boolean isTooltipEnabled() {
+    return tooltipEnabled;
+  }
+  
+  /**
+   * Formatiert einen Wert und belegt entsprechend das Label. 
+   * @see JLabel#setText(String)
+   */
+  @Override
+  public void setValue(Object value) {
+    if ( value == null ) {
+      setText( "" );
+      setToolTipText( "<null>" );
+    } else {
+      setText( cellFormatter != null ? cellFormatter.format(value) : value.toString() );
+      setToolTipText( tooltipFormatter != null ? tooltipFormatter.format(value) : value.toString() );
+    }
+    
+    // Tooltip initialisieren, wenn nicht aktiviert
+    if ( !tooltipEnabled )
+      setToolTipText(null);
+  }
+  
+}



More information about the Schmitzm-commits mailing list