- Timestamp:
- 2010-01-13T20:20:07+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r2842 r2851 23 23 import org.openstreetmap.josm.io.AllFormatsImporter; 24 24 import org.openstreetmap.josm.io.FileImporter; 25 import org.openstreetmap.josm.io.IllegalDataException;26 25 import org.openstreetmap.josm.io.OsmTransferException; 27 26 import org.openstreetmap.josm.tools.MultiMap; … … 110 109 chosenImporter = null; 111 110 } 112 getProgressMonitor().setTicks (files.size());111 getProgressMonitor().setTicksCount(files.size()); 113 112 114 113 if (chosenImporter != null) { // The importer was expicitely chosen, so use it. … … 132 131 else { // find apropriate importer 133 132 MultiMap<FileImporter, File> map = new MultiMap<FileImporter, File>(); 134 while (! files.isEmpty()) { 135 File f = files.get(0); 136 for (FileImporter importer : ExtensionFileFilter.importers) { 137 if (importer.acceptFile(f)) { 138 map.add(importer, f); 139 files.remove(f); 133 FILES: 134 for (File f: files) { 135 for (FileImporter importer : ExtensionFileFilter.importers) { 136 if (importer.acceptFile(f)) { 137 map.add(importer, f); 138 continue FILES; 139 } 140 140 } 141 throw new RuntimeException(); // no importer found 141 142 } 142 if (files.contains(f))143 throw new RuntimeException(); // no importer found144 }145 143 List<FileImporter> ims = new ArrayList<FileImporter>(map.keySet()); 146 144 Collections.sort(ims); … … 165 163 } 166 164 getProgressMonitor().indeterminateSubTask(msg); 167 importer.importDataHandleExceptions(files); 168 getProgressMonitor().worked(files.size()); 165 importer.importDataHandleExceptions(files, getProgressMonitor().createSubTaskMonitor(files.size(), false)); 169 166 } else { 170 167 for (File f : files) { 171 168 if (cancelled) return; 172 169 getProgressMonitor().indeterminateSubTask(tr("Opening file ''{0}'' ...", f.getAbsolutePath())); 173 importer.importDataHandleExceptions(f); 174 getProgressMonitor().worked(1); 170 importer.importDataHandleExceptions(f, getProgressMonitor().createSubTaskMonitor(1, false)); 175 171 } 176 172 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r2850 r2851 66 66 import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker; 67 67 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 68 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 68 69 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 69 70 import org.openstreetmap.josm.io.JpgImporter; … … 284 285 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", getName()) + names, 285 286 getAssociatedFile(), me); 286 if (sel != null) { 287 double firstStartTime = sel[0].lastModified() / 1000.0 /* ms -> seconds */ 288 - AudioUtil.getCalibratedDuration(sel[0]); 289 290 Markers m = new Markers(); 291 for (int i = 0; i < sel.length; i++) { 292 importAudio(sel[i], ml, firstStartTime, m); 293 } 287 double firstStartTime = sel[0].lastModified() / 1000.0 /* ms -> seconds */ 288 - AudioUtil.getCalibratedDuration(sel[0]); 289 290 Markers m = new Markers(); 291 for (int i = 0; i < sel.length; i++) { 292 importAudio(sel[i], ml, firstStartTime, m); 294 293 } 295 294 Main.main.addLayer(ml); … … 334 333 return; 335 334 addRecursiveFiles(files, sel); 336 importer.importDataHandleExceptions(files );335 importer.importDataHandleExceptions(files, NullProgressMonitor.INSTANCE); 337 336 } 338 337 … … 526 525 ****************************************************************/ 527 526 if ((computeCacheMaxLineLengthUsed != maxLineLength) || (!neutralColor.equals(computeCacheColorUsed)) 528 527 || (computeCacheColored != colored) || (computeCacheColorTracksTune != colorTracksTune)) { 529 528 // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + 530 529 // computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + -
trunk/src/org/openstreetmap/josm/io/FileImporter.java
r2719 r2851 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 14 15 15 16 public abstract class FileImporter implements Comparable<FileImporter> { 16 17 17 public ExtensionFileFilter filter;18 public final ExtensionFileFilter filter; 18 19 19 20 public FileImporter(ExtensionFileFilter filter) { … … 34 35 /** 35 36 * Needs to be implemented if isBatchImporter() returns false. 37 * @throws IllegalDataException 36 38 */ 37 public void importData(File file ) throws IOException, IllegalDataException {39 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 38 40 throw new IOException(tr("Could not import ''{0}''.", file.getName())); 39 41 } … … 41 43 /** 42 44 * Needs to be implemented if isBatchImporter() returns true. 45 * @throws IllegalDataException 43 46 */ 44 public void importData(List<File> files ) throws IOException, IllegalDataException {47 public void importData(List<File> files, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 45 48 throw new IOException(tr("Could not import files.")); 46 49 } … … 49 52 * Wrapper to give meaningful output if things go wrong. 50 53 */ 51 public void importDataHandleExceptions(File f ) {54 public void importDataHandleExceptions(File f, ProgressMonitor progressMonitor) { 52 55 try { 53 56 System.out.println("Open file: " + f.getAbsolutePath() + " (" + f.length() + " bytes)"); 54 importData(f );57 importData(f, progressMonitor); 55 58 } catch (Exception e) { 56 59 e.printStackTrace(); … … 63 66 } 64 67 } 65 public void importDataHandleExceptions(List<File> files ) {68 public void importDataHandleExceptions(List<File> files, ProgressMonitor progressMonitor) { 66 69 try { 67 70 System.out.println("Open "+files.size()+" files"); 68 importData(files );71 importData(files, progressMonitor); 69 72 } catch (Exception e) { 70 73 e.printStackTrace(); … … 90 93 return (new Double(this.getPriority())).compareTo(other.getPriority()); 91 94 } 95 92 96 } -
trunk/src/org/openstreetmap/josm/io/GpxImporter.java
r2795 r2851 18 18 import org.openstreetmap.josm.gui.layer.GpxLayer; 19 19 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 20 21 import org.xml.sax.SAXException; 21 22 … … 26 27 } 27 28 28 @Override public void importData(final File file ) throws IOException {29 @Override public void importData(final File file, ProgressMonitor progressMonitor) throws IOException { 29 30 final String fn = file.getName(); 30 31 -
trunk/src/org/openstreetmap/josm/io/IllegalDataException.java
r2512 r2851 6 6 public IllegalDataException() { 7 7 super(); 8 // TODO Auto-generated constructor stub9 8 } 10 9 11 10 public IllegalDataException(String message, Throwable cause) { 12 11 super(message, cause); 13 // TODO Auto-generated constructor stub14 12 } 15 13 16 14 public IllegalDataException(String message) { 17 15 super(message); 18 // TODO Auto-generated constructor stub19 16 } 20 17 21 18 public IllegalDataException(Throwable cause) { 22 19 super(cause); 23 // TODO Auto-generated constructor stub24 20 } 25 21 -
trunk/src/org/openstreetmap/josm/io/JpgImporter.java
r2799 r2851 6 6 import java.io.File; 7 7 import java.io.IOException; 8 import java.util.ArrayList; 8 9 import java.util.Arrays; 9 import java.util. LinkedList;10 import java.util.HashSet; 10 11 import java.util.List; 12 import java.util.Set; 11 13 12 14 import org.openstreetmap.josm.actions.ExtensionFileFilter; 13 15 import org.openstreetmap.josm.gui.layer.GpxLayer; 14 16 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 18 16 19 public class JpgImporter extends FileImporter { … … 32 35 33 36 @Override 34 public void importData(List<File> sel) throws IOException, IllegalDataException { 35 if (sel == null || sel.size() == 0) 36 return; 37 LinkedList<File> files = new LinkedList<File>(); 38 addRecursiveFiles(files, sel); 39 if(files.isEmpty()) throw new IOException(tr("No image files found.")); 40 GeoImageLayer.create(files, gpx); 37 public void importData(List<File> sel, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 38 progressMonitor.beginTask(tr("Looking for image files"), 1); 39 try { 40 List<File> files = new ArrayList<File>(); 41 Set<String> visitedDirs = new HashSet<String>(); 42 addRecursiveFiles(files, visitedDirs, sel, progressMonitor.createSubTaskMonitor(1, true)); 43 44 if (progressMonitor.isCancelled()) 45 return; 46 47 if (files.isEmpty()) 48 throw new IOException(tr("No image files found.")); 49 50 GeoImageLayer.create(files, gpx); 51 } finally { 52 progressMonitor.finishTask(); 53 } 41 54 } 42 55 43 private void addRecursiveFiles(LinkedList<File> files, List<File> sel) { 44 for (File f : sel) { 45 if (f.isDirectory()) { 46 addRecursiveFiles(files, Arrays.asList(f.listFiles())); 47 } else if (f.getName().toLowerCase().endsWith(".jpg")) { 48 files.add(f); 56 private void addRecursiveFiles(List<File> files, Set<String> visitedDirs, List<File> sel, ProgressMonitor progressMonitor) throws IOException { 57 58 if (progressMonitor.isCancelled()) 59 return; 60 61 progressMonitor.beginTask(null, sel.size()); 62 try { 63 for (File f : sel) { 64 if (f.isDirectory()) { 65 if (visitedDirs.add(f.getCanonicalPath())) { // Do not loop over symlinks 66 File[] dirFiles = f.listFiles(); // Can be null for some strange directories (like lost+found) 67 if (dirFiles != null) { 68 addRecursiveFiles(files, visitedDirs, Arrays.asList(dirFiles), progressMonitor.createSubTaskMonitor(1, true)); 69 } 70 } else { 71 progressMonitor.worked(1); 72 } 73 } else { 74 if (f.getName().toLowerCase().endsWith(".jpg")) { 75 files.add(f); 76 } 77 progressMonitor.worked(1); 78 } 49 79 } 80 } finally { 81 progressMonitor.finishTask(); 50 82 } 51 83 } -
trunk/src/org/openstreetmap/josm/io/NMEAImporter.java
r2290 r2851 14 14 import org.openstreetmap.josm.gui.layer.GpxLayer; 15 15 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 16 17 17 18 public class NMEAImporter extends FileImporter { … … 23 24 } 24 25 25 @Override public void importData(File file ) throws IOException {26 @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException { 26 27 String fn = file.getName(); 27 28 NmeaReader r = new NmeaReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile()); -
trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java
r2070 r2851 11 11 import org.apache.tools.bzip2.CBZip2InputStream; 12 12 import org.openstreetmap.josm.actions.ExtensionFileFilter; 13 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 13 14 14 15 public class OsmBzip2Importer extends OsmImporter { … … 20 21 21 22 @Override 22 public void importData(File file ) throws IOException, IllegalDataException {23 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 23 24 BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); 24 25 int b = bis.read(); -
trunk/src/org/openstreetmap/josm/io/OsmGzipImporter.java
r2070 r2851 10 10 11 11 import org.openstreetmap.josm.actions.ExtensionFileFilter; 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 13 13 14 public class OsmGzipImporter extends OsmImporter { … … 18 19 19 20 @Override 20 public void importData(File file ) throws IOException, IllegalDataException {21 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 21 22 GZIPInputStream in = new GZIPInputStream(new FileInputStream(file)); 22 23 importData(in, file); -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r2181 r2851 17 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 18 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 19 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 19 20 20 21 public class OsmImporter extends FileImporter { … … 28 29 } 29 30 30 @Override public void importData(File file ) throws IOException, IllegalDataException {31 @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 31 32 try { 32 33 FileInputStream in = new FileInputStream(file);
Note:
See TracChangeset
for help on using the changeset viewer.