Java Code Examples for org.geotools.factory.CommonFactoryFinder#getStyleFactory()

The following examples show how to use org.geotools.factory.CommonFactoryFinder#getStyleFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyleGenerator.java    From constellation with Apache License 2.0 6 votes vote down vote up
private static Rule makeFillRule() {
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();

    // create a partially opaque outline stroke
    final Stroke stroke = styleFactory.createStroke(
            filterFactory.literal(Color.BLACK),
            filterFactory.literal(1),
            filterFactory.literal(.5)
    );

    // create a partially opaque fill
    Fill fill = styleFactory.createFill(
            filterFactory.literal(COLORS.next()),
            filterFactory.literal(.5)
    );

    // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
    final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);

    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    return rule;
}
 
Example 2
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPolygonStyle(final SimpleFeatureCollection features) {
    // get name based rule names
    final List<Rule> ruleList = new ArrayList<>();
    final Set<String> nameSet = new HashSet<>();

    // setup custom rules for polygons
    final SimpleFeatureIterator featureIterator = features.features();
    while (featureIterator.hasNext()) {
        final SimpleFeature feature = featureIterator.next();
        if (nameSet.add((String) feature.getAttribute(ATTRIBUTE))) {
            ruleList.add(makeFillRule(feature));
        }
    }

    // create a partially opaque outline stroke
    final Rule defaultRule = makeFillRule();
    defaultRule.setElseFilter(true);
    defaultRule.setName("Default Rule");
    ruleList.add(defaultRule);

    // Create rule defined style
    final Rule[] rules = ruleList.toArray(new Rule[ruleList.size()]);
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FeatureTypeStyle featureTypeStyle = styleFactory.createFeatureTypeStyle(rules);

    final StyleBuilder builder = new StyleBuilder();
    final Style style = builder.createStyle();
    style.getDescription().setTitle("Polygon Style");
    style.featureTypeStyles().add(featureTypeStyle);

    return style;
}
 
Example 3
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPolygonStyle() {
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();

    // create a partially opaque outline stroke
    final Stroke stroke = styleFactory.createStroke(
            filterFactory.literal(Color.BLACK),
            filterFactory.literal(1),
            filterFactory.literal(.5)
    );

    // create a partially opaque fill
    final Fill fill = styleFactory.createFill(
            filterFactory.literal(COLORS.next()),
            filterFactory.literal(.5)
    );

    // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
    final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);

    // make rule
    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
    final Style style = styleFactory.createStyle();
    style.getDescription().setTitle("Polygon Style");
    style.featureTypeStyles().add(fts);

    return style;
}
 
Example 4
Source File: FieldConfigFeatureTypeConstraintTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#generateExpression()}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#populateExpression(java.lang.Object)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.util.List)}. Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#populateField(java.util.List)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#getFeatureTypeConstraint()}.
 */
@Test
public void testGenerateExpression() {
    FieldConfigFeatureTypeConstraint field =
            new FieldConfigFeatureTypeConstraint(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));
    List<FeatureTypeConstraint> testValue = null;
    field.populate(null);
    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    field.populateField(testValue);

    field.createUI();
    assertNull(field.getStringValue());

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeConstraint expectedValue1 =
            styleFactory.createFeatureTypeConstraint("Feature", Filter.INCLUDE, new Extent[0]);

    testValue = new ArrayList<FeatureTypeConstraint>();
    testValue.add(expectedValue1);
    field.populateField(testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));

    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));

    field.populateExpression((String) null);
}
 
Example 5
Source File: ExtentModelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.ExtentModel#getExtentList()}. Test
 * method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.ExtentModel#removeEntries(int, int)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.featuretypeconstraint.ExtentModel#populate(org.geotools.styling.Extent[])}.
 */
