use of org.geotools.styling.StyleFactoryImpl 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);
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class SelectedSymbolTest method testGetSymbolList.
/**
* Test method for
* {@link com.sldeditor.common.data.SelectedSymbol#getSymbolList(org.opengis.style.GraphicalSymbol)}.
*/
@Test
public void testGetSymbolList() {
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Stroke stroke = null;
Fill fill = styleFactory.createFill(ff.literal(DefaultSymbols.defaultColour()));
GraphicalSymbol symbolToAdd = styleFactory.mark(ff.literal("circle"), fill, stroke);
List<GraphicalSymbol> symbolList = SelectedSymbol.getInstance().getSymbolList(symbolToAdd);
assertEquals(1, symbolList.size());
assertEquals(symbolToAdd, symbolList.get(0));
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class ExternalGraphicDetailsTest method testSetValueExternalGraphicImpl.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.ExternalGraphicDetails#setValue(org.geotools.styling.ExternalGraphicImpl)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.ExternalGraphicDetails#getSymbol()}.
*/
@Test
public void testSetValueExternalGraphicImpl() {
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
ExternalGraphicImpl externalGraphic = null;
DummyExternalGraphicUpdate callback = new DummyExternalGraphicUpdate();
ExternalGraphicDetails panel = new ExternalGraphicDetails(callback);
assertNull(panel.getSymbol());
panel.setValue(externalGraphic);
String expectedString = "a/b/c/test.png";
URL expectedURL = null;
try {
expectedURL = new File(expectedString).toURI().toURL();
externalGraphic = (ExternalGraphicImpl) styleFactory.createExternalGraphic(expectedURL, "image/png");
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
assertFalse(callback.isCalled());
panel.setValue(externalGraphic);
ExternalGraphicImpl actual = (ExternalGraphicImpl) panel.getSymbol();
try {
assertEquals(expectedURL.toExternalForm(), actual.getLocation().toExternalForm());
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
assertTrue(callback.isCalled());
expectedString = "http://example.com/test.png";
externalGraphic = (ExternalGraphicImpl) styleFactory.createExternalGraphic(expectedString, "image/png");
assertFalse(callback.isCalled());
panel.setValue(externalGraphic);
actual = (ExternalGraphicImpl) panel.getSymbol();
assertTrue(callback.isCalled());
try {
assertEquals(externalGraphic.getLocation().toExternalForm(), actual.getLocation().toExternalForm());
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class VOGeoServerContrastEnhancementNormalizeBlueTest method testVOGeoServerContrastEnhancementNormalizeBlue.
/**
* Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeBlue#VOGeoServerContrastEnhancementNormalizeBlue(java.lang.Class, com.sldeditor.ui.detail.RasterSymbolizerDetails)}.
* Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.raster.VOGeoServerContrastEnhancementNormalizeBlue#getContrastEnhancement(com.sldeditor.common.xml.ui.GroupIdEnum, org.geotools.styling.ChannelSelection)}.
*/
@Test
public void testVOGeoServerContrastEnhancementNormalizeBlue() {
RasterSymbolizerDetails panel = new RasterSymbolizerDetails();
VOGeoServerContrastEnhancementNormalizeBlue testObj = new VOGeoServerContrastEnhancementNormalizeBlue(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_BLUE_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);
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class FieldConfigFeatureTypeConstraintTest method testUndoAction.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#undoAction(com.sldeditor.common.undo.UndoInterface)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#redoAction(com.sldeditor.common.undo.UndoInterface)}.
*/
@Test
public void testUndoAction() {
FieldConfigFeatureTypeConstraint field = new FieldConfigFeatureTypeConstraint(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", true));
field.undoAction(null);
field.redoAction(null);
field.createUI();
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FeatureTypeConstraint expectedValue1 = styleFactory.createFeatureTypeConstraint("Feature", Filter.INCLUDE, new Extent[0]);
List<FeatureTypeConstraint> testValue = new ArrayList<FeatureTypeConstraint>();
testValue.add(expectedValue1);
field.populateField(testValue);
assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));
FeatureTypeConstraint expectedValue2 = styleFactory.createFeatureTypeConstraint("Feature2", Filter.INCLUDE, new Extent[0]);
List<FeatureTypeConstraint> testValue2 = new ArrayList<FeatureTypeConstraint>();
testValue2.add(expectedValue1);
testValue2.add(expectedValue2);
field.populateField(testValue2);
UndoManager.getInstance().undo();
assertEquals(1, field.getFeatureTypeConstraint().size());
assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));
UndoManager.getInstance().redo();
assertEquals(2, field.getFeatureTypeConstraint().size());
assertEquals(expectedValue2, field.getFeatureTypeConstraint().get(1));
// Increase the code coverage
field.undoAction(null);
field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
field.redoAction(null);
field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
Aggregations