[Schmitzm-commits] r407 - in branches/1.0-gt2-2.6: dist src/schmitzm/geotools/gui src/schmitzm/geotools/gui/resource/locales
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Sep 14 20:38:47 CEST 2009
Author: mojays
Date: 2009-09-14 20:38:36 +0200 (Mon, 14 Sep 2009)
New Revision: 407
Added:
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter_WGS84.java
Modified:
branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6-src.zip
branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapPanel.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanel.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties
Log:
new GridPanelFormatter for GridPanel
Modified: branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6-src.zip
===================================================================
(Binary files differ)
Modified: branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
===================================================================
(Binary files differ)
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapPanel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapPanel.java 2009-09-14 18:06:27 UTC (rev 406)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapPanel.java 2009-09-14 18:38:36 UTC (rev 407)
@@ -51,6 +51,8 @@
public class ColorMapPanel extends JPanel {
/** Holds the color map table. */
protected ColorMapTable colMapTable = null;
+ /** Holds the combo box to chose the color map type (Ramp, Intervals,
+ * Values). */
protected SelectionInputOption<Integer> colMapType = null;
/**
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanel.java 2009-09-14 18:06:27 UTC (rev 406)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanel.java 2009-09-14 18:38:36 UTC (rev 407)
@@ -35,11 +35,13 @@
import java.text.DecimalFormat;
import org.apache.log4j.Logger;
+import org.geotools.factory.Hints;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.referencing.operation.projection.PointOutsideEnvelopeException;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeographicCRS;
import org.opengis.referencing.operation.MathTransform;
import schmitzm.lang.LangUtil;
@@ -55,10 +57,7 @@
*/
public class GridPanel extends JPanel {
private final Logger LOGGER = LangUtil.createLogger(this);
- private static final ResourceProvider RES = GeotoolsGUIUtil.RESOURCE;
- private static final DecimalFormat numFormat = new DecimalFormat("###,###,##0");
-
/** Laenge der Grid-Abschnitts-Linien. */
private static final int GRID_LINE_SIZE = 10;
/** Container-Breite bei vertikalem Grid. */
@@ -83,17 +82,38 @@
protected MathTransform gridToMap = null;
/** Speichert das CRS, fuer das die Transformationen erstellt wurden. */
private CoordinateReferenceSystem transformedMapCRS = null;
+ /** Enthaelt Informationen, in welchem CRS die Koordinaten-Leiste dargestellt wird,
+ * und entsprechend, wie die Koordinaten in diesem CRS dargestellt werden. */
+ protected GridPanelFormatter formatter = null;
+ /** Flag, um das Verdrehen der Koorinaten nach der Projektion zu erzwingen.
+ * Kann in manchen Situationen sinnvoll sein. */
+ protected boolean forceXYIndexSwitch = false;
+
+ /**
+ * Erzeugt eine WGS84-Koordinaten-Leiste fuer ein {@link JMapPane}.
+ * @param orientation Orientierung ({@link #HORIZONTAL} oder {@link #VERTICAL})
+ * @param mapPane Karte an der die Koordinaten-Leiste ausgerichtet wird
+ * @see GridPanelFormatter_WGS84
+ */
+ public GridPanel(int orientation, JMapPane mapPane) {
+ this(orientation,mapPane,null);
+ }
/**
* Erzeugt eine Koordinaten-Leiste fuer ein {@link JMapPane}.
* @param orientation Orientierung ({@link #HORIZONTAL} oder {@link #VERTICAL})
* @param mapPane Karte an der die Koordinaten-Leiste ausgerichtet wird
+ * @param formatter definiert das CRS und Koordinaten-Format fuer die Koordinaten
+ * Leiste (wenn {@code null} wird ein {@link GridPanelFormatter_WGS84}
+ * verwendet)
*/
- public GridPanel(int orientation, JMapPane mapPane) {
+ public GridPanel(int orientation, JMapPane mapPane, GridPanelFormatter formatter) {
super();
-
this.orientation = orientation;
this.mapPane = mapPane;
+ setGridFormatter(formatter);
+ setXYIndexSwitchForced(false);
+
if ( isVertical() )
SwingUtil.setPreferredWidth(this,VERT_WIDTH);
else
@@ -122,8 +142,52 @@
public boolean isVertical() {
return this.orientation == VERTICAL;
}
+
+ /**
+ * Liefert den {@link GridPanelFormatter}, mit dem die Darstellung der
+ * Koordinaten bestimmt wird.
+ */
+ public GridPanelFormatter getGridFormatter() {
+ return this.formatter;
+ }
/**
+ * Aendert den {@link GridPanelFormatter}, mit dem die Darstellung der
+ * Koordinaten bestimmt wird.
+ * @param formatter neuer {@link GridPanelFormatter} (wenn {@code null}
+ * wird ein {@link GridPanelFormatter_WGS84} verwendet)
+ */
+ public void setGridFormatter(GridPanelFormatter formatter) {
+ GridPanelFormatter oldFormatter = getGridFormatter();
+ if ( formatter == null )
+ formatter = new GridPanelFormatter_WGS84();
+ this.formatter = formatter;
+ // wenn sich der Formatter geaendert hat, die Transformation initialisieren,
+ // diese beim naechsten paint(.) erneuert werden
+ if ( getGridFormatter() != oldFormatter ) {
+ mapToGrid = null;
+ gridToMap = null;
+ }
+
+ }
+
+ /**
+ * Liefert {@code true}, wenn das Verdrehen der X- und Y-Koordinate nach
+ * der Transformation erzwungen wird (Default: {@code false}).
+ */
+ public boolean isXYIndexSwitchForced() {
+ return forceXYIndexSwitch;
+ }
+
+ /**
+ * Ermoeglicht, das Verdrehen der X- und Y-Koordinate nach
+ * der Transformation zu erzwingen (Default: {@code false}).
+ */
+ public void setXYIndexSwitchForced(boolean forceXYSwitch) {
+ this.forceXYIndexSwitch = forceXYSwitch;
+ }
+
+ /**
* Zeichnet die Koordinaten-Leiste.
* @param g Graphics
*/
@@ -146,12 +210,12 @@
// return;
// }
-
mapCRS = mapPane.getContext().getCoordinateReferenceSystem();
-
- gridCRS = DefaultGeographicCRS.WGS84;// lat/lon
-// LOGGER.debug("mapCRS: "+mapCRS);
-// LOGGER.debug("gridCRS: "+gridCRS);
+ gridCRS = formatter.getCRS();// lat/lon
+ LOGGER.debug("mapCRS = "+LangUtil.getSimpleClassName(mapCRS));
+ LOGGER.debug("gridCRS = "+LangUtil.getSimpleClassName(gridCRS));
+ LOGGER.debug("mapCRS: "+mapCRS);
+ LOGGER.debug("gridCRS: "+gridCRS);
double minX = mapPane.getMapArea().getMinX();
double minY = mapPane.getMapArea().getMinY();
@@ -180,7 +244,7 @@
transformedMapCRS = mapCRS;
}
} catch (FactoryException err) {
- LOGGER.warn("CRS-Transformation to WGS84 failed: "+err.getMessage());
+ LOGGER.warn("CRS-Transformation to grid CRS ("+gridCRS.getName()+") failed: "+err.getMessage());
mapToGrid = CRS.findMathTransform(mapCRS, gridCRS, true);
gridToMap = CRS.findMathTransform(gridCRS, mapCRS, true);
LOGGER.warn("CRS-Transformation without datum shift");
@@ -192,8 +256,8 @@
} catch (PointOutsideEnvelopeException err) {
return;
} catch (Exception err) {
- LOGGER.error("CRS-Transformation to WGS84 failed: "+err.getMessage());
- LOGGER.debug("CRS-Transformation to WGS84 failed: "+err.getMessage(),err);
+ LOGGER.error("CRS-Transformation to grid CRS ("+gridCRS.getName()+") failed: "+err.getMessage());
+ LOGGER.debug("CRS-Transformation to grid CRS ("+gridCRS.getName()+") failed: "+err.getMessage(),err);
}
// // Ergebnis von Transform: {Latitude,Longitude}
@@ -202,7 +266,18 @@
// manchmal {Longitude,Latitude}!!
// WORKAROUND (klappt natuerlich nicht mit allen CRS!):
// Wenn X_MCRS > Y_MCRS, dann muss auch X_GCRS > Y_GCRS
- int idx = determineCompatibleArrayIndex(mapMin_MCRS,mapMin_GCRS,mapMax_MCRS,mapMax_GCRS);
+// int idx = determineCompatibleArrayIndex(mapMin_MCRS,mapMin_GCRS,mapMax_MCRS,mapMax_GCRS);
+
+ // Neuer Versuch des WORKAROUND:
+ // Default: {Longitude,Latitude}, also {X,Y}
+ int idx = isHorizontal() ? 0 : 1;
+ // Wenn die CRS verdreht sind, ist auch das Resultat der Transformation verdreht
+ boolean switchXY = isXYIndexSwitchForced() || !(mapCRS instanceof GeographicCRS ^ gridCRS instanceof GeographicCRS);
+ if ( switchXY ) {
+ LOGGER.debug("Coordinates switched!");
+ idx = 1-idx;
+ }
+
// LOGGER.debug( isVertical() ? "V" : "H" );
// LOGGER.debug( "Min MCRS: "+mapMin_MCRS[0]+", "+mapMin_MCRS[1]+" GCRS:"+mapMin_GCRS[0]+", "+mapMin_GCRS[1]);
// LOGGER.debug( "Max MCRS: "+mapMax_MCRS[0]+", "+mapMax_MCRS[1]+" GCRS:"+mapMax_GCRS[0]+", "+mapMax_GCRS[1]);
@@ -214,7 +289,7 @@
int maxSize = isHorizontal() ? getParent().getWidth() : getParent().getHeight();
// Passende Grid-Unterteilung in Grad
- double gridDist = determineGridDistance(mapMin,mapMax,maxSize);
+ double gridDist = formatter.determineGridDistance(mapMin,mapMax,maxSize);
// Leiste zeichnen
if ( isHorizontal() )
g.drawLine(0,0,maxSize,0);
@@ -233,102 +308,27 @@
try {
gridToMap.transform(grid_GCRS, 0, grid_MCRS, 0, 1);
mapToWin.inverseTransform(grid_MCRS,0,grid_WINDOW,0,1);
-// } catch (Exception err) {
} catch (Throwable err) {
LOGGER.warn("Error ignored during paint of coordinate grid: "+err);
continue;
}
+
// Grid-Abschnitt zeichnen
int x1 = isVertical() ? VERT_WIDTH-GRID_LINE_SIZE : (int)grid_WINDOW[0];
int y1 = isVertical() ? (int)grid_WINDOW[1] : 0;
int x2 = isVertical() ? x1+GRID_LINE_SIZE : x1;
int y2 = isVertical() ? y1 : y1+GRID_LINE_SIZE;
g.drawLine(x1,y1,x2,y2);
-
+
// Koordinate anzeigen
- double coord = grid_GCRS[idx];
- int degrees = (int)coord;
- int minutes = (int)Math.round((coord-degrees)*60 );
- // Aufgrund des Minuten-Systems kann schlecht im Vorhinein gerundet
- // werden. Deshalb wird im Nachhinein ein etwaiger Rundungsfehler
- // ausgeglichen
- if ( Math.abs(minutes) >= 60 ) {
- degrees += Math.signum(minutes);
- minutes -= Math.signum(minutes) * 60;
- }
- String coordStr = Math.abs(degrees)+"°"+Math.abs(minutes);
- if ( degrees != 0 || minutes != 0 ) {
- if (isVertical())
- coordStr += RES.getString( (coord < 0) ? "schmitzm.geotools.gui.GeotoolsGUIUtil.SOUTH.Abb" : "schmitzm.geotools.gui.GeotoolsGUIUtil.NORTH.Abb" );
- else
- coordStr += RES.getString( (coord < 0) ? "schmitzm.geotools.gui.GeotoolsGUIUtil.WEST.Abb" : "schmitzm.geotools.gui.GeotoolsGUIUtil.EAST.Abb" );
- }
+ String coordStr = formatter.formatCoordinate(this, grid_GCRS[idx]);
x1 = isVertical() ? 5 : x1 + 5;
y1 = isVertical() ? y1-2 : y1 + 12;
g.drawString( coordStr, x1, y1 );
}
-
-///////////// Test und Debugging /////////////////
-// System.out.println("2 UTM lat="+minY+" lon="+minX+" --> Degree lat="+dest2[0]+" lon="+dest2[1]);
-
-// org.geotools.referencing.operation.DefaultMathTransformFactory.main(new String[] {});
-// if ( debug == 0) {
-// schmitzm.lang.WorkingThread w = new schmitzm.lang.WorkingThread() {
-// java.util.Set codes = null;
-// public void performInit() {
-// codes = CRS.getSupportedCodes("EPSG");
-// }
-// public void performWork() {
-// for (Object code : codes) {
-// String crsCode = ((String)code).startsWith("EPSG") ? (String)code : "EPSG:"+((String)code);
-// try {
-// CoordinateReferenceSystem crs = CRS.decode(crsCode);
-// System.out.println(code+"\t"+crsCode+"\t"+crs.getName());
-// } catch (Exception e) {
-// System.out.println(code+"\t"+crsCode+"\tError");
-// break;
-// }
-// }
-// }
-// public void performDispose() {
-// }
-// };
-// debug = 1;
-// w.start();
-// }
}
- /**
- * Bestimmt eine "passende" Unterteilung fuer das Grid.
- */
- private static double determineGridDistance(double mapMin_LL, double mapMax_LL, int panelSize) {
- // Differenz zwischen Min/Max-Koordinaten = darzustellender Bereich in Grad
- double diff = Math.abs( mapMin_LL - mapMax_LL );
- // Distanz zwischen zwei Unterteilungen in Grad
- double dist = 0.0;
- if ( diff < 10/60.0 ) // < 10 Min. --> 1 Min.-Aufteilung
- dist = 1/60.0;
- else if ( diff < 30/60.0 ) // < 30 Min. --> 5 Min.-Aufteilung
- dist = 5/60.0;
- else if ( diff < 1 ) // < 1? --> 10 Min.-Aufteilung
- dist = 10/60.0;
- else if ( diff < 3 ) // < 3? --> 15 Min.-Aufteilung
- dist = 15/60.0;
- else if ( diff < 5 ) // < 5? --> 30 Min.-Aufteilung
- dist = 30/60.0;
- else if ( diff < 11 ) // < 11? --> 1?-Aufteilung
- dist = 1;
- else // sonst --> 2?-Aufteilung
- dist = 2;
- // Solange der Abstand zwischen 2 Unterteilungen weniger als 40 Pixel
- // betraegt --> Unterteilung verdoppeln
- while ( diff != 0 && dist != 0 && panelSize / (diff / dist) < 40 )
- dist *=2;
-
- return dist;
- }
-
// /**
// * Diese Methode stellt einen Workaround fuer einen sehr sehr merkwuerdigen
// * {@link MathTransform}-Effekt dar. Mal liefert Transform die Koordinaten
@@ -354,26 +354,26 @@
// return idx;
// }
- /**
- * Diese Methode stellt einen Workaround fuer einen sehr sehr merkwuerdigen
- * {@link MathTransform}-Effekt dar. Mal liefert Transform die Koordinaten
- * als {Latitude,Longitude}-Array, und manchmal als {Longitude,Latitude}!
- * Diese Methode versucht zu ermitteln, in welchem Array-Index die
- * benoetigte Koordinate (je nachdem ob es sich um ein horizontales oder
- * vertikales Grid handelt) tatsaechlich befindet.
- */
- private int determineCompatibleArrayIndex(double[] mapMin_MCRS, double[] mapMin_GCRS,double[] mapMax_MCRS, double[] mapMax_GCRS) {
- // SEHR SEHR MERKWUERDIG: Mal liefert Transform {Latitude,Longitude}, und
- // manchmal {Longitude,Latitude}!!
- // WORKAROUND (klappt natuerlich nicht mit allen CRS!):
- // Wenn X_sourceCRS > Y_sourceCRS, dann muss auch X_destCRS > Y_destCRS
-
-
- double diff0_GCRS = mapMax_GCRS[0] - mapMin_GCRS[0];
- double diff1_GCRS = mapMax_GCRS[1] - mapMin_GCRS[1];
-
- return diff0_GCRS > diff1_GCRS ? 0 : 1;
- }
+// /**
+// * Diese Methode stellt einen Workaround fuer einen sehr sehr merkwuerdigen
+// * {@link MathTransform}-Effekt dar. Mal liefert Transform die Koordinaten
+// * als {Latitude,Longitude}-Array, und manchmal als {Longitude,Latitude}!
+// * Diese Methode versucht zu ermitteln, in welchem Array-Index die
+// * benoetigte Koordinate (je nachdem ob es sich um ein horizontales oder
+// * vertikales Grid handelt) tatsaechlich befindet.
+// */
+// private int determineCompatibleArrayIndex(double[] mapMin_MCRS, double[] mapMin_GCRS,double[] mapMax_MCRS, double[] mapMax_GCRS) {
+// // SEHR SEHR MERKWUERDIG: Mal liefert Transform {Latitude,Longitude}, und
+// // manchmal {Longitude,Latitude}!!
+// // WORKAROUND (klappt natuerlich nicht mit allen CRS!):
+// // Wenn X_sourceCRS > Y_sourceCRS, dann muss auch X_destCRS > Y_destCRS
+//
+//
+// double diff0_GCRS = mapMax_GCRS[0] - mapMin_GCRS[0];
+// double diff1_GCRS = mapMax_GCRS[1] - mapMin_GCRS[1];
+//
+// return diff0_GCRS > diff1_GCRS ? 0 : 1;
+// }
/**
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht wird) wird. Dann werden wird der
Added: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter.java 2009-09-14 18:06:27 UTC (rev 406)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter.java 2009-09-14 18:38:36 UTC (rev 407)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.geotools.gui;
+
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+/**
+ * This class defines how the {@link GridPanel} shows the coordinate
+ * grid and the coordinates.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public abstract class GridPanelFormatter {
+ /** CRS the formatter is created for. */
+ protected CoordinateReferenceSystem crs = null;
+
+ /**
+ * Creates a new formatter.
+ * @param crs the CRS the formatter can format
+ */
+ public GridPanelFormatter(CoordinateReferenceSystem crs) {
+ this.crs = crs;
+ }
+
+ /**
+ * Returns the CRS the formatter can format.
+ */
+ public CoordinateReferenceSystem getCRS() {
+ return crs;
+ }
+
+
+ /**
+ * Determines a "fitting" fragmentation for the grid.
+ * @param mapMinCoord minimal coordinate to show in the grid (in the grid CRS)
+ * @param mapMaxCoord maximal coordinate to show in the grid (in the grid CRS)
+ * @param panelSize size of the grid panel in pixels
+ */
+ public abstract double determineGridDistance(double mapMinCoord, double mapMaxCoord, int panelSize);
+
+
+ /**
+ * Formats a coordinate for the grid CRS.
+ * @param coord the coordinate
+ * @param gridPanel indicates (amongst others) the grid orientation
+ * @return
+ */
+ public abstract String formatCoordinate(GridPanel panel, double coord);
+
+}
Added: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter_WGS84.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter_WGS84.java 2009-09-14 18:06:27 UTC (rev 406)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GridPanelFormatter_WGS84.java 2009-09-14 18:38:36 UTC (rev 407)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * 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.geotools.gui;
+
+import java.text.DecimalFormat;
+
+import org.geotools.referencing.crs.DefaultGeographicCRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import schmitzm.lang.ResourceProvider;
+
+/**
+ * This class defines a {@link GridPanelFormatter} for the WGS84
+ * {@link CoordinateReferenceSystem}.
+ * The coordinates are formated in degrees and minutes along with
+ * the wind direction abbreviation (E/W, N/S).
+ * grid and the coordinates. * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class GridPanelFormatter_WGS84 extends GridPanelFormatter {
+ private static final ResourceProvider RES = GeotoolsGUIUtil.RESOURCE;
+ private static final DecimalFormat numFormat = new DecimalFormat("###,###,##0");
+
+ /**
+ * Creates a new formatter.
+ * @param crs the CRS the formatter can format
+ */
+ public GridPanelFormatter_WGS84() {
+ //super(GTUtil.WGS84);
+ super(DefaultGeographicCRS.WGS84);
+ }
+
+ /**
+ * Formats a coordinate to degrees and minutes.
+ * @param coord the lat/lon coordinate
+ * @param gridPanel indicates (amongst others) the grid orientation
+ * @return
+ */
+ @Override
+ public String formatCoordinate(GridPanel panel, double coord) {
+ int degrees = (int)coord;
+ int minutes = (int)Math.round((coord-degrees)*60 );
+ // Aufgrund des Minuten-Systems kann schlecht im Vorhinein gerundet
+ // werden. Deshalb wird im Nachhinein ein etwaiger Rundungsfehler
+ // ausgeglichen
+ if ( Math.abs(minutes) >= 60 ) {
+ degrees += Math.signum(minutes);
+ minutes -= Math.signum(minutes) * 60;
+ }
+ String coordStr = Math.abs(degrees)+"°"+Math.abs(minutes)+"'";
+ if ( degrees != 0 || minutes != 0 ) {
+ if (panel.isVertical())
+ coordStr += RES.getString( (coord < 0) ? "schmitzm.geotools.gui.GeotoolsGUIUtil.SOUTH.Abb" : "schmitzm.geotools.gui.GeotoolsGUIUtil.NORTH.Abb" );
+ else
+ coordStr += RES.getString( (coord < 0) ? "schmitzm.geotools.gui.GeotoolsGUIUtil.WEST.Abb" : "schmitzm.geotools.gui.GeotoolsGUIUtil.EAST.Abb" );
+ }
+ return coordStr;
+ }
+
+ /**
+ * Determines a "fitting" fragmentation for the grid.
+ * @param mapMin_LL minimal Lat/Lon coordinate to show in the grid
+ * @param mapMax_LL maximal Lat/Lon coordinate to show in the grid
+ * @param panelSize size of the grid panel in pixels
+ */
+ @Override
+ public double determineGridDistance(double mapMin_LL, double mapMax_LL, int panelSize) {
+ // Differenz zwischen Min/Max-Koordinaten = darzustellender Bereich in Grad
+ double diff = Math.abs( mapMin_LL - mapMax_LL );
+ // Distanz zwischen zwei Unterteilungen in Grad
+ double dist = 0.0;
+ if ( diff < 10/60.0 ) // < 10 Min. --> 1 Min.-Aufteilung
+ dist = 1/60.0;
+ else if ( diff < 30/60.0 ) // < 30 Min. --> 5 Min.-Aufteilung
+ dist = 5/60.0;
+ else if ( diff < 1 ) // < 1? --> 10 Min.-Aufteilung
+ dist = 10/60.0;
+ else if ( diff < 3 ) // < 3? --> 15 Min.-Aufteilung
+ dist = 15/60.0;
+ else if ( diff < 5 ) // < 5? --> 30 Min.-Aufteilung
+ dist = 30/60.0;
+ else if ( diff < 11 ) // < 11? --> 1?-Aufteilung
+ dist = 1;
+ else // sonst --> 2?-Aufteilung
+ dist = 2;
+
+ // Solange der Abstand zwischen 2 Unterteilungen weniger als 40 Pixel
+ // betraegt --> Unterteilung verdoppeln
+ while ( diff != 0 && dist != 0 && panelSize / (diff / dist) < 40 )
+ dist *=2;
+
+ return dist;
+ }
+}
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties 2009-09-14 18:06:27 UTC (rev 406)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties 2009-09-14 18:38:36 UTC (rev 407)
@@ -68,6 +68,10 @@
org.geotools.styling.StyleBuilder.MARK_TRIANGLE=Dreieck
org.geotools.styling.StyleBuilder.MARK_X=X
+org.geotools.styling.ColorMap.TYPE_RAMP=Farb-Interpolation
+org.geotools.styling.ColorMap.TYPE_VALUES=Farb-Klassifizierung
+org.geotools.styling.ColorMap.TYPE_INTERVALS=Farb-Intervalle
+
schmitzm.geotools.gui.FeatureCollectionFilterPanel.TestButton=Filter testen
schmitzm.geotools.gui.FeatureCollectionFilterPanel.TestResultDetailsButton=?
schmitzm.geotools.gui.FeatureCollectionFilterPanel.TestResultDetailsToolTip=Fehler-Details anzeigen...
More information about the Schmitzm-commits
mailing list