@Test
public void testGetExtentList() {
    TestModelUpdate testUpdate = new TestModelUpdate();
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    ExtentModel model = new ExtentModel(testUpdate);

    Extent[] extentArray = null;
    model.populate(extentArray);

    extentArray = new Extent[5];
    extentArray[0] = styleFactory.createExtent("extent 1", "1 1 1 1");
    extentArray[1] = styleFactory.createExtent("extent 2", "2 2 2 2");
    extentArray[2] = styleFactory.createExtent("extent 3", "3 3 3 3");
    extentArray[3] = styleFactory.createExtent("extent 4", "4 4 4 4");
    extentArray[4] = styleFactory.createExtent("extent 5", "5 5 5 5");
    model.populate(extentArray);

    List<Extent> actualList = model.getExtentList();

    assertEquals(5, actualList.size());
    assertTrue(actualList.get(2).getName().compareTo("extent 3") == 0);

    assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
    model.removeEntries(-1, 2);
    assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
    model.removeEntries(2, 22);
    assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
    model.removeEntries(22, 2);
    assertFalse(testUpdate.hasExtentUpdatedBeenCalled());
    model.removeEntries(2, 2);
    assertTrue(testUpdate.hasExtentUpdatedBeenCalled());
    actualList = model.getExtentList();

    assertEquals(4, actualList.size());
    assertTrue(actualList.get(2).getName().compareTo("extent 4") == 0);
}
 
Example 6
Source File: SLDTreeToolsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewImageOutlinePolygon()}. */
@Test
public void testAddNewImageOutlinePolygon() {
    SLDTreeTools treeTools = new SLDTreeTools();

    TestSLDTree sldTree = new TestSLDTree(null, treeTools);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    SelectedSymbol.getInstance().setSld(sld);

    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);

    DefaultMutableTreeNode rootNode = sldTree.getRootNode();

    // Make sure we have a rule selected
    DefaultMutableTreeNode rule =
            (DefaultMutableTreeNode)
                    rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    assertEquals(0, rule.getChildCount());

    treeTools.addNewRaster();

    DefaultMutableTreeNode rasterNode = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(RasterSymbolizerImpl.class, rasterNode.getUserObject().getClass());

    treeTools.addNewImageOutlinePolygon();
    DefaultMutableTreeNode imageOutlineNode = (DefaultMutableTreeNode) rasterNode.getChildAt(0);
    assertEquals(PolygonSymbolizerImpl.class, imageOutlineNode.getUserObject().getClass());
}
 
Example 7
Source File: SLDTreeToolsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewText()}. */
@Test
public void testAddNewText() {
    SLDTreeTools treeTools = new SLDTreeTools();

    TestSLDTree sldTree = new TestSLDTree(null, treeTools);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    SelectedSymbol.getInstance().setSld(sld);

    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);

    DefaultMutableTreeNode rootNode = sldTree.getRootNode();

    // Make sure we have a rule selected
    DefaultMutableTreeNode rule =
            (DefaultMutableTreeNode)
                    rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    assertEquals(0, rule.getChildCount());

    treeTools.addNewText();

    DefaultMutableTreeNode textNode = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(TextSymbolizerImpl.class, textNode.getUserObject().getClass());
}
 
Example 8
Source File: SLDTreeToolsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewMarker()}. */
@Test
public void testAddNewMarker() {
    SLDTreeTools treeTools = new SLDTreeTools();

    TestSLDTree sldTree = new TestSLDTree(null, treeTools);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    SelectedSymbol.getInstance().setSld(sld);

    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);

    DefaultMutableTreeNode rootNode = sldTree.getRootNode();

    // Make sure we have a rule selected
    DefaultMutableTreeNode rule =
            (DefaultMutableTreeNode)
                    rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    assertEquals(0, rule.getChildCount());

    treeTools.addNewMarker();

    DefaultMutableTreeNode marker = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PointSymbolizerImpl.class, marker.getUserObject().getClass());
}
 
Example 9
Source File: VOGeoServerContrastEnhancementNormalizeOverallTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeOverall#VOGeoServerContrastEnhancementNormalizeOverall(java.lang.Class,
 * com.sldeditor.ui.detail.RasterSymbolizerDetails)}. Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeOverall#getContrastEnhancement(com.sldeditor.common.xml.ui.GroupIdEnum,
 * org.geotools.styling.ChannelSelection)}.
 */
