Class StrokeChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class StrokeChooser extends JPanel

The StrokeChooser class is a panel that displays line dash pattern and thickness controls to allow the user to select the line stroke. When the user selects a stroke, a property change event is fired whose property is given by STROKE_PROPERTY.

The chooser has some limitations in the line stroke. Only Stroke objects of type BasicStroke may be used, and must have an integer line thicknesses and the dash pattern given by an element of the DASH_PATTERNS array.

Since:
3.1.7
Author:
Peter Hollemans
See Also:
  • Field Details

    • STROKE_PROPERTY

      public static String STROKE_PROPERTY
      The stroke property.
    • DASH_PATTERNS

      public static final float[][] DASH_PATTERNS
      The line stroke dash patterns.
  • Constructor Details

    • StrokeChooser

      public StrokeChooser()
      Creates a new stroke chooser. A simple line stroke with line thickness 1 and no dashes is used initially.
    • StrokeChooser

      public StrokeChooser(Stroke stroke)
      Creates a new stroke chooser with the specified initial stroke.
      Parameters:
      stroke - the initial stroke for the main stroke chooser. If null, a simple line stroke with line thickness 1 and no dashes is used.
  • Method Details

    • getDashPattern

      public float[] getDashPattern(BasicStroke stroke)
      Gets the dash pattern from this chooser that corresponds to the dash pattern in the specified stroke. Generally, this requires that the stroke was obtained from this chooser.
      Parameters:
      stroke - the stroke to search.
      Returns:
      the dash pattern array, or null if not found.
    • getBasicStroke

      public static Stroke getBasicStroke(int lineWidth, float[] dashPattern)
      Creates a new stroke object of the specified line width and dash pattern index. In order for the resulting stroke to be compatible with the stroke chooser, the line width must be in the range [1..10] and the dash pattern must be an entry in the DASH_PATTERNS array.
      Parameters:
      lineWidth - the line width.
      dashPattern - a dash pattern from the DASH_PATTERNS array.
      Returns:
      a new stroke object.
    • getStroke

      public Stroke getStroke()
      Gets the stroke selected by this stroke chooser.
    • setStroke

      public void setStroke(Stroke newStroke)
      Sets the stroke selected by this stroke chooser. The stroke may be null, in which case this method has no effect. The stroke must be a stroke object obtained from the getBasicStroke() method in order to be compatible with the chooser.
    • main

      public static void main(String[] argv)
      Tests this class.
      Parameters:
      argv - the array of command line parameters.