Java Code Examples for org.geotools.styling.Rule#setName()

The following examples show how to use org.geotools.styling.Rule#setName() . 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: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a default {@link Rule} for a point.
 * 
 * @return the default rule.
 */
public static Rule createDefaultPointRule() {
    Graphic graphic = sf.createDefaultGraphic();
    Mark circleMark = sf.getCircleMark();
    circleMark.setFill(sf.createFill(ff.literal("#" + Integer.toHexString(Color.RED.getRGB() & 0xffffff))));
    circleMark.setStroke(sf.createStroke(ff.literal("#" + Integer.toHexString(Color.BLACK.getRGB() & 0xffffff)),
            ff.literal(DEFAULT_WIDTH)));
    graphic.graphicalSymbols().clear();
    graphic.graphicalSymbols().add(circleMark);
    graphic.setSize(ff.literal(DEFAULT_SIZE));

    PointSymbolizer pointSymbolizer = sf.createPointSymbolizer();
    Rule rule = sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(pointSymbolizer);

    pointSymbolizer.setGraphic(graphic);
    return rule;
}
 
Example 2
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Rule makeFillRule(final SimpleFeature feature) {
    final Rule rule = makeFillRule();
    rule.setName((String) feature.getAttribute(ATTRIBUTE));

    // create a filter based on name
    final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
    rule.setFilter(ff.equals(ff.property(ATTRIBUTE), ff.literal(feature.getAttribute(ATTRIBUTE))));

    return rule;
}
 
Example 3
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 4
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a default {@link Rule} for a line.
 * 
 * @return the default rule.
 */
public static Rule createDefaultLineRule() {
    LineSymbolizer lineSymbolizer = sf.createLineSymbolizer();
    lineSymbolizer.setStroke(createDefaultStroke());

    Rule rule = sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(lineSymbolizer);

    return rule;
}
 
Example 5
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a default {@link Rule} for a polygon.
 * 
 * @return the default rule.
 */
public static Rule createDefaultPolygonRule() {
    PolygonSymbolizer polygonSymbolizer = sf.createPolygonSymbolizer();
    Fill fill = createDefaultFill();
    polygonSymbolizer.setFill(fill);
    polygonSymbolizer.setStroke(createDefaultStroke());

    Rule rule = sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(polygonSymbolizer);

    return rule;
}
 
Example 6
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Rule createRule(Filter filter, FeatureStyleInfo featureStyle) throws LayerException {
	Rule rule = styleBuilder.createRule(createGeometrySymbolizer(featureStyle));
	if (filter.equals(Filter.INCLUDE)) {
		rule.setElseFilter(true);
	} else {
		rule.setFilter(filter);
	}
	rule.setName(featureStyle.getName());
	rule.setTitle(featureStyle.getName());
	return rule;
}
 
