use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.
the class FieldConfigInlineFeature method undoAction.
/**
* Undo action.
*
* @param undoRedoObject the undo/redo object
*/
@Override
public void undoAction(UndoInterface undoRedoObject) {
if (undoRedoObject != null) {
if (undoRedoObject.getOldValue() instanceof String) {
String oldValue = (String) undoRedoObject.getOldValue();
UserLayer userLayer = DefaultSymbols.createNewUserLayer();
InlineFeatureUtils.setInlineFeatures(userLayer, oldValue);
if (inlineGML != null) {
inlineGML.setInlineFeatures(oldValue);
}
if (inlineFeature != null) {
inlineFeature.setInlineFeatures(userLayer);
}
}
}
}
use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.
the class InlineFeatureUtils method extractUserLayers.
/**
* Extract user layers from an SLD.
*
* @param sld the sld
* @return the list of user layers
*/
public static List<UserLayer> extractUserLayers(StyledLayerDescriptor sld) {
List<UserLayer> userLayerList = new ArrayList<UserLayer>();
if (sld != null) {
for (StyledLayer layer : sld.layers()) {
if (layer instanceof UserLayer) {
UserLayer userLayer = (UserLayer) layer;
userLayerList.add(userLayer);
}
}
}
return userLayerList;
}
use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.
the class SLDTreeTools method removeItem.
/**
* Removes the item.
*/
public void removeItem() {
if (symbolTree == null) {
return;
}
TreePath path = symbolTree.getSelectionPath();
if (path == null) {
return;
}
DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
Object obj = lastNode.getUserObject();
// CHECKSTYLE:OFF
Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
if (obj instanceof NamedLayer) {
SelectedSymbol.getInstance().removeUserNamedLayer((NamedLayer) obj);
removeTreeNode(lastNode);
} else if (obj instanceof UserLayer) {
SelectedSymbol.getInstance().removeUserNamedLayer((UserLayer) obj);
removeTreeNode(lastNode);
} else if (obj instanceof Style) {
SelectedSymbol.getInstance().removeStyle((Style) obj);
removeTreeNode(lastNode);
} else if (obj instanceof FeatureTypeStyle) {
SelectedSymbol.getInstance().removeFeatureTypeStyle((FeatureTypeStyle) obj);
removeTreeNode(lastNode);
} else if (obj instanceof Rule) {
SelectedSymbol.getInstance().removeRule((Rule) obj);
removeTreeNode(lastNode);
} else if (obj instanceof Symbolizer) {
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) lastNode.getParent();
if (parentNode != null) {
if (parentNode.getUserObject() instanceof RasterSymbolizer) {
SelectedSymbol.getInstance().removeRasterImageOutline((RasterSymbolizer) parentNode.getUserObject());
} else {
SelectedSymbol.getInstance().removeSymbolizer((Symbolizer) obj);
}
removeTreeNode(lastNode);
}
} else {
return;
}
SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
// Re-render the symbol
if (renderList != null) {
for (RenderSymbolInterface render : renderList) {
render.renderSymbol();
}
}
Object newValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
UndoManager.getInstance().addUndoEvent(new UndoEvent(sldTree.getUndoObject(), getClass().getName(), oldValueObj, newValueObj));
}
use of org.geotools.styling.UserLayer 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.UserLayer in project sldeditor by robward-scisys.
the class UserLayerTreeItemTest method testGetTreeString.
/**
* Test method for
* {@link com.sldeditor.ui.tree.item.UserLayerTreeItem#getTreeString(java.lang.Object)}.
*/
@Test
public void testGetTreeString() {
UserLayerTreeItem item = new UserLayerTreeItem();
String actualValue = item.getTreeString(null, null);
String expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.userlayer"), "");
assertTrue(actualValue.compareTo(expectedValue) == 0);
UserLayer userLayer = DefaultSymbols.createNewUserLayer();
actualValue = item.getTreeString(null, userLayer);
assertTrue(actualValue.compareTo(expectedValue) == 0);
String expectedName = "test name";
userLayer.setName(expectedName);
actualValue = item.getTreeString(null, userLayer);
expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.userlayer"), expectedName);
assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Aggregations