use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.
the class LegendOptionDataTest method testTransparent.
/**
* Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#isTransparent()}.
* Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#setTransparent(boolean)}.
*/
@Test
public void testTransparent() {
LegendOptionData data = new LegendOptionData();
data.setTransparent(true);
assertTrue(data.isTransparent());
data.setTransparent(false);
assertFalse(data.isTransparent());
}
use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.
the class LegendOptionDataTest method testBackgroundColour.
/**
* Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#getBackgroundColour()}.
* Test method for {@link com.sldeditor.ui.legend.option.LegendOptionData#setBackgroundColour(java.awt.Color)}.
*/
@Test
public void testBackgroundColour() {
LegendOptionData data = new LegendOptionData();
Color expectedColor = Color.YELLOW;
data.setBackgroundColour(expectedColor);
assertEquals(expectedColor, data.getBackgroundColour());
}
use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.
the class SLDEditorFileHandler method readSLDEditorFile.
/**
* Read sld editor file.
*
* @param file the file
* @return the SLD data
*/
private SLDDataInterface readSLDEditorFile(File file) {
SLDDataInterface sldData = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder;
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(file);
String sldFile = extractTextData(document, SLDEditorFileHandler.SLD_ELEMENT);
DataSourcePropertiesInterface dataSourceProperties = DataSourceProperties.decodeXML(document, SLDEditorFileHandler.DATASOURCE_ELEMENT);
List<VersionData> vendorOptionList = extractVendorOptionData(document, SLDEditorFileHandler.VENDOR_OPTION_ELEMENT);
File f = new File(sldFile);
String sldContents = readFile(f, Charset.defaultCharset());
sldData = new SLDData(new StyleWrapper(sldFile), sldContents);
sldData.setDataSourceProperties(dataSourceProperties);
sldData.setVendorOptionList(vendorOptionList);
List<DataSourceAttributeData> fieldList = null;
sldData.setFieldList(fieldList);
sldData.setSLDFile(f);
sldData.setReadOnly(false);
sldData.setSldEditorFile(file);
List<EnvVar> envVarList = extractEnvironmentVariables(document, SLDEditorFileHandler.ENVVAR_ELEMENT);
sldData.setEnvVarList(envVarList);
LegendOptionData legendOption = LegendOptionData.decodeXML(document, SLDEditorFileHandler.LEGEND_OPTION_ELEMENT);
sldData.setLegendOptions(legendOption);
} catch (ParserConfigurationException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (SAXException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
return sldData;
}
use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.
the class SLDEditorFileHandler method save.
/*
* (non-Javadoc)
*
* @see com.sldeditor.extension.input.file.FileHandlerInterface#save(com.sldeditor.ui.iface.SLDDataInterface)
*/
@Override
public boolean save(SLDDataInterface sldData) {
if (sldData == null) {
return false;
}
File fileToSave = sldData.getSldEditorFile();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder;
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document doc = documentBuilder.newDocument();
Element root = doc.createElement(SLDEditorFileHandler.ROOT_ELEMENT);
doc.appendChild(root);
// SLD contents
Element sldElement = doc.createElement(SLDEditorFileHandler.SLD_ELEMENT);
sldElement.appendChild(doc.createTextNode(sldData.getSLDFile().getAbsolutePath()));
root.appendChild(sldElement);
// Vendor options
List<VersionData> vendorOptionList = sldData.getVendorOptionList();
if (vendorOptionList != null) {
for (VersionData versionData : vendorOptionList) {
Element vendorOptionElement = doc.createElement(SLDEditorFileHandler.VENDOR_OPTION_ELEMENT);
VendorOptionVersion vendorOption = new VendorOptionVersion(versionData.getVendorOptionType(), versionData);
vendorOptionElement.appendChild(doc.createTextNode(vendorOption.toString()));
root.appendChild(vendorOptionElement);
}
}
// Write out the data source connector
DataSourcePropertiesInterface dataSourceProperties = sldData.getDataSourceProperties();
if (dataSourceProperties != null) {
dataSourceProperties.encodeXML(doc, root, SLDEditorFileHandler.DATASOURCE_ELEMENT);
}
// Environment variables
Element envVarListElement = doc.createElement(SLDEditorFileHandler.ENVVARLIST_ELEMENT);
root.appendChild(envVarListElement);
List<EnvVar> envVarList = sldData.getEnvVarList();
if (envVarList != null) {
for (EnvVar envVar : envVarList) {
Element envVarElement = doc.createElement(SLDEditorFileHandler.ENVVAR_ELEMENT);
envVarElement.setAttribute(SLDEditorFileHandler.ENVVAR_NAME_ATTRIBUTE, envVar.getName());
envVarElement.setAttribute(SLDEditorFileHandler.ENVVAR_TYPE_ATTRIBUTE, envVar.getType().getName());
if (envVar.getValue() != null) {
String value = envVar.getValue().toString();
envVarElement.setAttribute(SLDEditorFileHandler.ENVVAR_VALUE_ATTRIBUTE, value);
}
envVarListElement.appendChild(envVarElement);
}
}
// Write out the legend options
LegendOptionData legendOptions = sldData.getLegendOptions();
if (legendOptions != null) {
legendOptions.encodeXML(doc, root, SLDEditorFileHandler.LEGEND_OPTION_ELEMENT);
}
// Output the XML file contents
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, SLDEditorFileHandler.YES);
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, SLDEditorFileHandler.YES);
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(stringWriter));
String outputXML = stringWriter.getBuffer().toString();
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(fileToSave));
writer.write(outputXML);
} catch (IOException e) {
// Do nothing
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
// Do nothing
}
}
} catch (ParserConfigurationException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (TransformerConfigurationException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (TransformerFactoryConfigurationError e) {
ConsoleManager.getInstance().exception(this, e.getException());
} catch (TransformerException e) {
ConsoleManager.getInstance().exception(this, e);
}
return true;
}
use of com.sldeditor.ui.legend.option.LegendOptionData in project sldeditor by robward-scisys.
the class SLDDataTest method testLegendOptions.
/**
* Test legend options.
*/
@Test
public void testLegendOptions() {
SLDData data = new SLDData(null, null);
LegendOptionData legendOptions = null;
assertNotNull(data.getLegendOptions());
data.setLegendOptions(legendOptions);
assertNotNull(data.getLegendOptions());
legendOptions = new LegendOptionData();
data.setLegendOptions(legendOptions);
assertEquals(legendOptions, data.getLegendOptions());
}
Aggregations