Changeset 3679 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-11-29T08:24:10+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r3530 r3679 76 76 static public class OpenFileTask extends PleaseWaitRunnable { 77 77 private List<File> files; 78 private List<File> successfullyOpenedFiles = new ArrayList<File>(); 78 79 private FileFilter fileFilter; 79 80 private boolean cancelled; 80 81 81 public OpenFileTask(List<File> files, FileFilter fileFilter ) {82 super(t r("Opening files"), false /* don't ignore exception */);82 public OpenFileTask(List<File> files, FileFilter fileFilter, String title) { 83 super(title, false /* don't ignore exception */); 83 84 this.files = new ArrayList<File>(files); 84 85 this.fileFilter = fileFilter; 85 86 } 87 88 public OpenFileTask(List<File> files, FileFilter fileFilter) { 89 this(files, fileFilter, tr("Opening files")); 90 } 91 86 92 @Override 87 93 protected void cancel() { … … 240 246 getProgressMonitor().setCustomText(msg); 241 247 getProgressMonitor().indeterminateSubTask(msg); 242 importer.importDataHandleExceptions(files, getProgressMonitor().createSubTaskMonitor(files.size(), false)); 248 if (importer.importDataHandleExceptions(files, getProgressMonitor().createSubTaskMonitor(files.size(), false))) { 249 successfullyOpenedFiles.addAll(files); 250 } 243 251 } else { 244 252 for (File f : files) { 245 253 if (cancelled) return; 246 254 getProgressMonitor().indeterminateSubTask(tr("Opening file ''{0}'' ...", f.getAbsolutePath())); 247 importer.importDataHandleExceptions(f, getProgressMonitor().createSubTaskMonitor(1, false)); 248 } 249 } 255 if (importer.importDataHandleExceptions(f, getProgressMonitor().createSubTaskMonitor(1, false))) { 256 successfullyOpenedFiles.add(f); 257 } 258 } 259 } 260 } 261 262 public List<File> getSuccessfullyOpenedFiles() { 263 return successfullyOpenedFiles; 250 264 } 251 265 } -
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r3675 r3679 5 5 6 6 import java.io.File; 7 import java.io.FileInputStream;8 import java.io.FileNotFoundException;9 7 import java.io.IOException; 10 8 import java.util.ArrayList; … … 22 20 23 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask; 24 23 import org.openstreetmap.josm.data.osm.DataSet; 25 24 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; … … 32 31 import org.openstreetmap.josm.gui.layer.Layer; 33 32 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 34 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;35 import org.openstreetmap.josm.io.IllegalDataException;36 33 import org.openstreetmap.josm.io.OsmExporter; 37 import org.openstreetmap.josm.io.OsmReader; 38 34 35 /** 36 * Saves data layers periodically so they can be recovered in case of a crash. 37 */ 39 38 public class AutosaveTask extends TimerTask implements LayerChangeListener, Listener { 40 39 … … 55 54 final Deque<File> backupFiles = new LinkedList<File>(); 56 55 } 57 58 //"data layer 1_20100711_1330"59 56 60 57 private final DataSetListenerAdapter datasetAdapter = new DataSetListenerAdapter(this); … … 261 258 } 262 259 263 public List<OsmDataLayer> getUnsavedLayers() { 264 List<OsmDataLayer> result = new ArrayList<OsmDataLayer>(); 265 266 for (File f: getUnsavedLayersFiles()) { 267 try { 268 DataSet ds = OsmReader.parseDataSet(new FileInputStream(f), NullProgressMonitor.INSTANCE); 269 String layerName = f.getName(); 270 layerName = layerName.substring(0, layerName.lastIndexOf('.')); 271 result.add(new OsmDataLayer(ds, layerName, null)); 272 moveToDeletedLayersFolder(f); 273 } catch (FileNotFoundException e) { 274 // Should not happen 275 System.err.println("File " + f.getAbsolutePath() + " not found"); 276 } catch (IllegalDataException e) { 277 System.err.println(tr("Unable to read autosaved osm data ({0}) - {1}", f.getAbsoluteFile(), e.getMessage())); 278 } 279 } 280 281 return result; 260 public void recoverUnsavedLayers() { 261 List<File> files = getUnsavedLayersFiles(); 262 final OpenFileTask openFileTsk = new OpenFileTask(files, null, tr("Restoring files")); 263 Main.worker.submit(openFileTsk); 264 Main.worker.submit(new Runnable() { 265 public void run() { 266 for (File f: openFileTsk.getSuccessfullyOpenedFiles()) { 267 moveToDeletedLayersFolder(f); 268 } 269 } 270 }); 282 271 } 283 272 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r3675 r3679 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 import java.awt.EventQueue;8 7 import java.awt.GridBagConstraints; 9 8 import java.awt.GridBagLayout; … … 30 29 import javax.swing.JPanel; 31 30 import javax.swing.JTextArea; 31 import javax.swing.SwingUtilities; 32 32 33 33 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.actions.AutoScaleAction;35 34 import org.openstreetmap.josm.data.AutosaveTask; 36 35 import org.openstreetmap.josm.data.Preferences; 37 import org.openstreetmap.josm.gui.layer.OsmDataLayer;38 36 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 39 37 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 250 248 } 251 249 252 if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) { 253 AutosaveTask autosaveTask = new AutosaveTask(); 254 List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles(); 255 if (!unsavedLayerFiles.isEmpty()) { 256 System.err.println("autosave debug: unsavedLayerFiles="+unsavedLayerFiles); 257 ExtendedDialog dialog = new ExtendedDialog( 258 Main.parent, 259 tr("Unsaved osm data"), 260 new String[] {tr("Restore"), tr("Cancel"), tr("Discard")} 261 ); 262 dialog.setContent( 263 trn("JOSM found {0} unsaved osm data layer. ", 264 "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) + 265 tr("It looks like JOSM crashed last time. Do you like to restore the data?")); 266 dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/remove"}); 267 int selection = dialog.showDialog().getValue(); 268 System.err.println("autosave debug: user selection="+selection); 269 if (selection == 1) { 270 for (OsmDataLayer layer: autosaveTask.getUnsavedLayers()) { 271 Main.main.addLayer(layer); 250 SwingUtilities.invokeLater(new Runnable() { 251 public void run() { 252 if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) { 253 AutosaveTask autosaveTask = new AutosaveTask(); 254 List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles(); 255 if (!unsavedLayerFiles.isEmpty()) { 256 System.err.println("autosave debug: unsavedLayerFiles="+unsavedLayerFiles); 257 ExtendedDialog dialog = new ExtendedDialog( 258 Main.parent, 259 tr("Unsaved osm data"), 260 new String[] {tr("Restore"), tr("Cancel"), tr("Discard")} 261 ); 262 dialog.setContent( 263 trn("JOSM found {0} unsaved osm data layer. ", 264 "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) + 265 tr("It looks like JOSM crashed last time. Do you like to restore the data?")); 266 dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/remove"}); 267 int selection = dialog.showDialog().getValue(); 268 System.err.println("autosave debug: user selection="+selection); 269 if (selection == 1) { 270 autosaveTask.recoverUnsavedLayers(); 271 } else if (selection == 3) { 272 System.err.println("autosave debug: discard autosaved layers"); 273 autosaveTask.dicardUnsavedLayers(); 274 System.err.println("autosave debug: discard autosaved layers [DONE]"); 275 } 272 276 } 273 AutoScaleAction.autoScale("data"); 274 } else if (selection == 3) { 275 System.err.println("autosave debug: discard autosaved layers"); 276 autosaveTask.dicardUnsavedLayers(); 277 System.err.println("autosave debug: discard autosaved layers [DONE]"); 277 autosaveTask.schedule(); 278 278 } 279 } 280 autosaveTask.schedule(); 281 } 282 283 284 EventQueue.invokeLater(new Runnable() { 285 public void run() { 279 286 280 main.postConstructorProcessCmdLine(args); 287 281 } -
trunk/src/org/openstreetmap/josm/io/FileImporter.java
r3501 r3679 36 36 /** 37 37 * Needs to be implemented if isBatchImporter() returns false. 38 * @throws IllegalDataException39 38 */ 40 39 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { … … 44 43 /** 45 44 * Needs to be implemented if isBatchImporter() returns true. 46 * @throws IllegalDataException47 45 */ 48 46 public void importData(List<File> files, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { … … 52 50 /** 53 51 * Wrapper to give meaningful output if things go wrong. 52 * @return true if data import was successful 54 53 */ 55 public voidimportDataHandleExceptions(File f, ProgressMonitor progressMonitor) {54 public boolean importDataHandleExceptions(File f, ProgressMonitor progressMonitor) { 56 55 try { 57 56 System.out.println("Open file: " + f.getAbsolutePath() + " (" + f.length() + " bytes)"); 58 57 importData(f, progressMonitor); 58 return true; 59 59 } catch (Exception e) { 60 60 e.printStackTrace(); … … 65 65 JOptionPane.ERROR_MESSAGE, null 66 66 ); 67 return false; 67 68 } 68 69 } 69 public voidimportDataHandleExceptions(List<File> files, ProgressMonitor progressMonitor) {70 public boolean importDataHandleExceptions(List<File> files, ProgressMonitor progressMonitor) { 70 71 try { 71 72 System.out.println("Open "+files.size()+" files"); 72 73 importData(files, progressMonitor); 74 return true; 73 75 } catch (Exception e) { 74 76 e.printStackTrace(); … … 79 81 JOptionPane.ERROR_MESSAGE, null 80 82 ); 83 return false; 81 84 } 82 85 }
Note:
See TracChangeset
for help on using the changeset viewer.