Changeset 3461 in josm for trunk


Ignore:
Timestamp:
2010-08-24T10:32:50+02:00 (14 years ago)
Author:
bastiK
Message:

added gui preference for autosave; fixed #5359 - Button to delete autosaved data

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r3435 r3461  
    2525import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
    2626import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter.Listener;
     27import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2728import org.openstreetmap.josm.data.preferences.IntegerProperty;
    2829import org.openstreetmap.josm.gui.MapView;
     
    4142    private static final String DELETED_LAYERS_DIR = "autosave/deleted_layers";
    4243
    43 
     44    public static final BooleanProperty PROP_AUTOSAVE_ENABLED = new BooleanProperty("autosave.enabled", true);
    4445    public static final IntegerProperty PROP_FILES_PER_LAYER = new IntegerProperty("autosave.filesPerLayer", 1);
    4546    public static final IntegerProperty PROP_DELETED_LAYERS = new IntegerProperty("autosave.deletedLayersBackupCount", 5);
    4647    public static final IntegerProperty PROP_INTERVAL = new IntegerProperty("autosave.interval", 5 * 60);
     48    public static final IntegerProperty PROP_INDEX_LIMIT = new IntegerProperty("autosave.index-limit", 1000);
    4749
    4850    private static class AutosaveLayerInfo {
     
    5961    private final List<AutosaveLayerInfo> layersInfo = new ArrayList<AutosaveLayerInfo>();
    6062    private Timer timer;
    61     private Object layersLock = new Object();
     63    private final Object layersLock = new Object();
    6264    private final Deque<File> deletedLayers = new LinkedList<File>();
    6365
     
    136138                else {
    137139                    System.out.println(tr("Unable to create file {0}, other filename will be used", result.getAbsolutePath()));
     140                    if (index > PROP_INDEX_LIMIT.get())
     141                        throw new IOException("index limit exceeded");
    138142                }
    139143            } catch (IOException e) {
     
    278282    }
    279283
     284    public void dicardUnsavedLayers() {
     285        for (File f: getUnsavedLayersFiles()) {
     286            f.renameTo(new File(deletedLayersDir, f.getName()));
     287        }
     288    }
    280289
    281290}
  • trunk/src/org/openstreetmap/josm/data/preferences/IntegerProperty.java

    r3451 r3461  
    2222    }
    2323
     24    /**
     25     * parses and saves an integer value
     26     * @param value the value to be parsed
     27     * @return true - preference value has changed
     28     *         false - parsing failed or preference value has not changed
     29     */
     30    public boolean parseAndPut(String value) {
     31        Integer intVal;
     32        try {
     33            intVal = Integer.parseInt(value);
     34        } catch (NumberFormatException ex) {
     35            return false;
     36        }
     37        return put(intVal);
     38    }
     39
    2440    public String getKey() {
    2541        return key;
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r3435 r3461  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    56
    67import java.awt.EventQueue;
     
    247248        }
    248249
    249         AutosaveTask autosaveTask = new AutosaveTask();
    250         List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles();
    251         if (!unsavedLayerFiles.isEmpty()) {
    252             ExtendedDialog dialog = new ExtendedDialog(
    253                     Main.parent,
    254                     tr("Unsaved osm data"),
    255                     new String[] {tr("Restore"), tr("Cancel")}
    256             );
    257             dialog.setContent(tr("JOSM found {0} unsaved osm data layers. It looks like JOSM crashed last time. Do you want to restore data?",
    258                     unsavedLayerFiles.size()));
    259             dialog.setButtonIcons(new String[] {"ok.png", "cancel.png"});
    260             dialog.showDialog();
    261             if (dialog.getValue() == 1) {
    262                 for (OsmDataLayer layer: autosaveTask.getUnsavedLayers()) {
    263                     Main.main.addLayer(layer);
     250        if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) {
     251            AutosaveTask autosaveTask = new AutosaveTask();
     252            List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles();
     253            if (!unsavedLayerFiles.isEmpty()) {
     254                ExtendedDialog dialog = new ExtendedDialog(
     255                        Main.parent,
     256                        tr("Unsaved osm data"),
     257                        new String[] {tr("Restore"), tr("Cancel"), tr("Discard")}
     258                );
     259                dialog.setContent(
     260                        trn("JOSM found {0} unsaved osm data layer. ",
     261                        "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) +
     262                        tr("It looks like JOSM crashed last time. Do you like to restore the data?"));
     263                dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/remove"});
     264                int selection = dialog.showDialog().getValue();
     265                if (selection == 1) {
     266                    for (OsmDataLayer layer: autosaveTask.getUnsavedLayers()) {
     267                        Main.main.addLayer(layer);
     268                    }
     269                    AutoScaleAction.autoScale("data");
     270                } else if (selection == 3) {
     271                    autosaveTask.dicardUnsavedLayers();
    264272                }
    265                 AutoScaleAction.autoScale("data");
    266             }
    267 
    268 
    269         }
    270         autosaveTask.schedule();
     273            }
     274            autosaveTask.schedule();
     275        }
    271276
    272277
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r3321 r3461  
    7878                    WindowGeometry.centerInWindow(
    7979                            getParent(),
    80                             new Dimension(600,800)
     80                            new Dimension(700,800)
    8181                    )
    8282            ).applySafe(this);
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r3321 r3461  
    268268        settingsFactory.add(new MapPaintPreference.Factory());
    269269        settingsFactory.add(new TaggingPresetPreference.Factory());
     270        settingsFactory.add(new BackupPreference.Factory());
    270271        if(!Main.applet) {
    271272            settingsFactory.add(new PluginPreference.Factory());
  • trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

    r3406 r3461  
    2929import org.openstreetmap.josm.data.projection.ProjectionSubPrefs;
    3030import org.openstreetmap.josm.gui.NavigatableComponent;
     31import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
    3132import org.openstreetmap.josm.tools.GBC;
    3233
     
    107108     * This is the panel holding all projection preferences
    108109     */
    109     private JPanel projPanel = new JPanel();
     110    private JPanel projPanel = new VerticallyScrollablePanel();
    110111
    111112    /**
  • trunk/src/org/openstreetmap/josm/gui/preferences/ServerAccessPreference.java

    r2801 r3461  
    3636    private ProxyPreferencesPanel pnlProxyPreferences;
    3737    /** panel for backup preferences */
    38     private BackupPreferencesPanel pnlBackupPreferences;
    3938
    4039    /**
     
    6362        pnlProxyPreferences = new ProxyPreferencesPanel();
    6463        tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlProxyPreferences));
    65         pnlBackupPreferences = new BackupPreferencesPanel();
    66         tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlBackupPreferences));
    6764
    6865        tpServerPreferences.setTitleAt(0, tr("Authentication"));
    6966        tpServerPreferences.setTitleAt(1, tr("Proxy settings"));
    70         tpServerPreferences.setTitleAt(2, tr("File backup"));
    7167        tpServerPreferences.setToolTipTextAt(0, tr("Configure your identity and how to authenticate at the OSM server"));
    7268        tpServerPreferences.setToolTipTextAt(1, tr("Configure whether to use a proxy server"));
    73         tpServerPreferences.setToolTipTextAt(2, tr("Configure whether to create backup files"));
    7469
    7570        pnl.add(tpServerPreferences, BorderLayout.CENTER);
     
    127122        pnlAuthPreferences.initFromPreferences();
    128123        pnlProxyPreferences.initFromPreferences();
    129         pnlBackupPreferences.initFromPreferences();
    130124    }
    131125
     
    137131        pnlAuthPreferences.saveToPreferences();
    138132        pnlProxyPreferences.saveToPreferences();
    139         pnlBackupPreferences.saveToPreferences();
    140133        return false;
    141134    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/HtmlPanel.java

    r3083 r3461  
    1313
    1414/**
    15  * This panel can be used to display larger larger sections of formatted text in
     15 * This panel can be used to display larger sections of formatted text in
    1616 * HTML.
    1717 *
     
    6161    }
    6262
     63    public HtmlPanel(String text) {
     64        this();
     65        setText(text);
     66    }
     67
    6368    /**
    6469     * Replies the editor pane used internally to render the HTML text.
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r3378 r3461  
    7979            }
    8080            // FIXME - how to close?
    81             if (!Main.pref.getBoolean("save.keepbackup") && (tmpFile != null)) {
     81            if (!Main.pref.getBoolean("save.keepbackup", false) && (tmpFile != null)) {
    8282                tmpFile.delete();
    8383            }
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r3433 r3461  
    118118
    119119    /**
    120      * Set by MainApplication. Changes here later will probably mess up everything, because
    121      * many strings are already loaded.
     120     * Translates some text for the current locale.
     121     * These strings are collected by a script that runs on the source code files.
     122     * After translation, the localizations are distributed with the main program.
     123     *
     124     * @param text the text to translate.
     125     * Must be a string literal. (No constants or local vars.)
     126     * Can be broken over multiple lines.
     127     * An apostrophe ' must be quoted by another apostrophe.
     128     * @param objects Parameters for the string.
     129     * Mark occurrences in <code>text</code> with {0}, {1}, ...
     130     * @return the translated string
     131     *
     132     * Example: tr("JOSM''s default value is ''{0}''.", val);
    122133     */
    123134    public static final String tr(String text, Object... objects) {
     
    131142    }
    132143
    133     public static final String trc(String ctx, String text) {
    134         if (ctx == null)
     144    /**
     145     * Provide translation in a context.
     146     * There can be different translations for the same text (but
     147     * different context).
     148     *
     149     * @param context string that helps translators to find an appropriate
     150     * translation for <code>text</code>
     151     * @param text the text to translate
     152     * @return the translated string
     153     */
     154    public static final String trc(String context, String text) {
     155        if (context == null)
    135156            return tr(text);
    136157        if (text == null)
    137158            return null;
    138         return MessageFormat.format(gettext(text, ctx), (Object)null);
    139     }
    140 
    141     /* NOTE: marktr does NOT support context strings - use marktrc instead */
     159        return MessageFormat.format(gettext(text, context), (Object)null);
     160    }
     161
     162    /**
     163     * Marks a string for translation (such that a script can harvest
     164     * the translatable strings from the source files).
     165     *
     166     * Example:
     167     * String[] options = new String[] {marktr("up"), marktr("down")};
     168     * lbl.setText(tr(options[0]));
     169     */
    142170    public static final String marktr(String text) {
    143171        return text;
     
    148176    }
    149177
     178    /**
     179     * Example: trn("Found {0} error!", "Found {0} errors!", i, Integer.toString(i));
     180     */
    150181    public static final String trn(String text, String pluralText, long n, Object... objects) {
    151182        return MessageFormat.format(gettextn(text, pluralText, null, n), objects);
    152183    }
    153184
     185    /**
     186     * Example: trn("There was an error!", "There were errors!", i);
     187     */
    154188    public static final String trn(String text, String pluralText, long n) {
    155189        return MessageFormat.format(gettextn(text, pluralText, null, n), (Object)null);
Note: See TracChangeset for help on using the changeset viewer.