Changeset 1493 in josm
- Timestamp:
- 2009-03-17T18:50:36+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
r1465 r1493 14 14 15 15 import javax.swing.JOptionPane; 16 import javax.swing.SwingUtilities; 16 17 17 18 import org.openstreetmap.josm.Main; … … 30 31 private boolean closeDialogCalled = false; 31 32 private boolean cancelled = false; 33 private boolean ignoreException; 32 34 33 35 private final String title; 36 37 /** 38 * Create the runnable object with a given message for the user. 39 */ 40 public PleaseWaitRunnable(String title) { 41 this(title, false); 42 } 34 43 35 44 /** 36 45 * Create the runnable object with a given message for the user. 46 * @param title Message for user 47 * @param ignoreException If true, exception will be propaged to calling code. If false then 48 * exception will be thrown directly in EDT. When this runnable is executed using executor framework 49 * then use false unless you read result of task (because exception will get lost if you don't) 37 50 */ 38 public PleaseWaitRunnable(String title) { 51 public PleaseWaitRunnable(String title, boolean ignoreException) { 39 52 this.title = title; 53 this.ignoreException = ignoreException; 40 54 Main.pleaseWaitDlg.cancel.addActionListener(new ActionListener(){ 41 55 public void actionPerformed(ActionEvent e) { … … 61 75 public final void run() { 62 76 try { 63 if (cancelled) 64 return; // since realRun isn't executed, do not call to finish 77 try { 78 if (cancelled) 79 return; // since realRun isn't executed, do not call to finish 65 80 66 // reset dialog state 67 Main.pleaseWaitDlg.setTitle(title); 68 Main.pleaseWaitDlg.cancel.setEnabled(true); 69 Main.pleaseWaitDlg.setCustomText(""); 70 errorMessage = null; 71 closeDialogCalled = false; 81 // reset dialog state 82 Main.pleaseWaitDlg.setTitle(title); 83 Main.pleaseWaitDlg.cancel.setEnabled(true); 84 Main.pleaseWaitDlg.setCustomText(""); 85 errorMessage = null; 86 closeDialogCalled = false; 72 87 73 // show the dialog 74 synchronized (this) { 75 EventQueue.invokeLater(new Runnable() { 88 // show the dialog 89 synchronized (this) { 90 EventQueue.invokeLater(new Runnable() { 91 public void run() { 92 synchronized (PleaseWaitRunnable.this) { 93 PleaseWaitRunnable.this.notifyAll(); 94 } 95 Main.pleaseWaitDlg.setVisible(true); 96 } 97 }); 98 try {wait();} catch (InterruptedException e) {} 99 } 100 101 realRun(); 102 } catch (SAXException x) { 103 x.printStackTrace(); 104 errorMessage = tr("Error while parsing")+": "+x.getMessage(); 105 } catch (FileNotFoundException x) { 106 x.printStackTrace(); 107 errorMessage = tr("File not found")+": "+x.getMessage(); 108 } catch (IOException x) { 109 x.printStackTrace(); 110 errorMessage = x.getMessage(); 111 } finally { 112 closeDialog(); 113 } 114 } catch (final Throwable e) { 115 if (!ignoreException) { 116 // Exception has to thrown in EDT to be shown to user 117 SwingUtilities.invokeLater(new Runnable() { 76 118 public void run() { 77 synchronized (PleaseWaitRunnable.this) { 78 PleaseWaitRunnable.this.notifyAll(); 79 } 80 Main.pleaseWaitDlg.setVisible(true); 81 } 119 throw new RuntimeException(e); 120 } 82 121 }); 83 try {wait();} catch (InterruptedException e) {}84 122 } 85 86 realRun();87 } catch (SAXException x) {88 x.printStackTrace();89 errorMessage = tr("Error while parsing")+": "+x.getMessage();90 } catch (FileNotFoundException x) {91 x.printStackTrace();92 errorMessage = tr("File not found")+": "+x.getMessage();93 } catch (IOException x) {94 x.printStackTrace();95 errorMessage = x.getMessage();96 } finally {97 closeDialog();98 123 } 99 124 }
Note:
See TracChangeset
for help on using the changeset viewer.