Class ProbabilityDistributionEditor<T>

Type Parameters:
T - category type
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class ProbabilityDistributionEditor<T> extends LinearMultiSlider<Double>
Editor for a distribution of probabilities of all possible categories. The probabilities must sum to 1.0.

Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
See Also:
  • Constructor Details

    • ProbabilityDistributionEditor

      public ProbabilityDistributionEditor(List<T> categories, double[] probabilities, int valuesPerPercent)
      Constructor.
      Parameters:
      categories - categories
      probabilities - probabilities
      valuesPerPercent - number of values the slider allows per percent
  • Method Details

    • mapIndexToValue

      protected Double mapIndexToValue(int index)
      Specified by:
      mapIndexToValue in class AbstractMultiSlider<Double>
    • setCategoryLabelFunction

      public void setCategoryLabelFunction(BiFunction<T,Double,String> labelfunction)
      Sets the label function. This function receives the category object and the probability in the normalized [0...1] range.
      Parameters:
      labelfunction - label function receiving the category object and the probability in the normalized [0...1] range
    • setCategoryFontSize

      public void setCategoryFontSize(float categoryFontSize)
      Set the font size for the category labels.
      Parameters:
      categoryFontSize - font size for the category labels
    • paint

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent
    • getProbabilities

      public double[] getProbabilities()
      Retrieve the current probability values.
      Returns:
      the probability values
    • getProbability

      public double getProbability(T t)
      Returns the probability of the given category.
      Parameters:
      t - category
      Returns:
      the probability of the given category
      Throws:
      IllegalArgumentException - if the category object is not part of the distribution
    • getProbability

      public double getProbability(int i)
      Returns the probability of category with given index.
      Parameters:
      i - category index
      Returns:
      the probability of category with given index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds