use of com.sldeditor.common.undo.UndoEvent 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 com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.
the class SLDTreeTools method addNewPolygon.
/**
* Adds the new polygon symbolizer.
*/
public void addNewPolygon() {
if (symbolTree == null) {
return;
}
// Store current state of the SLD before the add
Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
PolygonSymbolizer newPolygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
DefaultMutableTreeNode ruleNode = getRuleTreeNode();
SelectedSymbol.getInstance().addSymbolizerToRule(newPolygonSymbolizer);
DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, newPolygonSymbolizer, true);
if (newNode != null) {
sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getFill(newPolygonSymbolizer), true);
sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getStroke(newPolygonSymbolizer), true);
SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
// Select the item just added
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 com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.
the class SLDTreeTools method addNewRaster.
/**
* Adds the new raster symbolizer.
*/
public void addNewRaster() {
if (symbolTree == null) {
return;
}
// Store current state of the SLD before the add
Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
RasterSymbolizer newRasterSymbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
DefaultMutableTreeNode ruleNode = getRuleTreeNode();
SelectedSymbol.getInstance().addSymbolizerToRule(newRasterSymbolizer);
DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, newRasterSymbolizer, 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 com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.
the class SLDTreeTools method addArrow.
/**
* Adds the arrow.
*
* @param isSourceArrow the is source arrow
*/
private void addArrow(boolean isSourceArrow) {
if (symbolTree == null) {
return;
}
// Store current state of the SLD before the add
Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
PointSymbolizer pointSymbolizer = DefaultSymbols.createArrow(isSourceArrow);
DefaultMutableTreeNode ruleNode = getRuleTreeNode();
SelectedSymbol.getInstance().addSymbolizerToRule(pointSymbolizer);
DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, pointSymbolizer, true);
// Select the item just added
if (newNode != null) {
sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getFill(pointSymbolizer), true);
SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
// Re-render the symbol
if (renderList != null) {
for (RenderSymbolInterface render : renderList) {
render.renderSymbol();
}
}
// 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 com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.
the class SLDTreeTools method addNewLine.
/**
* Adds the new line symbolizer.
*/
public void addNewLine() {
if (symbolTree == null) {
return;
}
// Store current state of the SLD before the add
Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
LineSymbolizer newLineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
DefaultMutableTreeNode ruleNode = getRuleTreeNode();
SelectedSymbol.getInstance().addSymbolizerToRule(newLineSymbolizer);
DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, newLineSymbolizer, true);
if (newNode != null) {
sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getStroke(newLineSymbolizer), true);
SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
// Select the item just added
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));
}
}
Aggregations