[Schmitzm-commits] r378 - in branches/1.0-gt2-2.6/src/schmitzm/geotools: gui styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Sep 4 14:53:15 CEST 2009
Author: mojays
Date: 2009-09-04 14:53:12 +0200 (Fri, 04 Sep 2009)
New Revision: 378
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapTable.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
Log:
ColorMapTable: adding/removing of ColorMapEntries moved to StylingUtil to automatically apply ColorMap properties to copied instance and ensure sorted ColorMap.
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapTable.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapTable.java 2009-09-04 11:33:03 UTC (rev 377)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/ColorMapTable.java 2009-09-04 12:53:12 UTC (rev 378)
@@ -177,11 +177,7 @@
* @param row Zeilennummer (beginnend bei 0)
*/
public void performRemoveRow(int row) {
- ColorMapEntry[] entry = colMap.getColorMapEntries();
- colMap = new ColorMapImpl();
- for (int i=0; i<entry.length; i++)
- if ( i != row )
- colMap.addColorMapEntry(entry[i]);
+ colMap = StylingUtil.removeColorMapEntry(colMap, row);
}
/**
@@ -189,7 +185,10 @@
* angegeben werden kann.
*/
public void performAddRow() {
- colMap.addColorMapEntry( StylingUtil.createColorMapEntry("",0.0,Color.WHITE,1.0) );
+ colMap = StylingUtil.addColorMapEntryAndSort(
+ colMap,
+ StylingUtil.createColorMapEntry("",0.0,Color.WHITE,1.0)
+ );
}
/*
@@ -296,6 +295,9 @@
try {
switch( col ) {
case 0: colMap.getColorMapEntry(row).setQuantity( StylingUtil.STYLE_BUILDER.literalExpression(Double.parseDouble((String)obj)) );
+ // if quantity has changed, sort the color map
+ colMap = StylingUtil.sortColorMap(colMap);
+ fireTableDataChanged();
break;
case 2: colMap.getColorMapEntry(row).setLabel( (String)obj );
break;
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java 2009-09-04 11:33:03 UTC (rev 377)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java 2009-09-04 12:53:12 UTC (rev 378)
@@ -48,6 +48,7 @@
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.Vector;
import javax.measure.unit.Unit;
import javax.swing.Box;
@@ -77,6 +78,7 @@
import org.geotools.styling.ColorMap;
import org.geotools.styling.ColorMapEntry;
import org.geotools.styling.ColorMapEntryImpl;
+import org.geotools.styling.ColorMapImpl;
import org.geotools.styling.ExternalGraphic;
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.FeatureTypeStyleImpl;
@@ -436,7 +438,121 @@
return entry;
return null;
}
+
+ /**
+ * Applies general properties (color map type and extended colors) to
+ * a {@link ColorMap}.
+ * @param sourceColorMap color map the properties are taken from
+ * @param destColormap color map the properties are set
+ */
+ public static void applyColorMapProperties(ColorMap sourceColorMap, ColorMap destColormap) {
+ if ( sourceColorMap == null || destColormap == null )
+ return;
+ destColormap.setExtendedColors( sourceColorMap.getExtendedColors() );
+ destColormap.setType( sourceColorMap.getType() );
+ }
+
+ /**
+ * Unless {@link ColorMap} has no methods to remove an entry this
+ * method creates a new {@link ColorMap} with the identical entries
+ * except the one to remove.
+ * @param colorMap the color map to remove entries from
+ * @param idx the entry index to remove
+ */
+ public static ColorMap removeColorMapEntry(ColorMap colorMap, int idx) {
+ ColorMap newColorMap = new ColorMapImpl();
+ applyColorMapProperties(colorMap, newColorMap);
+ ColorMapEntry[] entry = colorMap.getColorMapEntries();
+ for (int i=0; i<entry.length; i++)
+ if ( i != idx )
+ newColorMap.addColorMapEntry(entry[i]);
+
+ return newColorMap;
+ }
+
+ /**
+ * Unless {@link ColorMap} has no methods to remove an entry this
+ * method creates a new {@link ColorMap} with the identical entries
+ * except the one to remove.
+ * @param colorMap the color map to remove entries from
+ * @param colorMapEntry the entry to remove
+ */
+ public static ColorMap removeColorMapEntry(ColorMap colorMap, ColorMapEntry colorMapEntry) {
+ ColorMap newColorMap = new ColorMapImpl();
+ applyColorMapProperties(colorMap, newColorMap);
+
+ ColorMapEntry[] entry = colorMap.getColorMapEntries();
+ for (int i=0; i<entry.length; i++)
+ if ( entry[i] != colorMapEntry )
+ newColorMap.addColorMapEntry(entry[i]);
+
+ return newColorMap;
+ }
+
+ /**
+ * Unless {@link ColorMap} is not sorted automatically, this
+ * method calls {@link #sortColorMap(ColorMap)} after inserting
+ * the color map entry.
+ * @param colorMap the color map to extend
+ * @param colorMapEntry the new entry
+ */
+ public static ColorMap addColorMapEntryAndSort(ColorMap colorMap, ColorMapEntry colorMapEntry) {
+ colorMap.addColorMapEntry(colorMapEntry);
+ return sortColorMap(colorMap);
+ }
+
+ /**
+ * Sorts a {@link ColorMap} according to the value of its
+ * entries.
+ * @param colorMap the color map to sort
+ */
+ public static ColorMap sortColorMap(ColorMap colorMap) {
+ ColorMap newColorMap = new ColorMapImpl();
+ applyColorMapProperties(colorMap, newColorMap);
+
+ // Put all color map entries in a sorted map (with
+ // collision lists!)
+ SortedMap<Double,Vector<ColorMapEntry>> sortedEntries = new TreeMap<Double, Vector<ColorMapEntry>>();
+ for (ColorMapEntry entry : colorMap.getColorMapEntries()) {
+ double quantity = getQuantityFromColorMapEntry(entry);
+ Vector<ColorMapEntry> collisionList = sortedEntries.get( quantity );
+ if ( collisionList == null ) {
+ collisionList = new Vector<ColorMapEntry>();
+ sortedEntries.put(quantity, collisionList);
+ }
+ collisionList.add(entry);
+ }
+
+ // According to the order of the sorted map, put all
+ // color map entries to the new ColorMap
+ for (Vector<ColorMapEntry> collisionList : sortedEntries.values())
+ for (ColorMapEntry entry : collisionList)
+ newColorMap.addColorMapEntry(entry);
+
+ return newColorMap;
+ }
+
+ /**
+ * Returns the color map type specified by a given string.
+ * @param typeStr a string
+ * @see ColorMap#getType()
+ */
+ public static int getColorMapType(String typeStr) {
+ if ( typeStr == null )
+ throw new IllegalArgumentException("Unknown color map type: "+typeStr);
+
+ typeStr = typeStr.trim().toLowerCase();
+ if ( typeStr.equals("ramp") || typeStr.equals("type_ramp") )
+ return ColorMap.TYPE_RAMP;
+ if ( typeStr.equals("intervals") || typeStr.equals("type_intervals") )
+ return ColorMap.TYPE_INTERVALS;
+ if ( typeStr.equals("values") || typeStr.equals("type_values") )
+ return ColorMap.TYPE_VALUES;
+
+ throw new IllegalArgumentException("Unknown color map type: "+typeStr);
+ }
+
/**
* Kopiert eine {@link ColorMap}.
*
@@ -444,24 +560,42 @@
* ist
*/
public static ColorMap cloneColorMap(ColorMap colorMap) {
- DuplicatingStyleVisitor duplicatingStyleVisitor = new DuplicatingStyleVisitor();
- colorMap.accept(duplicatingStyleVisitor);
- return (ColorMap)duplicatingStyleVisitor.getCopy();
+// MS: Leider kommt der DuplicatingStyleVisitor nicht damit klar, dass
+// der SLDParser Value und Opacity als String setzt. Und selbst wenn
+// man dies fixed sind Value und Opacity nach dem Clonen NULL.
+// --> zurueck zu meinem alten Code!! :-)
+// DuplicatingStyleVisitor duplicatingStyleVisitor = new DuplicatingStyleVisitor();
+// colorMap.accept(duplicatingStyleVisitor);
+// ColorMap clone = (ColorMap)duplicatingStyleVisitor.getCopy();
+// return clone;
-//
-//
-// if (colorMap == null)
-// return null;
-// ColorMapEntry[] entry = colorMap.getColorMapEntries();
-// ColorMap newColorMap = new ColorMapImpl();
-// newColorMap.setType(colorMap.getType()); // Hat noch keinen Effekt in
-// // 2.3.2, aber dennoch, SK
-// for (int i = 0; i < entry.length; i++)
-// newColorMap.addColorMapEntry(cloneColorMapEntry(entry[i]));
-// return newColorMap;
+ if (colorMap == null)
+ return null;
+ ColorMapEntry[] entry = colorMap.getColorMapEntries();
+ ColorMap newColorMap = new ColorMapImpl();
+ newColorMap.setType(colorMap.getType());
+ for (int i = 0; i < entry.length; i++)
+ newColorMap.addColorMapEntry(cloneColorMapEntry(entry[i]));
+ return newColorMap;
}
/**
+ * Kopiert einen {@link ColorMapEntry}.
+ *
+ * @return <code>null</code> wenn der uebergebene ColorMapEntry
+ * <code>null</code> ist
+ */
+ public static ColorMapEntry cloneColorMapEntry(ColorMapEntry colorMapEntry) {
+ if (colorMapEntry == null)
+ return null;
+
+ return createColorMapEntry(colorMapEntry.getLabel(),
+ getQuantityFromColorMapEntry(colorMapEntry),
+ getColorFromColorMapEntry(colorMapEntry),
+ getOpacityFromColorMapEntry(colorMapEntry));
+ }
+
+ /**
* Prueft, ob zwei {@link ColorMap}-Instanzen gleich sind.
*
* @param cm1
More information about the Schmitzm-commits
mailing list