Search in sources :

Example 1 with SLDDataInterface

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

the class MXDParser method importLayer.

/**
 * Import layer.
 *
 * @param layer the layer
 * @param outputFormat the output format
 * @return the styled layer descriptor
 */
private SLDDataInterface importLayer(JsonObject layer, SLDOutputFormatEnum outputFormat) {
    StyledLayerDescriptor sld = null;
    String layerName = layer.get("name").getAsString();
    double minScale = layer.get("minScale").getAsDouble();
    double maxScale = layer.get("maxScale").getAsDouble();
    int transparency = layer.get("transparency").getAsInt();
    JsonElement renderElement = layer.get("renderer");
    sld = getRenderer(layerName, minScale, maxScale, transparency, renderElement);
    JsonElement labelRenderArrayElement = layer.get("labelRenderers");
    if (labelRenderArrayElement != null) {
        processLabelRenderer(sld, labelRenderArrayElement.getAsJsonArray(), transparency);
    }
    JsonElement fieldArray = layer.get("fields");
    List<DataSourceFieldInterface> fieldList = processFields(layerName, fieldArray);
    JsonElement dataSourcePropertiesElement = layer.get("dataSource");
    DataSourcePropertiesInterface dataSourceProperties = processDataSource(layerName, dataSourcePropertiesElement);
    String sldContents = SLDWriterFactory.createWriter(outputFormat).encodeSLD(sld);
    StyleWrapper styleWrapper = new StyleWrapper(layerName, layerName);
    SLDDataInterface sldData = new SLDData(styleWrapper, sldContents);
    sldData.setDataSourceProperties(dataSourceProperties);
    sldData.setFieldList(fieldList);
    sldData.setReadOnly(true);
    return sldData;
}
Also used : SLDData(com.sldeditor.common.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.StyleWrapper) SLDDataInterface(com.sldeditor.common.SLDDataInterface) JsonElement(com.google.gson.JsonElement) DataSourceFieldInterface(com.sldeditor.common.datasource.DataSourceFieldInterface) DataSourcePropertiesInterface(com.sldeditor.common.datasource.DataSourcePropertiesInterface)

Example 2 with SLDDataInterface

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

the class ExportSLD method main.

/**
 * The main method.
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    if ((args.length != 2) && (args.length != 3)) {
        System.out.println("Usage:");
        System.out.println("ExportSLD <input JSON file> <destination folder> [<output format>]");
        System.out.println("Where <output format> is SLD, YSLD.  The default IS SLD");
        System.exit(0);
    }
    String filename = args[0];
    File outputFolder = new File(args[1]);
    if (!outputFolder.exists()) {
        outputFolder.mkdirs();
    }
    if (args.length == 3) {
        SLDOutputFormatEnum format;
        try {
            format = SLDOutputFormatEnum.valueOf(args[2]);
            outputFormat = format;
        } catch (IllegalArgumentException e) {
            System.err.println("Unknown output format : " + args[2]);
            System.exit(1);
        }
    }
    Map<String, SLDDataInterface> layerMap = MXDParser.readLayers(filename, outputFormat);
    if (layerMap != null) {
        for (String layerName : layerMap.keySet()) {
            File f = new File(outputFolder, generateFilename(layerName));
            writeData(f, layerName, layerMap.get(layerName));
        }
    }
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) SLDOutputFormatEnum(com.sldeditor.common.output.SLDOutputFormatEnum) File(java.io.File)

Example 3 with SLDDataInterface

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

the class MapBoxToolTest method testSetSelectedItems.

/**
 * Test method for
 * {@link com.sldeditor.tool.mapbox.MapBoxTool#setSelectedItems(java.util.List, java.util.List)}.
 */