@Test
public void testVOGeoServerContrastEnhancementNormalizeOverall() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();

    VOGeoServerContrastEnhancementNormalizeOverall testObj =
            new VOGeoServerContrastEnhancementNormalizeOverall(panel.getClass(), panel);
    RasterSymbolizer rasterSymbolizer = null;
    testObj.setParentPanel(panel);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    rasterSymbolizer = styleFactory.createRasterSymbolizer();

    GroupConfigInterface constrastMethodGroup =
            panel.getGroup(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD);
    assertNotNull(constrastMethodGroup);
    MultiOptionGroup constrastMethodGroup2 = (MultiOptionGroup) constrastMethodGroup;
    Box box = Box.createVerticalBox();
    constrastMethodGroup2.createUI(panel.getFieldDataManager(), box, panel, panel.getPanelId());
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_LOGARITHMIC);

    ChannelSelection channelSelection =
            createChannelSelection(styleFactory, ContrastMethod.LOGARITHMIC);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);

    SelectedSymbol.getInstance().setSymbolizer(rasterSymbolizer);
    Controller.getInstance().setPopulating(true);
    panel.populate(SelectedSymbol.getInstance());
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.EXPONENTIAL);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_EXPONENTIAL);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.HISTOGRAM);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_HISTOGRAM);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.NORMALIZE);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    // Error
    channelSelection = createChannelSelectionError(styleFactory, ContrastMethod.NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    // Increase code coverage
    testObj.populate((SelectedSymbol) null);
    testObj.populate((TextSymbolizer) null);
    testObj.populate((PolygonSymbolizer) null);
    testObj.updateSymbol((TextSymbolizer) null);
    testObj.updateSymbol((PolygonSymbolizer) null);
    testObj.preLoadSymbol();

    assertTrue(testObj.isDataPresent());

    testObj.dataChanged(FieldIdEnum.DESCRIPTION);
}
 
Example 10
Source File: VOChannelNameTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for populate {@link
 * com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeRed#VOGeoServerContrastEnhancementNormalizeRed(java.lang.Class,
 * com.sldeditor.ui.detail.RasterSymbolizerDetails)}.
 */
@Test
public void testPopulate() {
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();
    VendorOptionRasterFactory vendorOptionRasterFactory =
            new VendorOptionRasterFactory(getClass(), panel);

    List<VersionData> stringVersionDataList = new ArrayList<VersionData>();
    stringVersionDataList.add(VersionData.decode(GeoServerVendorOption.class, "2.3.1"));

    List<VersionData> expressionVersionDataList = new ArrayList<VersionData>();
    expressionVersionDataList.add(VersionData.decode(GeoServerVendorOption.class, "2.14.0"));

    // Change vendor option to string
    VendorOptionManager.getInstance().setSelectedVendorOptions(stringVersionDataList);

    String expectedNameString = "test grey name string";
    SelectedChannelType channelTypeString =
            styleFactory.createSelectedChannelType(
                    expectedNameString, (ContrastEnhancement) null);

    vendorOptionRasterFactory.setChannelName(
            GroupIdEnum.RASTER_GREY_CHANNEL, channelTypeString);
    Expression actual =
            vendorOptionRasterFactory.getChannelName(GroupIdEnum.RASTER_GREY_CHANNEL);

    assertTrue(actual.toString().equals(expectedNameString));

    // Change vendor option to expression
    VendorOptionManager.getInstance().setSelectedVendorOptions(expressionVersionDataList);

    String expectedNameExpression = "test grey name expression";
    SelectedChannelType channelTypeExpression =
            styleFactory.createSelectedChannelType(
                    expectedNameExpression, (ContrastEnhancement) null);

    vendorOptionRasterFactory.setChannelName(
            GroupIdEnum.RASTER_GREY_CHANNEL, channelTypeExpression);
    actual = vendorOptionRasterFactory.getChannelName(GroupIdEnum.RASTER_GREY_CHANNEL);
    assertTrue(actual.toString().equals(expectedNameExpression));
}
 
Example 11
Source File: VOGeoServerContrastEnhancementNormalizeGreyTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeGrey#VOGeoServerContrastEnhancementNormalizeGrey(java.lang.Class,
 * com.sldeditor.ui.detail.RasterSymbolizerDetails)}. Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeGrey#getContrastEnhancement(com.sldeditor.common.xml.ui.GroupIdEnum,
 * org.geotools.styling.ChannelSelection)}.
 */
