use of org.geotools.styling.Rule in project sldeditor by robward-scisys.
the class SLDTreeTools method addNewThing.
/**
* Adds the new thing.
*
* @param hint the hint when the are multiple possibilities
*/
public void addNewThing(Class<?> hint) {
if (symbolTree == null) {
return;
}
TreePath path = symbolTree.getSelectionPath();
if (path == null) {
return;
}
DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
DefaultMutableTreeNode newNode = null;
Object obj = lastNode.getUserObject();
// Store current state of the SLD before the add
Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
if (obj instanceof String) {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
if (hint == NamedLayer.class) {
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
newNode = sldTree.addObject(lastNode, namedLayer, true);
} else if (hint == UserLayer.class) {
UserLayer userLayer = DefaultSymbols.createNewUserLayer();
SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
newNode = sldTree.addObject(lastNode, userLayer, true);
}
} else if (obj instanceof StyledLayerDescriptor) {
if (hint == NamedLayer.class) {
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
newNode = sldTree.addObject(lastNode, namedLayer, true);
} else if (hint == UserLayer.class) {
UserLayer userLayer = DefaultSymbols.createNewUserLayer();
SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
newNode = sldTree.addObject(lastNode, userLayer, true);
}
} else if (obj instanceof NamedLayer) {
Style style = DefaultSymbols.createNewStyle();
SelectedSymbol.getInstance().addNewStyle(style);
newNode = sldTree.addObject(lastNode, style, true);
} else if (obj instanceof UserLayer) {
Style style = DefaultSymbols.createNewStyle();
SelectedSymbol.getInstance().addNewStyle(style);
newNode = sldTree.addObject(lastNode, style, true);
} else if (obj instanceof Style) {
FeatureTypeStyle featureTypeStyle = DefaultSymbols.createNewFeatureTypeStyle();
SelectedSymbol.getInstance().addNewFeatureTypeStyle(featureTypeStyle);
newNode = sldTree.addObject(lastNode, featureTypeStyle, true);
} else if (obj instanceof FeatureTypeStyle) {
Rule rule = DefaultSymbols.createNewRule();
SelectedSymbol.getInstance().addNewRule(rule);
newNode = sldTree.addObject(lastNode, rule, true);
}
// Select the item just added
if (newNode != null) {
SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
TreePath newPath = getPath(newNode);
symbolTree.setSelectionPath(newPath);
// Store current state of the SLD after the add
Object newValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
UndoManager.getInstance().addUndoEvent(new UndoEvent(sldTree.getUndoObject(), getClass().getName(), oldValueObj, newValueObj));
}
}
use of org.geotools.styling.Rule in project sldeditor by robward-scisys.
the class SLDTreeTools method getRuleTreeNode.
/**
* Gets the rule tree node.
*
* @return the rule tree node
*/
private DefaultMutableTreeNode getRuleTreeNode() {
if (symbolTree != null) {
TreePath path = symbolTree.getSelectionPath();
DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
Object obj = lastNode.getUserObject();
if (obj instanceof Symbolizer) {
return (DefaultMutableTreeNode) lastNode.getParent();
} else if (obj instanceof Rule) {
return (DefaultMutableTreeNode) lastNode;
}
}
return rootNode;
}
use of org.geotools.styling.Rule in project sldeditor by robward-scisys.
the class RuleTreeItem 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) {
Rule rule = (Rule) nodeObject;
String name = "";
if (rule != null) {
if (rule.getName() != null) {
name = rule.getName();
}
}
return String.format("%s : %s", TITLE, name);
}
use of org.geotools.styling.Rule 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.Rule in project sldeditor by robward-scisys.
the class SLDExternalImagesTest method createTestPoint.
/**
* Creates the test point.
*
* @param url the url
* @return the styled layer descriptor
*/
private StyledLayerDescriptor createTestPoint(URL url) {
StyleBuilder sb = new StyleBuilder();
StyleFactory styleFactory = sb.getStyleFactory();
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
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);
PointSymbolizer point = styleFactory.createPointSymbolizer();
rule.symbolizers().add(point);
Graphic graphic = createGraphic(url, styleFactory);
point.setGraphic(graphic);
return sld;
}
Aggregations