Search in sources :

Example 76 with StyledLayerDescriptor

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

the class SLDEditor method populate.

/**
 * Populate the application with the SLD.
 *
 * @param sldData the sld data
 */
protected void populate(SLDDataInterface sldData) {
    String layerName = sldData.getLayerName();
    File sldEditorFile = sldData.getSldEditorFile();
    if (sldEditorFile != null) {
        ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDEditorFile"), sldEditorFile.getAbsolutePath()));
    }
    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDFile"), layerName));
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    SelectedSymbol selectedSymbolInstance = SelectedSymbol.getInstance();
    selectedSymbolInstance.setSld(sld);
    selectedSymbolInstance.setFilename(layerName);
    selectedSymbolInstance.setName(layerName);
    SLDEditorFile.getInstance().setSLDData(sldData);
    // Reload data source if sticky flag is set
    boolean isDataSourceSticky = SLDEditorFile.getInstance().isStickyDataSource();
    DataSourcePropertiesInterface previousDataSource = dataSource.getDataConnectorProperties();
    dataSource.reset();
    if (isDataSourceSticky) {
        SLDEditorFile.getInstance().setDataSource(previousDataSource);
    }
    dataSource.connect(ExternalFilenames.removeSuffix(layerName), SLDEditorFile.getInstance(), CheckAttributeFactory.getCheckList());
    VendorOptionManager.getInstance().loadSLDFile(uiMgr, sld, sldData);
    LegendManager.getInstance().SLDLoaded(sldData.getLegendOptions());
    SLDEditorFile.getInstance().fileOpenedSaved();
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 77 with StyledLayerDescriptor

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

the class NewSLDPanel method showDialog.

/**
 * Show dialog.
 *
 * @param parent the parent
 * @return the created SLD if selected
 */
public List<SLDDataInterface> showDialog(JFrame parent) {
    List<SLDDataInterface> newSLDList = null;
    selected = null;
    if (parent != null) {
        this.setLocationRelativeTo(parent);
        int x = ((parent.getWidth() - getWidth()) / 2);
        int y = ((parent.getHeight() - getHeight()) / 2);
        this.setLocation(x, y);
    }
    setVisible(true);
    if (selected != null) {
        newSLDList = new ArrayList<SLDDataInterface>();
        StyledLayerDescriptor sld = selected.create();
        if (sldWriter == null) {
            sldWriter = SLDWriterFactory.createWriter(null);
        }
        newSLDList.add(new SLDData(new StyleWrapper(selected.getName()), sldWriter.encodeSLD(null, sld)));
        return newSLDList;
    }
    return null;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 78 with StyledLayerDescriptor

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

the class SaveSLDTool method saveAllSLDToFolder.

/**
 * Save all to folder.
 *
 * @param destinationFolder the destination folder
 * @param saveExternalResources the save external resources
 */
private void saveAllSLDToFolder(File destinationFolder, boolean saveExternalResources) {
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    if (!destinationFolder.exists()) {
        destinationFolder.mkdirs();
    }
    logger.info(Localisation.getString(SaveSLDTool.class, "SaveSLDTool.saveAllSLD"));
    boolean yesToAll = false;
    for (SLDDataInterface sldData : sldDataList) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        String layerName = sldData.getLayerName();
        if (sld != null) {
            String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
            String sldFilename = layerName + ExternalFilenames.addFileExtensionSeparator(SLDEditorFile.getSLDFileExtension());
            File fileToSave = new File(destinationFolder, sldFilename);
            ConsoleManager.getInstance().information(this, Localisation.getField(SaveSLDTool.class, "SaveSLDTool.savingSLDr") + " " + layerName);
            BufferedWriter out;
            try {
                out = new BufferedWriter(new FileWriter(fileToSave));
                out.write(sldString);
                out.close();
            } catch (IOException e) {
                ConsoleManager.getInstance().exception(this, e);
            }
            // Save external images if requested
            if (saveExternalResources) {
                List<String> externalImageList = SLDExternalImages.getExternalImages(sldData.getResourceLocator(), sld);
                for (String externalImage : externalImageList) {
                    File output = new File(destinationFolder, externalImage);
                    File parentFolder = output.getParentFile();
                    // Check to see if the destination folder exists
                    if (!parentFolder.exists()) {
                        if (output.getParentFile().mkdirs()) {
                            ConsoleManager.getInstance().error(this, Localisation.getField(SaveSLDTool.class, "SaveSLDTool.error1") + output.getAbsolutePath());
                        }
                    }
                    if (parentFolder.exists()) {
                        boolean writeOutputFile = true;
                        if (output.exists()) {
                            if (!yesToAll) {
                                Object[] options = { "Yes to All", "Yes", "No" };
                                int n = JOptionPane.showOptionDialog(Controller.getInstance().getFrame(), "Overwrite destination file?\n" + output.getAbsolutePath(), "Desintation file exists", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
                                switch(n) {
                                    case 0:
                                        yesToAll = true;
                                        break;
                                    case 1:
                                        break;
                                    case 2:
                                    default:
                                        writeOutputFile = false;
                                        break;
                                }
                            }
                        }
                        if (writeOutputFile) {
                            try {
                                URL input = DataUtilities.extendURL(sldData.getResourceLocator(), externalImage);
                                URLConnection connection = input.openConnection();
                                InputStream inputStream = connection.getInputStream();
                                BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
                                byte[] buffer = new byte[BUFFER_SIZE];
                                int n = -1;
                                FileOutputStream outputStream = new FileOutputStream(output);
                                while ((n = inputStream.read(buffer)) != -1) {
                                    outputStream.write(buffer, 0, n);
                                }
                                in.close();
                                outputStream.close();
                                ConsoleManager.getInstance().information(this, Localisation.getField(SaveSLDTool.class, "SaveSLDTool.savingExternalImage") + " " + externalImage);
                            } catch (MalformedURLException e) {
                                ConsoleManager.getInstance().exception(this, e);
                            } catch (IOException e) {
                                ConsoleManager.getInstance().exception(this, e);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) BufferedWriter(java.io.BufferedWriter) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 79 with StyledLayerDescriptor

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

the class MissingSLDAttributes method checkAttributes.

/*
     * (non-Javadoc)
     *
     * @see com.sldeditor.datasource.impl.CheckAttributeInterface#checkAttributes(com.sldeditor.
     * datasource.SLDEditorFileInterface)
     */
@Override
public void checkAttributes(SLDEditorFileInterface editorFile) {
    if (editorFile == null) {
        return;
    }
    ExtractAttributes extract = new ExtractAttributes();
    StyledLayerDescriptor sld = editorFile.getSLD();
    extract.extractDefaultFields(sld);
    List<DataSourceAttributeData> sldFieldList = extract.getFields();
    SLDDataInterface sldData = editorFile.getSLDData();
    List<DataSourceAttributeData> dataSourceList = null;
    if (sldData != null) {
        dataSourceList = sldData.getFieldList();
    }
    for (DataSourceAttributeData sldField : sldFieldList) {
        if ((dataSourceList == null) || !dataSourceList.contains(sldField)) {
            ConsoleManager.getInstance().error(this, Localisation.getField(DataSourceImpl.class, "DataSourceImpl.missingAttribute") + " " + sldField.getName());
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DataSourceImpl(com.sldeditor.datasource.impl.DataSourceImpl) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes)

Example 80 with StyledLayerDescriptor

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

the class NewSLDPanel method getSelectedSLD.

/**
 * Gets the selected SLD.
 *
 * @return the selected SLD
 */
protected List<SLDDataInterface> getSelectedSLD() {
    List<SLDDataInterface> newSLDList = null;
    if (selected != null) {
        newSLDList = new ArrayList<>();
        StyledLayerDescriptor sld = selected.create();
        if (sldWriter == null) {
            sldWriter = SLDWriterFactory.createWriter(null);
        }
        newSLDList.add(new SLDData(new StyleWrapper(selected.getName()), sldWriter.encodeSLD(null, sld)));
    }
    return newSLDList;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)134 Test (org.junit.jupiter.api.Test)80 Rule (org.geotools.styling.Rule)54 Style (org.geotools.styling.Style)52 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)50 NamedLayer (org.geotools.styling.NamedLayer)48 SLDData (com.sldeditor.common.data.SLDData)25 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)24 File (java.io.File)22 StyledLayer (org.geotools.styling.StyledLayer)21 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 SLDDataInterface (com.sldeditor.common.SLDDataInterface)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)17 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 StyleWrapper (com.sldeditor.common.data.StyleWrapper)16 IOException (java.io.IOException)16 PointSymbolizer (org.geotools.styling.PointSymbolizer)16 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)15 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)13 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)12