Example 7
Source File: RuleTreeItemTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.tree.item.RuleTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    RuleTreeItem item = new RuleTreeItem();
    String actualValue = item.getTreeString(null, null);
    String expectedValue =
            String.format(
                    "%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.rule"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    Rule rule = DefaultSymbols.createNewRule();

    actualValue = item.getTreeString(null, rule);
    expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.rule"),
                    Localisation.getString(SLDTreeTools.class, "TreeItem.newRule"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    rule.setName(null);
    actualValue = item.getTreeString(null, rule);
    expectedValue =
            String.format(
                    "%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.rule"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);

    String expectedName = "test name";
    rule.setName(expectedName);
    actualValue = item.getTreeString(null, rule);
    expectedValue =
            String.format(
                    "%s : %s",
                    Localisation.getString(SLDTreeTools.class, "TreeItem.rule"), expectedName);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
 
Example 8
Source File: LineSymbolizerDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.LineSymbolizerDetails#LineSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.LineSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.LineSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#isDataPresent()}. Test
 * method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#preLoadSymbol()}.
 */
@Test
public void testLineSymbolizerDetails() {
    LineSymbolizerDetails panel = new LineSymbolizerDetails();
    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);

    LineSymbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    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 9
Source File: StrokeDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testStrokeDetailsPolygon() {
    StrokeDetails panel = new StrokeDetails();
    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 expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);

    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();

    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);

    FieldConfigSymbolType symbolTypeField =
            (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
    symbolTypeField.populateField("circle");

    double expectedAngle = 14.5;
    FieldConfigDouble angleField =
            (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
    angleField.populateField(expectedAngle);

    FieldConfigSlider opacityField =
            (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
    double opacity = 0.15;
    opacityField.populateField(opacity);

    FieldConfigString dashField =
            (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
    String dashArray = "1 2";
    dashField.populateField(dashArray);

    panel.dataChanged(null);

    double actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
    assertTrue(panel.isDataPresent());

    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - opacity) < 0.01);

    // Reset to default value
    panel.preLoadSymbol();
    actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.01);
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
 
Example 10
Source File: StrokeDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testStrokeDetailsCircle() {
    StrokeDetails panel = new StrokeDetails();
    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 expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);

    PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    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);

    FieldConfigSymbolType symbolTypeField =
            (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
    symbolTypeField.populateField("circle");

    double expectedAngle = 14.5;
    FieldConfigDouble angleField =
            (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
    angleField.populateField(expectedAngle);

    FieldConfigSlider opacityField =
            (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
    double opacity = 0.15;
    opacityField.populateField(opacity);

    FieldConfigString dashField =
            (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
    String dashArray = "1 2";
    dashField.populateField(dashArray);

    panel.dataChanged(null);

    double actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
    assertFalse(panel.isDataPresent());

    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - opacity) < 0.01);

    // Reset to default value
    panel.preLoadSymbol();
    actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.01);
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
 
Example 11
Source File: FeatureTypeStyleDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.FeatureTypeStyleDetails#FeatureTypeStyleDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.FeatureTypeStyleDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.FeatureTypeStyleDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.FeatureTypeStyleDetails#getFieldDataManager()}. Test method for
 * {@link com.sldeditor.ui.detail.FeatureTypeStyleDetails#isDataPresent()}. Test method for
 * {@link com.sldeditor.ui.detail.FeatureTypeStyleDetails#preLoadSymbol()}.
 */
@Test
public void testFeatureTypeStyleDetails() {
    FeatureTypeStyleDetails panel = new FeatureTypeStyleDetails();
    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 expectedNameValue = "feature type style test value";
    fts.setName(expectedNameValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedRuleNameValue = "rule test value";
    rule.setName(expectedRuleNameValue);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);

    panel.populate(SelectedSymbol.getInstance());
    panel.dataChanged(null);
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);

    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    String actualValue = nameField.getStringValue();
    assertTrue(expectedNameValue.compareTo(actualValue) == 0);
    assertTrue(panel.isDataPresent());

    // Reset to default value
    panel.preLoadSymbol();
    actualValue = nameField.getStringValue();
    assertTrue("".compareTo(actualValue) == 0);
}
 
Example 12
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 13
Source File: PolygonFillDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.PolygonFillDetailsTest#PolygonFillDetailsTest(java.lang.Class,
 * com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testFillDetailsPolygon() {
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    PolygonFillDetails panel = new PolygonFillDetails();
    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 expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);

    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();

    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);

    double expectedAngle = 14.5;
    FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.ANGLE);
    angleField.populateField(expectedAngle);

    FieldConfigSlider opacityField =
            (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
    double opacity = 0.15;
    opacityField.populateField(opacity);

    panel.dataChanged(FieldIdEnum.UNKNOWN);

    double actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
    assertTrue(panel.isDataPresent());

    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - opacity) < 0.01);

    // Reset to default value
    panel.preLoadSymbol();
    actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.01);
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 1.0) < 0.01);

    // Increase the coverage, set the fill
    Fill fill = styleFactory.createFill(ff.literal("#123456"));
    Graphic graphic = styleFactory.createDefaultGraphic();
    fill.setGraphicFill(graphic);
    symbolizer.setFill(fill);
    panel.populate(SelectedSymbol.getInstance());

    Graphic graphic2 = styleFactory.createDefaultGraphic();
    graphic2.setDisplacement(styleFactory.createDisplacement(ff.literal(6.0), ff.literal(7.0)));
    graphic2.setAnchorPoint(styleFactory.anchorPoint(ff.literal(6.0), ff.literal(7.0)));
    Fill fill2 = styleFactory.createFill(ff.literal("#123456"));
    fill2.setGraphicFill(graphic2);
    symbolizer.setFill(fill2);
    panel.populate(SelectedSymbol.getInstance());

    symbolizer.setFill(null);
    panel.populate(SelectedSymbol.getInstance());
}
 
