Search in sources :

Example 26 with SLDDataInterface

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

the class VectorTool method importFeatureClass.

/**
 * Import feature class.
 *
 * @param featureClassNode the feature class node
 * @return true, if successful
 */
protected boolean importFeatureClass(DatabaseFeatureClassNode featureClassNode) {
    if (featureClassNode != null) {
        DatabaseClientInterface dbClient = DatabaseConnectionManager.getInstance().getConnectionMap().get(featureClassNode.getConnectionData());
        if (dbClient != null) {
            ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.createSymbol"), featureClassNode.toString()));
            SLDDataInterface sldData = vectorReader.createVectorSLDData(featureClassNode.getConnectionData(), featureClassNode.toString());
            DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
            DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(dbClient.getClass());
            dsProperties = dsc.getDataSourceProperties(dbClient.getDBConnectionParams());
            dsProperties.setFilename(featureClassNode.toString());
            loadSymbol(dsProperties, sldData, featureClassNode.toString(), featureClassNode.getConnectionData().getConnectionName());
        }
    }
    return false;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface)

Example 27 with SLDDataInterface

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

the class VectorTool method importFile.

/**
 * Import file.
 *
 * @param fileTreeNode the file tree node
 */
protected boolean importFile(FileTreeNode fileTreeNode) {
    if (fileTreeNode != null) {
        File vectorFile = fileTreeNode.getFile();
        ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.createSymbol"), vectorFile.getAbsolutePath()));
        SLDDataInterface sldData = vectorReader.createVectorSLDData(vectorFile);
        DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
        DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
        try {
            String vectorFilename = vectorFile.toURI().toURL().toString();
            dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(vectorFilename));
        } catch (MalformedURLException exceptionObj) {
            ConsoleManager.getInstance().exception(VectorTool.class, exceptionObj);
            return false;
        }
        loadSymbol(dsProperties, sldData, vectorFile);
    }
    return true;
}
Also used : MalformedURLException(java.net.MalformedURLException) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 28 with SLDDataInterface

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

the class YSLDTool 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 (exportToYSLDButton != null) {
        int sldFilesCount = 0;
        int ysldFilesCount = 0;
        if (sldDataList != null) {
            for (SLDDataInterface sldData : sldDataList) {
                String fileExtension = ExternalFilenames.getFileExtension(sldData.getSLDFile().getAbsolutePath());
                if (fileExtension.compareTo(SLDEditorFile.getSLDFileExtension()) == 0) {
                    sldFilesCount++;
                } else if (fileExtension.compareTo(YSLDTool.YSLD_FILE_EXTENSION) == 0) {
                    ysldFilesCount++;
                }
            }
        }
        exportToYSLDButton.setEnabled(sldFilesCount > 0);
        exportToSLDButton.setEnabled(ysldFilesCount > 0);
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface)

Example 29 with SLDDataInterface

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

the class YSLDTool method exportToSLD.

/**
 * Export to SLD.
 */
private void exportToSLD() {
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        String layerName = sldData.getLayerNameWithOutSuffix();
        if (sld != null) {
            String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
            String destinationFolder = sldData.getSLDFile().getParent();
            File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, SLDEditorFile.getSLDFileExtension());
            String sldFilename = fileToSave.getName();
            if (fileToSave.exists()) {
                ConsoleManager.getInstance().error(this, Localisation.getField(YSLDTool.class, "YSLDTool.destinationAlreadyExists") + " " + sldFilename);
            } else {
                ConsoleManager.getInstance().information(this, Localisation.getField(YSLDTool.class, "YSLDTool.exportToSLDMsg") + " " + sldFilename);
                BufferedWriter out;
                try {
                    out = new BufferedWriter(new FileWriter(fileToSave));
                    out.write(sldString);
                    out.close();
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(this, e);
                }
            }
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileWriter(java.io.FileWriter) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 30 with SLDDataInterface

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

the class BatchUpdateFontData method updateFont.

/**
 * Update font.
 *
 * @param sldWriter the sld writer
 * @return true, if successful
 */
public boolean updateFont(SLDWriterInterface sldWriter) {
    boolean refreshUI = false;
    if ((rule != null) && (sldWriter != null)) {
        List<Font> fontList = symbolizer.fonts();
        Font font = fontList.get(0);
        if (isFontNameUpdated()) {
            font.getFamily().clear();
            font.getFamily().addAll(this.font.getFamily());
        }
        if (isFontStyleUpdated()) {
            font.setStyle(ff.literal(this.font.getStyle()));
        }
        if (isFontWeightUpdated()) {
            font.setWeight(ff.literal(this.font.getWeight()));
        }
        if (isFontSizeUpdated()) {
            font.setSize(ff.literal(this.font.getSize()));
        }
        String sldContents = sldWriter.encodeSLD(null, this.sld);
        SLDDataInterface current = SLDEditorFile.getInstance().getSLDData();
        if ((current != null) && (sldData != null)) {
            if (((current.getSLDFile() == null) && (sldData.getSLDFile() == null)) || ((current.getSLDFile() != null) && current.getSLDFile().equals(sldData.getSLDFile())) || ((current.getSLDURL() != null) && current.getSLDURL().equals(sldData.getSLDURL()))) {
                Symbolizer currentSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, SelectedSymbol.getInstance().getSld());
                if (currentSymbolizer != null) {
                    if (currentSymbolizer instanceof TextSymbolizer) {
                        TextSymbolizer textSymbolizer = (TextSymbolizer) currentSymbolizer;
                        textSymbolizer.fonts().clear();
                        textSymbolizer.fonts().add(font);
                        refreshUI = true;
                    }
                }
            }
        }
        sldData.updateSLDContents(sldContents);
        setOriginalData(font);
    }
    return refreshUI;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) TextSymbolizer(org.geotools.styling.TextSymbolizer) Font(org.geotools.styling.Font) Symbolizer(org.geotools.styling.Symbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

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