use of org.geotools.styling.NamedLayerImpl in project sldeditor by robward-scisys.
the class SLDTreeTools method setButtonState.
/**
* Sets the buttons state.
*
* @param parentNode the parent node
* @param selectedNode the new button state
* @param currentGeometryType the current geometry type
*/
public void setButtonState(DefaultMutableTreeNode parentNode, DefaultMutableTreeNode selectedNode, GeometryTypeEnum currentGeometryType) {
boolean addButtonEnabled = true;
boolean removeButtonEnabled = true;
boolean addNamedLayerButtonEnabled = false;
boolean addUserLayerButtonEnabled = false;
boolean showMoveButtons = true;
boolean hasMoreThan1Item = false;
boolean isFirstSelected = false;
boolean isLastSelected = false;
boolean showLineArrowButtons = false;
symbolizerButtonState.setGeometryType(currentGeometryType);
Object obj = null;
Object parentObj = null;
if (selectedNode != null) {
obj = selectedNode.getUserObject();
if (parentNode != null) {
parentObj = parentNode.getUserObject();
}
if (obj instanceof StyledLayerDescriptor) {
addNamedLayerButtonEnabled = true;
addUserLayerButtonEnabled = true;
addButtonEnabled = false;
} else if (obj instanceof StyledLayer) {
if (parentObj != null) {
StyledLayerDescriptor sld = (StyledLayerDescriptor) parentObj;
hasMoreThan1Item = sld.layers().size() > 1;
isFirstSelected = (obj == sld.layers().get(0));
isLastSelected = (obj == sld.layers().get(sld.layers().size() - 1));
}
} else if (obj instanceof Style) {
if (parentObj != null) {
if (parentObj instanceof NamedLayerImpl) {
NamedLayerImpl namedLayer = (NamedLayerImpl) parentObj;
hasMoreThan1Item = namedLayer.styles().size() > 1;
isFirstSelected = (obj == namedLayer.styles().get(0));
isLastSelected = (obj == namedLayer.styles().get(namedLayer.styles().size() - 1));
}
}
} else if (obj instanceof FeatureTypeStyle) {
if (parentObj != null) {
Style style = (Style) parentObj;
hasMoreThan1Item = style.featureTypeStyles().size() > 1;
isFirstSelected = (obj == style.featureTypeStyles().get(0));
isLastSelected = (obj == style.featureTypeStyles().get(style.featureTypeStyles().size() - 1));
}
} else if (obj instanceof Rule) {
symbolizerButtonState.showSymbolizerButtons();
addButtonEnabled = false;
if (parentObj != null) {
FeatureTypeStyle fts = (FeatureTypeStyle) parentObj;
hasMoreThan1Item = fts.rules().size() > 1;
isFirstSelected = (obj == fts.rules().get(0));
isLastSelected = (obj == fts.rules().get(fts.rules().size() - 1));
}
} else if (obj instanceof Symbolizer) {
symbolizerButtonState.showSymbolizerButtons();
addButtonEnabled = false;
if (parentObj != null) {
if (parentObj instanceof Rule) {
Rule rule = (Rule) parentObj;
hasMoreThan1Item = rule.symbolizers().size() > 1;
isFirstSelected = (obj == rule.symbolizers().get(0));
isLastSelected = (obj == rule.symbolizers().get(rule.symbolizers().size() - 1));
}
}
showLineArrowButtons = (obj instanceof LineSymbolizer);
} else {
addButtonEnabled = false;
removeButtonEnabled = false;
showMoveButtons = false;
}
}
btnAddNamedLayerButton.setVisible(addNamedLayerButtonEnabled);
btnAddUserLayerButton.setVisible(addUserLayerButtonEnabled);
btnAddButton.setVisible(addButtonEnabled);
// All symbolizer types are allowed be added to an SLD
boolean allSymbolizer = symbolizerButtonState.isMarkerVisible(parentObj, obj) || symbolizerButtonState.isLineVisible(parentObj, obj) || symbolizerButtonState.isPolygonVisible(parentObj, obj) || symbolizerButtonState.isRasterVisible(parentObj, obj);
btnNewMarker.setVisible(allSymbolizer);
btnNewLine.setVisible(allSymbolizer);
btnNewImageOutlineLine.setVisible(symbolizerButtonState.isImageOutlineLineVisible(parentObj, obj));
btnNewPolygon.setVisible(allSymbolizer);
btnNewImageOutlinePolygon.setVisible(symbolizerButtonState.isImageOutlinePolygonVisible(parentObj, obj));
btnNewRaster.setVisible(allSymbolizer);
btnNewText.setVisible(symbolizerButtonState.isTextVisible(parentObj, obj));
btnRemoveMarker.setVisible(removeButtonEnabled);
// Up / down buttons
btnMoveUp.setVisible(showMoveButtons);
btnMoveUp.setEnabled(hasMoreThan1Item && !isFirstSelected);
btnMoveDown.setVisible(showMoveButtons);
btnMoveDown.setEnabled(hasMoreThan1Item && !isLastSelected);
btnSourceArrowButton.setVisible(showLineArrowButtons);
btnDestArrowButton.setVisible(showLineArrowButtons);
}
use of org.geotools.styling.NamedLayerImpl in project sldeditor by robward-scisys.
the class NameLayerTreeItem method getTreeString.
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.tree.item.SLDTreeItemInterface#getTreeString(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)
*/
@Override
public String getTreeString(DefaultMutableTreeNode node, Object nodeObject) {
NamedLayerImpl namedLayer = (NamedLayerImpl) nodeObject;
String name = "";
if (namedLayer != null) {
if (namedLayer.getName() != null) {
name = namedLayer.getName();
}
}
return String.format("%s : %s", TITLE, name);
}
use of org.geotools.styling.NamedLayerImpl in project sldeditor by robward-scisys.
the class SLDTree method populateSLD.
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.tree.UpdateTreeStructureInterface#populateSLD()
*/
@Override
public void populateSLD() {
reset();
SelectedSymbol selectedSymbol = SelectedSymbol.getInstance();
if (selectedSymbol != null) {
StyledLayerDescriptor sld = selectedSymbol.getSld();
rootNode.setUserObject(sld);
treeModel.nodeChanged(rootNode);
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
if (styledLayerList != null) {
for (StyledLayer styledLayer : styledLayerList) {
DefaultMutableTreeNode styledLayerTreeNode = null;
List<Style> styleList = null;
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
styleList = namedLayerImpl.styles();
styledLayerTreeNode = addObject(rootNode, namedLayerImpl, true);
} else if (styledLayer instanceof UserLayerImpl) {
UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
styleList = userLayerImpl.userStyles();
styledLayerTreeNode = addObject(rootNode, userLayerImpl, true);
}
if (styleList != null) {
for (Style style : styleList) {
DefaultMutableTreeNode styleTreeNode = addObject(styledLayerTreeNode, style, true);
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
DefaultMutableTreeNode ftsTreeNode = addObject(styleTreeNode, fts, true);
for (Rule rule : fts.rules()) {
DefaultMutableTreeNode ruleTreeNode = addObject(ftsTreeNode, rule, true);
for (Symbolizer symbolizer : rule.symbolizers()) {
DefaultMutableTreeNode symbolizerTreeNode = addObject(ruleTreeNode, symbolizer, true);
if ((symbolizer instanceof PointSymbolizer) || (symbolizer instanceof PolygonSymbolizer)) {
addObject(symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getFill(symbolizer), true);
}
if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof LineSymbolizer)) {
addObject(symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getStroke(symbolizer), true);
}
if (symbolizer instanceof RasterSymbolizer) {
handleRasterSymbolizer(symbolizer, symbolizerTreeNode);
}
}
}
}
}
}
}
}
}
}
}
use of org.geotools.styling.NamedLayerImpl in project sldeditor by robward-scisys.
the class RenderSymbolTest method testRenderSymbol.
/**
* Test method for {@link com.sldeditor.render.RenderSymbol#RenderSymbol()}.
*/
@Test
public void testRenderSymbol() {
RenderSymbol symbol = new RenderSymbol();
StyledLayerDescriptor sld = createSLD();
StyledLayer styledLayer = sld.layers().get(0);
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
Style expectedStyle = namedLayerImpl.styles().get(0);
SelectedSymbol.getInstance().setSld(sld);
Style actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());
assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
assertEquals(expectedStyle.getName(), actualStyle.getName());
Rule expectedRule = expectedStyle.featureTypeStyles().get(0).rules().get(1);
SelectedSymbol.getInstance().setFeatureTypeStyle(expectedStyle.featureTypeStyles().get(0));
SelectedSymbol.getInstance().setRule(expectedRule);
actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());
assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
assertEquals(expectedRule.getName(), actualStyle.featureTypeStyles().get(0).rules().get(0).getName());
}
}
use of org.geotools.styling.NamedLayerImpl in project sldeditor by robward-scisys.
the class RuleRenderVisitorTest method testRuleRenderVisitor.
/**
* Test rule render visitor.
*/
@Test
public void testRuleRenderVisitor() {
StyledLayerDescriptor sld = createSLD();
StyledLayer styledLayer = sld.layers().get(0);
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
Style style = namedLayerImpl.styles().get(0);
FeatureTypeStyle ftsToRender = style.featureTypeStyles().get(0);
// Just find matching feature type style
int symbolIndex = 0;
RuleRenderVisitor visitor = new RuleRenderVisitor(ftsToRender, null, symbolIndex, new RuleRenderOptions());
style.accept(visitor);
Style copy = (Style) visitor.getCopy();
Rule ruleToRender = ftsToRender.rules().get(0);
Rule actualRule = copy.featureTypeStyles().get(0).rules().get(0);
// Filters should be null
assertNull(actualRule.getFilter());
assertEquals(ruleToRender.symbolizers(), actualRule.symbolizers());
// Now try and find 2nd rule, 2nd symbolizer
ruleToRender = ftsToRender.rules().get(1);
symbolIndex = 1;
visitor = new RuleRenderVisitor(ftsToRender, ruleToRender, symbolIndex, new RuleRenderOptions());
style.accept(visitor);
copy = (Style) visitor.getCopy();
assertEquals(1, copy.featureTypeStyles().get(0).rules().size());
actualRule = copy.featureTypeStyles().get(0).rules().get(0);
assertNull(actualRule.getFilter());
assertEquals(1, actualRule.symbolizers().size());
assertEquals(ruleToRender.symbolizers().get(1), actualRule.symbolizers().get(0));
}
}
Aggregations