@Test
public void testVOGeoServerContrastEnhancementNormalizeGrey() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();

    VOGeoServerContrastEnhancementNormalizeGrey testObj =
            new VOGeoServerContrastEnhancementNormalizeGrey(panel.getClass(), panel);
    RasterSymbolizer rasterSymbolizer = null;
    testObj.setParentPanel(panel);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    rasterSymbolizer = styleFactory.createRasterSymbolizer();

    GroupConfigInterface constrastMethodGroup =
            panel.getGroup(GroupIdEnum.RASTER_RGB_CHANNEL_GREY_CONTRAST_METHOD);
    assertNotNull(constrastMethodGroup);
    MultiOptionGroup constrastMethodGroup2 = (MultiOptionGroup) constrastMethodGroup;
    Box box = Box.createVerticalBox();
    constrastMethodGroup2.createUI(panel.getFieldDataManager(), box, panel, panel.getPanelId());
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_LOGARITHMIC);

    ChannelSelection channelSelection =
            createChannelSelection(styleFactory, ContrastMethod.LOGARITHMIC);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);

    SelectedSymbol.getInstance().setSymbolizer(rasterSymbolizer);
    Controller.getInstance().setPopulating(true);
    panel.populate(SelectedSymbol.getInstance());
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.EXPONENTIAL);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_EXPONENTIAL);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.HISTOGRAM);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_HISTOGRAM);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.NORMALIZE);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    // Error
    channelSelection = createChannelSelectionError(styleFactory, ContrastMethod.NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    // Increase code coverage
    testObj.populate((SelectedSymbol) null);
    testObj.populate((TextSymbolizer) null);
    testObj.populate((PolygonSymbolizer) null);
    testObj.updateSymbol((TextSymbolizer) null);
    testObj.updateSymbol((PolygonSymbolizer) null);
    testObj.preLoadSymbol();

    assertTrue(testObj.isDataPresent());

    testObj.dataChanged(FieldIdEnum.DESCRIPTION);
}
 
Example 12
Source File: VOGeoServerFTSCompositeBaseTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.featuretypestyle.VOGeoServerFTSCompositeBase#VOGeoServerFTSCompositeBase(java.lang.Class)}.
 */
