use of org.geotools.styling.Rule in project sldeditor by robward-scisys.
the class RuleRenderVisitor method visit.
/**
* Visit.
*
* @param rule the rule
*/
/*
* (non-Javadoc)
*
* @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.Rule)
*/
@SuppressWarnings("deprecation")
@Override
public void visit(Rule rule) {
Rule copy = null;
Symbolizer[] symsCopy = null;
if (!displayOverall) {
if ((symbolizerIndex >= 0) && (symbolizerIndex < rule.getSymbolizers().length)) {
symsCopy = new Symbolizer[1];
symsCopy[0] = copy(rule.getSymbolizers()[symbolizerIndex]);
}
}
// As a catch all copy everything
if (symsCopy == null) {
symsCopy = rule.getSymbolizers();
for (int i = 0; i < symsCopy.length; i++) {
symsCopy[i] = copy(symsCopy[i]);
}
}
Graphic[] legendCopy = rule.getLegendGraphic();
for (int i = 0; i < legendCopy.length; i++) {
legendCopy[i] = copy(legendCopy[i]);
}
Description descCopy = rule.getDescription();
descCopy = copy(descCopy);
copy = sf.createRule();
copy.setSymbolizers(symsCopy);
copy.setDescription(descCopy);
copy.setLegendGraphic(legendCopy);
copy.setName(rule.getName());
Filter filterCopy = null;
copy.setFilter(filterCopy);
copy.setElseFilter(rule.isElseFilter());
if (STRICT && !copy.equals(rule)) {
throw new IllegalStateException("Was unable to duplicate provided Rule:" + rule);
}
pages.push(copy);
}
use of org.geotools.styling.Rule in project sldeditor by robward-scisys.
the class BatchUpdateFontUtils method containsFonts.
/**
* Contains font details.
*
* @param sldData the sld data
* @return the scale sld data
*/
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
List<BatchUpdateFontData> dataList = null;
if (sldData != null) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
if (sld != null) {
for (StyledLayer styledLayer : styledLayerList) {
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
for (Style style : namedLayerImpl.styles()) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule rule : fts.rules()) {
for (Symbolizer symbolizer : rule.symbolizers()) {
if (symbolizer instanceof TextSymbolizer) {
TextSymbolizer textSymbol = (TextSymbolizer) symbolizer;
Font font = textSymbol.getFont();
if (font != null) {
if (dataList == null) {
dataList = new ArrayList<BatchUpdateFontData>();
}
BatchUpdateFontData fontSLDData = new BatchUpdateFontData(sld, sldData);
fontSLDData.setNamedLayer(namedLayerImpl.getName());
fontSLDData.setFeatureTypeStyle(fts.getName());
fontSLDData.setStyle(style.getName());
fontSLDData.setRule(rule);
fontSLDData.setSymbolizer(textSymbol);
fontSLDData.setFont(font);
dataList.add(fontSLDData);
}
}
}
}
}
}
}
}
}
}
}
return dataList;
}
use of org.geotools.styling.Rule in project sldeditor by robward-scisys.
the class ScaleSLDData method updateScales.
/**
* Update scales.
*
* @param sldWriter the sld writer
*/
public boolean updateScales(SLDWriterInterface sldWriter) {
boolean refreshUI = false;
if (rule != null) {
if (isMinimumScaleUpdated()) {
rule.setMinScaleDenominator(minScale);
minimumScaleUpdated = false;
}
if (isMaximumScaleUpdated()) {
rule.setMaxScaleDenominator(maxScale);
maximumScaleUpdated = false;
}
String sldContents = sldWriter.encodeSLD(null, this.sld);
SLDDataInterface current = SLDEditorFile.getInstance().getSLDData();
if (current.getSLDFile().equals(sldData.getSLDFile()) || current.getSLDURL().equals(sldData.getSLDURL())) {
Rule currentFule = SLDUtils.findRule(sld, rule, SelectedSymbol.getInstance().getSld());
if (currentFule != null) {
currentFule.setMinScaleDenominator(minScale);
currentFule.setMaxScaleDenominator(maxScale);
refreshUI = true;
}
}
sldData.updateSLDContents(sldContents);
}
return refreshUI;
}
use of org.geotools.styling.Rule 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.Rule 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);
}
Aggregations