/[schmitzm]/trunk/src/skrueger/geotools/StyledLayerUtil.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/StyledLayerUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java revision 534 by alfonx, Fri Nov 20 10:28:01 2009 UTC branches/2.0-RC1/src/skrueger/geotools/StyledLayerUtil.java revision 607 by alfonx, Wed Dec 9 15:13:42 2009 UTC
# Line 43  import java.io.FileNotFoundException; Line 43  import java.io.FileNotFoundException;
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    
# Line 78  import org.jdom.input.SAXBuilder; Line 79  import org.jdom.input.SAXBuilder;
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    
# Line 245  public class StyledLayerUtil { Line 248  public class StyledLayerUtil {
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);
# Line 993  public class StyledLayerUtil { Line 998  public class StyledLayerUtil {
998                  final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData                  final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
999                                  .createSampleRasters();                                  .createSampleRasters();
1000    
1001                  final JPanel panel = new JPanel(new MigLayout("wrap 2"));                  final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0"));
1002    
1003                  for (final Double rValue : legendRasterValues) {                  for (final Double rValue : legendRasterValues) {
1004    
# Line 1082  public class StyledLayerUtil { Line 1087  public class StyledLayerUtil {
1087                          }                          }
1088    
1089                          final JLabel iconLabel = new JLabel(new ImageIcon(buffImage));                          final JLabel iconLabel = new JLabel(new ImageIcon(buffImage));
                         // hbox.setAlignmentX(0f);  
1090                          panel.add(iconLabel, "sgx1");                          panel.add(iconLabel, "sgx1");
                         // hbox.add(Box.createHorizontalStrut(3));  