@Test
public void testVOGeoServerFTSCompositeBase() {
    Class<FeatureTypeStyleDetails> panelId = FeatureTypeStyleDetails.class;
    VOGeoServerFTSCompositeBase obj = new VOGeoServerFTSCompositeBase(panelId);
    assertEquals(panelId, obj.getPanelId());

    assertNotNull(obj.getFieldDataManager());
    assertNotNull(obj.getPanel());
    assertTrue(obj.isDataPresent());

    assertNotNull(obj.getVendorOptionInfo());

    // Check getVendorOptionVersion
    VendorOptionVersion vendorOption = obj.getVendorOption();
    assertEquals(GeoServerVendorOption.class, vendorOption.getClassType());
    String actualVersionString = vendorOption.getEarliest().getVersionString();
    String expectedVersionString = "2.7.0";
    assertEquals(expectedVersionString, actualVersionString);

    obj.setParentPanel(null);
    assertNull(obj.getParentPanel());
    obj.preLoadSymbol();

    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    String testString = "test";
    obj.getMinimumVersion(null, testString, vendorOptionsPresentList);
    assertTrue(vendorOptionsPresentList.isEmpty());

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    obj.getMinimumVersion(null, fts, vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Valid string
    String expectedValue = "true";
    fts.getOptions().put(FeatureTypeStyle.COMPOSITE_BASE, expectedValue);
    obj.getMinimumVersion(null, fts, vendorOptionsPresentList);
    assertEquals(1, vendorOptionsPresentList.size());

    obj.populate(fts);
    obj.updateSymbol(fts);
    String actualValue = fts.getOptions().get(FeatureTypeStyle.COMPOSITE_BASE);
    assertEquals(actualValue, expectedValue);

    // No opacity
    expectedValue = "false";
    fts.getOptions().put(FeatureTypeStyle.COMPOSITE_BASE, expectedValue);

    obj.populate(fts);
    obj.updateSymbol(fts);
    actualValue = fts.getOptions().get(FeatureTypeStyle.COMPOSITE_BASE);
    assertEquals(actualValue, expectedValue);

    // Invalid string
    expectedValue = "invalid";
    fts.getOptions().put(FeatureTypeStyle.COMPOSITE_BASE, expectedValue);

    obj.populate(fts);
    obj.updateSymbol(fts);
    actualValue = fts.getOptions().get(FeatureTypeStyle.COMPOSITE_BASE);
    assertEquals("false", actualValue);

    // Increase code coverage
    obj.populate((PolygonSymbolizer) null);
    obj.updateSymbol((PolygonSymbolizer) null);
    obj.populate((RasterSymbolizer) null);
    obj.updateSymbol((RasterSymbolizer) null);
    obj.populate((TextSymbolizer) null);
    obj.updateSymbol((TextSymbolizer) null);
    obj.populate((SelectedSymbol) null);
    obj.dataChanged(FieldIdEnum.VO_FTS_COMPOSITE_BASE_BOOL);
}
 
Example 13
Source File: VOGeoServerFTSCompositeTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.featuretypestyle.VOGeoServerFTSComposite#VOGeoServerFTSComposite(java.lang.Class)}.
 */
@Test
public void testVOGeoServerFTSComposite() {
    Class<FeatureTypeStyleDetails> panelId = FeatureTypeStyleDetails.class;
    VOGeoServerFTSComposite obj = new VOGeoServerFTSComposite(panelId);
    assertEquals(panelId, obj.getPanelId());

    assertNotNull(obj.getFieldDataManager());
    assertNotNull(obj.getPanel());
    assertTrue(obj.isDataPresent());

    assertNotNull(obj.getVendorOptionInfo());

    // Check getVendorOptionVersion
    VendorOptionVersion vendorOption = obj.getVendorOption();
    assertEquals(GeoServerVendorOption.class, vendorOption.getClassType());
    String actualVersionString = vendorOption.getEarliest().getVersionString();
    String expectedVersionString = "2.7.0";
    assertEquals(expectedVersionString, actualVersionString);

    obj.setParentPanel(null);
    assertNull(obj.getParentPanel());
    obj.preLoadSymbol();

    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    String testString = "test";
    obj.getMinimumVersion(null, testString, vendorOptionsPresentList);
    assertTrue(vendorOptionsPresentList.isEmpty());

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    obj.getMinimumVersion(null, fts, vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Valid string
    String expectedValue = "copy,0.42";
    fts.getOptions().put(FeatureTypeStyle.COMPOSITE, expectedValue);
    obj.getMinimumVersion(null, fts, vendorOptionsPresentList);
    assertEquals(1, vendorOptionsPresentList.size());

    obj.populate(fts);
    obj.updateSymbol(fts);
    String actualValue = fts.getOptions().get(FeatureTypeStyle.COMPOSITE);
    assertEquals(actualValue, expectedValue);

    // No opacity
    expectedValue = "source-in";
    fts.getOptions().put(FeatureTypeStyle.COMPOSITE, expectedValue);

    obj.populate(fts);
    obj.updateSymbol(fts);
    actualValue = fts.getOptions().get(FeatureTypeStyle.COMPOSITE);
    assertEquals(actualValue, expectedValue);

    // Invalid string
    expectedValue = "invalid";
    fts.getOptions().put(FeatureTypeStyle.COMPOSITE, expectedValue);

    obj.populate(fts);
    obj.updateSymbol(fts);
    actualValue = fts.getOptions().get(FeatureTypeStyle.COMPOSITE);
    assertEquals(actualValue, "copy");

    // Increase code coverage
    obj.populate((PolygonSymbolizer) null);
    obj.updateSymbol((PolygonSymbolizer) null);
    obj.populate((RasterSymbolizer) null);
    obj.updateSymbol((RasterSymbolizer) null);
    obj.populate((TextSymbolizer) null);
    obj.updateSymbol((TextSymbolizer) null);
    obj.populate((SelectedSymbol) null);
    obj.dataChanged(FieldIdEnum.VO_FTS_COMPOSITE_OPACITY);
}
 
Example 14
Source File: VOGeoServerTextSpacingTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSpacingTest#VOGeoServerTextSpacingTest(java.lang.Class,
 * com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSpacingTest() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();

    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSpacing testObj = new VOGeoServerTextSpacing(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);

    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);

    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols()
                .add(
                        styleFactory.createExternalGraphic(
                                new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);

    textSymbolizer.getOptions().put("wordSpacing", String.valueOf(42));
    textSymbolizer.getOptions().put("charSpacing", String.valueOf(21));

    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(2, vendorOptionsPresentList.size());

    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(
            null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());

    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);

    FeatureTypeStyle fts = null;
    testObj.populate(fts);
    testObj.updateSymbol(fts);

    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
 
Example 15
Source File: BatchUpdateFontPanelTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.tool.batchupdatefont.BatchUpdateFontPanel#populate(java.util.List)}.
 */
@Test
void testPopulateUpdateFontData() {
    TestSLDEditorInterface app = new TestSLDEditorInterface();

    TestBatchUpdateFontPanel testObj = new TestBatchUpdateFontPanel(app);

    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();

    DummyInternalSLDFile3 dummy = new DummyInternalSLDFile3();
    sldDataList.add(dummy.getSLDData());

    testObj.populate(sldDataList);

    testObj.testSaveData();
    assertNull(app.savedParent);

    Double expectedFontSizeIncrease = 24.0;

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    String[] families =
            GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    String originalFontname = families[0];
    String originalFontStyle = "normal";
    String originalFontWeight = "normal";
    Font expectedFont =
            styleFactory.createFont(
                    ff.literal(originalFontname),
                    ff.literal(originalFontStyle),
                    ff.literal(originalFontWeight),
                    ff.literal(expectedFontSizeIncrease));

    testObj.setUpdateFont(expectedFont);

    testObj.testApplyData();
    testObj.testSaveData();

    assertEquals(originalFontname, getFontName(app.savedSldData));
}
 
Example 16
Source File: SLDUtilsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testFindRule() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font =
            styleFactory.createFont(
                    ff.literal("abc"),
                    ff.literal("normal"),
                    ff.literal("normal"),
                    ff.literal(10));
    symbolizer.setFont(font);

    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();

    Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);

    assertNotNull(actualRule);
    assertEquals(rule.getName(), actualRule.getName());

    actualRule = SLDUtils.findRule(sld, null, sldCopy);
    assertNull(actualRule);

    actualRule = SLDUtils.findRule(sld, rule, null);
    assertNull(actualRule);
}
 
