[3461] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[4968] | 2 | package org.openstreetmap.josm.gui.preferences.map;
|
---|
[3461] | 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.GridBagLayout;
|
---|
| 7 | import java.awt.event.ActionEvent;
|
---|
| 8 | import java.awt.event.ActionListener;
|
---|
| 9 |
|
---|
| 10 | import javax.swing.BorderFactory;
|
---|
| 11 | import javax.swing.Box;
|
---|
| 12 | import javax.swing.JCheckBox;
|
---|
| 13 | import javax.swing.JLabel;
|
---|
| 14 | import javax.swing.JPanel;
|
---|
| 15 | import javax.swing.JScrollPane;
|
---|
| 16 | import javax.swing.JSeparator;
|
---|
| 17 |
|
---|
| 18 | import org.openstreetmap.josm.data.AutosaveTask;
|
---|
| 19 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
[4968] | 20 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
| 21 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
| 22 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
| 23 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
[3461] | 24 | import org.openstreetmap.josm.gui.widgets.HtmlPanel;
|
---|
[6357] | 25 | import org.openstreetmap.josm.gui.widgets.JosmTextField;
|
---|
[3461] | 26 | import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
|
---|
| 27 | import org.openstreetmap.josm.tools.GBC;
|
---|
| 28 |
|
---|
[4968] | 29 | public 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 | }
|
---|