source: src/main/java/genius/gui/deadline/DeadlinePanel.java@ 346

Last change on this file since 346 was 199, checked in by Tim Baarslag, 5 years ago

60s timeout default

File size: 2.1 KB
RevLine 
[1]1package genius.gui.deadline;
2
3import java.awt.BorderLayout;
4import java.awt.Component;
5import java.awt.Dimension;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8
9import javax.swing.JComboBox;
10import javax.swing.JLabel;
11import javax.swing.JPanel;
12import javax.swing.JSpinner;
13import javax.swing.SpinnerNumberModel;
14import javax.swing.event.ChangeEvent;
15import javax.swing.event.ChangeListener;
16
17import genius.core.DeadlineType;
18import genius.core.listener.Listener;
19
20/**
21 * panel allowing user to set the deadline.
22 *
23 * @author W.Pasman
24 *
25 */
26@SuppressWarnings("serial")
27public class DeadlinePanel extends JPanel {
[199]28 private final SpinnerNumberModel valuemodel = new SpinnerNumberModel(60, 1,
[8]29 10000, 10);
[1]30 private JSpinner spinner = new JSpinner(valuemodel);
[8]31 private JComboBox<DeadlineType> combobox = new JComboBox<DeadlineType>(
32 DeadlineType.values());
[1]33 private JLabel label = new JLabel("Deadline");
34 private DeadlineModel model;
35
36 public DeadlinePanel(final DeadlineModel model) {
37 if (model == null)
38 throw new NullPointerException("model");
39 this.model = model;
40 setLayout(new BorderLayout());
[8]41 label.setPreferredSize(new Dimension(120, 10));
[1]42 add(label, BorderLayout.WEST);
43 add(spinner, BorderLayout.CENTER);
44 add(combobox, BorderLayout.EAST);
45 setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
46 setAlignmentX(Component.RIGHT_ALIGNMENT);
47
48 syncWithModel();
49
50 spinner.addChangeListener(new ChangeListener() {
51 @Override
52 public void stateChanged(ChangeEvent e) {
53 model.setValue((Integer) valuemodel.getValue());
54 }
55 });
56 combobox.addActionListener(new ActionListener() {
57 @Override
58 public void actionPerformed(ActionEvent e) {
59 model.setType((DeadlineType) combobox.getSelectedItem());
60 }
61 });
62
63 model.addListener(new Listener<DeadlineModel>() {
64
65 @Override
66 public void notifyChange(DeadlineModel data) {
67 syncWithModel();
68 }
69
70 });
71 }
72
73 /**
74 * Sync panel with the model.
75 */
76 private void syncWithModel() {
77 spinner.setValue(model.getDeadline().getValue());
78 combobox.setSelectedItem(model.getDeadline().getType());
79 }
80
81}
Note: See TracBrowser for help on using the repository browser.