Search in sources :

Example 16 with StyledLayer

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();
}
Also used : ImageIcon(javax.swing.ImageIcon) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) BufferedImage(java.awt.image.BufferedImage)

Example 17 with StyledLayer

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();
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) PointSymbolizer(org.geotools.styling.PointSymbolizer) MalformedURLException(java.net.MalformedURLException) StyledLayer(org.geotools.styling.StyledLayer) MarkImpl(org.geotools.styling.MarkImpl) URL(java.net.URL) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) File(java.io.File) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 18 with StyledLayer

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);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) NewPolygonSLD(com.sldeditor.create.sld.NewPolygonSLD) StyledLayer(org.geotools.styling.StyledLayer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) NamedLayer(org.geotools.styling.NamedLayer) Symbolizer(org.geotools.styling.Symbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Test(org.junit.Test)

Example 19 with StyledLayer

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);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) LineSymbolizer(org.geotools.styling.LineSymbolizer) NewLineSLD(com.sldeditor.create.sld.NewLineSLD) NamedLayer(org.geotools.styling.NamedLayer) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Test(org.junit.Test)

Example 20 with StyledLayer

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());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayer(org.geotools.styling.StyledLayer) ArrayList(java.util.ArrayList) GeoServerClient(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

StyledLayer (org.geotools.styling.StyledLayer)43 Style (org.geotools.styling.Style)28 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)25 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)22 Rule (org.geotools.styling.Rule)19 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)19 UserLayerImpl (org.geotools.styling.UserLayerImpl)16 Symbolizer (org.geotools.styling.Symbolizer)12 NamedLayer (org.geotools.styling.NamedLayer)10 Test (org.junit.Test)10 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)7 LineSymbolizer (org.geotools.styling.LineSymbolizer)6 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)5 IOException (java.io.IOException)4 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)4 SLDData (com.sldeditor.common.data.SLDData)3 ArrayList (java.util.ArrayList)3 UserLayer (org.geotools.styling.UserLayer)3 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)2