source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/server/FeaturesPanel.java@ 14259

Last change on this file since 14259 was 14259, checked in by Don-vip, 6 years ago

fix #16749 - don't disable unrelated text field in preferences dialog

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.server;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7
8import javax.swing.BorderFactory;
9import javax.swing.JCheckBox;
10import javax.swing.JLabel;
11import javax.swing.JPanel;
12
13import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
14import org.openstreetmap.josm.gui.widgets.JosmTextField;
15import org.openstreetmap.josm.io.MessageNotifier;
16import org.openstreetmap.josm.tools.GBC;
17
18/**
19 * Preferences panel for OSM messages notifier.
20 * @since 6349
21 */
22public class FeaturesPanel extends JPanel {
23
24 private JCheckBox notifier;
25 private JLabel intervalLabel;
26 private final JosmTextField notifierInterval = new JosmTextField(4);
27 private final JosmTextField notesDaysClosed = new JosmTextField(4);
28
29 /**
30 * Constructs a new {@code MessagesNotifierPanel}.
31 */
32 public FeaturesPanel() {
33 build();
34 initFromPreferences();
35 updateEnabledState();
36 }
37
38 private void build() {
39 setLayout(new GridBagLayout());
40 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
41
42 notifier = new JCheckBox(tr("Periodically check for new messages"));
43 add(notifier, GBC.eol());
44 notifier.addChangeListener(e -> updateEnabledState());
45
46 intervalLabel = new JLabel(tr("Check interval (minutes):"));
47 intervalLabel.setLabelFor(notifierInterval);
48 add(intervalLabel, GBC.std().insets(25, 0, 0, 0));
49
50 notifierInterval.setToolTipText(tr("Default value: {0}", MessageNotifier.PROP_INTERVAL.getDefaultValue()));
51 notifierInterval.setMinimumSize(notifierInterval.getPreferredSize());
52 add(notifierInterval, GBC.eol().insets(5, 0, 0, 0));
53
54 final JLabel notesDaysClosedLabel = new JLabel(tr("Max age for closed notes (days):"));
55 notesDaysClosedLabel.setLabelFor(notesDaysClosed);
56 notesDaysClosedLabel.setToolTipText(tr("Specifies the number of days a note needs to be closed to no longer be downloaded"));
57 add(notesDaysClosedLabel, GBC.std().insets(0, 20, 0, 0));
58 notesDaysClosed.setToolTipText(tr("Default value: {0}", DownloadNotesTask.DAYS_CLOSED.getDefaultValue()));
59 notesDaysClosed.setMinimumSize(notesDaysClosed.getPreferredSize());
60 add(notesDaysClosed, GBC.eol().insets(5, 20, 0, 0));
61 }
62
63 private void updateEnabledState() {
64 boolean enabled = notifier.isSelected();
65 intervalLabel.setEnabled(enabled);
66 notifierInterval.setEnabled(enabled);
67 notifierInterval.setEditable(enabled);
68 }
69
70 /**
71 * Initializes the panel from preferences
72 */
73 public final void initFromPreferences() {
74 notifier.setSelected(MessageNotifier.PROP_NOTIFIER_ENABLED.get());
75 notifierInterval.setText(Integer.toString(MessageNotifier.PROP_INTERVAL.get()));
76 notesDaysClosed.setText(Integer.toString(DownloadNotesTask.DAYS_CLOSED.get()));
77 }
78
79 /**
80 * Saves the current values to preferences
81 */
82 public void saveToPreferences() {
83 final boolean enabled = notifier.isSelected();
84 boolean changed = MessageNotifier.PROP_NOTIFIER_ENABLED.put(enabled);
85 changed |= MessageNotifier.PROP_INTERVAL.parseAndPut(notifierInterval.getText());
86 changed |= DownloadNotesTask.DAYS_CLOSED.parseAndPut(notesDaysClosed.getText());
87 // If parameters have changed, restart notifier
88 if (changed) {
89 MessageNotifier.stop();
90 if (enabled) {
91 MessageNotifier.start();
92 }
93 } else {
94 // Even if they have not changed, notifier should be stopped if user is no more identified enough
95 if (!MessageNotifier.isUserEnoughIdentified()) {
96 MessageNotifier.stop();
97 } else if (enabled && !MessageNotifier.isRunning()) {
98 // or restarted if user is again identified and notifier was enabled in preferences
99 MessageNotifier.start();
100 }
101 }
102 }
103}
Note: See TracBrowser for help on using the repository browser.