Search in sources :

Example 31 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface 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 32 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class MapBoxTool method setSelectedItems.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.tool.ToolInterface#setSelectedItems(java.util.List, java.util.List)
     */
@Override
public void setSelectedItems(List<NodeInterface> nodeTypeList, List<SLDDataInterface> sldDataList) {
    this.sldDataList = sldDataList;
    if (exportToSLDButton != null) {
        int mapBoxFilesCount = 0;
        if (sldDataList != null) {
            for (SLDDataInterface sldData : sldDataList) {
                String fileExtension = ExternalFilenames.getFileExtension(sldData.getSLDFile().getAbsolutePath());
                if (fileExtension.compareTo(MapBoxTool.MAPBOX_FILE_EXTENSION) == 0) {
                    mapBoxFilesCount++;
                }
            }
        }
        exportToSLDButton.setEnabled(mapBoxFilesCount > 0);
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface)

Example 33 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface 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 34 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class ScaleToolPanel method populate.

/**
 * Populate the dialog.
 *
 * @param sldDataList the sld data list
 */
public void populate(List<SLDDataInterface> sldDataList) {
    List<ScaleSLDData> scaleDataList = new ArrayList<ScaleSLDData>();
    for (SLDDataInterface sldData : sldDataList) {
        List<ScaleSLDData> scaleSLDDataList = ScalePanelUtils.containsScales(sldData);
        if ((scaleSLDDataList != null) && !scaleSLDDataList.isEmpty()) {
            scaleDataList.addAll(scaleSLDDataList);
        }
    }
    dataModel.loadData(scaleDataList);
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) ArrayList(java.util.ArrayList)

Example 35 with SLDDataInterface

use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.

the class ScaleSLDData method updateScales.

/**
 * Update scales.
 *
 * @param sldWriter the sld writer
 */
public boolean updateScales(SLDWriterInterface sldWriter) {
    boolean refreshUI = false;
    if (rule != null) {
        if (isMinimumScaleUpdated()) {
            rule.setMinScaleDenominator(minScale);
            minimumScaleUpdated = false;
        }
        if (isMaximumScaleUpdated()) {
            rule.setMaxScaleDenominator(maxScale);
            maximumScaleUpdated = false;
        }
        String sldContents = sldWriter.encodeSLD(null, this.sld);
        SLDDataInterface current = SLDEditorFile.getInstance().getSLDData();
        if (current.getSLDFile().equals(sldData.getSLDFile()) || current.getSLDURL().equals(sldData.getSLDURL())) {
            Rule currentFule = SLDUtils.findRule(sld, rule, SelectedSymbol.getInstance().getSld());
            if (currentFule != null) {
                currentFule.setMinScaleDenominator(minScale);
                currentFule.setMaxScaleDenominator(maxScale);
                refreshUI = true;
            }
        }
        sldData.updateSLDContents(sldContents);
    }
    return refreshUI;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) Rule(org.geotools.styling.Rule)

Aggregations

SLDDataInterface (com.sldeditor.common.SLDDataInterface)72 File (java.io.File)34 IOException (java.io.IOException)21 SLDData (com.sldeditor.common.data.SLDData)20 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)20 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)17 URL (java.net.URL)17 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)14 StyleWrapper (com.sldeditor.common.data.StyleWrapper)12 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)12 FileNotFoundException (java.io.FileNotFoundException)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 URISyntaxException (java.net.URISyntaxException)10 NodeInterface (com.sldeditor.common.NodeInterface)9 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)5 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5