use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class SLDEditorMenusTest method testSLDEditorMenus.
/**
* Test method for {@link com.sldeditor.ui.menu.SLDEditorMenus#SLDEditorMenus(com.sldeditor.common.SLDEditorInterface)}.
*/
@Test
public void testSLDEditorMenus() {
SLDEditorMenus.createMenus(null, null);
SLDEditorMenus.destroyInstance();
SLDEditorInterface application = new SLDEditorInterface() {
@Override
public JPanel getAppPanel() {
return null;
}
@Override
public void updateWindowTitle(boolean dataEditedFlag) {
}
@Override
public void chooseNewSLD() {
}
@Override
public void exitApplication() {
}
@Override
public void saveFile(URL url) {
}
@Override
public void saveSLDData(SLDDataInterface sldData) {
}
@Override
public LoadSLDInterface getLoadSLDInterface() {
return null;
}
@Override
public JFrame getApplicationFrame() {
return null;
}
@Override
public void openFile(URL selectedURL) {
}
@Override
public String getAppName() {
return null;
}
@Override
public void refreshPanel(Class<?> parent, Class<?> panelClass) {
}
};
SLDEditorMenus.createMenus(application, null);
SLDEditorMenus.destroyInstance();
SLDEditorMenus.createMenus(application, new ArrayList<ExtensionInterface>());
SLDEditorMenus.destroyInstance();
EnvironmentVariableManager.destroyInstance();
SLDEditorFile.destroyInstance();
VendorOptionManager.destroyInstance();
UndoManager.destroyInstance();
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class CreateExternalDataSource method connect.
/**
* Connect.
*
* @param typeName the type name
* @param geometryFieldName the geometry field name
* @param editorFile the editor file
* @return the list of datastores
*/
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
List<DataSourceInfo> dataSourceInfoList = new ArrayList<DataSourceInfo>();
dataSourceInfoList.add(dsInfo);
dsInfo.reset();
if (editorFile != null) {
SLDDataInterface sldData = editorFile.getSLDData();
DataSourcePropertiesInterface dataSourceProperties = sldData.getDataSourceProperties();
Map<String, Object> map = dataSourceProperties.getConnectionProperties();
if (dataSourceProperties.hasPassword()) {
String password = dataSourceProperties.getPassword();
if (password == null) {
password = "dummy password";
dataSourceProperties.setPassword(password);
map = dataSourceProperties.getConnectionProperties();
}
}
DataStore dataStore = null;
try {
dataStore = DataStoreFinder.getDataStore(map);
if (dataStore != null) {
// Try connecting to a vector data source
dsInfo.setTypeName(typeName);
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
SimpleFeatureType schema = source.getSchema();
if (schema.getCoordinateReferenceSystem() == null) {
// No crs found to set a default and reload
if (dataStore instanceof ShapefileDataStore) {
ShapefileDataStore shapeFileDatastore = (ShapefileDataStore) dataStore;
CoordinateReferenceSystem crs = JCRSChooser.showDialog(Localisation.getString(CreateExternalDataSource.class, "CRSPanel.title"), defaultCRS.getIdentifiers().iterator().next().toString());
if (crs != null) {
shapeFileDatastore.forceSchemaCRS(crs);
}
source = dataStore.getFeatureSource(typeName);
schema = source.getSchema();
}
}
dsInfo.setSchema(schema);
determineGeometryType(schema.getGeometryDescriptor().getType());
} else {
// Try connecting to a raster data source
Object rasterFilename = map.get(DataSourceConnectorInterface.FILE_MAP_KEY);
if (rasterFilename != null) {
File rasterFile = new File(ExternalFilenames.convertURLToFile((String) rasterFilename));
ChooseRasterFormatInterface panel = new ChooseRasterFormatPanel(Controller.getInstance().getFrame());
AbstractGridFormat format = DetermineRasterFormat.choose(rasterFile, panel);
AbstractGridCoverage2DReader reader = format.getReader(rasterFile);
dsInfo.setGridCoverageReader(reader);
} else {
logger.error("No matching datastore");
}
}
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
dsInfo.setDataStore(dataStore);
if (!dsInfo.hasData()) {
ConsoleManager.getInstance().error(this, Localisation.getField(CreateExternalDataSource.class, "CreateExternalDataSource.failedToConnect") + dataSourceProperties.getDebugConnectionString());
}
}
return dataSourceInfoList;
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class DataFlavourManager method copy.
/**
* Copy.
*
* @param destinationTreeNode the destination tree node
* @param transferredData the transferred data
* @return true, if successful
*/
public static boolean copy(NodeInterface destinationTreeNode, TransferredData transferredData) {
if ((destinationTreeNode == null) || (transferredData == null)) {
return false;
}
Map<NodeInterface, List<SLDDataInterface>> map = new LinkedHashMap<NodeInterface, List<SLDDataInterface>>();
for (int index = 0; index < transferredData.getDataListSize(); index++) {
NodeInterface nodeToTransfer = (NodeInterface) transferredData.getTreePath(index).getLastPathComponent();
SelectedFiles selectedFiles = nodeToTransfer.getHandler().getSLDContents(nodeToTransfer);
map.put(nodeToTransfer, selectedFiles.getSldData());
}
return destinationTreeNode.getHandler().copyNodes(destinationTreeNode, map);
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class RasterTool method createUI.
/**
* Creates the ui.
*/
private void createUI() {
rasterPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) rasterPanel.getLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
rasterPanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(RasterTool.class, "RasterTool.title")));
//
// Import raster
//
importRasterButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.import"), "tool/importraster.png");
rasterPanel.add(importRasterButton);
importRasterButton.setEnabled(false);
importRasterButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
File rasterFile = fileTreeNode.getFile();
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.createSymbol"), rasterFile.getAbsolutePath()));
SLDDataInterface sldData = rasterReader.createRasterSLDData(rasterFile);
// Raster file
DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFile.getAbsolutePath()));
SLDEditorFile.getInstance().setSLDData(sldData);
SLDEditorFile.getInstance().setDataSource(dsProperties);
// Clear the data change flag
SLDEditorFile.getInstance().fileOpenedSaved();
// Load sld
List<SLDDataInterface> sldFilesToLoad = new ArrayList<SLDDataInterface>();
sldFilesToLoad.add(sldData);
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setSldData(sldFilesToLoad);
selectedFiles.setFolderName(rasterFile.getParent());
LoadSLDInterface loadSLD = sldEditorInterface.getLoadSLDInterface();
loadSLD.loadSLDString(selectedFiles);
}
}
}
});
//
// Set data source
//
dataSourceButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.dataSource"), "tool/setdatasource.png");
rasterPanel.add(dataSourceButton);
dataSourceButton.setEnabled(false);
dataSourceButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
if (sldEditorInterface != null) {
FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
File rasterFile = fileTreeNode.getFile();
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.setDataSource"), rasterFile.getAbsolutePath()));
// Raster file
DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
String rasterFilename = null;
try {
rasterFilename = rasterFile.toURI().toURL().toString();
} catch (MalformedURLException exceptionObj) {
ConsoleManager.getInstance().exception(RasterTool.class, exceptionObj);
return;
}
DataSourcePropertiesInterface dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFilename));
SLDEditorFile.getInstance().setDataSource(dsProperties);
DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
if (dataSource != null) {
dataSource.connect(rasterFilename, SLDEditorFile.getInstance(), null);
}
}
}
}
});
rasterPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
use of com.sldeditor.common.SLDDataInterface 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);
}
}
}
}
}
}
}
}
Aggregations