source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/map/BackupPreference.java@ 17281

Last change on this file since 17281 was 17281, checked in by Klumbumbus, 3 years ago
  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.map;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.awt.event.ActionListener;
8
9import javax.swing.BorderFactory;
10import javax.swing.Box;
11import javax.swing.JCheckBox;
12import javax.swing.JLabel;
13import javax.swing.JPanel;
14import javax.swing.JSeparator;
15
16import org.openstreetmap.josm.data.preferences.BooleanProperty;
17import org.openstreetmap.josm.gui.layer.AutosaveTask;
18import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
19import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
20import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
21import org.openstreetmap.josm.gui.widgets.HtmlPanel;
22import org.openstreetmap.josm.gui.widgets.JosmTextField;
23import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
24import org.openstreetmap.josm.tools.GBC;
25
26/**
27 * Preference settings for data layer autosave.
28 */
29public class BackupPreference extends DefaultTabPreferenceSetting {
30
31 /**
32 * Factory used to create a new {@code BackupPreference}.
33 */
34 public static class Factory implements PreferenceSettingFactory {
35 @Override
36 public BackupPreference createPreferenceSetting() {
37 return new BackupPreference();
38 }
39 }
40
41 private static final BooleanProperty PROP_KEEP_BACKUP = new BooleanProperty("save.keepbackup", false);
42 private JCheckBox notification;
43 private JCheckBox keepBackup;
44 private JCheckBox autosave;
45 private final JosmTextField autosaveInterval = new JosmTextField(8);
46 private final JosmTextField backupPerLayer = new JosmTextField(8);
47
48 BackupPreference() {
49 super(/* ICON(preferences/) */ "backup", tr("File backup"), tr("Configure whether to create backup files"));
50 }
51
52 @Override
53 public void addGui(PreferenceTabbedPane gui) {
54 JPanel panel = new VerticallyScrollablePanel(new GridBagLayout());
55 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
56
57 autosave = new JCheckBox(tr("Auto save enabled"));
58 autosave.setSelected(AutosaveTask.PROP_AUTOSAVE_ENABLED.get());
59 panel.add(autosave, GBC.eol());
60
61 final JLabel autosaveIntervalLabel = new JLabel(tr("Auto save interval (seconds)"));
62 autosaveIntervalLabel.setLabelFor(autosaveInterval);
63 panel.add(autosaveIntervalLabel, GBC.std().insets(60, 0, 0, 0));
64 autosaveInterval.setText(Integer.toString(AutosaveTask.PROP_INTERVAL.get()));
65 autosaveInterval.setToolTipText(tr("Default value: {0}", AutosaveTask.PROP_INTERVAL.getDefaultValue()));
66 autosaveInterval.setMinimumSize(autosaveInterval.getPreferredSize());
67 panel.add(autosaveInterval, GBC.eol().insets(5, 0, 0, 5));
68
69 final JLabel backupPerLayerLabel = new JLabel(tr("Auto saved files per layer"));
70 backupPerLayerLabel.setLabelFor(backupPerLayer);
71 panel.add(backupPerLayerLabel, GBC.std().insets(60, 0, 0, 0));
72 backupPerLayer.setText(Integer.toString(AutosaveTask.PROP_FILES_PER_LAYER.get()));
73 backupPerLayer.setToolTipText(tr("Default value: {0}", AutosaveTask.PROP_FILES_PER_LAYER.getDefaultValue()));
74 backupPerLayer.setMinimumSize(backupPerLayer.getPreferredSize());
75 panel.add(backupPerLayer, GBC.eol().insets(5, 0, 0, 10));
76
77 panel.add(new HtmlPanel(
78 tr("<i>(Autosave stores the changed data layers in periodic intervals. " +
79 "The backups are saved in JOSM''s preference folder. " +
80 "In case of a crash, JOSM tries to recover the unsaved changes " +
81 "on next start.)</i>")),
82 GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 10));
83
84 panel.add(new JSeparator(), GBC.eop().fill(GBC.HORIZONTAL));
85
86 keepBackup = new JCheckBox(tr("Keep backup files when saving data layers"));
87 keepBackup.setSelected(PROP_KEEP_BACKUP.get());
88 keepBackup.setToolTipText(tr("When saving, keep backup files ending with a ~"));
89 panel.add(keepBackup, GBC.eop());
90
91 panel.add(new HtmlPanel(
92 tr("<i>(JOSM can keep a backup file when saving data layers. "+
93 "It appends ''~'' to the file name and saves it in the same folder.)</i>")),
94 GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0));
95
96 panel.add(new JSeparator(), GBC.eop().fill(GBC.HORIZONTAL));
97
98 notification = new JCheckBox(tr("Notification at each save"));
99 notification.setSelected(AutosaveTask.PROP_NOTIFICATION.get());
100 notification.setToolTipText(tr("When saving, display a small notification"));
101 panel.add(notification, GBC.eop());
102
103 ActionListener autosaveEnabled = e -> {
104 boolean enabled = autosave.isSelected();
105 autosaveIntervalLabel.setEnabled(enabled);
106 autosaveInterval.setEnabled(enabled);
107 backupPerLayerLabel.setEnabled(enabled);
108 backupPerLayer.setEnabled(enabled);
109 };
110 autosave.addActionListener(autosaveEnabled);
111 autosaveEnabled.actionPerformed(null);
112
113 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
114 gui.createPreferenceTab(this).add(panel, GBC.eol().fill(GBC.BOTH));
115 }
116
117 @Override
118 public boolean ok() {
119 boolean restartRequired = false;
120 PROP_KEEP_BACKUP.put(keepBackup.isSelected());
121
122 restartRequired |= AutosaveTask.PROP_AUTOSAVE_ENABLED.put(autosave.isSelected());
123 restartRequired |= AutosaveTask.PROP_INTERVAL.parseAndPut(autosaveInterval.getText());
124 AutosaveTask.PROP_FILES_PER_LAYER.parseAndPut(backupPerLayer.getText());
125 AutosaveTask.PROP_NOTIFICATION.put(notification.isSelected());
126 return restartRequired;
127 }
128
129 @Override
130 public boolean isExpert() {
131 return false;
132 }
133
134}
Note: See TracBrowser for help on using the repository browser.