averbraeck / djutils

Delft Java Utilities for statistics, stochastics, data analysis and serialization
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Create and test `MultiSlider` with categorial and floating point values #69

Open averbraeck opened 2 hours ago

averbraeck commented 2 hours ago

Currently, MultiSlider accepts only int values, but it is often used in situations where other scales might be needed, such as a categorial scale, a floating point scale, or a scale using a djunits quantity. In a sense, we want a MultiSlider<T> where T indicates the type that can be set on the ticks of the MultiSlider.

This can either be an extension of the current MultiSlider class, or the MultiSlider can be made generic itself.

averbraeck commented 2 hours ago

An example what a constructor could look like is:

Integer, where the second value 100 indicates the number of ticks on the scale:

new MultiSlider<Integer>(SwingConstants.HORIZONTAL, 0, 100, 100, new int[] {25, 50, 75});

Double, where the value 200 indicates the number of ticks on the scale:

new MultiSlider<Double>(SwingConstants.HORIZONTAL, 0.0, 100.0, 200, 
        new double[] {25.0, 50.0, 75.0});

Map<Integer, String> where the integers are the ticks and the strings the values:

var sliderMap = new HashMap<Integer, String>();
sliderMap.add(1, "A");
sliderMap.add(2, "B");
sliderMap.add(3, "C");
sliderMap.add(4, "D");
sliderMap.add(5, "E");
sliderMap.add(6, "F");
new MultiSlider<String>(SwingConstants.HORIZONTAL, sliderMap, new String[] {"A", "D");