Search in sources :

Example 16 with TextSymbolizer

use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.

the class SLDTreeLeafTextTest method testCreateStroke.

/**
 * Test method for {@link com.sldeditor.common.tree.leaf.SLDTreeLeafText#createStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testCreateStroke() {
    SLDTreeLeafText leaf = new SLDTreeLeafText();
    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    leaf.createStroke(textSymbolizer);
// Does nothing
}
Also used : TextSymbolizer(org.geotools.styling.TextSymbolizer) SLDTreeLeafText(com.sldeditor.common.tree.leaf.SLDTreeLeafText) Test(org.junit.Test)

Example 17 with TextSymbolizer

use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.

the class BatchUpdateFontModelTest method testLoadData.

/**
 * Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel#loadData(java.util.List)}.
 */
@Test
public void testLoadData() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(fts);
    Rule rule = 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(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);
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String sldContents = sldWriter.encodeSLD(null, sld);
    String expectedWorkspace = "workspace";
    String expectedStyle = "layer.sld";
    StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
    SLDData data = new SLDData(styleWrapper, sldContents);
    File testFile = new File("test.sld");
    data.setSLDFile(testFile);
    SLDEditorFile.getInstance().setSldFile(testFile);
    SLDEditorFile.getInstance().setSLDData(data);
    BatchUpdateFontData testObj = new BatchUpdateFontData(sld, data);
    SelectedSymbol.getInstance().setSld(sld);
    testObj.setNamedLayer(expectedNamedLayer);
    testObj.setStyle(expectedStyleLayer);
    testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
    testObj.setRule(rule);
    testObj.setSymbolizer(symbolizer);
    testObj.setFont(font);
    List<BatchUpdateFontData> dataList = new ArrayList<BatchUpdateFontData>();
    dataList.add(testObj);
    BatchUpdateFontModel model = new BatchUpdateFontModel();
    model.loadData(dataList);
    for (int col = 0; col < model.getColumnCount(); col++) {
        assertFalse(model.hasValueBeenUpdated(0, col));
    }
    assertFalse(model.anyChanges());
    assertFalse(model.saveData(null));
    List<Font> actualFontlist = model.getFontEntries(new int[] { 0 });
    assertEquals(1, actualFontlist.size());
    assertEquals(1, model.getRowCount());
    // Update font
    String originalFontname = "New Font";
    String originalFontStyle = "italic";
    String originalFontWeight = "bold";
    int originalFontSize = 16;
    font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    model.applyData(new int[] { 0 }, font);
    assertTrue(model.hasValueBeenUpdated(0, 7));
    assertTrue(model.hasValueBeenUpdated(0, 8));
    assertTrue(model.hasValueBeenUpdated(0, 9));
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertTrue(model.anyChanges());
    assertEquals(originalFontname, model.getValueAt(0, 7));
    assertEquals(originalFontStyle, model.getValueAt(0, 8));
    assertEquals(originalFontWeight, model.getValueAt(0, 9));
    assertEquals(String.valueOf(originalFontSize), model.getValueAt(0, 10));
    model.revertData();
    assertFalse(model.anyChanges());
    int expectedFontSize = 99;
    model.applyData(new int[] { 0 }, expectedFontSize);
    // Font size
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertEquals(expectedWorkspace, model.getValueAt(0, 0));
    assertEquals(expectedStyle, model.getValueAt(0, 1));
    assertEquals(expectedNamedLayer, model.getValueAt(0, 2));
    assertEquals(expectedStyleLayer, model.getValueAt(0, 3));
    assertEquals(expectedFeatureTypeStyleLayer, model.getValueAt(0, 4));
    assertEquals(expectedRule, model.getValueAt(0, 5));
    assertEquals(expectedSymbolizer, model.getValueAt(0, 6));
    assertEquals("abc", model.getValueAt(0, 7));
    assertEquals("normal", model.getValueAt(0, 8));
    assertEquals("normal", model.getValueAt(0, 9));
    assertEquals(String.valueOf(10 + expectedFontSize), model.getValueAt(0, 10));
    assertNull(model.getValueAt(0, 42));
    assertTrue(model.saveData(null));
    SelectedSymbol.destroyInstance();
    SLDEditorFile.destroyInstance();
    model.setColumnRenderer(null);
    JTable table = new JTable();
    table.setModel(model);
    model.setColumnRenderer(table.getColumnModel());
    assertFalse(model.isCellEditable(0, 0));
    assertEquals(Localisation.getString(BatchUpdateFontModel.class, "BatchUpdateFontModel.workspace"), model.getColumnName(0));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) ArrayList(java.util.ArrayList) BatchUpdateFontModel(com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) StyleWrapper(com.sldeditor.common.data.StyleWrapper) JTable(javax.swing.JTable) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Rule(org.geotools.styling.Rule) BatchUpdateFontData(com.sldeditor.tool.batchupdatefont.BatchUpdateFontData) NamedLayer(org.geotools.styling.NamedLayer) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.Test)

Example 18 with TextSymbolizer

use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.

the class SLDUtilsTest method testFindRule.

@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);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Test(org.junit.Test)

Example 19 with TextSymbolizer

use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.

the class SLDUtilsTest method testFindSymbolizer.

@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);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) Test(org.junit.Test)

Example 20 with TextSymbolizer

use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.

the class SLDTreeLeafFactoryTest method testUpdateFill.

/**
 * Test method for
 * {@link com.sldeditor.common.tree.leaf.SLDTreeLeafFactory#updateFill(boolean, org.opengis.style.Symbolizer)}.
 */
@Test
public void testUpdateFill() {
    assertNull(SLDTreeLeafFactory.getInstance().updateFill(true, null));
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    assertEquals(SLDTreeLeafFactory.getInstance().updateFill(false, polygonSymbolizer), styleFactory.getDefaultFill());
    assertTrue(SLDTreeLeafFactory.getInstance().updateFill(true, polygonSymbolizer) != null);
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    assertEquals(SLDTreeLeafFactory.getInstance().updateFill(false, pointSymbolizer), styleFactory.getDefaultFill());
    assertTrue(SLDTreeLeafFactory.getInstance().updateFill(true, pointSymbolizer) != null);
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    assertEquals(SLDTreeLeafFactory.getInstance().updateFill(false, lineSymbolizer), styleFactory.getDefaultFill());
    assertEquals(SLDTreeLeafFactory.getInstance().updateFill(true, lineSymbolizer), styleFactory.getDefaultFill());
    TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    assertEquals(SLDTreeLeafFactory.getInstance().updateFill(false, textSymbolizer), styleFactory.getDefaultFill());
    assertEquals(SLDTreeLeafFactory.getInstance().updateFill(true, textSymbolizer), styleFactory.getDefaultFill());
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Test(org.junit.Test)

Aggregations

TextSymbolizer (org.geotools.styling.TextSymbolizer)33 Test (org.junit.Test)19 Font (org.geotools.styling.Font)9 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 Rule (org.geotools.styling.Rule)9 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)8 LineSymbolizer (org.geotools.styling.LineSymbolizer)8 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)8 Style (org.geotools.styling.Style)8 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 NamedLayer (org.geotools.styling.NamedLayer)5 SLDTreeLeafText (com.sldeditor.common.tree.leaf.SLDTreeLeafText)4 SLDData (com.sldeditor.common.data.SLDData)3 StyleWrapper (com.sldeditor.common.data.StyleWrapper)3 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)3 VendorOptionPresent (com.sldeditor.common.vendoroption.minversion.VendorOptionPresent)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 BatchUpdateFontData (com.sldeditor.tool.batchupdatefont.BatchUpdateFontData)3 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)3 Symbolizer (org.geotools.styling.Symbolizer)3