43 |
import java.io.FileWriter; |
import java.io.FileWriter; |
44 |
import java.net.URL; |
import java.net.URL; |
45 |
import java.text.DecimalFormat; |
import java.text.DecimalFormat; |
46 |
|
import java.util.ArrayList; |
47 |
import java.util.List; |
import java.util.List; |
48 |
import java.util.Map; |
import java.util.Map; |
49 |
|
|
79 |
import org.jdom.output.XMLOutputter; |
import org.jdom.output.XMLOutputter; |
80 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
81 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
82 |
|
import org.opengis.feature.type.AttributeDescriptor; |
83 |
|
import org.opengis.feature.type.GeometryDescriptor; |
84 |
import org.opengis.feature.type.Name; |
import org.opengis.feature.type.Name; |
85 |
import org.opengis.parameter.GeneralParameterValue; |
import org.opengis.parameter.GeneralParameterValue; |
86 |
|
|
248 |
* @param visible |
* @param visible |
249 |
* indicated whether the visible or invisible entries are |
* indicated whether the visible or invisible entries are |
250 |
* returned |
* returned |
251 |
* |
* |
252 |
* TODO replace with {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
* TODO replace with |
253 |
|
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
254 |
*/ |
*/ |
255 |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
256 |
final AttributeMetadataMap amdMap, final boolean visible) { |
final AttributeMetadataMap amdMap, final boolean visible) { |
257 |
|
|
258 |
final AttributeMetadataMap filteredMap = new AttributeMetadataMap(amdMap.getLanguages()); |
final AttributeMetadataMap filteredMap = new AttributeMetadataMap( |
259 |
|
amdMap.getLanguages()); |
260 |
for (final AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadata amd : amdMap.values()) |
261 |
if (amd.isVisible() == visible) |
if (amd.isVisible() == visible) |
262 |
filteredMap.put(amd.getName(), amd); |
filteredMap.put(amd.getName(), amd); |
307 |
* |
* |
308 |
* @param element |
* @param element |
309 |
* {@link Element} to parse |
* {@link Element} to parse |
310 |
|
* |
311 |
|
* TODO Since GP 1.3 the {@link AttributeMetadata} class has more |
312 |
|
* attributes which are not used by Xulu/ISDSS. GP |
313 |
|
* exports/imports the AMD via AMLExporter and AMLImporter |
314 |
|
* classes. (SK, 3.2.2010) * |
315 |
*/ |
*/ |
316 |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
317 |
final Element element) { |
final Element element) { |
344 |
* |
* |
345 |
* @param amd |
* @param amd |
346 |
* meta data for one attribute |
* meta data for one attribute |
347 |
|
* |
348 |
|
* TODO Since GP 1.3 the {@link AttributeMetadata} class has more |
349 |
|
* attributes which are not used by Xulu/ISDSS. GP |
350 |
|
* exports/imports the AMD via AMLExporter and AMLImporter |
351 |
|
* classes. (SK, 3.2.2010) |
352 |
*/ |
*/ |
353 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
354 |
final AttributeMetadata amd) { |
final AttributeMetadata amd) { |
1008 |
final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
1009 |
.createSampleRasters(); |
.createSampleRasters(); |
1010 |
|
|
1011 |
final JPanel panel = new JPanel(new MigLayout("wrap 2")); |
final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0")); |
1012 |
|
|
1013 |
for (final Double rValue : legendRasterValues) { |
for (final Double rValue : legendRasterValues) { |
1014 |
|
|
1097 |
} |
} |
1098 |
|
|
1099 |
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage)); |
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage)); |
|
// hbox.setAlignmentX(0f); |
|
1100 |
panel.add(iconLabel, "sgx1"); |
panel.add(iconLabel, "sgx1"); |
|
// hbox.add(Box.createHorizontalStrut(3)); |
|
1101 |
|
|
1102 |
final Translation labelT = rasterLegendData.get(rValue); |
final Translation labelT = rasterLegendData.get(rValue); |
1103 |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
1104 |
panel.add(classTitleLabel, "sgx2" |
panel.add(classTitleLabel, "sgx2" |
1105 |
+ (rasterLegendData.getPaintGaps() ? ", gapy 0 3" : "")); |
+ (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5" |
1106 |
|
: "")); |
1107 |
classTitleLabel.setLabelFor(iconLabel); |
classTitleLabel.setLabelFor(iconLabel); |
1108 |
|
|
1109 |
// box.add(hbox); |
if (rasterLegendData.isPaintGaps()) { |
|
|
|
|
if (rasterLegendData.getPaintGaps()) { |
|
1110 |
iconLabel |
iconLabel |
1111 |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
1112 |
} |
} |
1164 |
public static boolean isStyleable( |
public static boolean isStyleable( |
1165 |
final StyledRasterInterface<?> styledRaster) { |
final StyledRasterInterface<?> styledRaster) { |
1166 |
final ColorModel colorModel = getColorModel(styledRaster); |
final ColorModel colorModel = getColorModel(styledRaster); |
1167 |
|
|
1168 |
// LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
// LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
1169 |
// + colorModel != null ? colorModel.getClass().getSimpleName() : "NULL"); |
// + colorModel != null ? colorModel.getClass().getSimpleName() : |
1170 |
|
// "NULL"); |
1171 |
|
|
1172 |
if (colorModel == null) |
if (colorModel == null) |
1173 |
return true; |
return true; |
1183 |
* Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a |
* Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a |
1184 |
* repaint, so only use it when needed. |
* repaint, so only use it when needed. |
1185 |
* |
* |
1186 |
* @return <code>true</code> if the {@link MapLayer}'s {@link Style} has been changed. |
* @return <code>true</code> if the {@link MapLayer}'s {@link Style} has |
1187 |
|
* been changed. |
1188 |
*/ |
*/ |
1189 |
public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer, |
public static boolean updateMapLayerStyleIfChangedAndKeepSelection( |
1190 |
Style style2) { |
MapLayer mapLayer, Style style2) { |
1191 |
|
|
1192 |
Style mapLayerStyleCleaned = StylingUtil |
Style mapLayerStyleCleaned = StylingUtil |
1193 |
.removeSelectionFeatureTypeStyle(mapLayer.getStyle()); |
.removeSelectionFeatureTypeStyle(mapLayer.getStyle()); |
1194 |
|
|
1195 |
Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2); |
Style newStyleCleaned = StylingUtil |
1196 |
|
.removeSelectionFeatureTypeStyle(style2); |
1197 |
if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, |
|
1198 |
newStyleCleaned)) { |
if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) { |
1199 |
|
|
1200 |
// They are different when compared without SELECTION FTS! |
// They are different when compared without SELECTION FTS! |
1201 |
|
|
1202 |
// Now let's copy any SELECTION FTS to the now style |
// Now let's copy any SELECTION FTS to the now style |
1203 |
FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle( mapLayer.getStyle() ); |
FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil |
1204 |
|
.getSelectionFeatureTypeStyle(mapLayer.getStyle()); |
1205 |
if (selectionFeatureTypeStyle != null) { |
if (selectionFeatureTypeStyle != null) { |
1206 |
newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle); |
newStyleCleaned.featureTypeStyles().add( |
1207 |
// newStyleCleaned is not so clean anymore... We just alled a selcetion FTS |
selectionFeatureTypeStyle); |
1208 |
} |
// newStyleCleaned is not so clean anymore... We just alled a |
1209 |
|
// selcetion FTS |
1210 |
|
} |
1211 |
|
|
1212 |
mapLayer.setStyle(newStyleCleaned); |
mapLayer.setStyle(newStyleCleaned); |
1213 |
|
|
1214 |
return true; |
return true; |
1215 |
|
|
1216 |
} else { |
} else { |
1217 |
return false; |
return false; |
1218 |
} |
} |
1219 |
} |
} |
1220 |
|
|
1221 |
|
/** |
1222 |
|
* After loading an atlas, the AttribteMetaData contains whatever is written |
1223 |
|
* in the XML. But the DBF may have changed! This method checks an |
1224 |
|
* {@link AttributeMetadataMap} against a schema and also corrects |
1225 |
|
* upperCase/lowerCase problems. It will also remove any geometry column |
1226 |
|
* attribute metadata. |
1227 |
|
*/ |
1228 |
|
/** |
1229 |
|
* After loading an atlas, the AttribteMetaData contains whatever is written |
1230 |
|
* in the XML. But the DBF may have changed! |
1231 |
|
*/ |
1232 |
|
public static void checkAttribMetaData(AttributeMetadataMap attributeMetaDataMap, |
1233 |
|
SimpleFeatureType schema) { |
1234 |
|
|
1235 |
|
ArrayList<Name> willRemove = new ArrayList<Name>(); |
1236 |
|
|
1237 |
|
// 1. Check.. all attributes in the atm should be in the schema as well. |
1238 |
|
// maybe correct some upperCase/loweCase stuff |
1239 |
|
|
1240 |
|
for (AttributeMetadata atm : attributeMetaDataMap.values()) { |
1241 |
|
|
1242 |
|
AttributeDescriptor foundDescr = schema |
1243 |
|
.getDescriptor(atm.getName()); |
1244 |
|
if (foundDescr == null) { |
1245 |
|
Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema, |
1246 |
|
atm.getLocalName()); |
1247 |
|
if (bestMatch == null) |
1248 |
|
willRemove.add(atm.getName()); |
1249 |
|
else |
1250 |
|
atm.setName(bestMatch); |
1251 |
|
} else if (foundDescr instanceof GeometryDescriptor) { |
1252 |
|
// We don't want GeometryColumns in here |
1253 |
|
willRemove.add(atm.getName()); |
1254 |
|
} |
1255 |
|
} |
1256 |
|
|
1257 |
|
// Remove the ones that were not findable in the schema |
1258 |
|
for (Name removeName : willRemove) { |
1259 |
|
if (attributeMetaDataMap.remove(removeName) == null){ |
1260 |
|
LOGGER.warn("removing the AMData didn't work"); |
1261 |
|
} |
1262 |
|
} |
1263 |
|
|
1264 |
|
// 2. check... all attributes from the schema must have an ATM |
1265 |
|
for (AttributeDescriptor ad : schema.getAttributeDescriptors()) { |
1266 |
|
if (ad instanceof GeometryDescriptor) |
1267 |
|
continue; |
1268 |
|
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
1269 |
|
attributeMetaDataMap.put(ad.getName(), new AttributeMetadata( |
1270 |
|
ad, schema.getAttributeDescriptors().indexOf(ad), attributeMetaDataMap |
1271 |
|
.getLanguages())); |
1272 |
|
} |
1273 |
|
} |
1274 |
|
|
1275 |
|
} |
1276 |
|
|
1277 |
} |
} |