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;
}
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));
}
}
}
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());
}
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();
}
}
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;
}
Aggregations