use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testAddNewThingUserLayer.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewThing()}.
*/
@Test
public void testAddNewThingUserLayer() {
SLDTreeTools treeTools = new SLDTreeTools();
TestSLDTree sldTree = new TestSLDTree(null, treeTools);
treeTools.addNewThing(null);
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();
DefaultMutableTreeNode rootNode = sldTree.getRootNode();
// Check it has no structure below just the root node
assertEquals(0, rootNode.getChildCount());
// Add a thing - a quick way of creating sld structure
// This should add a user layer and select it
treeTools.addNewThing(UserLayer.class);
assertEquals(1, rootNode.getChildCount());
DefaultMutableTreeNode userLayer = (DefaultMutableTreeNode) rootNode.getChildAt(0);
assertEquals(UserLayerImpl.class, userLayer.getUserObject().getClass());
// This should add a style and select it
assertEquals(0, userLayer.getChildCount());
treeTools.addNewThing(null);
assertEquals(1, userLayer.getChildCount());
DefaultMutableTreeNode styleLayer = (DefaultMutableTreeNode) userLayer.getChildAt(0);
assertEquals(StyleImpl.class, styleLayer.getUserObject().getClass());
// This should add a feature type style and select it
assertEquals(0, styleLayer.getChildCount());
treeTools.addNewThing(null);
assertEquals(1, styleLayer.getChildCount());
DefaultMutableTreeNode featureTypeStyle = (DefaultMutableTreeNode) styleLayer.getChildAt(0);
assertEquals(FeatureTypeStyleImpl.class, featureTypeStyle.getUserObject().getClass());
// This should add a rule and select it
assertEquals(0, featureTypeStyle.getChildCount());
treeTools.addNewThing(null);
assertEquals(1, featureTypeStyle.getChildCount());
DefaultMutableTreeNode rule = (DefaultMutableTreeNode) featureTypeStyle.getChildAt(0);
assertEquals(RuleImpl.class, rule.getUserObject().getClass());
// This should do nothing
assertEquals(0, rule.getChildCount());
treeTools.addNewThing(null);
assertEquals(0, rule.getChildCount());
// Undo last add of rule to feature type style
UndoManager.getInstance().undo();
DefaultMutableTreeNode featureTypeStyleNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
assertEquals(FeatureTypeStyleImpl.class, featureTypeStyleNode.getUserObject().getClass());
assertEquals(0, featureTypeStyleNode.getChildCount());
// Undo last add of rule to feature type style
UndoManager.getInstance().redo();
featureTypeStyleNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
assertEquals(FeatureTypeStyleImpl.class, featureTypeStyleNode.getUserObject().getClass());
assertEquals(1, featureTypeStyleNode.getChildCount());
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testAddArrows.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addSourceArrow()}. Test method for
* {@link com.sldeditor.ui.tree.SLDTreeTools#addDestArrow()}.
*/
@Test
public void testAddArrows() {
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.addNewLine();
treeTools.addSourceArrow();
treeTools.addDestArrow();
DefaultMutableTreeNode lineNode = (DefaultMutableTreeNode) rule.getChildAt(0);
assertEquals(LineSymbolizerImpl.class, lineNode.getUserObject().getClass());
DefaultMutableTreeNode srcArrowNode = (DefaultMutableTreeNode) rule.getChildAt(1);
assertEquals(PointSymbolizerImpl.class, srcArrowNode.getUserObject().getClass());
DefaultMutableTreeNode destArrowNode = (DefaultMutableTreeNode) rule.getChildAt(2);
assertEquals(PointSymbolizerImpl.class, destArrowNode.getUserObject().getClass());
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class SLDTreeToolsTest method testAddNewText.
/**
* 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());
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class CreateInternalDataSourceTest method testDetermineGeometryType.
/**
* Test method for
* {@link com.sldeditor.datasource.impl.CreateInternalDataSource#determineGeometryType(StyledLayerDescriptor)}.
*/
@Test
public void testDetermineGeometryType() {
TestCreateInternalDataSource ds = new TestCreateInternalDataSource();
assertEquals(GeometryTypeEnum.UNKNOWN, ds.callDetermineGeometryType(null));
// Create StyledLayerDescriptor
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
UserLayer userLayer = styleFactory.createUserLayer();
sld.addStyledLayer(userLayer);
Style style = styleFactory.createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
ftsList.add(fts);
Rule rule = styleFactory.createRule();
fts.rules().add(rule);
// Raster
RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
rule.symbolizers().add(raster);
assertEquals(GeometryTypeEnum.RASTER, ds.callDetermineGeometryType(sld));
// Polygon
rule.symbolizers().clear();
PolygonSymbolizer polygon = DefaultSymbols.createDefaultPolygonSymbolizer();
rule.symbolizers().add(polygon);
assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
// Line
rule.symbolizers().clear();
LineSymbolizer line = DefaultSymbols.createDefaultLineSymbolizer();
rule.symbolizers().add(line);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Point
rule.symbolizers().clear();
PointSymbolizer point = DefaultSymbols.createDefaultPointSymbolizer();
rule.symbolizers().add(point);
assertEquals(GeometryTypeEnum.POINT, ds.callDetermineGeometryType(sld));
// Add line to point
rule.symbolizers().add(line);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Add point, line
rule.symbolizers().clear();
rule.symbolizers().add(line);
rule.symbolizers().add(point);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Add polygon, line
rule.symbolizers().clear();
rule.symbolizers().add(point);
rule.symbolizers().add(polygon);
assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
}
use of org.geotools.styling.StyleFactoryImpl in project sldeditor by robward-scisys.
the class RasterSymbolizerDetailsTest method testRasterSymbolizerDetailsGreyChannel.
/**
* 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 testRasterSymbolizerDetailsGreyChannel() {
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);
RasterSymbolizer symbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(ff.literal(.5), "ramp");
SelectedChannelType greyChannel = styleFactory.createSelectedChannelType("grey", contrastEnhancement);
symbolizer.setChannelSelection(styleFactory.channelSelection(greyChannel));
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();
}
Aggregations