Changeset 12747 in osm for applications/editors/josm/plugins/agpifoj/src
- Timestamp:
- 2009-01-01T07:05:23+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/AgpifojLayer.java
r10122 r12747 18 18 import java.text.ParseException; 19 19 import java.util.ArrayList; 20 import java.util.Collection;21 20 import java.util.Collections; 22 21 import java.util.Date; 22 import java.util.HashSet; 23 23 import java.util.List; 24 24 … … 82 82 } 83 83 84 /** Loads a set of images, while displaying a dialog that indicates what the plugin is currently doing. 85 * In facts, this object is instantiated with a list of files. These files may be JPEG files or 86 * directories. In case of directories, they are scanned to find all the images they contain. 87 * Then all the images that have be found are loaded as ImageEntry instances. 88 */ 84 89 private static final class Loader extends PleaseWaitRunnable { 85 90 86 91 private boolean cancelled = false; 87 92 private AgpifojLayer layer; 88 private final Collection<File> files; 89 90 public Loader(Collection<File> files) { 93 private final File[] selection; 94 private HashSet<String> loadedDirectories = new HashSet<String>(); 95 96 public Loader(File[] selection) { 91 97 super(tr("Extracting GPS locations from EXIF")); 92 this. files = files;98 this.selection = selection; 93 99 } 94 100 95 101 @Override protected void realRun() throws IOException { 96 102 103 Main.pleaseWaitDlg.currentAction.setText(tr("Starting directory scan")); 104 List<File> files = new ArrayList<File>(); 105 try { 106 addRecursiveFiles(files, selection); 107 } catch(NullPointerException npe) { 108 errorMessage += tr("One of the selected files was null !!!"); 109 } 110 111 if (cancelled) { 112 return; 113 } 114 97 115 Main.pleaseWaitDlg.currentAction.setText(tr("Read photos...")); 98 116 … … 128 146 } 129 147 layer = new AgpifojLayer(data); 148 files.clear(); 149 } 150 151 private void addRecursiveFiles(List<File> files, File[] sel) { 152 boolean nullFile = false; 153 154 for (File f : sel) { 155 156 if(cancelled) { 157 break; 158 } 159 160 if (f == null) { 161 nullFile = true; 162 163 } else if (f.isDirectory()) { 164 String canonical = null; 165 try { 166 canonical = f.getCanonicalPath(); 167 } catch (IOException e) { 168 e.printStackTrace(); 169 errorMessage += tr("Unable to get canonical path for directory {0}\n", 170 f.getAbsolutePath()); 171 } 172 173 if (canonical == null || loadedDirectories.contains(canonical)) { 174 continue; 175 } else { 176 loadedDirectories.add(canonical); 177 } 178 179 File[] children = f.listFiles(AgpifojPlugin.JPEG_FILE_FILTER); 180 if (children != null) { 181 Main.pleaseWaitDlg.currentAction.setText(tr("Scanning directory {0}", f.getPath())); 182 try { 183 addRecursiveFiles(files, children); 184 } catch(NullPointerException npe) { 185 npe.printStackTrace(); 186 errorMessage += tr("Found null file in directory {0}\n", f.getPath()); 187 } 188 } else { 189 errorMessage += tr("Error while getting files from directory {0}\n", f.getPath()); 190 } 191 192 } else { 193 files.add(f); 194 } 195 } 196 197 if (nullFile) { 198 throw new NullPointerException(); 199 } 130 200 } 131 201 … … 134 204 Main.main.addLayer(layer); 135 205 layer.hook_up_mouse_events(); // Main.map.mapView should exist 136 // now. Can add mouse lis ener206 // now. Can add mouse listener 137 207 138 208 if (! cancelled && layer.data.size() > 0) { … … 155 225 } 156 226 157 public static void create( Collection<File>files) {227 public static void create(File[] files) { 158 228 Loader loader = new Loader(files); 159 229 Main.worker.execute(loader); -
applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/AgpifojPlugin.java
r12640 r12747 7 7 import static org.openstreetmap.josm.tools.I18n.tr; 8 8 9 import java.awt.BorderLayout;10 9 import java.awt.event.ActionEvent; 11 10 import java.io.File; … … 14 13 15 14 import javax.swing.JFileChooser; 16 import javax.swing.JMenu;17 import javax.swing.JMenuBar;18 import javax.swing.JMenuItem;19 import javax.swing.JToggleButton;20 import javax.swing.JToolBar;21 import javax.swing.filechooser.FileFilter;22 15 23 16 import org.openstreetmap.josm.Main; 24 17 import org.openstreetmap.josm.actions.JosmAction; 25 18 import org.openstreetmap.josm.gui.IconToggleButton; 19 import org.openstreetmap.josm.gui.MainMenu; 26 20 import org.openstreetmap.josm.gui.MapFrame; 27 import org.openstreetmap.josm.gui.MainMenu;28 21 import org.openstreetmap.josm.gui.layer.Layer; 29 22 import org.openstreetmap.josm.plugins.Plugin; 30 23 31 24 public class AgpifojPlugin extends Plugin { 25 26 static class JpegFileFilter extends javax.swing.filechooser.FileFilter 27 implements java.io.FileFilter { 28 29 @Override public boolean accept(File f) { 30 if (f.isDirectory()) { 31 return true; 32 } else { 33 String name = f.getName().toLowerCase(); 34 return name.endsWith(".jpg") || name.endsWith(".jpeg"); 35 } 36 } 37 38 @Override public String getDescription() { 39 return tr("JPEG images (*.jpg)"); 40 } 41 }; 42 43 static final JpegFileFilter JPEG_FILE_FILTER = new JpegFileFilter(); 32 44 33 45 private class Action extends JosmAction { … … 46 58 fc.setMultiSelectionEnabled(true); 47 59 fc.setAcceptAllFileFilterUsed(false); 48 fc.setFileFilter( 49 new FileFilter() { 50 @Override public boolean accept(File f) { 51 return f.isDirectory() 52 || f.getName().toLowerCase().endsWith(".jpg"); 53 } 54 55 @Override public String getDescription() { 56 return tr("JPEG images (*.jpg)"); 57 } 58 }); 60 fc.setFileFilter(JPEG_FILE_FILTER); 59 61 60 62 fc.showOpenDialog(Main.parent); … … 65 67 } 66 68 67 List<File> files = new ArrayList<File>();68 addRecursiveFiles(files, sel);69 69 Main.pref.put("tagimages.lastdirectory", fc.getCurrentDirectory().getPath()); 70 70 71 AgpifojLayer.create(files); 72 } 73 74 private void addRecursiveFiles(List<File> files, File[] sel) { 75 for (File f : sel) { 76 if (f.isDirectory()) { 77 addRecursiveFiles(files, f.listFiles()); 78 } else if (f.getName().toLowerCase().endsWith(".jpg")) { 79 files.add(f); 80 } 81 } 71 AgpifojLayer.create(sel); 82 72 } 83 73 } 84 74 85 75 public AgpifojPlugin() { 86 76 MainMenu.add(Main.main.menu.fileMenu, new Action()); … … 88 78 89 79 /** 90 * Called after Main.mapFrame is init alized. (After the first data is loaded).80 * Called after Main.mapFrame is initialized. (After the first data is loaded). 91 81 * You can use this callback to tweak the newFrame to your needs, as example install 92 82 * an alternative Painter. … … 109 99 } 110 100 } 111 112 113 101 } -
applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/CorrelateGpxWithImages.java
r12740 r12747 334 334 fc.setMultiSelectionEnabled(false); 335 335 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 336 fc.setFileFilter(new FileFilter(){ 337 @Override public boolean accept(File f) { 338 return (f.isDirectory() 339 || f .getName().toLowerCase().endsWith(".jpg") 340 || f.getName().toLowerCase().endsWith(".jpeg")); 341 } 342 @Override public String getDescription() { 343 return tr("JPEG images (*.jpg)"); 344 } 345 }); 336 fc.setFileFilter(AgpifojPlugin.JPEG_FILE_FILTER); 346 337 fc.showOpenDialog(Main.parent); 347 338 File sel = fc.getSelectedFile();
Note:
See TracChangeset
for help on using the changeset viewer.