Example 14
Source File: PointSymbolizerDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.PointSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.PointSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#isDataPresent()}. Test
 * method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#preLoadSymbol()}. Test
 * method for {@link
 * com.sldeditor.ui.detail.PointSymbolizerDetails#PointSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testPointSymbolizerDetails() {
    SelectedSymbol.destroyInstance();
    PointSymbolizerDetails panel = new PointSymbolizerDetails();
    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);

    PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    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 descriptionField =
            (FieldConfigString) fieldDataManager.get(FieldIdEnum.DESCRIPTION);
    assertNull(descriptionField);
    assertTrue(panel.isDataPresent());

    // Reset to default value
    panel.preLoadSymbol();
}
 
Example 15
Source File: TextSymbolizerDetailsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.TextSymbolizerDetails#TextSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.TextSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.TextSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#isDataPresent()}. Test
 * method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#preLoadSymbol()}.
 */
@Test
public void testTextSymbolizerDetails() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();
    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);

    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    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 16
Source File: BatchUpdateFontUtilsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.tool.batchupdatefont.BatchUpdateFontUtils#containsFonts(com.sldeditor.common.SLDDataInterface)}.
 */
@Test
public void testContainsFonts() {

    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);

    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    rule.symbolizers().add(DefaultSymbols.createDefaultPointSymbolizer());
    fts.rules().add(rule);
    sld.layers().add(namedLayer);

    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String sldContents = sldWriter.encodeSLD(null, sld);

    SLDData sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);

    // Empty sld
    List<BatchUpdateFontData> actualList = BatchUpdateFontUtils.containsFonts(null);
    assertNull(actualList);

    // No fonts
    actualList = BatchUpdateFontUtils.containsFonts(sldData);
    assertNull(actualList);

    // With textsymbolizer
    rule.symbolizers().add(symbolizer);
    sldContents = sldWriter.encodeSLD(null, sld);
    sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), sldContents);
    actualList = BatchUpdateFontUtils.containsFonts(sldData);
    assertEquals(1, actualList.size());
    assertEquals(rule.getName(), actualList.get(0).getRuleName());

    // Bump up the code coverage
    sldData = new SLDData(new StyleWrapper("workspace", "layer.sld"), "empty");
    actualList = BatchUpdateFontUtils.containsFonts(sldData);
    assertNull(actualList);
}
 
Example 17
Source File: DefaultSymbols.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the new rule.
 *
 * @return the rule
 */
public static Rule createNewRule() {
    Rule rule = styleFactory.createRule();
    rule.setName(Localisation.getString(SLDTreeTools.class, "TreeItem.newRule"));
    return rule;
}
 
Example 18
Source File: LabelEngineLayerProperties.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void convert(List<Rule> labelRuleList, Rule rule, JsonElement json, int transparency)
{       
    if((json != null) && (rule != null) && (labelRuleList != null))
    {
        JsonObject jsonObj = json.getAsJsonObject();

        TextSymbolizer textSymbolizer = styleFactory.createTextSymbolizer();

        textSymbolizer.setUnitOfMeasure(NonSI.PIXEL);

        textSymbolizer.setLabel(extractExpression(jsonObj));
        JsonElement jsonElement = jsonObj.get(LabelEngineLayerPropertiesKey.SYMBOL);
        SymbolManager.getInstance().convertTextSymbols(textSymbolizer, transparency, jsonElement);

        // Yes, this really is round the wrong way
        double maxScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MINIMUM_SCALE);
        double minScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MAXIMUM_SCALE);
        
        if((minScale > 0.0) || (maxScale > 0.0))
        {
            Rule labelRule = styleFactory.createRule();

            labelRule.setName(extractString(jsonObj, LabelEngineLayerPropertiesKey.CLASS));
            if(minScale > 0.0)
            {
                labelRule.setMinScaleDenominator(minScale);
            }

            if(maxScale > 0.0)
            {
                labelRule.setMaxScaleDenominator(maxScale);
            }
            labelRule.symbolizers().add(textSymbolizer);
            
            labelRuleList.add(labelRule);
        }
        else
        {
            rule.symbolizers().add(textSymbolizer);
        }
    }
}
 
