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

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

checkstyle - Comments Indentation

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