Java源码示例:org.geotools.styling.Stroke
示例1
private static Rule makeFillRule() {
final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
// create a partially opaque outline stroke
final Stroke stroke = styleFactory.createStroke(
filterFactory.literal(Color.BLACK),
filterFactory.literal(1),
filterFactory.literal(.5)
);
// create a partially opaque fill
Fill fill = styleFactory.createFill(
filterFactory.literal(COLORS.next()),
filterFactory.literal(.5)
);
// setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);
final Rule rule = styleFactory.createRule();
rule.symbolizers().add(sym);
return rule;
}
示例2
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
if(element == null) return;
if(rule == null) return;
JsonObject obj = element.getAsJsonObject();
@SuppressWarnings("unused")
int style = getInt(obj, CommonSymbolKeys.STYLE);
List<Symbolizer> symbolizerList = rule.symbolizers();
List<Stroke> strokeList = convert(obj);
Stroke stroke = null;
if(!strokeList.isEmpty())
{
stroke = strokeList.get(0);
}
LineSymbolizer lineSymbolizer = styleFactory.createLineSymbolizer(stroke, null);
symbolizerList.add(lineSymbolizer);
}
示例3
/**
* Convert.
*
* @param rule the rule
* @param element the element
* @param layerName the layer name
* @param transparency the transparency
*/
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
if(rule == null) return;
if(element == null) return;
JsonObject obj = element.getAsJsonObject();
List<Symbolizer> symbolizerList = rule.symbolizers();
List<Stroke> strokeList = convert(obj);
Stroke stroke = null;
if(!strokeList.isEmpty())
{
stroke = strokeList.get(0);
}
LineSymbolizer lineSymbolizer = styleFactory.createLineSymbolizer(stroke, null);
symbolizerList.add(lineSymbolizer);
}
示例4
@Override
public List<Stroke> convert(JsonElement element) {
if(element == null) return null;
List<Stroke> strokeList = null;
JsonArray layerList = element.getAsJsonArray();
if(layerList.size() > 0)
{
strokeList = new ArrayList<Stroke>();
for(int index = 0; index < layerList.size(); index ++)
{
JsonObject obj = layerList.get(index).getAsJsonObject();
List<Stroke> strokeSymbolList = SymbolManager.getInstance().getStrokeList(obj.get(MultiLayerLineSymbolKeys.LINE));
if(strokeSymbolList != null)
{
strokeList.addAll(strokeSymbolList);
}
}
}
return strokeList;
}
示例5
/**
* Gets the stroke.
*
* @param jsonElementSymbol the json element symbol
* @return the stroke list
*/
public List<Stroke> getStrokeList(JsonElement jsonElementSymbol) {
List<Stroke> strokeList = null;
if(jsonElementSymbol != null)
{
JsonObject jsonSymbol = jsonElementSymbol.getAsJsonObject();
for(String lineSymbolType : lineSymbolMap.keySet())
{
JsonElement obj = jsonSymbol.get(lineSymbolType);
if(obj != null)
{
EsriLineSymbolInterface esriLineSymbol = lineSymbolMap.get(lineSymbolType);
strokeList = esriLineSymbol.convert(obj);
break;
}
}
}
return strokeList;
}
示例6
/**
* Gets the geo server stroke value.
*
* @param fieldConfigManager the field config manager
* @return the geo server stroke value
*/
private Stroke getGeoServerStrokeValue(GraphicPanelFieldManager fieldConfigManager) {
Stroke stroke;
Expression strokeColour = null;
FieldConfigBase field = fieldConfigManager.get(fillFieldConfig.getColour());
if (field != null) {
strokeColour = ((FieldConfigColour) field).getColourExpression();
}
Expression strokeColourOpacity = null;
field = fieldConfigManager.get(fillFieldConfig.getOpacity());
if (field != null) {
strokeColourOpacity = field.getExpression();
}
Expression strokeWidth = null;
field = fieldConfigManager.get(fillFieldConfig.getWidth());
if (field != null) {
strokeWidth = field.getExpression();
}
stroke = getStyleFactory().createStroke(strokeColour, strokeWidth, strokeColourOpacity);
return stroke;
}
示例7
/**
* Gets the stroke value.
*
* @param fieldConfigManager the field config manager
* @param strokeEnabled the stroke enabled
* @return the stroke value
*/
private Stroke getStrokeValue(
GraphicPanelFieldManager fieldConfigManager, boolean strokeEnabled) {
FieldConfigBase field;
Stroke stroke = null;
if (strokeEnabled && (strokeFieldConfig != null)) {
Expression expStrokeColour = null;
Expression expStrokeColourOpacity = null;
field = fieldConfigManager.get(strokeFieldConfig.getColour());
if (field instanceof FieldConfigColour) {
FieldConfigColour colourField = (FieldConfigColour) field;
expStrokeColour = colourField.getColourExpression();
}
field = fieldConfigManager.get(strokeFieldConfig.getOpacity());
if (field != null) {
expStrokeColourOpacity = field.getExpression();
}
stroke = getStyleFactory().createStroke(expStrokeColour, expStrokeColourOpacity);
}
return stroke;
}
示例8
/**
* Gets the stroke.
*
* @param symbolizer the symbolizer
* @return the stroke
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.tree.SLDTreeLeafInterface#getStroke(org.opengis.style.Symbolizer)
*/
@Override
public Stroke getStroke(Symbolizer symbolizer) {
Stroke stroke = null;
if (symbolizer instanceof LineSymbolizer) {
LineSymbolizer line = (LineSymbolizer) symbolizer;
stroke = line.getStroke();
}
return stroke;
}
示例9
/**
* Update stroke.
*
* @param selected the selected
* @param symbolizer the symbolizer
* @return the stroke
*/
public Stroke updateStroke(boolean selected, Symbolizer symbolizer) {
if (symbolizer == null) {
return null;
}
boolean currentValue = hasStroke(symbolizer);
if (currentValue != selected) {
SLDTreeLeafInterface obj = map.get(symbolizer.getClass());
if (obj != null) {
if (selected) {
logger.debug("Set stroke");
obj.createStroke(symbolizer);
} else {
logger.debug("Clear stroke");
obj.removeStroke(symbolizer);
}
}
}
return getStroke(symbolizer);
}
示例10
/**
* Update stroke.
*
* @param resourceLocator the resource locator
* @param stroke the stroke
* @param externalImageList the external image list
*/
private static void updateStroke(
URL resourceLocator,
Stroke stroke,
List<String> externalImageList,
ProcessGraphicSymbolInterface process) {
if (stroke != null) {
if (stroke.getGraphicFill() != null) {
process.processGraphicalSymbol(
resourceLocator,
stroke.getGraphicFill().graphicalSymbols(),
externalImageList);
}
if (stroke.getGraphicStroke() != null) {
process.processGraphicalSymbol(
resourceLocator,
stroke.getGraphicStroke().graphicalSymbols(),
externalImageList);
}
}
}
示例11
/**
* Test method for {@link
* com.sldeditor.ui.tree.item.StrokeTreeItem#getTreeString(java.lang.Object)}.
*/
@Test
public void testGetTreeString() {
StrokeTreeItem item = new StrokeTreeItem();
String actualValue = item.getTreeString(null, null);
String expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.stroke");
assertTrue(actualValue.compareTo(expectedValue) == 0);
Stroke stroke = DefaultSymbols.createDefaultStroke();
actualValue = item.getTreeString(null, stroke);
assertTrue(actualValue.compareTo(expectedValue) == 0);
actualValue = item.getTreeString(null, stroke);
assertTrue(actualValue.compareTo(expectedValue) == 0);
}
示例12
/** Test method for StrokeDetails */
@Test
public void testStrokeGetMinimumVersion() {
StrokeDetails details = new StrokeDetails();
details.getMinimumVersion(null, null, null);
Stroke stroke = styleFactory.createStroke(ff.literal("#654321"), ff.literal(3.2));
Graphic graphicStroke = styleFactory.createDefaultGraphic();
stroke.setGraphicStroke(graphicStroke);
List<VendorOptionPresent> vendorOptionsPresentList = null;
Object parentObj = null;
details.getMinimumVersion(parentObj, stroke, vendorOptionsPresentList);
vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
details.getMinimumVersion(parentObj, stroke, vendorOptionsPresentList);
assertTrue(vendorOptionsPresentList.size() == 0);
}
示例13
/**
* Create a default polygon style.
*
* @return the created style.
*/
public static Style createPolygonStyle() {
// create a partially opaque outline stroke
final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1),
filterFactory.literal(0.5));
// create a partial opaque fill
final Fill fill = styleFactory.createFill(filterFactory.literal(Color.CYAN), filterFactory.literal(0.5));
/*
* Setting the geometryPropertyName arg to null signals that we want to draw the default geomettry of features
*/
final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);
final Rule rule = styleFactory.createRule();
rule.symbolizers().add(sym);
final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
final Style style = styleFactory.createStyle();
style.featureTypeStyles().add(fts);
return style;
}
示例14
/**
* Create a default line style.
*
* @return the created style.
*/
public static Style createLineStyle() {
final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1));
/*
* Setting the geometryPropertyName arg to null signals that we want to draw the default geomettry of features
*/
final LineSymbolizer sym = styleFactory.createLineSymbolizer(stroke, null);
final Rule rule = styleFactory.createRule();
rule.symbolizers().add(sym);
final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
final Style style = styleFactory.createStyle();
style.featureTypeStyles().add(fts);
return style;
}
示例15
private static Style createPolygonStyle() {
PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
Fill fill = styleFactory.createFill(
filterFactory.literal("#FFAA00"),
filterFactory.literal(0.5)
);
final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLACK),
filterFactory.literal(1));
symbolizer.setFill(fill);
symbolizer.setStroke(stroke);
Rule rule = styleFactory.createRule();
rule.symbolizers().add(symbolizer);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.rules().add(rule);
Style style = styleFactory.createStyle();
style.featureTypeStyles().add(fts);
return style;
}
示例16
private Stroke createStroke(FeatureStyleInfo featureStyle) throws LayerException {
Stroke stroke = styleBuilder.createStroke(styleBuilder.literalExpression(featureStyle.getStrokeColor()),
styleBuilder.literalExpression(featureStyle.getStrokeWidth()),
styleBuilder.literalExpression(featureStyle.getStrokeOpacity()));
if (featureStyle.getDashArray() != null) {
String[] strings = featureStyle.getDashArray().split(",");
float[] nrs = new float[strings.length];
for (int i = 0; i < strings.length; i++) {
try {
nrs[i] = parseFloat(strings[i]);
} catch (NumberFormatException e) {
log.warn("Dash array cannot be parsed " + featureStyle.getDashArray(), e);
}
}
stroke.setDashArray(nrs);
}
return stroke;
}
示例17
private static Style createPolygonStyle() {
final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
// create a partially opaque outline stroke
final Stroke stroke = styleFactory.createStroke(
filterFactory.literal(Color.BLACK),
filterFactory.literal(1),
filterFactory.literal(.5)
);
// create a partially opaque fill
final Fill fill = styleFactory.createFill(
filterFactory.literal(COLORS.next()),
filterFactory.literal(.5)
);
// setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);
// make rule
final Rule rule = styleFactory.createRule();
rule.symbolizers().add(sym);
final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
final Style style = styleFactory.createStyle();
style.getDescription().setTitle("Polygon Style");
style.featureTypeStyles().add(fts);
return style;
}
示例18
private static Style createLineStyle() {
final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
// create a partially opaque outline stroke
final Stroke stroke = styleFactory.createStroke(
filterFactory.literal(Color.WHITE),
filterFactory.literal(1),
filterFactory.literal(.5)
);
// create a partially opaque fill
final Fill fill = styleFactory.createFill(
filterFactory.literal(Color.RED),
filterFactory.literal(.25)
);
// setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);
// make rule
final Rule rule = styleFactory.createRule();
rule.symbolizers().add(sym);
final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
final Style style = styleFactory.createStyle();
style.getDescription().setTitle("Line Style");
style.featureTypeStyles().add(fts);
return style;
}
示例19
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
if(element == null) return;
if(rule == null) return;
JsonObject obj = element.getAsJsonObject();
@SuppressWarnings("unused")
int style = getInt(obj, CommonSymbolKeys.STYLE);
List<Symbolizer> symbolizerList = rule.symbolizers();
JsonElement jsonOutlineElement = obj.get(SimpleFillSymbolKeys.OUTLINE);
List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(jsonOutlineElement);
Stroke stroke = null;
if(strokeList != null)
{
if(!strokeList.isEmpty())
{
stroke = strokeList.get(0);
}
}
Expression fillColour = getColour(obj.get(SimpleFillSymbolKeys.FILL_COLOUR));
Fill fill = null;
if(fillColour != null)
{
fill = styleFactory.createFill(fillColour, getTransparency(transparency));
}
PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer(stroke, fill, null);
symbolizerList.add(polygonSymbolizer);
}
示例20
/**
* Convert.
*
* @param rule the rule
* @param element the element
* @param layerName the layer name
* @param transparency the transparency
*/
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
if(rule == null) return;
if(element == null) return;
JsonArray layerArray = element.getAsJsonArray();
List<Symbolizer> symbolizerList = rule.symbolizers();
if(layerArray.size() > 0)
{
for(int index = 0; index < layerArray.size(); index ++)
{
JsonObject obj = layerArray.get(index).getAsJsonObject();
List<Stroke> strokeList = null;
JsonElement jsonOutlineElement = obj.get(MultiLayerLineSymbolKeys.LINE);
strokeList = SymbolManager.getInstance().getStrokeList(jsonOutlineElement);
if(strokeList != null)
{
for(Stroke stroke : strokeList)
{
LineSymbolizer lineSymbolizer = styleFactory.createLineSymbolizer(stroke, null);
symbolizerList.add(lineSymbolizer);
}
}
}
}
}
示例21
/**
* Gets the stroke value.
*
* @param fieldConfigManager the field config manager
* @return the stroke value
*/
private Stroke getStrokeValue(GraphicPanelFieldManager fieldConfigManager) {
Stroke stroke;
FieldConfigBase field;
Expression expStrokeColour = null;
Expression expStrokeColourOpacity = null;
field = fieldConfigManager.get(this.strokeFieldConfig.getColour());
if (field instanceof FieldConfigColour) {
FieldConfigColour colourField = (FieldConfigColour) field;
expStrokeColour = colourField.getColourExpression();
}
// Stroke width
Expression strokeWidth = null;
field = fieldConfigManager.get(this.strokeFieldConfig.getWidth());
if (field != null) {
strokeWidth = field.getExpression();
}
// Opacity
field = fieldConfigManager.get(this.strokeFieldConfig.getOpacity());
if (field != null) {
expStrokeColourOpacity = field.getExpression();
}
stroke =
getStyleFactory()
.createStroke(expStrokeColour, strokeWidth, expStrokeColourOpacity);
return stroke;
}
示例22
/**
* Gets the value.
*
* @param fieldConfigManager the field config manager
* @param symbolType the symbol type
* @param fillEnabled the fill enabled
* @param strokeEnabled the stroke enabled
* @return the value
*/
@Override
public List<GraphicalSymbol> getValue(
GraphicPanelFieldManager fieldConfigManager,
Expression symbolType,
boolean fillEnabled,
boolean strokeEnabled) {
List<GraphicalSymbol> symbolList = new ArrayList<>();
Expression wellKnownName = null;
if ((getConfigField() != null) && (fieldConfigManager != null)) {
wellKnownName = getConfigField().getExpression();
if (wellKnownName != null) {
Expression expFillColour = null;
Expression expFillColourOpacity = null;
FieldConfigBase field = fieldConfigManager.get(FieldIdEnum.FILL_COLOUR);
if (field != null) {
FieldConfigColour colourField = (FieldConfigColour) field;
expFillColour = colourField.getColourExpression();
}
Stroke stroke = null;
Fill fill = getStyleFactory().createFill(expFillColour, expFillColourOpacity);
Expression size = null;
Expression rotation = null;
Mark mark =
getStyleFactory().createMark(wellKnownName, stroke, fill, size, rotation);
symbolList.add(mark);
}
}
return symbolList;
}
示例23
/**
* Creates the default point symbolizer.
*
* @return the point symbolizer
*/
public static PointSymbolizer createDefaultPointSymbolizer() {
String geometryFieldName = null;
Expression geometryField = ff.property(geometryFieldName);
List<GraphicalSymbol> symbolList = new ArrayList<>();
Stroke stroke = null;
AnchorPoint anchorPoint = null;
Displacement displacement = null;
Fill fill = styleFactory.createFill(ff.literal(DEFAULT_MARKER_COLOUR));
GraphicalSymbol symbol = styleFactory.mark(ff.literal(DEFAULT_MARKER_SYMBOL), fill, stroke);
symbolList.add(symbol);
Graphic graphic =
styleFactory.graphic(
symbolList,
ff.literal(DEFAULT_COLOUR_OPACITY),
ff.literal(DEFAULT_MARKER_SYMBOL_SIZE),
ff.literal(0.0),
anchorPoint,
displacement);
return styleFactory.pointSymbolizer(
Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker"),
geometryField,
null,
null,
graphic);
}
示例24
/**
* Creates the default polygon symbolizer.
*
* @return the polygon symbolizer
*/
public static PolygonSymbolizer createDefaultPolygonSymbolizer() {
Stroke stroke = styleFactory.createStroke(ff.literal(DEFAULT_LINE_COLOUR), ff.literal(2));
Fill fill = styleFactory.getDefaultFill();
PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer();
polygonSymbolizer.setStroke(stroke);
polygonSymbolizer.setFill(fill);
return polygonSymbolizer;
}
示例25
/**
* Gets the stroke.
*
* @param symbolizer the symbolizer
* @return the stroke
*/
public Stroke getStroke(Symbolizer symbolizer) {
Stroke stroke = null;
if (symbolizer != null) {
SLDTreeLeafInterface obj = map.get(symbolizer.getClass());
if (obj != null) {
stroke = obj.getStroke(symbolizer);
}
if (stroke == null) {
stroke = styleFactory.getDefaultStroke();
}
}
return stroke;
}
示例26
/**
* Checks if item is selected.
*
* @param userObject the user object
* @param parentSymbolizer the parent symbolizer
* @return true, if is item selected
*/
public boolean isItemSelected(Object userObject, Symbolizer parentSymbolizer) {
boolean selectedItem = false;
if (userObject instanceof Fill) {
selectedItem = hasFill(parentSymbolizer);
} else if (userObject instanceof Stroke) {
selectedItem = hasStroke(parentSymbolizer);
}
return selectedItem;
}
示例27
@Override
public Stroke getStroke(Symbolizer symbolizer) {
Stroke stroke = null;
if (symbolizer instanceof PolygonSymbolizer) {
PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer;
stroke = polygon.getStroke();
}
return stroke;
}
示例28
/**
* Test method for {@link
* com.sldeditor.common.tree.leaf.SLDTreeLeafLine#getStroke(org.opengis.style.Symbolizer)}.
*/
@Test
public void testGetStroke() {
SLDTreeLeafLine leaf = new SLDTreeLeafLine();
assertNull(leaf.getStroke(null));
PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
assertNull(leaf.getStroke(polygonSymbolizer));
LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
Stroke stroke = leaf.getStroke(lineSymbolizer);
assertEquals(stroke, lineSymbolizer.getStroke());
}
示例29
/**
* TODO summary sentence for setStroke ...
*
* @param line
* @param mode
* @param defaultColor
*/
public void setStroke(final Stroke aLine, final Mode mode, final Color defaultColor) {
listen(false);
try {
boolean enabled = true;
Stroke line = aLine;
if (line == null) {
final StyleBuilder builder = new StyleBuilder();
line = builder.createStroke(defaultColor);
enabled = false;
}
this.enabled = enabled && mode != Mode.NONE && line != null;
this.color = SLD.color(line);
this.width = SLD.width(line);
this.opacity = SLD.opacity(line);
// Stroke is used in line, point and polygon
this.on.setEnabled(mode != Mode.NONE);
this.chooser.setColor(this.color);
String text = MessageFormat.format("{0,number,#0}", this.width); //$NON-NLS-1$
this.size.setText(text);
this.size.select(this.size.indexOf(text));
text = MessageFormat.format("{0,number,#0%}", this.opacity); //$NON-NLS-1$
this.percent.setText(text);
this.percent.select(this.percent.indexOf(text));
this.on.setSelection(this.enabled);
this.chooser.setEnabled(this.enabled);
this.size.setEnabled(this.enabled);
this.percent.setEnabled(this.enabled);
} finally {
listen(true); // listen to user now
}
}
示例30
public void setWkMarkColorFill( String wkMarkColorFill ) {
this.wkMarkColorFill = wkMarkColorFill;
checkMarkExists();
if (wkMarkColorFill != null) {
Stroke markStroke = mark.getStroke();
markStroke.setColor(ff.literal(wkMarkColorFill));
}
}