Example 19
Source File: UniqueValueRenderer.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    boolean useDefaultSymbol = false;
    JsonElement useDefaultSymbolElement = json.get(UniqueValueRendererKeys.USE_DEFAULTSYMBOL);
    if(useDefaultSymbolElement != null)
    {
        useDefaultSymbol = useDefaultSymbolElement.getAsBoolean();
    }

    JsonElement jsonElement = json.get(CommonRendererKeys.LABEL);
    if(jsonElement != null)
    {
        namedLayer.setName(jsonElement.getAsString());
    }
    sld.addStyledLayer(namedLayer);

    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);

    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();

    // style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());

    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

    ftsList.add(fts);

    JsonElement element = json.get(UniqueValueRendererKeys.VALUES);
    if(element != null)
    {
        JsonArray valueList = element.getAsJsonArray();

        for(int index = 0; index < valueList.size(); index ++)
        {
            JsonElement valueElement = valueList.get(index);
            if(valueElement != null)
            {
                Rule rule = styleFactory.createRule();
                JsonObject valueObj = valueElement.getAsJsonObject();

                String value = getString(valueObj, UniqueValueRendererKeys.VALUES_VALUE);

                String label = getString(valueObj, UniqueValueRendererKeys.VALUES_LABEL);
                rule.setName(label);

                createFilter(rule, json.get(UniqueValueRendererKeys.FIELDS), json.get(UniqueValueRendererKeys.FIELD_DELIMETER), value);

                // Heading /description
                String heading = getString(valueObj, UniqueValueRendererKeys.VALUES_HEADING);
                @SuppressWarnings("unused")
                String description = getString(valueObj, UniqueValueRendererKeys.VALUES_DESCRIPTION);

                if((heading != null) && !heading.isEmpty() || (label != null) && !label.isEmpty())
                {
                    if(label == null)
                    {
                        label = "";
                    }
                    InternationalString titleString = Text.text(label);
                    
                    if(heading == null)
                    {
                        heading = "";
                    }

                    InternationalString descriptionString = Text.text(heading);

                    Description descriptionObj = styleFactory.description(titleString, descriptionString);

                    rule.setDescription(descriptionObj);
                }

                if(minScale > 0.0)
                {
                    rule.setMinScaleDenominator(minScale);
                }

                if(maxScale > 0.0)
                {
                    rule.setMaxScaleDenominator(maxScale);
                }

                JsonElement jsonSymbolElement = valueObj.get(UniqueValueRendererKeys.VALUES_SYMBOL);
                SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonSymbolElement);

                if(useDefaultSymbol && value == null)
                {
                    rule.setIsElseFilter(true);
                }
                fts.rules().add(rule);
            }
        }
    }
    return sld;
}
 
Example 20
Source File: SimpleRenderer.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    String label = json.get(CommonRendererKeys.LABEL).getAsString();
    namedLayer.setName(label);
    sld.addStyledLayer(namedLayer);

    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);

    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();

    // style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());

    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

    ftsList.add(fts);

    Rule rule = styleFactory.createRule();

    if(minScale > 0.0)
    {
        rule.setMinScaleDenominator(minScale);
    }

    if(maxScale > 0.0)
    {
        rule.setMaxScaleDenominator(maxScale);
    }

    JsonElement jsonElement = json.get(CommonRendererKeys.SYMBOL);
    rule.setName(label);
    SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonElement);

    fts.rules().add(rule);

    return sld;
}