Search in sources :

Example 51 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class ReloadManagerTest method testReloadFile.

/**
 * Test method for
 * {@link com.sldeditor.common.watcher.ReloadManager#fileAdded(java.nio.file.Path)}. Test method
 * for {@link com.sldeditor.common.watcher.ReloadManager#fileModified(java.nio.file.Path)}. Test
 * method for
 * {@link com.sldeditor.common.watcher.ReloadManager#fileDeleted(java.nio.file.Path)}. Test
 * method for
 * {@link com.sldeditor.common.watcher.ReloadManager#sldDataUpdated(com.sldeditor.common.SLDDataInterface, boolean)}.
 * Test method for
 * {@link com.sldeditor.common.watcher.ReloadManager#addListener(com.sldeditor.common.LoadSLDInterface)}.
 */
@Test
public void testReloadFile() {
    ReloadManager.getInstance().fileAdded(null);
    ReloadManager.getInstance().fileModified(null);
    ReloadManager.getInstance().fileDeleted(null);
    SLDData sldData = new SLDData(new StyleWrapper(), "");
    ReloadManager.getInstance().sldDataUpdated(sldData, true);
    File expectedFile = new File("/tmp/testFile.sld");
    Path path = expectedFile.toPath();
    // Try with no callback
    ReloadManager.getInstance().fileModified(path);
    DummyCallback callback = new DummyCallback();
    ReloadManager.getInstance().addListener(callback);
    assertEquals(0, callback.reloadCallbackCalled);
    // Set loaded file - should match
    sldData.setSLDFile(expectedFile);
    ReloadManager.getInstance().sldDataUpdated(sldData, true);
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(1, callback.reloadCallbackCalled);
    // Set loaded file - won't match
    callback.reloadCallbackCalled = 0;
    File expectedFile2 = new File("/tmp/differenttestFile.sld");
    path = expectedFile2.toPath();
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(0, callback.reloadCallbackCalled);
    // Now try valid multiple calls
    path = expectedFile.toPath();
    ReloadManager.getInstance().fileModified(path);
    ReloadManager.getInstance().fileModified(path);
    ReloadManager.getInstance().fileModified(path);
    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(1, callback.reloadCallbackCalled);
}
Also used : Path(java.nio.file.Path) SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File) Test(org.junit.Test)

Example 52 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class SLDTree method repopulateTree.

/**
 * Repopulate tree for a undo/redo operation.
 *
 * @param sldContents the sld contents
 */
private void repopulateTree(String sldContents) {
    int[] selectedRows = symbolTree.getSelectionRows();
    SLDDataInterface sldData = new SLDData(null, sldContents);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    SelectedSymbol.getInstance().setSld(sld);
    populateSLD();
    if ((selectedRows != null) && (selectedRows.length > 0)) {
        symbolTree.setSelectionRow(selectedRows[0]);
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface)

Example 53 with SLDData

use of com.sldeditor.common.data.SLDData 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;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 54 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class InlineFeatureUtilsTest method testGetInlineFeaturesText.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#getInlineFeaturesText(org.geotools.styling.UserLayer)}.
 */
@Test
public void testGetInlineFeaturesText() {
    String actualResult = InlineFeatureUtils.getInlineFeaturesText(null);
    assertTrue(actualResult.compareTo("") == 0);
    // Test 1
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    UserLayer userLayer1 = (UserLayer) sld.layers().get(0);
    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer1);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));
    // Test 2
    sldData = new SLDData(null, testInline1b);
    sld = SLDUtils.createSLDFromString(sldData);
    UserLayer userLayer2 = (UserLayer) sld.layers().get(0);
    actualResult = InlineFeatureUtils.getInlineFeaturesText(userLayer2);
    assertTrue(actualResult.startsWith("<FeatureCollection>"));
    assertTrue(actualResult.endsWith("</FeatureCollection>"));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) UserLayer(org.geotools.styling.UserLayer) Test(org.junit.Test)

Example 55 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class InlineFeatureUtilsTest method testContainsInLineFeatures.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#containsInLineFeatures(org.geotools.styling.StyledLayerDescriptor)}.
 */
@Test
public void testContainsInLineFeatures() {
    assertFalse(InlineFeatureUtils.containsInLineFeatures(null));
    // Contains inline data
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    assertTrue(InlineFeatureUtils.containsInLineFeatures(sld));
    // Contains no inline data
    sldData = new SLDData(null, testNoInline);
    sld = SLDUtils.createSLDFromString(sldData);
    assertFalse(InlineFeatureUtils.containsInLineFeatures(sld));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Test(org.junit.Test)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4