Example 17
Source File: SLDUtilsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testFindSymbolizer() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font =
            styleFactory.createFont(
                    ff.literal("abc"),
                    ff.literal("normal"),
                    ff.literal("normal"),
                    ff.literal(10));
    symbolizer.setFont(font);

    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();

    Symbolizer actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, sldCopy);

    assertNotNull(actualSymbolizer);
    assertEquals(
            symbolizer.getLabel().toString(),
            ((TextSymbolizer) actualSymbolizer).getLabel().toString());

    actualSymbolizer = SLDUtils.findSymbolizer(sld, null, sldCopy);
    assertNull(actualSymbolizer);

    actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, null);
    assertNull(actualSymbolizer);
}
 
Example 18
Source File: VOGeoServerContrastEnhancementNormalizeRedTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeRed#VOGeoServerContrastEnhancementNormalizeRed(java.lang.Class,
 * com.sldeditor.ui.detail.RasterSymbolizerDetails)}. Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeRed#getContrastEnhancement(com.sldeditor.common.xml.ui.GroupIdEnum,
 * org.geotools.styling.ChannelSelection)}.
 */
@Test
public void testVOGeoServerContrastEnhancementNormalizeRed() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();

    VOGeoServerContrastEnhancementNormalizeRed testObj =
            new VOGeoServerContrastEnhancementNormalizeRed(panel.getClass(), panel);
    RasterSymbolizer rasterSymbolizer = null;
    testObj.setParentPanel(panel);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();

    rasterSymbolizer = styleFactory.createRasterSymbolizer();

    GroupConfigInterface constrastMethodGroup =
            panel.getGroup(GroupIdEnum.RASTER_RGB_CHANNEL_RED_CONTRAST_METHOD);
    assertNotNull(constrastMethodGroup);
    MultiOptionGroup constrastMethodGroup2 = (MultiOptionGroup) constrastMethodGroup;
    Box box = Box.createVerticalBox();
    constrastMethodGroup2.createUI(panel.getFieldDataManager(), box, panel, panel.getPanelId());
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_LOGARITHMIC);

    ChannelSelection channelSelection =
            createChannelSelection(styleFactory, ContrastMethod.LOGARITHMIC);
    rasterSymbolizer.setChannelSelection(channelSelection);

    testObj.populate(rasterSymbolizer);

    SelectedSymbol.getInstance().setSymbolizer(rasterSymbolizer);
    Controller.getInstance().setPopulating(true);
    panel.populate(SelectedSymbol.getInstance());
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.EXPONENTIAL);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_EXPONENTIAL);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.HISTOGRAM);
    rasterSymbolizer.setChannelSelection(channelSelection);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_HISTOGRAM);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    channelSelection = createChannelSelection(styleFactory, ContrastMethod.NORMALIZE);
    constrastMethodGroup2.setOption(GroupIdEnum.RASTER_OVERALL_CONTRAST_METHOD_NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    // Error
    channelSelection = createChannelSelectionError(styleFactory, ContrastMethod.NORMALIZE);
    rasterSymbolizer.setChannelSelection(channelSelection);
    testObj.populate(rasterSymbolizer);
    testObj.updateSymbol(rasterSymbolizer);

    // Increase code coverage
    testObj.populate((SelectedSymbol) null);
    testObj.populate((TextSymbolizer) null);
    testObj.populate((PolygonSymbolizer) null);
    testObj.updateSymbol((TextSymbolizer) null);
    testObj.updateSymbol((PolygonSymbolizer) null);
    testObj.preLoadSymbol();

    assertTrue(testObj.isDataPresent());

    testObj.dataChanged(FieldIdEnum.DESCRIPTION);
}
 
