use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.
the class LegendPanelImage method renderSymbol.
/**
* Render symbol.
*/
public void renderSymbol() {
if (SelectedSymbol.getInstance().isValid()) {
StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
if (sld != null) {
// Style name
String styleNameHeading = null;
if (showStyleName) {
if (!sld.layers().isEmpty()) {
StyledLayer styledLayer = sld.layers().get(0);
if (styledLayer != null) {
styleNameHeading = styledLayer.getName();
}
}
if (styleNameHeading == null) {
styleNameHeading = "";
}
}
// Filename
String filename = null;
if (showFilename) {
filename = SelectedSymbol.getInstance().getFilename();
if (filename == null) {
filename = "";
}
}
BufferedImage bImage = legend.createLegend(sld, styleNameHeading, filename);
if (bImage != null) {
imageIcon = new ImageIcon(bImage);
} else {
imageIcon = null;
}
this.setIcon(imageIcon);
} else {
this.setIcon(null);
}
} else {
this.setIcon(null);
}
repaint();
}
use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.
the class SLDUtilsTest method testCreateSLDFromStringFile.
@Test
public void testCreateSLDFromStringFile() {
StyleWrapper wrapper = new StyleWrapper();
SLDData sldData = new SLDData(wrapper, expectedSld);
String filename = "D:/tmp/test.sld";
File file = new File(filename);
sldData.setSLDFile(file);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(null);
assertNull(sld);
sld = SLDUtils.createSLDFromString(sldData);
StyledLayer[] styledLayers = sld.getStyledLayers();
NamedLayer namedLayer = (NamedLayer) styledLayers[0];
Style[] actualStyles = namedLayer.getStyles();
PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
assertEquals("circle", mark.getWellKnownName().toString());
// Check resource locator
try {
URL url = file.getParentFile().toURI().toURL();
String actualResourceLocator = sldData.getResourceLocator().toExternalForm();
String expectedResourcelocator = url.toExternalForm();
assertTrue(expectedResourcelocator.compareTo(actualResourceLocator) == 0);
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
}
use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.
the class NewPolygonSLDTest method testNewPolygonSLD.
/**
* Test new polygon sld.
*/
@Test
public void testNewPolygonSLD() {
NewPolygonSLD newData = new NewPolygonSLD();
StyledLayerDescriptor sld = newData.create();
assertTrue(sld.layers().size() == 1);
StyledLayer styledLayer = sld.layers().get(0);
NamedLayer namedLayer = (NamedLayer) styledLayer;
Symbolizer symbolizer = namedLayer.styles().get(0).featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
assertTrue(symbolizer instanceof PolygonSymbolizer);
}
use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.
the class NewLineSLDTest method testNewLineSLD.
/**
* Test new line sld.
*/
@Test
public void testNewLineSLD() {
NewLineSLD newData = new NewLineSLD();
StyledLayerDescriptor sld = newData.create();
assertTrue(sld.layers().size() == 1);
StyledLayer styledLayer = sld.layers().get(0);
NamedLayer namedLayer = (NamedLayer) styledLayer;
Symbolizer symbolizer = namedLayer.styles().get(0).featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
assertTrue(symbolizer instanceof LineSymbolizer);
}
use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.
the class GeoServerClientTest method testInitialiseWithValidConnection.
/**
* Only works if a default GeoServer instance is running
*
* <p>Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#initialise(com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgressInterface, com.sldeditor.common.data.GeoServerConnection)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#retrieveData()}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#connect()}. Test
* method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#uploadSLD(com.sldeditor.common.data.StyleWrapper, java.lang.String)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getWorkspaceList()}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#refreshWorkspace(java.lang.String)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#deleteStyle(com.sldeditor.common.data.StyleWrapper)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#disconnect()}.
*/
@Ignore
@Test
public void testInitialiseWithValidConnection() {
GeoServerClient client = new GeoServerClient();
TestProgressClass progress = new TestProgressClass();
client.initialise(progress, testConnection);
assertTrue(client.connect());
assertEquals(testConnection, client.getConnection());
List<String> actualWorkspaceList = client.getWorkspaceList();
assertTrue(actualWorkspaceList.size() > 0);
client.retrieveData();
int count = 0;
while (!progress.hasFinished() && count < 50) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
}
assertTrue(progress.hasFinished());
// CHECKSTYLE:OFF
int actualNoOfStyles = progress.styleTotal;
// CHECKSTYLE:ON
// Retrieve style
StyleWrapper styleWrapper = new StyleWrapper(client.getDefaultWorkspaceName(), "point");
String sldContents = client.getStyle(styleWrapper);
assertTrue(sldContents != null);
SLDData sldData = new SLDData(styleWrapper, sldContents);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
assertEquals("default_point", sld.layers().get(0).getName());
// Upload as new style
String timeString = "" + System.currentTimeMillis();
String styleName = "New_Test_style_" + timeString;
styleWrapper.setStyle(styleName);
assertTrue(client.uploadSLD(styleWrapper, sldContents));
List<StyleWrapper> stylesToDeleteList = new ArrayList<StyleWrapper>();
stylesToDeleteList.add(styleWrapper.clone());
// Replace the existing style
StyledLayer styledLayer = sld.layers().get(0);
styledLayer.setName("test point sld");
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
String updatedSLDBody = sldWriter.encodeSLD(null, sld);
assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
// Change the workspace name - invalid
styleWrapper.setWorkspace("Test workspace");
assertFalse(client.uploadSLD(styleWrapper, updatedSLDBody));
// Change the workspace name - valid
String expectedWorkspace = "Test_workspace_" + timeString;
styleWrapper.setWorkspace(expectedWorkspace);
assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
stylesToDeleteList.add(styleWrapper.clone());
actualWorkspaceList = client.getWorkspaceList();
assertTrue(actualWorkspaceList.contains(expectedWorkspace));
// Update the contents
styledLayer.setName("updated test point sld");
updatedSLDBody = sldWriter.encodeSLD(null, sld);
assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
// Check refresh workspace works
client.refreshWorkspace(client.getDefaultWorkspaceName());
count = 0;
while (!progress.hasFinished() && count < 50) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
}
assertTrue(progress.hasFinished());
assertEquals(actualNoOfStyles + 1, progress.styleTotal);
//
for (StyleWrapper styleToDelete : stylesToDeleteList) {
System.out.println("Deleting style : " + styleToDelete.getWorkspace() + "/" + styleToDelete.getStyle());
assertTrue(client.deleteStyle(styleToDelete));
}
assertFalse(client.deleteStyle(null));
assertFalse(client.deleteStyle(new StyleWrapper()));
StyleWrapper tmpStyle = styleWrapper.clone();
tmpStyle.setStyle("invalid");
assertFalse(client.deleteStyle(tmpStyle));
tmpStyle = styleWrapper.clone();
tmpStyle.setWorkspace("invalid");
assertFalse(client.deleteStyle(tmpStyle));
System.out.println("Deleting workspace : " + expectedWorkspace);
assertTrue(client.deleteWorkspace(expectedWorkspace));
client.disconnect();
assertFalse(client.isConnected());
}
Aggregations