source: src/main/java/genius/gui/panels/SliderPanel.java@ 345

Last change on this file since 345 was 95, checked in by Wouter Pasman, 6 years ago

#28 isLocked now reflected in GUI appearance of boolean and integer values.

File size: 1.5 KB
Line 
1package genius.gui.panels;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5
6import javax.swing.JLabel;
7import javax.swing.JPanel;
8import javax.swing.JSlider;
9import javax.swing.JSpinner;
10
11import genius.core.listener.Listener;
12
13/**
14 * Shows slider plus spinner with optional ticks, optionally logarithmic, and
15 * optionally with percentages
16 *
17 */
18@SuppressWarnings("serial")
19public class SliderPanel extends JPanel {
20 private IntegerModel model;
21 private JSlider slider;
22 private JLabel label;
23 private JSpinner spinner;
24
25 public SliderPanel(String name, IntegerModel m) {
26 model = m;
27 setLayout(new BorderLayout());
28 label = new JLabel(name);
29 add(label, BorderLayout.WEST);
30
31 slider = new JSlider(new IntegerToBoundeRangeAdapter(model));
32 add(slider, BorderLayout.CENTER);
33 spinner = new JSpinner(model.getSpinnerModel());
34 spinner.setMaximumSize(new Dimension(300, 30));
35 add(spinner, BorderLayout.EAST);
36
37 // connect model->enabled to GUI appearance.
38 model.addListener(new Listener<Integer>() {
39 @Override
40 public void notifyChange(Integer data) {
41 updateEnabledness();
42 }
43
44 });
45 updateEnabledness();
46 }
47
48 /**
49 *
50 * @return the slider part. Used for testing, you should not need this and
51 * communicate through the model you provided.
52 */
53 public JSlider getSlider() {
54 return slider;
55 }
56
57 private void updateEnabledness() {
58 boolean enabled = !model.isLocked();
59 setEnabled(enabled);
60 label.setEnabled(enabled);
61 slider.setEnabled(enabled);
62 spinner.setEnabled(enabled);
63 }
64
65}
Note: See TracBrowser for help on using the repository browser.