1091    
1092                          final Translation labelT = rasterLegendData.get(rValue);                          final Translation labelT = rasterLegendData.get(rValue);
1093                          final JLabel classTitleLabel = new JLabel(labelT.toString());                          final JLabel classTitleLabel = new JLabel(labelT.toString());
1094                          panel.add(classTitleLabel, "sgx2"                          panel.add(classTitleLabel, "sgx2"
1095                                          + (rasterLegendData.getPaintGaps() ? ", gapy 0 3" : ""));                                          + (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5"
1096                                                            : ""));
1097                          classTitleLabel.setLabelFor(iconLabel);                          classTitleLabel.setLabelFor(iconLabel);
1098    
1099                          // box.add(hbox);                          if (rasterLegendData.isPaintGaps()) {
   
                         if (rasterLegendData.getPaintGaps()) {  
1100                                  iconLabel                                  iconLabel
1101                                                  .setBorder(BorderFactory.createLineBorder(Color.black));                                                  .setBorder(BorderFactory.createLineBorder(Color.black));
1102                          }                          }
# Line 1152  public class StyledLayerUtil { Line 1154  public class StyledLayerUtil {
1154          public static boolean isStyleable(          public static boolean isStyleable(
1155                          final StyledRasterInterface<?> styledRaster) {                          final StyledRasterInterface<?> styledRaster) {
1156                  final ColorModel colorModel = getColorModel(styledRaster);                  final ColorModel colorModel = getColorModel(styledRaster);
1157                    
1158  //              LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "                  // LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
1159  //                              + colorModel != null ? colorModel.getClass().getSimpleName() : "NULL");                  // + colorModel != null ? colorModel.getClass().getSimpleName() :
1160                    // "NULL");
1161    
1162                  if (colorModel == null)                  if (colorModel == null)
1163                          return true;                          return true;
# Line 1170  public class StyledLayerUtil { Line 1173  public class StyledLayerUtil {
1173           * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a           * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a
1174           * repaint, so only use it when needed.           * repaint, so only use it when needed.
1175           *           *
1176           * @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
1177             *         been changed.
1178           */           */
1179          public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer,          public static boolean updateMapLayerStyleIfChangedAndKeepSelection(
1180                          Style style2) {                          MapLayer mapLayer, Style style2) {
1181    
1182                  Style mapLayerStyleCleaned = StylingUtil                  Style mapLayerStyleCleaned = StylingUtil
1183                                                  .removeSelectionFeatureTypeStyle(mapLayer.getStyle());                                  .removeSelectionFeatureTypeStyle(mapLayer.getStyle());
1184                    
1185                  Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2);                  Style newStyleCleaned = StylingUtil
1186                                                    .removeSelectionFeatureTypeStyle(style2);
1187                  if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned,  
1188                                  newStyleCleaned)) {                  if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) {
1189                            
1190                          // They are different when compared without SELECTION FTS!                          // They are different when compared without SELECTION FTS!
1191                            
1192                          // Now let's copy any SELECTION FTS to the now style                          // Now let's copy any SELECTION FTS to the now style
1193                          FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle( mapLayer.getStyle() );                          FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil
1194                                            .getSelectionFeatureTypeStyle(mapLayer.getStyle());
1195                          if (selectionFeatureTypeStyle != null) {                          if (selectionFeatureTypeStyle != null) {
1196                                  newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle);                                  newStyleCleaned.featureTypeStyles().add(
1197                                  // newStyleCleaned is not so clean anymore... We just alled a selcetion FTS                                                  selectionFeatureTypeStyle);
1198                          }                                    // newStyleCleaned is not so clean anymore... We just alled a
1199                                                            // selcetion FTS
1200                            }
1201    
1202                          mapLayer.setStyle(newStyleCleaned);                          mapLayer.setStyle(newStyleCleaned);
1203                            
1204                          return true;                          return true;
1205                            
1206                  } else {                  } else {
1207                          return false;                          return false;
1208                  }                  }
1209          }          }
1210    
1211            /**
1212             * After loading an atlas, the AttribteMetaData contains whatever is written
1213             * in the XML. But the DBF may have changed! This method checks an
1214             * {@link AttributeMetadataMap} against a schema and also corrects
1215             * upperCase/lowerCase problems. It will also remove any geometry column
1216             * attribute metadata.
1217             */
1218            /**
1219             * After loading an atlas, the AttribteMetaData contains whatever is written
1220             * in the XML. But the DBF may have changed!
1221             */
1222            public static void checkAttribMetaData(AttributeMetadataMap attributeMetaDataMap,
1223                            SimpleFeatureType schema) {
1224    
1225                    ArrayList<Name> willRemove = new ArrayList<Name>();
1226    
1227                    // 1. Check.. all attributes in the atm should be in the schema as well.
1228                    // maybe correct some upperCase/loweCase stuff
1229    
1230                    for (AttributeMetadata atm : attributeMetaDataMap.values()) {
1231    
1232                            AttributeDescriptor foundDescr = schema
1233                                            .getDescriptor(atm.getName());
1234                            if (foundDescr == null) {
1235                                    Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema,
1236                                                    atm.getLocalName());
1237                                    if (bestMatch == null)
1238                                            willRemove.add(atm.getName());
1239                                    else
1240                                            atm.setName(bestMatch);
1241                            } else if (foundDescr instanceof GeometryDescriptor) {
1242                                    // We don't want GeometryColumns in here
1243                                    willRemove.add(atm.getName());
1244                            }
1245                    }
1246    
1247                    // Remove the ones that were not findable in the schema
1248                    for (Name removeName : willRemove) {
1249                            if (attributeMetaDataMap.remove(removeName) == null){
1250                                    LOGGER.warn("removing the AMData didn't work");
1251                            }
1252                    }
1253    
1254                    // 2. check... all attributes from the schema must have an ATM
1255                    for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
1256                            if (ad instanceof GeometryDescriptor)
1257                                    continue;
1258                            if (!attributeMetaDataMap.containsKey(ad.getName())) {
1259                                    attributeMetaDataMap.put(ad.getName(), new AttributeMetadata(
1260                                                    ad, schema.getAttributeDescriptors().indexOf(ad), attributeMetaDataMap
1261                                                                    .getLanguages()));
1262                            }
1263                    }
1264    
1265            }
1266    
1267  }  }

Legend:
Removed from v.534  
changed lines
  Added in v.607

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26