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

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

fix #5382 - add an option to display a notification at each autosave (disabled by default)

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