@Test
public void testSetSelectedItems() {
    MapBoxTool tool = new MapBoxTool();
    JPanel panel = tool.getPanel();
    ToolButton toSLD = null;
    for (Component c : panel.getComponents()) {
        if (c instanceof ToolButton) {
            ToolButton button = (ToolButton) c;
            String toolTipText = button.getToolTipText();
            if (toolTipText.compareTo(Localisation.getString(MapBoxTool.class, "MapBoxTool.exportToSLD")) == 0) {
                toSLD = button;
            }
        }
    }
    File testFile1 = null;
    File testFile3 = null;
    try {
        testFile1 = File.createTempFile("invalid", ".tst");
        testFile3 = File.createTempFile("valid", ".json");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    tool.setSelectedItems(null, null);
    // Invalid file
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData1 = new SLDData(null, null);
    sldData1.setSLDFile(testFile1);
    sldDataList.add(sldData1);
    tool.setSelectedItems(null, sldDataList);
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    /*
         * // Try with valid mapbox file sldDataList = new ArrayList<SLDDataInterface>(); SLDData
         * sldData3 = getSLDDataFile("/point/mapbox/circleStyleTest.json");
         * sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList);
         * 
         * // SLD should be enabled assertTrue(toSLD.isEnabled()); toSLD.doClick();
         * 
         * // Try with valid sld files sldDataList = new ArrayList<SLDDataInterface>();
         * sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList);
         * 
         * // SLD should be enabled assertTrue(toSLD.isEnabled());
         */
    testFile1.delete();
    testFile3.delete();
// tidyUpTempFiles(sldData3.getSLDFile());
}
Also used : JPanel(javax.swing.JPanel) SLDData(com.sldeditor.common.data.SLDData) ToolButton(com.sldeditor.tool.ToolButton) SLDDataInterface(com.sldeditor.common.SLDDataInterface) MapBoxTool(com.sldeditor.tool.mapbox.MapBoxTool) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Component(java.awt.Component) File(java.io.File) Test(org.junit.Test)

Example 4 with SLDDataInterface

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

the class VectorToolTest method testSupports.

/**
 * Test method for {@link com.sldeditor.tool.vector.VectorTool#supports(java.util.List, java.util.List, java.util.List)}.
 */
@Test
public void testSupports() {
    try {
        FileTreeNode vectorTreeNode = new FileTreeNode(new File("/test"), "sld_cookbook_polygon.shp");
        vectorTreeNode.setFileCategory(FileTreeNodeTypeEnum.VECTOR);
        FileTreeNode rasterTreeNode = new FileTreeNode(new File("/test"), "sld_cookbook_polygon.tif");
        rasterTreeNode.setFileCategory(FileTreeNodeTypeEnum.RASTER);
        List<Class<?>> uniqueNodeTypeList = new ArrayList<Class<?>>();
        List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
        List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
        // Try vector file
        nodeTypeList.add(vectorTreeNode);
        VectorTool vectorTool = new VectorTool(null);
        assertTrue(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try raster file
        nodeTypeList.clear();
        nodeTypeList.add(rasterTreeNode);
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try database feature class
        nodeTypeList.clear();
        DatabaseFeatureClassNode databaseFeatureClassNode = new DatabaseFeatureClassNode(null, null, "db fc");
        nodeTypeList.add(databaseFeatureClassNode);
        assertTrue(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try invalid node class
        nodeTypeList.clear();
        nodeTypeList.add(new GeoServerStyleHeadingNode(null, null, "test"));
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try with no nodes
        nodeTypeList.clear();
        assertFalse(vectorTool.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
        // Try with null
        assertFalse(vectorTool.supports(uniqueNodeTypeList, null, sldDataList));
    } catch (SecurityException e) {
        e.printStackTrace();
        fail();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) VectorTool(com.sldeditor.tool.vector.VectorTool) DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) GeoServerStyleHeadingNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test)

Example 5 with SLDDataInterface

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

the class SLDEditor method loadSLDString.

/**
 * Load sld string.
 *
 * @param selectedFiles the selected files
 * @return true, if successful
 */
@Override
public boolean loadSLDString(SelectedFiles selectedFiles) {
    boolean loadNewSymbol = true;
    PrefManager.getInstance().setLastFolderViewed(selectedFiles);
    List<SLDDataInterface> sldFilesToLoad = selectedFiles.getSldData();
    if (!selectedFiles.isFolder()) {
        // Application can only support editing one SLD file at a time
        if (sldFilesToLoad.size() == 1) {
            SLDDataInterface firstObject = sldFilesToLoad.get(0);
            if (firstObject != null) {
                if (dataEditedFlag && !isUnderTestFlag()) {
                    loadNewSymbol = sldEditorDlg.load(frame);
                }
                if (loadNewSymbol) {
                    populate(firstObject);
                }
                ReloadManager.getInstance().reset();
            }
        }
        if (!selectedFiles.isDataSource()) {
            // Inform UndoManager that a new SLD file has been
            // loaded and to clear undo history
            UndoManager.getInstance().fileLoaded();
            Controller.getInstance().setPopulating(true);
            uiMgr.populateUI(sldFilesToLoad.size());
            Controller.getInstance().setPopulating(false);
        }
    }
    return loadNewSymbol;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface)

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