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