Class ShapeFeatureStyle
ShapeFeatureRenderer layer.
ShapeFeatureStyle is a mutable configuration object intentionally
designed for fluent construction at the call site. Unlike the immutable
MapTheme, styles for individual layers are expected to be created
once per layer and not shared or modified afterward.
Per-geometry-type defaults
The defaults are chosen so that a style can be used with any geometry type without explicit configuration, but callers will almost always want to set at least the stroke or fill color to match their data:
- Fill color:
null— polygons are not filled by default. Set viafillColor(Color)for lakes, land cover, etc. - Stroke color:
Color.BLUE— a visible default for polylines such as rivers. Set viastrokeColor(Color). - Stroke width: 1.0 pt.
- Point radius: 3.0 screen pixels.
- Point color:
Color.RED. - Label field:
null— no labels drawn by default. - Antialiasing: enabled.
Usage
// Rivers — thin blue lines, no fill, no labels
ShapeFeatureStyle riverStyle = new ShapeFeatureStyle()
.strokeColor(new Color(0x6B9FD4))
.strokeWidth(0.8f);
// Lakes — filled blue polygons with a slightly darker border
ShapeFeatureStyle lakeStyle = new ShapeFeatureStyle()
.fillColor(new Color(0x6B9FD4))
.strokeColor(new Color(0x4A7FB5))
.strokeWidth(0.5f)
.labelField("name");
// Urban areas — semi-transparent fill, no border
ShapeFeatureStyle urbanStyle = new ShapeFeatureStyle()
.fillColor(new Color(180, 120, 80, 120))
.strokeColor(null);
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new style with all defaults applied.ShapeFeatureStyle(ShapeFeatureStyle source) Creates a copy of another shapefile style. -
Method Summary
Modifier and TypeMethodDescriptionantialias(boolean antialias) Enables or disables antialiased rendering for this layer.Returns aStrokebuilt from the currentgetStrokeWidth().feedbackFields(String... fields) Sets the.dbffield names whose values appear in the hit-test feedback, in the order given.Sets the fill color for polygon features.Returns an unmodifiable view of the feedback field names.Returns the polygon fill color, ornullif polygons are not filled.Returns the label text color.Returns the.dbffield name used for labels, ornullif labels are suppressed.Returns the point marker color.doubleReturns the point marker radius in screen pixels.Returns the stroke color for polygon outlines and polylines, ornullif stroking is suppressed.floatReturns the stroke width in points.Deprecated.booleanReturns whether antialiased rendering is enabled.labelColor(Color labelColor) Sets the color used to draw feature labels.labelField(String labelField) Sets the.dbffield name whose value is drawn as a label next to each feature.pointColor(Color pointColor) Sets the color of point marker dots.pointRadius(double pointRadius) Sets the radius of point marker dots in screen pixels.strokeColor(Color strokeColor) Sets the stroke color for polygon outlines and polylines.strokeWidth(float strokeWidth) Sets the stroke width in points for polygon outlines and polylines.tooltipFields(String... fields) Deprecated.usefeedbackFields(String...); these fields feed the map feedback and hover displays, not a Swing tooltip
-
Constructor Details
-
ShapeFeatureStyle
public ShapeFeatureStyle()Creates a new style with all defaults applied. See the class-level documentation for the default values. -
ShapeFeatureStyle
Creates a copy of another shapefile style.- Parameters:
source- source style; must not benull
-
-
Method Details
-
fillColor
Sets the fill color for polygon features.Pass
nullto skip polygon filling (outline only). The fill color may include an alpha channel for semi-transparent overlays:new Color(r, g, b, alpha).- Parameters:
fillColor- fill color, ornullfor no fill- Returns:
- this style, for chaining
-
strokeColor
Sets the stroke color for polygon outlines and polylines.Pass
nullto suppress stroking entirely. For polygons with a fill but no border, passnullhere and setfillColor(Color).- Parameters:
strokeColor- stroke color, ornullfor no stroke- Returns:
- this style, for chaining
-
strokeWidth
Sets the stroke width in points for polygon outlines and polylines.- Parameters:
strokeWidth- stroke width; clamped to a minimum of 0.1- Returns:
- this style, for chaining
-
pointColor
Sets the color of point marker dots.- Parameters:
pointColor- point color; must not benull- Returns:
- this style, for chaining
-
pointRadius
Sets the radius of point marker dots in screen pixels.- Parameters:
pointRadius- radius; clamped to a minimum of 0.5- Returns:
- this style, for chaining
-
labelField
Sets the.dbffield name whose value is drawn as a label next to each feature.Pass
nullto suppress labels. The field name is case-sensitive and must match a column in the shapefile's.dbftable. Common values for Natural Earth data:"name","NAME","name_en".- Parameters:
labelField- field name to use for labels, ornull- Returns:
- this style, for chaining
-
labelColor
Sets the color used to draw feature labels.- Parameters:
labelColor- label color; must not benull- Returns:
- this style, for chaining
-
feedbackFields
Sets the.dbffield names whose values appear in the hit-test feedback, in the order given.Replaces any previously configured feedback fields. Pass no arguments (or call with an empty array) to clear them. Example:
new ShapeFeatureStyle() .fillColor(new Color(0x6B9FD4)) .feedbackFields("name", "scalerank");- Parameters:
fields- zero or more.dbffield names (case-sensitive)- Returns:
- this style, for chaining
-
tooltipFields
Deprecated.usefeedbackFields(String...); these fields feed the map feedback and hover displays, not a Swing tooltipLegacy alias forfeedbackFields(String...).- Parameters:
fields- zero or more DBF field names- Returns:
- this style, for chaining
-
antialias
Enables or disables antialiased rendering for this layer.- Parameters:
antialias-trueto enable antialiasing (default)- Returns:
- this style, for chaining
-
getFillColor
Returns the polygon fill color, ornullif polygons are not filled.- Returns:
- fill color or
null
-
getStrokeColor
Returns the stroke color for polygon outlines and polylines, ornullif stroking is suppressed.- Returns:
- stroke color or
null
-
getStrokeWidth
public float getStrokeWidth()Returns the stroke width in points.- Returns:
- stroke width (≥ 0.1)
-
buildStroke
Returns aStrokebuilt from the currentgetStrokeWidth(). Convenience method used byShapeFeatureRenderer.- Returns:
- a
BasicStrokewith the configured width
-
getPointColor
Returns the point marker color.- Returns:
- point color; never
null
-
getPointRadius
public double getPointRadius()Returns the point marker radius in screen pixels.- Returns:
- point radius (≥ 0.5)
-
getLabelField
Returns the.dbffield name used for labels, ornullif labels are suppressed.- Returns:
- label field name or
null
-
getLabelColor
Returns the label text color.- Returns:
- label color; never
null
-
getFeedbackFields
Returns an unmodifiable view of the feedback field names.If empty, feedback falls back to
getLabelField()when set. If both are absent, no feature feedback is produced.- Returns:
- unmodifiable ordered list of feedback field names
-
getTooltipFields
Deprecated.Legacy alias forgetFeedbackFields().- Returns:
- unmodifiable ordered list of feedback field names
-
isAntialias
public boolean isAntialias()Returns whether antialiased rendering is enabled.- Returns:
trueif antialiasing is on
-
getFeedbackFields()