Class ShapeFeatureStyle

java.lang.Object
edu.cnu.mdi.mapping.shapefile.ShapeFeatureStyle

public final class ShapeFeatureStyle extends Object
Configures the visual appearance of a 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 via fillColor(Color) for lakes, land cover, etc.
  • Stroke color: Color.BLUE — a visible default for polylines such as rivers. Set via strokeColor(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 Details

    • ShapeFeatureStyle

      public ShapeFeatureStyle()
      Creates a new style with all defaults applied. See the class-level documentation for the default values.
    • ShapeFeatureStyle

      public ShapeFeatureStyle(ShapeFeatureStyle source)
      Creates a copy of another shapefile style.
      Parameters:
      source - source style; must not be null
  • Method Details

    • fillColor

      public ShapeFeatureStyle fillColor(Color fillColor)
      Sets the fill color for polygon features.

      Pass null to 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, or null for no fill
      Returns:
      this style, for chaining
    • strokeColor

      public ShapeFeatureStyle strokeColor(Color strokeColor)
      Sets the stroke color for polygon outlines and polylines.

      Pass null to suppress stroking entirely. For polygons with a fill but no border, pass null here and set fillColor(Color).

      Parameters:
      strokeColor - stroke color, or null for no stroke
      Returns:
      this style, for chaining
    • strokeWidth

      public ShapeFeatureStyle strokeWidth(float 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

      public ShapeFeatureStyle pointColor(Color pointColor)
      Sets the color of point marker dots.
      Parameters:
      pointColor - point color; must not be null
      Returns:
      this style, for chaining
    • pointRadius

      public ShapeFeatureStyle pointRadius(double 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

      public ShapeFeatureStyle labelField(String labelField)
      Sets the .dbf field name whose value is drawn as a label next to each feature.

      Pass null to suppress labels. The field name is case-sensitive and must match a column in the shapefile's .dbf table. Common values for Natural Earth data: "name", "NAME", "name_en".

      Parameters:
      labelField - field name to use for labels, or null
      Returns:
      this style, for chaining
    • labelColor

      public ShapeFeatureStyle labelColor(Color labelColor)
      Sets the color used to draw feature labels.
      Parameters:
      labelColor - label color; must not be null
      Returns:
      this style, for chaining
    • feedbackFields

      public ShapeFeatureStyle feedbackFields(String... fields)
      Sets the .dbf field 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 .dbf field names (case-sensitive)
      Returns:
      this style, for chaining
    • tooltipFields

      @Deprecated public ShapeFeatureStyle tooltipFields(String... fields)
      Deprecated.
      use feedbackFields(String...); these fields feed the map feedback and hover displays, not a Swing tooltip
      Legacy alias for feedbackFields(String...).
      Parameters:
      fields - zero or more DBF field names
      Returns:
      this style, for chaining
    • antialias

      public ShapeFeatureStyle antialias(boolean antialias)
      Enables or disables antialiased rendering for this layer.
      Parameters:
      antialias - true to enable antialiasing (default)
      Returns:
      this style, for chaining
    • getFillColor

      public Color getFillColor()
      Returns the polygon fill color, or null if polygons are not filled.
      Returns:
      fill color or null
    • getStrokeColor

      public Color getStrokeColor()
      Returns the stroke color for polygon outlines and polylines, or null if stroking is suppressed.
      Returns:
      stroke color or null
    • getStrokeWidth

      public float getStrokeWidth()
      Returns the stroke width in points.
      Returns:
      stroke width (≥ 0.1)
    • buildStroke

      public Stroke buildStroke()
      Returns a Stroke built from the current getStrokeWidth(). Convenience method used by ShapeFeatureRenderer.
      Returns:
      a BasicStroke with the configured width
    • getPointColor

      public Color 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

      public String getLabelField()
      Returns the .dbf field name used for labels, or null if labels are suppressed.
      Returns:
      label field name or null
    • getLabelColor

      public Color getLabelColor()
      Returns the label text color.
      Returns:
      label color; never null
    • getFeedbackFields

      public List<String> 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 public List<String> getTooltipFields()
      Deprecated.
      Legacy alias for getFeedbackFields().
      Returns:
      unmodifiable ordered list of feedback field names
    • isAntialias

      public boolean isAntialias()
      Returns whether antialiased rendering is enabled.
      Returns:
      true if antialiasing is on