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

Last change on this file since 4067 was 3716, checked in by bastiK, 13 years ago

applied #5731 (patch by Claudius Henrichs) - Missing translation for auto save enabled

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