use of org.geotools.styling.FeatureTypeStyle 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.FeatureTypeStyle in project sldeditor by robward-scisys.
the class FeatureTypeStyleTreeItem method itemSelected.
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.tree.item.SLDTreeItemInterface#itemSelected(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)
*/
@Override
public void itemSelected(DefaultMutableTreeNode node, Object userObject) {
FeatureTypeStyle fts = (FeatureTypeStyle) userObject;
SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
}
use of org.geotools.styling.FeatureTypeStyle 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.FeatureTypeStyle 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;
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class SLDExternalImagesTest method createTestPolygon.
/**
* Creates the test polygon.
*
* @param url the url
* @return the styled layer descriptor
*/
private StyledLayerDescriptor createTestPolygon(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);
PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();
rule.symbolizers().add(polygon);
Graphic graphicFill1 = createGraphic(url, styleFactory);
Graphic graphicFill2 = createGraphic(url, styleFactory);
Graphic graphicStroke = createGraphic(url, styleFactory);
Fill fill = styleFactory.createFill(null, null, null, graphicFill1);
polygon.setFill(fill);
Stroke stroke = styleFactory.createStroke(null, null, null, null, null, null, null, graphicFill2, graphicStroke);
polygon.setStroke(stroke);
return sld;
}
Aggregations