Example 19
Source File: RasterSymbolizerDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.RasterSymbolizerDetails#RasterSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#isDataPresent()}. Test
 * method for {@link
 * com.sldeditor.ui.detail.RasterSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.RasterSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.RasterSymbolizerDetails#getFieldDataManager()}. Test method for
 * {@link com.sldeditor.ui.detail.RasterSymbolizerDetails#preLoadSymbol()}.
 */
@Test
public void testRasterSymbolizerDetailsColourChannel() {
    RasterSymbolizerDetails panel = new RasterSymbolizerDetails();
    panel.populate(null);

    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedRuleValue = "rule test value";
    rule.setName(expectedRuleValue);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ContrastEnhancement contrastEnhancement =
            (ContrastEnhancement) styleFactory.contrastEnhancement(ff.literal(.5), "ramp");
    SelectedChannelType redChannel =
            styleFactory.createSelectedChannelType("red", contrastEnhancement);
    SelectedChannelType greenChannel =
            styleFactory.createSelectedChannelType("green", contrastEnhancement);
    SelectedChannelType blueChannel =
            styleFactory.createSelectedChannelType("blue", contrastEnhancement);

    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = redChannel;
    channels[1] = greenChannel;
    channels[2] = blueChannel;

    RasterSymbolizer symbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
    symbolizer.setChannelSelection(styleFactory.createChannelSelection(channels));
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    OverlapBehavior overlapBehavior = OverlapBehavior.EARLIEST_ON_TOP;
    symbolizer.setOverlapBehavior(overlapBehavior);
    ShadedRelief shadedRelief = styleFactory.createShadedRelief(ff.literal(0.75));
    symbolizer.setShadedRelief(shadedRelief);
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    SelectedSymbol.getInstance().setSymbolizer(symbolizer);

    panel.populate(SelectedSymbol.getInstance());

    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);

    panel.dataChanged(null);

    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    assertNull(nameField);
    assertTrue(panel.isDataPresent());

    // Reset to default value
    panel.preLoadSymbol();
}
 
Example 20
Source File: FieldConfigMarkerTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigMarker field =
            new FieldConfigMarker(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    assertFalse(field.accept(null));

    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic =
            (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));

    Mark marker = styleBuilder.createMark("triangle");
    assertFalse(field.accept(marker));

    List<ValueComboBoxData> dataList = new ArrayList<ValueComboBoxData>();

    dataList.add(new ValueComboBoxData("star", "Star", this.getClass()));
    dataList.add(new ValueComboBoxData("square", "Square", this.getClass()));
    dataList.add(new ValueComboBoxData("triangle", "Triangle", this.getClass()));

    List<ValueComboBoxDataGroup> groupList = new ArrayList<ValueComboBoxDataGroup>();
    groupList.add(new ValueComboBoxDataGroup(dataList));

    field.populateSymbolList(String.class, groupList);
    field.populateSymbolList(PointFillDetails.class, groupList);
    assertTrue(field.accept(marker));
    field.populateSymbolList(PointFillDetails.class, groupList);
    assertTrue(field.accept(marker));

    // Try some invalid values
    StyleFactory sf = CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    marker = sf.createMark();
    marker.setWellKnownName(ff.property("testproperty"));
    assertFalse(field.accept(marker));

    marker = sf.createMark();
    marker.setWellKnownName(ff.literal(12));
    assertFalse(field.accept(marker));
}