source: src/main/java/genius/gui/uncertainty/SteppingSlider.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.1 KB
Line 
1package genius.gui.uncertainty;
2
3import java.util.Arrays;
4import java.util.Hashtable;
5
6import javax.swing.JLabel;
7import javax.swing.JSlider;
8
9public class SteppingSlider extends JSlider
10{
11 private static final long serialVersionUID = -1195270044097152629L;
12 private Integer[] values = { 10, 30, 60, 100 };
13 private final Hashtable<Integer, JLabel> LABELS = new Hashtable<>();
14
15
16 public SteppingSlider(Integer...allvalues)
17 {
18 super(0, allvalues.length - 1, 0);
19 values = allvalues;
20 for(int i = 0; i < values.length; ++i)
21 {
22 LABELS.put(i, new JLabel(values[i].toString()));
23 }
24 setLabelTable(LABELS);
25 setPaintTicks(true);
26 setPaintLabels(true);
27 setSnapToTicks(true);
28 setMajorTickSpacing(1);
29 }
30
31 public int getDomainValue()
32 {
33 return values[getValue()];
34 }
35
36 public void setDomainValue(int val)
37 {
38 int binarySearch = Arrays.binarySearch(values, val);
39 int index = binarySearch >= 0 ? binarySearch : -binarySearch - 1; // insertion point
40 setValue(index);
41 }
42}
Note: See TracBrowser for help on using the repository browser.