[87] | 1 | package genius.gui.panels;
|
---|
| 2 |
|
---|
| 3 | import java.awt.BorderLayout;
|
---|
| 4 | import java.awt.Dimension;
|
---|
| 5 |
|
---|
| 6 | import javax.swing.JLabel;
|
---|
| 7 | import javax.swing.JPanel;
|
---|
| 8 | import javax.swing.JSlider;
|
---|
| 9 | import javax.swing.JSpinner;
|
---|
| 10 |
|
---|
[93] | 11 | import genius.core.listener.Listener;
|
---|
| 12 |
|
---|
[87] | 13 | /**
|
---|
[89] | 14 | * Shows slider plus spinner with optional ticks, optionally logarithmic, and
|
---|
| 15 | * optionally with percentages
|
---|
[87] | 16 | *
|
---|
| 17 | */
|
---|
[89] | 18 | @SuppressWarnings("serial")
|
---|
[87] | 19 | public class SliderPanel extends JPanel {
|
---|
[95] | 20 | private IntegerModel model;
|
---|
[88] | 21 | private JSlider slider;
|
---|
[95] | 22 | private JLabel label;
|
---|
| 23 | private JSpinner spinner;
|
---|
[88] | 24 |
|
---|
[95] | 25 | public SliderPanel(String name, IntegerModel m) {
|
---|
| 26 | model = m;
|
---|
[87] | 27 | setLayout(new BorderLayout());
|
---|
[95] | 28 | label = new JLabel(name);
|
---|
[93] | 29 | add(label, BorderLayout.WEST);
|
---|
[87] | 30 |
|
---|
[92] | 31 | slider = new JSlider(new IntegerToBoundeRangeAdapter(model));
|
---|
[88] | 32 | add(slider, BorderLayout.CENTER);
|
---|
[95] | 33 | spinner = new JSpinner(model.getSpinnerModel());
|
---|
[87] | 34 | spinner.setMaximumSize(new Dimension(300, 30));
|
---|
| 35 | add(spinner, BorderLayout.EAST);
|
---|
[93] | 36 |
|
---|
| 37 | // connect model->enabled to GUI appearance.
|
---|
| 38 | model.addListener(new Listener<Integer>() {
|
---|
| 39 | @Override
|
---|
| 40 | public void notifyChange(Integer data) {
|
---|
[95] | 41 | updateEnabledness();
|
---|
[93] | 42 | }
|
---|
[95] | 43 |
|
---|
[93] | 44 | });
|
---|
[95] | 45 | updateEnabledness();
|
---|
[87] | 46 | }
|
---|
| 47 |
|
---|
[88] | 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 |
|
---|
[95] | 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 |
|
---|
[87] | 65 | }
|
---|