Changeset 2047 in josm
- Timestamp:
- 2009-09-04T08:31:03+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r2039 r2047 11 11 import java.awt.event.KeyEvent; 12 12 import java.io.File; 13 import java.io.IOException; 13 14 import java.net.URI; 14 15 import java.net.URISyntaxException; … … 30 31 import javax.swing.UIManager; 31 32 33 import org.openstreetmap.josm.actions.OpenFileAction; 32 34 import org.openstreetmap.josm.actions.SaveAction; 33 35 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; … … 412 414 dialog.setVisible(true); 413 415 switch(dialog.getUserAction()) { 414 case CANCEL: return false; 415 case PROCEED: return true; 416 default: return false; 416 case CANCEL: return false; 417 case PROCEED: return true; 418 default: return false; 417 419 } 418 420 } … … 455 457 456 458 switch(ed.getValue()) { 457 case 2: /* discard and exit */ return true; 458 case 3: /* cancel */ return false; 459 case 2: /* discard and exit */ return true; 460 case 3: /* cancel */ return false; 459 461 } 460 462 boolean savefailed = false; … … 486 488 487 489 if (s.startsWith("file:")) { 490 File f = null; 488 491 try { 489 main.menu.openFile.openFile(new File(new URI(s)));492 f = new File(new URI(s)); 490 493 } catch (URISyntaxException e) { 491 494 JOptionPane.showMessageDialog( … … 496 499 ); 497 500 } 501 try { 502 if (f!=null) { 503 OpenFileAction.openFile(f); 504 } 505 }catch(IOException e) { 506 e.printStackTrace(); 507 JOptionPane.showMessageDialog( 508 Main.parent, 509 tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), 510 tr("Error"), 511 JOptionPane.ERROR_MESSAGE 512 ); 513 } 498 514 return; 499 515 } … … 508 524 } 509 525 } 510 511 main.menu.openFile.openFile(new File(s)); 526 File f = new File(s); 527 try { 528 OpenFileAction.openFile(f); 529 }catch(IOException e) { 530 e.printStackTrace(); 531 JOptionPane.showMessageDialog( 532 Main.parent, 533 tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), 534 tr("Error"), 535 JOptionPane.ERROR_MESSAGE 536 ); 537 } 512 538 } 513 539 -
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r2017 r2047 8 8 import java.io.File; 9 9 import java.io.IOException; 10 import java.util.Arrays; 11 import java.util.List; 10 12 11 13 import javax.swing.JFileChooser; … … 13 15 14 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 15 18 import org.openstreetmap.josm.io.FileImporter; 19 import org.openstreetmap.josm.io.OsmTransferException; 16 20 import org.openstreetmap.josm.tools.Shortcut; 21 import org.xml.sax.SAXException; 17 22 18 23 /** … … 37 42 return; 38 43 File[] files = fc.getSelectedFiles(); 39 for (int i = files.length; i > 0; --i) { 40 openFile(files[i-1]); 41 } 42 } 43 44 /** 45 * Open the given file. 46 */ 47 public void openFile(File file) { 48 try { 49 System.out.println("Open file: " + file.getAbsolutePath() + " (" + file.length() + " bytes)"); 50 for (FileImporter importer : ExtensionFileFilter.importers) 51 if (importer.acceptFile(file)) { 52 importer.importData(file); 53 } 54 } catch (IOException x) { 55 x.printStackTrace(); 56 JOptionPane.showMessageDialog( 57 Main.parent, 58 tr("<html>Could not read file ''{0}\''. Error is: <br>{1}</html>", file.getName(), x.getMessage()), 59 tr("Error"), 60 JOptionPane.ERROR_MESSAGE 61 ); 62 63 } 44 OpenFileTask task = new OpenFileTask(Arrays.asList(files)); 45 Main.worker.submit(task); 64 46 } 65 47 … … 68 50 setEnabled(! Main.applet); 69 51 } 52 53 static public void openFile(File f) throws IOException { 54 for (FileImporter importer : ExtensionFileFilter.importers) 55 if (importer.acceptFile(f)) { 56 importer.importData(f); 57 } 58 } 59 60 static public class OpenFileTask extends PleaseWaitRunnable { 61 private List<File> files; 62 private boolean cancelled; 63 64 public OpenFileTask(List<File> files) { 65 super(tr("Opening files"), false /* don't ignore exception */); 66 this.files = files; 67 } 68 @Override 69 protected void cancel() { 70 this.cancelled = true; 71 } 72 73 @Override 74 protected void finish() { 75 // do nothing 76 } 77 78 @Override 79 protected void realRun() throws SAXException, IOException, OsmTransferException { 80 if (files == null || files.isEmpty()) return; 81 getProgressMonitor().setTicks(files.size()); 82 for (File f : files) { 83 if (cancelled) return; 84 getProgressMonitor().subTask(tr("Opening file ''{0}'' ...", f.getAbsolutePath())); 85 try { 86 System.out.println("Open file: " + f.getAbsolutePath() + " (" + f.length() + " bytes)"); 87 openFile(f); 88 } catch (Exception e) { 89 e.printStackTrace(); 90 JOptionPane.showMessageDialog( 91 Main.parent, 92 tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), 93 tr("Error"), 94 JOptionPane.ERROR_MESSAGE 95 ); 96 } 97 getProgressMonitor().worked(1); 98 } 99 } 100 } 70 101 } -
trunk/src/org/openstreetmap/josm/gui/FileDrop.java
r2039 r2047 9 9 import java.io.PrintStream; 10 10 import java.io.Reader; 11 import java.util.Arrays; 11 12 import java.util.List; 12 13 13 14 import javax.swing.BorderFactory; 14 15 16 import org.openstreetmap.josm.Main; 15 17 import org.openstreetmap.josm.actions.OpenFileAction; 16 18 … … 70 72 71 73 /* Constructor for JOSM file drop */ 72 public FileDrop(final java.awt.Component c) 73 { this( 74 null, // Logging stream 75 c, // Drop target 76 BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border 77 true, // Recursive 78 new FileDrop.Listener() 79 { 80 public void filesDropped( java.io.File[] files ) 81 { 82 OpenFileAction ofa = new OpenFileAction(); 83 for( int i = 0; i < files.length; i++ ) 84 { 85 ofa.openFile(files[i]); 86 } // end for: through each dropped file 87 } // end filesDropped 88 }); // end FileDrop.Listener 74 public FileDrop(final java.awt.Component c){ 75 this( 76 null, // Logging stream 77 c, // Drop target 78 BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border 79 true, // Recursive 80 new FileDrop.Listener(){ 81 public void filesDropped( java.io.File[] files ){ 82 // start asynchronous loading of files 83 OpenFileAction.OpenFileTask task = new OpenFileAction.OpenFileTask(Arrays.asList(files)); 84 Main.worker.submit(task); 85 } 86 } 87 ); 89 88 } 90 91 89 92 90 /**
Note:
See TracChangeset
for help on using the changeset viewer.