Changeset 4718 in josm for trunk/src/org
- Timestamp:
- 2011-12-27T12:56:27+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r4681 r4718 22 22 import java.util.Collection; 23 23 import java.util.Iterator; 24 import java.util.LinkedList;25 24 import java.util.List; 26 25 import java.util.Map; 27 26 import java.util.StringTokenizer; 28 27 import java.util.concurrent.ExecutorService; 29 import java.util.concurrent.Executors;30 28 import java.util.concurrent.Future; 31 29 import java.util.regex.Matcher; … … 41 39 import javax.swing.JTextArea; 42 40 import javax.swing.KeyStroke; 41 import javax.swing.RepaintManager; 43 42 import javax.swing.UIManager; 44 43 44 import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; 45 45 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 46 46 import org.openstreetmap.josm.actions.JosmAction; … … 76 76 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 77 77 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 78 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 79 import org.openstreetmap.josm.gui.progress.ProgressMonitorExecutor; 78 80 import org.openstreetmap.josm.io.OsmApi; 79 81 import org.openstreetmap.josm.plugins.PluginHandler; … … 116 118 * and sequential. 117 119 */ 118 public final static ExecutorService worker = Executors.newSingleThreadExecutor();120 public final static ExecutorService worker = new ProgressMonitorExecutor(); 119 121 /** 120 122 * Global application preferences … … 143 145 144 146 public UndoRedoHandler undoRedo = new UndoRedoHandler(); 147 148 public static PleaseWaitProgressMonitor currentProgressMonitor; 145 149 146 150 /** … … 208 212 209 213 PluginHandler.notifyMapFrameChanged(old, map); 214 if (map == null && currentProgressMonitor != null) { 215 currentProgressMonitor.showForegroundDialog(); 216 } 210 217 } 211 218 … … 238 245 isOpenjdk = System.getProperty("java.vm.name").toUpperCase().indexOf("OPENJDK") != -1; 239 246 240 if (initListener != null) 247 if (initListener != null) { 241 248 initListener.updateStatus(tr("Executing platform startup hook")); 249 } 242 250 platform.startupHook(); 243 251 … … 245 253 // capabilities are already known to the editor instance. However 246 254 // if it goes wrong that's not critical at this stage. 247 if (initListener != null) 255 if (initListener != null) { 248 256 initListener.updateStatus(tr("Initializing OSM API")); 257 } 249 258 try { 250 259 OsmApi.getOsmApi().initialize(null, true); … … 253 262 } 254 263 255 if (initListener != null) 264 if (initListener != null) { 256 265 initListener.updateStatus(tr("Building main menu")); 266 } 257 267 contentPanePrivate.add(panel, BorderLayout.CENTER); 258 268 panel.add(gettingStarted, BorderLayout.CENTER); … … 267 277 KeyEvent.VK_F1, Shortcut.GROUP_DIRECT)); 268 278 269 if (initListener != null) 279 if (initListener != null) { 270 280 initListener.updateStatus(tr("Initializing presets")); 281 } 271 282 TaggingPresetPreference.initialize(); 272 283 273 if (initListener != null) 284 if (initListener != null) { 274 285 initListener.updateStatus(tr("Initializing map styles")); 286 } 275 287 MapPaintPreference.initialize(); 276 288 277 if (initListener != null) 289 if (initListener != null) { 278 290 initListener.updateStatus(tr("Loading imagery preferences")); 291 } 279 292 ImageryPreference.initialize(); 280 293 281 if (initListener != null) 294 if (initListener != null) { 282 295 initListener.updateStatus(tr("Initializing validator")); 296 } 283 297 validator = new OsmValidator(); 284 298 MapView.addLayerChangeListener(validator); … … 293 307 FeatureAdapter.registerTranslationAdapter(I18n.getTranslationAdapter()); 294 308 295 if (initListener != null) 309 if (initListener != null) { 296 310 initListener.updateStatus(tr("Updating user interface")); 311 } 297 312 298 313 toolbar.refreshToolbarControl(); … … 527 542 tr("Warning"), 528 543 JOptionPane.WARNING_MESSAGE 529 );544 ); 530 545 } 531 546 if (f!=null) { … … 560 575 tr("Warning"), 561 576 JOptionPane.WARNING_MESSAGE 562 );577 ); 563 578 } 564 579 } … … 647 662 tr("Warning"), 648 663 JOptionPane.WARNING_MESSAGE 649 );664 ); 650 665 } else { 651 666 downloadFromParamBounds(rawGps, b); … … 664 679 new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())), 665 680 new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())) 666 );681 ); 667 682 downloadFromParamBounds(rawGps, b); 668 683 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r4521 r4718 15 15 import org.openstreetmap.josm.gui.layer.Layer; 16 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 import org.openstreetmap.josm.gui.progress.ProgressTaskId; 18 import org.openstreetmap.josm.gui.progress.ProgressTaskIds; 17 19 import org.openstreetmap.josm.io.BoundingBoxDownloader; 18 20 import org.openstreetmap.josm.io.OsmServerLocationReader; … … 24 26 25 27 private DownloadTask downloadTask; 26 28 27 29 private static final String PATTERN_TRACE_ID = "http://.*openstreetmap.org/trace/\\p{Digit}+/data"; 28 30 29 31 private static final String PATTERN_TRACKPOINTS_BBOX = "http://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*"; 30 32 … … 44 46 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 45 47 return Main.worker.submit(downloadTask); 46 48 47 49 } else if (url != null && url.matches(PATTERN_TRACKPOINTS_BBOX)) { 48 50 String[] table = url.split("\\?|=|&"); 49 51 for (int i = 0; i<table.length; i++) { 50 if (table[i].equals("bbox") && i<table.length-1 ) {52 if (table[i].equals("bbox") && i<table.length-1 ) 51 53 return download(newLayer, new Bounds(table[i+1], ",", ParseMethod.LEFT_BOTTOM_RIGHT_TOP), progressMonitor); 52 }53 54 } 54 55 } … … 124 125 if (l instanceof GpxLayer && (merge || ((GpxLayer)l).data.fromServer)) 125 126 return l; 126 return null;127 return null; 127 128 } 128 129 … … 133 134 } 134 135 } 136 137 @Override 138 public ProgressTaskId canRunInBackground() { 139 return ProgressTaskIds.DOWNLOAD_GPS; 140 } 135 141 } 136 142 } -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r4604 r4718 32 32 import javax.swing.JLabel; 33 33 import javax.swing.JPanel; 34 import javax.swing.JProgressBar; 34 35 import javax.swing.JScrollPane; 35 36 import javax.swing.JTextField; 36 37 import javax.swing.Popup; 37 38 import javax.swing.PopupFactory; 39 import javax.swing.UIManager; 38 40 39 41 import org.openstreetmap.josm.Main; … … 44 46 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 45 47 import org.openstreetmap.josm.gui.help.Helpful; 48 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 49 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog; 46 50 import org.openstreetmap.josm.tools.GBC; 47 51 import org.openstreetmap.josm.tools.ImageProvider; … … 95 99 } 96 100 101 public class BackgroundProgressMonitor implements ProgressMonitorDialog { 102 103 private String title; 104 private String customText; 105 106 private void updateText() { 107 if (customText != null && !customText.isEmpty()) { 108 progressBar.setToolTipText(tr("{0} ({1})", title, customText)); 109 } else { 110 progressBar.setToolTipText(title); 111 } 112 } 113 114 public void setVisible(boolean visible) { 115 progressBar.setVisible(visible); 116 } 117 118 public void updateProgress(int progress) { 119 progressBar.setValue(progress); 120 MapStatus.this.doLayout(); 121 } 122 123 public void setCustomText(String text) { 124 this.customText = text; 125 updateText(); 126 } 127 128 public void setTitle(String text) { 129 this.title = text; 130 updateText(); 131 } 132 133 public void setIndeterminate(boolean newValue) { 134 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100); 135 progressBar.setIndeterminate(newValue); 136 } 137 138 @Override 139 public void appendLogMessage(String message) { 140 if (message != null && !message.isEmpty()) { 141 System.out.println("appendLogMessage not implemented for background tasks. Message was: " + message); 142 } 143 } 144 145 } 146 97 147 final ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 11); 98 148 final ImageLabel nameText = new ImageLabel("name", tr("The name of the object at the mouse pointer."), 20); … … 102 152 final ImageLabel headingText = new ImageLabel("heading", tr("The (compass) heading of the line segment being drawn."), 6); 103 153 final ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 10); 154 final JProgressBar progressBar = new JProgressBar(); 155 public final BackgroundProgressMonitor progressMonitor = new BackgroundProgressMonitor(); 104 156 105 157 /** … … 658 710 helpText.setEditable(false); 659 711 add(nameText, GBC.std().insets(3,0,0,0)); 660 add(helpText, GBC.eol().insets(3,0,0,0).fill(GBC.HORIZONTAL)); 712 add(helpText, GBC.std().insets(3,0,0,0).fill(GBC.HORIZONTAL)); 713 714 progressBar.setMaximum(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX); 715 { 716 GBC gbc = GBC.eol(); 717 gbc.ipadx = 100; 718 add(progressBar,gbc); 719 } 720 progressBar.addMouseListener(new MouseAdapter() { 721 @Override 722 public void mouseClicked(MouseEvent e) { 723 PleaseWaitProgressMonitor monitor = Main.currentProgressMonitor; 724 if (monitor != null) { 725 monitor.showForegroundDialog(); 726 } 727 } 728 }); 661 729 662 730 // The background thread -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
r3501 r4718 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog; 26 27 import org.openstreetmap.josm.tools.GBC; 27 28 import org.openstreetmap.josm.tools.ImageProvider; 28 29 29 public class PleaseWaitDialog extends JDialog {30 public class PleaseWaitDialog extends JDialog implements ProgressMonitorDialog { 30 31 31 32 private final JProgressBar progressBar = new JProgressBar(); … … 34 35 private final JLabel customText = new JLabel(""); 35 36 public final BoundedRangeModel progress = progressBar.getModel(); 36 private JButton btnCancel; 37 private JButton btnCancel; 38 private JButton btnInBackground; 37 39 /** the text area and the scroll pane for the log */ 38 40 private JTextArea taLog = new JTextArea(5,50); … … 46 48 pane.add(customText, GBC.eol().fill(GBC.HORIZONTAL)); 47 49 pane.add(progressBar, GBC.eop().fill(GBC.HORIZONTAL)); 50 JPanel buttons = new JPanel(); 51 buttons.setLayout(new GridBagLayout()); 48 52 btnCancel = new JButton(tr("Cancel")); 49 53 btnCancel.setIcon(ImageProvider.get("cancel")); 50 54 btnCancel.setToolTipText(tr("Click to cancel the current operation")); 51 pane.add(btnCancel, GBC.eol().anchor(GBC.CENTER)); 55 buttons.add(btnCancel); 56 btnInBackground = new JButton(tr("In background")); 57 btnInBackground.setToolTipText(tr("Click to run job in background")); 58 buttons.add(btnInBackground, GBC.std().fill(GBC.VERTICAL).insets(5, 0, 0, 0)); 59 pane.add(buttons, GBC.eol().anchor(GBC.CENTER)); 52 60 GridBagConstraints gc = GBC.eol().fill(GBC.BOTH); 53 61 gc.weighty = 1.0; … … 132 140 } 133 141 142 public void setInBackgroundPossible(boolean value) { 143 btnInBackground.setVisible(value); 144 } 145 134 146 /** 135 147 * Installs a callback for the cancel button. If callback is null, all action listeners … … 148 160 } 149 161 } 162 163 /** 164 * Installs a callback for the "In background" button. If callback is null, all action listeners 165 * are removed from the cancel button. 166 * 167 * @param callback the cancel callback 168 */ 169 public void setInBackgroundCallback(ActionListener callback) { 170 if (callback == null) { 171 ActionListener[] listeners = btnInBackground.getActionListeners(); 172 for (ActionListener l: listeners) { 173 btnInBackground.removeActionListener(l); 174 } 175 } else { 176 btnInBackground.addActionListener(callback); 177 } 178 } 179 180 @Override 181 public void updateProgress(int progress) { 182 this.progress.setValue(progress); 183 } 184 150 185 } -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
r4310 r4718 11 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor.CancelListener; 13 import org.openstreetmap.josm.gui.progress.ProgressTaskId; 13 14 import org.openstreetmap.josm.io.OsmTransferException; 14 15 import org.openstreetmap.josm.tools.BugReportExceptionHandler; … … 35 36 this(title, false); 36 37 } 37 38 38 /** 39 39 * Create the runnable object with a given message for the user. … … 73 73 private void doRealRun() { 74 74 try { 75 ProgressTaskId oldTaskId = null; 75 76 try { 76 77 progressMonitor.addCancelListener(this); 77 78 progressMonitor.beginTask(title); 79 oldTaskId = progressMonitor.getProgressTaskId(); 80 progressMonitor.setProgressTaskId(canRunInBackground()); 78 81 try { 79 82 realRun(); … … 92 95 progressMonitor.finishTask(); 93 96 progressMonitor.removeCancelListener(this); 97 progressMonitor.setProgressTaskId(oldTaskId); 94 98 if (progressMonitor instanceof PleaseWaitProgressMonitor) { 95 99 ((PleaseWaitProgressMonitor)progressMonitor).close(); 96 100 } 101 afterFinish(); 97 102 } 98 103 } catch (final Exception e) { … … 110 115 } 111 116 } 117 } 118 119 /** 120 * Can be overriden if something needs to run after progress monitor is closed. 121 */ 122 protected void afterFinish() { 123 112 124 } 113 125 … … 152 164 return progressMonitor; 153 165 } 166 167 /** 168 * Task can run in background if returned value <> null. Note that it's tasks responsibility 169 * to ensure proper synchronization, PleaseWaitRunnable doesn't with it. 170 * @return If returned value is <> null then task can run in background. TaskId could be used in future for "Always run in background" checkbox 171 */ 172 public ProgressTaskId canRunInBackground() { 173 return null; 174 } 154 175 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r4701 r4718 1021 1021 getClass().getName() + ".geometry", 1022 1022 WindowGeometry.centerInWindow(Main.parent, new Dimension(1000, 500)) 1023 );1023 ); 1024 1024 ed.showDialog(); 1025 1025 int v = ed.getValue(); … … 1177 1177 @Override 1178 1178 protected void finish() { 1179 } 1180 1181 @Override 1182 protected void afterFinish() { 1179 1183 if(cancel) 1180 1184 return; … … 1274 1278 1275 1279 if (toDownload.size() > 1) { 1276 // hide progress dialog before displaying another pop up. Really closing the1277 // dialog will be handled by PleaseWaitRunnable.1278 if (progressMonitor instanceof PleaseWaitProgressMonitor) {1279 ((PleaseWaitProgressMonitor) progressMonitor).getDialog().setVisible(false);1280 }1281 1282 1280 int ret = JOptionPane.showConfirmDialog( 1283 1281 Main.parent, -
trunk/src/org/openstreetmap/josm/gui/progress/AbstractProgressMonitor.java
r4310 r4718 6 6 import java.util.LinkedList; 7 7 import java.util.Queue; 8 9 import javax.swing.SwingUtilities; 8 10 9 11 public abstract class AbstractProgressMonitor implements ProgressMonitor { … … 61 63 } 62 64 65 protected void doInEDT(Runnable runnable) { 66 if (SwingUtilities.isEventDispatchThread()) { 67 runnable.run(); 68 } else { 69 SwingUtilities.invokeLater(runnable); 70 } 71 } 72 63 73 /*======= 64 74 * Tasks … … 69 79 } 70 80 71 public synchronized void beginTask( finalString title, int ticks) {81 public synchronized void beginTask(String title, int ticks) { 72 82 this.taskTitle = title; 73 83 checkState(State.INIT); -
trunk/src/org/openstreetmap/josm/gui/progress/ChildProgress.java
r4642 r4718 55 55 parent.childFinished(this); 56 56 } 57 58 @Override 59 public void setProgressTaskId(ProgressTaskId taskId) { 60 parent.setProgressTaskId(taskId); 61 } 62 63 @Override 64 public ProgressTaskId getProgressTaskId() { 65 return parent.getProgressTaskId(); 66 } 57 67 } -
trunk/src/org/openstreetmap/josm/gui/progress/NullProgressMonitor.java
r4310 r4718 80 80 return 0; 81 81 } 82 83 @Override 84 public void setProgressTaskId(ProgressTaskId taskId) { 85 } 86 87 @Override 88 public ProgressTaskId getProgressTaskId() { 89 return null; 90 } 82 91 } -
trunk/src/org/openstreetmap/josm/gui/progress/PleaseWaitProgressMonitor.java
r4684 r4718 4 4 import java.awt.Component; 5 5 import java.awt.Dialog; 6 import java.awt.EventQueue;7 6 import java.awt.Frame; 8 7 import java.awt.Window; … … 16 15 17 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.gui.MapFrame; 18 import org.openstreetmap.josm.gui.MapStatus.BackgroundProgressMonitor; 18 19 import org.openstreetmap.josm.gui.PleaseWaitDialog; 19 20 20 21 public class PleaseWaitProgressMonitor extends AbstractProgressMonitor { 21 22 22 private static final int PROGRESS_BAR_MAX = 100; 23 /** 24 * Implemented by both foreground dialog and background progress dialog (in status bar) 25 */ 26 public interface ProgressMonitorDialog { 27 void setVisible(boolean visible); 28 void updateProgress(int progress); 29 void setCustomText(String text); 30 void setTitle(String text); 31 void setIndeterminate(boolean newValue); 32 void appendLogMessage(String message); 33 } 34 35 public static final int PROGRESS_BAR_MAX = 100; 23 36 private final Window dialogParent; 24 37 private int currentProgressValue = 0; 25 38 39 private boolean isInBackground; 26 40 private PleaseWaitDialog dialog; 27 41 private String windowTitle; 28 42 protected ProgressTaskId taskId; 43 29 44 private boolean cancelable; 45 46 private ProgressMonitorDialog getDialog() { 47 48 BackgroundProgressMonitor backgroundMonitor = null; 49 MapFrame map = Main.map; 50 if (map != null) { 51 backgroundMonitor = map.statusLine.progressMonitor; 52 } 53 54 if (backgroundMonitor != null) { 55 backgroundMonitor.setVisible(isInBackground); 56 } 57 if (dialog != null) { 58 dialog.setVisible(!isInBackground || backgroundMonitor == null); 59 } 60 61 if (isInBackground && backgroundMonitor != null) { 62 backgroundMonitor.setVisible(true); 63 if (dialog != null) { 64 dialog.setVisible(false); 65 } 66 return backgroundMonitor; 67 } else if (backgroundMonitor != null) { 68 backgroundMonitor.setVisible(false); 69 if (dialog != null) { 70 dialog.setVisible(true); 71 } 72 return dialog; 73 } else if (dialog != null) { 74 dialog.setVisible(true); 75 return dialog; 76 } else 77 return null; 78 } 30 79 31 80 public PleaseWaitProgressMonitor() { … … 55 104 }; 56 105 106 private ActionListener inBackgroundListener = new ActionListener() { 107 @Override 108 public void actionPerformed(ActionEvent e) { 109 isInBackground = true; 110 ProgressMonitorDialog dialog = getDialog(); 111 if (dialog != null) { 112 dialog.setVisible(true); 113 } 114 } 115 }; 116 57 117 private WindowListener windowListener = new WindowAdapter(){ 58 118 @Override public void windowClosing(WindowEvent e) { … … 69 129 } 70 130 71 private void doInEDT(Runnable runnable) {72 EventQueue.invokeLater(runnable);73 }74 75 131 @Override 76 132 public void doBeginTask() { 77 133 doInEDT(new Runnable() { 78 134 public void run() { 135 Main.currentProgressMonitor = PleaseWaitProgressMonitor.this; 79 136 if (dialogParent instanceof Frame && dialog == null) { 80 137 dialog = new PleaseWaitDialog(dialogParent); … … 89 146 dialog.setCancelEnabled(cancelable); 90 147 dialog.setCancelCallback(cancelListener); 148 dialog.setInBackgroundCallback(inBackgroundListener); 91 149 dialog.setCustomText(""); 92 150 dialog.addWindowListener(windowListener); … … 109 167 doInEDT(new Runnable() { 110 168 public void run() { 111 dialog.progress.setValue(currentProgressValue); 169 ProgressMonitorDialog dialog = getDialog(); 170 if (dialog != null) { 171 dialog.updateProgress(currentProgressValue); 172 } 112 173 } 113 174 }); … … 120 181 doInEDT(new Runnable() { 121 182 public void run() { 122 dialog.setCustomText(title); 183 ProgressMonitorDialog dialog = getDialog(); 184 if (dialog != null) { 185 dialog.setCustomText(title); 186 } 123 187 } 124 188 }); … … 130 194 doInEDT(new Runnable() { 131 195 public void run() { 132 dialog.currentAction.setText(title); 196 ProgressMonitorDialog dialog = getDialog(); 197 if (dialog != null) { 198 dialog.setTitle(title); 199 } 133 200 } 134 201 }); … … 139 206 doInEDT(new Runnable() { 140 207 public void run() { 141 if (value && dialog.progress.getValue() == 0) { 142 // Enable only if progress is at the beginning. Doing intermediate progress in the middle 143 // will hide already reached progress 144 dialog.setIndeterminate(true); 145 } else { 146 dialog.setIndeterminate(false); 208 // Enable only if progress is at the beginning. Doing intermediate progress in the middle 209 // will hide already reached progress 210 ProgressMonitorDialog dialog = getDialog(); 211 if (dialog != null) { 212 dialog.setIndeterminate(value && PleaseWaitProgressMonitor.this.dialog.progress.getValue() == 0); 147 213 } 148 214 } … … 154 220 doInEDT(new Runnable() { 155 221 public void run() { 156 dialog.appendLogMessage(message); 222 ProgressMonitorDialog dialog = getDialog(); 223 if (dialog != null) { 224 dialog.appendLogMessage(message); 225 } 157 226 } 158 227 }); … … 160 229 161 230 public void close() { 162 dialog.setVisible(false); 163 dialog.setCancelCallback(null); 164 dialog.removeWindowListener(windowListener); 165 dialog.dispose(); 166 dialog = null; 167 } 168 169 public Component getDialog() { 170 return dialog; 171 } 231 doInEDT(new Runnable() { 232 @Override 233 public void run() { 234 dialog.setVisible(false); 235 dialog.setCancelCallback(null); 236 dialog.setInBackgroundCallback(null); 237 dialog.removeWindowListener(windowListener); 238 dialog.dispose(); 239 dialog = null; 240 MapFrame map = Main.map; 241 if (map != null) { 242 map.statusLine.progressMonitor.setVisible(false); 243 } 244 Main.currentProgressMonitor = null; 245 } 246 }); 247 } 248 249 public void showForegroundDialog() { 250 isInBackground = false; 251 doInEDT(new Runnable() { 252 @Override 253 public void run() { 254 dialog.setInBackgroundPossible(PleaseWaitProgressMonitor.this.taskId != null && Main.isDisplayingMapView()); 255 getDialog(); 256 } 257 }); 258 259 } 260 261 @Override 262 public void setProgressTaskId(ProgressTaskId taskId) { 263 this.taskId = taskId; 264 doInEDT(new Runnable() { 265 @Override 266 public void run() { 267 dialog.setInBackgroundPossible(PleaseWaitProgressMonitor.this.taskId != null && Main.isDisplayingMapView()); 268 } 269 }); 270 } 271 272 @Override 273 public ProgressTaskId getProgressTaskId() { 274 return taskId; 275 } 276 172 277 } -
trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitor.java
r4310 r4718 50 50 */ 51 51 void beginTask(String title, int ticks); 52 52 53 /** 53 54 * Finish this progress monitor, close the dialog or inform the parent progress monitor … … 55 56 * then further calls are ignored) 56 57 */ 58 57 59 void finishTask(); 58 60 /** … … 126 128 */ 127 129 void appendLogMessage(String message); 130 131 /** 132 * Should be used only by PleaseWaitRunnable. If taskId <> null then "In background" button will be shown 133 * @param taskId 134 */ 135 void setProgressTaskId(ProgressTaskId taskId); 136 137 /** 138 * Should be used only by PleaseWaitRunnable 139 * @param taskId 140 */ 141 ProgressTaskId getProgressTaskId(); 128 142 } -
trunk/src/org/openstreetmap/josm/gui/progress/SwingRenderingProgressMonitor.java
r3083 r4718 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.progress; 3 4 import javax.swing.SwingUtilities;5 3 6 4 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 27 25 CheckParameterUtil.ensureParameterNotNull(delegate, "delegate"); 28 26 this.delegate = delegate; 29 }30 31 private void doInEDT(Runnable runnable) {32 if (SwingUtilities.isEventDispatchThread()) {33 runnable.run();34 } else {35 SwingUtilities.invokeLater(runnable);36 }37 27 } 38 28 … … 93 83 }); 94 84 } 85 86 @Override 87 public void setProgressTaskId(ProgressTaskId taskId) { 88 } 89 90 @Override 91 public ProgressTaskId getProgressTaskId() { 92 return null; 93 } 95 94 } -
trunk/src/org/openstreetmap/josm/io/session/SessionReader.java
r4702 r4718 5 5 import static org.openstreetmap.josm.tools.Utils.equal; 6 6 7 import java.awt.Component;8 7 import java.io.BufferedInputStream; 9 import java.io.IOException;10 import java.io.InputStream;11 8 import java.io.File; 12 9 import java.io.FileInputStream; 13 10 import java.io.FileNotFoundException; 11 import java.io.IOException; 12 import java.io.InputStream; 14 13 import java.lang.reflect.InvocationTargetException; 14 import java.net.URI; 15 import java.net.URISyntaxException; 15 16 import java.util.ArrayList; 16 17 import java.util.Collections; … … 25 26 import java.util.zip.ZipException; 26 27 import java.util.zip.ZipFile; 27 import java.net.URI;28 import java.net.URISyntaxException;29 28 30 29 import javax.swing.JOptionPane; … … 34 33 import javax.xml.parsers.ParserConfigurationException; 35 34 35 import org.openstreetmap.josm.Main; 36 import org.openstreetmap.josm.gui.ExtendedDialog; 37 import org.openstreetmap.josm.gui.layer.Layer; 38 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 39 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 40 import org.openstreetmap.josm.io.IllegalDataException; 41 import org.openstreetmap.josm.tools.MultiMap; 42 import org.openstreetmap.josm.tools.Utils; 36 43 import org.w3c.dom.Document; 37 44 import org.w3c.dom.Element; … … 39 46 import org.w3c.dom.NodeList; 40 47 import org.xml.sax.SAXException; 41 42 import org.openstreetmap.josm.Main;43 import org.openstreetmap.josm.gui.ExtendedDialog;44 import org.openstreetmap.josm.gui.layer.Layer;45 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;46 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;47 import org.openstreetmap.josm.gui.progress.ProgressMonitor;48 import org.openstreetmap.josm.io.IllegalDataException;49 import org.openstreetmap.josm.tools.MultiMap;50 import org.openstreetmap.josm.tools.Utils;51 48 52 49 /** … … 153 150 File file = getFile(uriStr); 154 151 try { 155 if (file != null) {152 if (file != null) 156 153 return new BufferedInputStream(new FileInputStream(file)); 157 }else if (inZipPath != null) {154 else if (inZipPath != null) { 158 155 ZipEntry entry = zipFile.getEntry(inZipPath); 159 156 if (entry != null) { … … 178 175 try { 179 176 URI uri = new URI(uriStr); 180 if ("file".equals(uri.getScheme())) {177 if ("file".equals(uri.getScheme())) 181 178 // absolute path 182 179 return new File(uri); 183 }else if (uri.getScheme() == null) {180 else if (uri.getScheme() == null) { 184 181 // Check if this is an absolute path without 'file:' scheme part. 185 182 // At this point, (as an exception) platform dependent path separator will be recognized. 186 183 // (This form is discouraged, only for users that like to copy and paste a path manually.) 187 184 File file = new File(uriStr); 188 if (file.isAbsolute()) {185 if (file.isAbsolute()) 189 186 return file; 190 }else {187 else { 191 188 // for relative paths, only forward slashes are permitted 192 189 if (isZip()) { … … 200 197 return null; 201 198 } 202 } else {199 } else 203 200 return new File(sessionFile.toURI().resolve(uri)); 204 } 205 } 206 } else { 201 } 202 } else 207 203 throw new IOException(tr("Unsupported scheme ''{0}'' in URI ''{1}''.", uri.getScheme(), uriStr)); 208 }209 204 } catch (URISyntaxException e) { 210 205 throw new IOException(e); … … 328 323 CancelOrContinueDialog dialog = new CancelOrContinueDialog(); 329 324 dialog.show( 330 tr("Unable to load layer"),331 tr("Cannot load layer of type ''{0}'' because no suitable importer was found.", type),332 JOptionPane.WARNING_MESSAGE,333 progressMonitor334 );325 tr("Unable to load layer"), 326 tr("Cannot load layer of type ''{0}'' because no suitable importer was found.", type), 327 JOptionPane.WARNING_MESSAGE, 328 progressMonitor 329 ); 335 330 if (dialog.isCancel()) { 336 331 progressMonitor.cancel(); … … 347 342 CancelOrContinueDialog dialog = new CancelOrContinueDialog(); 348 343 dialog.show( 349 tr("Unable to load layer"),350 tr("Cannot load layer {0} because it depends on layer {1} which has been skipped.", idx, d),351 JOptionPane.WARNING_MESSAGE,352 progressMonitor353 );344 tr("Unable to load layer"), 345 tr("Cannot load layer {0} because it depends on layer {1} which has been skipped.", idx, d), 346 JOptionPane.WARNING_MESSAGE, 347 progressMonitor 348 ); 354 349 if (dialog.isCancel()) { 355 350 progressMonitor.cancel(); … … 375 370 CancelOrContinueDialog dialog = new CancelOrContinueDialog(); 376 371 dialog.show( 377 tr("Error loading layer"),378 tr("<html>Could not load layer {0} ''{1}''.<br>Error is:<br>{2}</html>", idx, name, exception.getMessage()),379 JOptionPane.ERROR_MESSAGE,380 progressMonitor381 );372 tr("Error loading layer"), 373 tr("<html>Could not load layer {0} ''{1}''.<br>Error is:<br>{2}</html>", idx, name, exception.getMessage()), 374 JOptionPane.ERROR_MESSAGE, 375 progressMonitor 376 ); 382 377 if (dialog.isCancel()) { 383 378 progressMonitor.cancel(); … … 397 392 for (Entry<Integer, Layer> e : layersMap.entrySet()) { 398 393 Layer l = e.getValue(); 399 if (l == null) continue; 394 if (l == null) { 395 continue; 396 } 400 397 l.setName(names.get(e.getKey())); 401 398 layers.add(l); … … 418 415 SwingUtilities.invokeAndWait(new Runnable() { 419 416 @Override public void run() { 420 Component parent;421 if (progressMonitor instanceof PleaseWaitProgressMonitor) {422 parent = ((PleaseWaitProgressMonitor) progressMonitor).getDialog();423 } else {424 parent = Main.parent;425 }426 417 ExtendedDialog dlg = new ExtendedDialog( 427 parent,418 Main.parent, 428 419 title, 429 420 new String[] { tr("Cancel"), tr("Skip layer and continue") } 430 );421 ); 431 422 dlg.setButtonIcons(new String[] {"cancel", "dialogs/next"}); 432 423 dlg.setIcon(icon);
Note:
See TracChangeset
for help on using the changeset viewer.