Search in sources :

Example 41 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class BatchUpdateFontUtils method containsFonts.

/**
 * Contains font details.
 *
 * @param sldData the sld data
 * @return the scale sld data
 */
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
    List<BatchUpdateFontData> dataList = null;
    if (sldData != null) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        if (sld != null) {
            List<StyledLayer> styledLayerList = sld.layers();
            if (sld != null) {
                for (StyledLayer styledLayer : styledLayerList) {
                    if (styledLayer instanceof NamedLayerImpl) {
                        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                        for (Style style : namedLayerImpl.styles()) {
                            for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                                for (Rule rule : fts.rules()) {
                                    for (Symbolizer symbolizer : rule.symbolizers()) {
                                        if (symbolizer instanceof TextSymbolizer) {
                                            TextSymbolizer textSymbol = (TextSymbolizer) symbolizer;
                                            Font font = textSymbol.getFont();
                                            if (font != null) {
                                                if (dataList == null) {
                                                    dataList = new ArrayList<BatchUpdateFontData>();
                                                }
                                                BatchUpdateFontData fontSLDData = new BatchUpdateFontData(sld, sldData);
                                                fontSLDData.setNamedLayer(namedLayerImpl.getName());
                                                fontSLDData.setFeatureTypeStyle(fts.getName());
                                                fontSLDData.setStyle(style.getName());
                                                fontSLDData.setRule(rule);
                                                fontSLDData.setSymbolizer(textSymbol);
                                                fontSLDData.setFont(font);
                                                dataList.add(fontSLDData);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return dataList;
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Symbolizer(org.geotools.styling.Symbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) Font(org.geotools.styling.Font) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 42 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class LegendTool method saveAllLegendToFolder.

/**
 * Save all legend to folder.
 *
 * @param destinationFolder the destination folder
 */
private void saveAllLegendToFolder(File destinationFolder) {
    if (!destinationFolder.exists()) {
        destinationFolder.mkdirs();
    }
    logger.info(Localisation.getString(LegendTool.class, "LegendTool.saveAllLayerLegends"));
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        if (sld != null) {
            String heading = null;
            String filename = null;
            String layerName = sldData.getLayerNameWithOutSuffix();
            List<String> filenameList = new ArrayList<String>();
            LegendManager.getInstance().saveLegendImage(sld, destinationFolder, layerName, heading, filename, filenameList);
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList)

Example 43 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class ExportHTML method save.

/**
 * Save all html to folder.
 *
 * @param destinationFolder the destination folder
 * @param filename the filename
 * @param sldDataList the sld data list
 * @param backgroundColour the background colour
 */
public static void save(File destinationFolder, String filename, List<SLDDataInterface> sldDataList, Color backgroundColour) {
    if (!destinationFolder.exists()) {
        destinationFolder.mkdirs();
    }
    InputStream inputStream = ExportHTML.class.getResourceAsStream(HTML_TEMPLATE);
    if (inputStream == null) {
        ConsoleManager.getInstance().error(ExportHTML.class, "Failed to find html template");
    } else {
        String htmlTemplate = null;
        BufferedReader reader = null;
        File file = null;
        try {
            file = stream2file(inputStream);
            reader = new BufferedReader(new FileReader(file));
            String line = null;
            StringBuilder stringBuilder = new StringBuilder();
            String ls = System.getProperty("line.separator");
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
                stringBuilder.append(ls);
            }
            htmlTemplate = stringBuilder.toString();
        } catch (Exception e) {
            ConsoleManager.getInstance().exception(ExportHTML.class, e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(ExportHTML.class, e);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        sb.append("  <tr>\n");
        sb.append("    <th>Layer Name</th>\n");
        sb.append("    <th>Legend</th>\n");
        sb.append("  </tr>\n");
        for (SLDDataInterface sldData : sldDataList) {
            StyleWrapper styleWrapper = sldData.getStyle();
            String layerName = styleWrapper.getStyle();
            sb.append("  <tr>\n");
            sb.append(String.format("    <td>%s</td>\n", layerName));
            StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
            if (sld != null) {
                String showHeading = null;
                String showFilename = null;
                List<String> legendFileNameList = new ArrayList<String>();
                boolean result = LegendManager.getInstance().saveLegendImage(sld, destinationFolder, layerName, showHeading, showFilename, legendFileNameList);
                if (result) {
                    String legendFilename = legendFileNameList.get(0);
                    sb.append(String.format("    <td><img src=\"%s\" alt=\"%s\" ></td>\n", legendFilename, layerName));
                }
            }
            sb.append("  </tr>\n");
        }
        if (htmlTemplate != null) {
            htmlTemplate = htmlTemplate.replace(TEMPLATE_INSERT_CODE, sb.toString());
            PrintWriter out;
            try {
                File f = new File(destinationFolder, filename);
                out = new PrintWriter(f);
                out.println(htmlTemplate);
                out.close();
            } catch (FileNotFoundException e) {
                ConsoleManager.getInstance().exception(ExportHTML.class, e);
            }
        }
        if (file != null) {
            file.delete();
        }
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 44 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class VectorReader method createVectorSLDData.

/**
 * Creates the vector sld.
 *
 * @param vectorFile the vector file
 * @return the styled layer descriptor
 */
@Override
public SLDDataInterface createVectorSLDData(File vectorFile) {
    if (vectorFile == null) {
        return null;
    }
    Map<String, Object> map = null;
    try {
        map = DataSourceProperties.encodeFilename(vectorFile.toURI().toURL().toString());
    } catch (MalformedURLException e) {
        ConsoleManager.getInstance().exception(this, e);
        return null;
    }
    StyledLayerDescriptor sld = createSLDData(map, null);
    SLDData sldData = null;
    if (sld != null) {
        File sldFilename = ExternalFilenames.createSLDFilename(vectorFile);
        StyleWrapper styleWrapper = new StyleWrapper(sldFilename.getName());
        String sldContents = sldWriter.encodeSLD(null, sld);
        sldData = new SLDData(styleWrapper, sldContents);
        sldData.setSLDFile(sldFilename);
        sldData.setReadOnly(false);
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) MalformedURLException(java.net.MalformedURLException) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File)

Example 45 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class VectorReader method createVectorSLDData.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.tool.vector.VectorReaderInterface#createVectorSLDData(com.sldeditor.common.data.DatabaseConnection, java.lang.String)
     */
@Override
public SLDDataInterface createVectorSLDData(DatabaseConnection databaseConnection, String featureClass) {
    if ((databaseConnection == null) || (featureClass == null)) {
        return null;
    }
    Map<String, Object> map = DatabaseConnectionManager.getInstance().getDBConnectionParams(databaseConnection);
    StyledLayerDescriptor sld = createSLDData(map, featureClass);
    SLDData sldData = null;
    if (sld != null) {
        File sldFilename = null;
        StyleWrapper styleWrapper = new StyleWrapper(featureClass);
        String sldContents = sldWriter.encodeSLD(null, sld);
        sldData = new SLDData(styleWrapper, sldContents);
        sldData.setSLDFile(sldFilename);
        sldData.setReadOnly(false);
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File)

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)123 Test (org.junit.Test)73 Rule (org.geotools.styling.Rule)51 Style (org.geotools.styling.Style)49 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)47 NamedLayer (org.geotools.styling.NamedLayer)44 SLDData (com.sldeditor.common.data.SLDData)24 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)23 File (java.io.File)19 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 StyledLayer (org.geotools.styling.StyledLayer)19 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)16 StyleWrapper (com.sldeditor.common.data.StyleWrapper)15 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)14 IOException (java.io.IOException)14 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 LineSymbolizer (org.geotools.styling.LineSymbolizer)12