use of org.geotools.styling.PolygonSymbolizer in project sldeditor by robward-scisys.
the class SLDEditorBufferedImageLegendGraphicBuilder method getSampleShape.
/**
* Returns a <code>java.awt.Shape</code> appropiate to render a legend graphic given the
* symbolizer type and the legend dimensions.
*
* @param symbolizer the Symbolizer for whose type a sample shape will be created
* @param legendWidth the requested width, in output units, of the legend graphic
* @param legendHeight the requested height, in output units, of the legend graphic
*
* @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the symbolizer, wether it
* is a LineSymbolizer, a PolygonSymbolizer, or a Point ot Text Symbolizer
*
* @throws IllegalArgumentException if an unknown symbolizer impl was passed in.
*/
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
LiteShape2 sampleShape;
final float hpad = (legendWidth * LegendUtils.hpaddingFactor);
final float vpad = (legendHeight * LegendUtils.vpaddingFactor);
if (symbolizer instanceof LineSymbolizer) {
Coordinate[] coords = { new Coordinate(hpad, legendHeight - vpad - 1), new Coordinate(legendWidth - hpad - 1, vpad) };
LineString geom = geomFac.createLineString(coords);
try {
this.sampleLine = new LiteShape2(geom, null, null, false);
} catch (Exception e) {
this.sampleLine = null;
}
sampleShape = this.sampleLine;
} else if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof RasterSymbolizer)) {
final float w = legendWidth - (2 * hpad) - 1;
final float h = legendHeight - (2 * vpad) - 1;
Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, vpad + h), new Coordinate(hpad + w, vpad + h), new Coordinate(hpad + w, vpad), new Coordinate(hpad, vpad) };
LinearRing shell = geomFac.createLinearRing(coords);
Polygon geom = geomFac.createPolygon(shell, null);
try {
this.sampleRect = new LiteShape2(geom, null, null, false);
} catch (Exception e) {
this.sampleRect = null;
}
sampleShape = this.sampleRect;
} else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
Coordinate coord = new Coordinate(legendWidth / 2, legendHeight / 2);
try {
this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
} catch (Exception e) {
this.samplePoint = null;
}
sampleShape = this.samplePoint;
} else {
throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
}
return sampleShape;
}
use of org.geotools.styling.PolygonSymbolizer 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 org.geotools.styling.PolygonSymbolizer in project sldeditor by robward-scisys.
the class CheckBoxNodeEditor method isCellEditable.
/*
* (non-Javadoc)
*
* @see javax.swing.AbstractCellEditor#isCellEditable(java.util.EventObject)
*/
public boolean isCellEditable(EventObject event) {
boolean returnValue = false;
if (event instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) event;
TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
if (path != null) {
Object node = path.getLastPathComponent();
if ((node != null) && (node instanceof DefaultMutableTreeNode)) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
if (treeNode.getParent() != null) {
Object parentUserObject = ((DefaultMutableTreeNode) treeNode.getParent()).getUserObject();
if (parentUserObject instanceof PolygonSymbolizer) {
symbolizer = (Symbolizer) parentUserObject;
userObject = treeNode.getUserObject();
returnValue = treeNode.isLeaf();
}
}
}
}
}
return returnValue;
}
use of org.geotools.styling.PolygonSymbolizer 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.PolygonSymbolizer in project sldeditor by robward-scisys.
the class SLDTree method handleRasterSymbolizer.
/**
* Handle raster symbolizer.
*
* @param symbolizer the symbolizer
* @param symbolizerTreeNode the symbolizer tree node
*/
private void handleRasterSymbolizer(Symbolizer symbolizer, DefaultMutableTreeNode symbolizerTreeNode) {
// Handle the image outline symbolizer for raster symbols
Symbolizer outlineSymbolizer = ((RasterSymbolizer) symbolizer).getImageOutline();
if (outlineSymbolizer instanceof LineSymbolizer) {
LineSymbolizer outlineLineSymbolizer = (LineSymbolizer) outlineSymbolizer;
if (outlineLineSymbolizer != null) {
DefaultMutableTreeNode symbolizerImageOutlineLineNode = addObject(symbolizerTreeNode, outlineLineSymbolizer, true);
addObject(symbolizerImageOutlineLineNode, SLDTreeLeafFactory.getInstance().getStroke(outlineLineSymbolizer), true);
}
} else if (outlineSymbolizer instanceof PolygonSymbolizer) {
PolygonSymbolizer outlinePolygonSymbolizer = (PolygonSymbolizer) outlineSymbolizer;
if (outlinePolygonSymbolizer != null) {
DefaultMutableTreeNode symbolizerImageOutlinePolygonNode = addObject(symbolizerTreeNode, outlinePolygonSymbolizer, true);
addObject(symbolizerImageOutlinePolygonNode, SLDTreeLeafFactory.getInstance().getFill(outlinePolygonSymbolizer), true);
addObject(symbolizerImageOutlinePolygonNode, SLDTreeLeafFactory.getInstance().getStroke(outlinePolygonSymbolizer), true);
}
}
}
Aggregations