Revision 473 2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/DefaultMapControl3D.java

View differences:

DefaultMapControl3D.java
202 202

  
203 203
    public void dispose() {
204 204
        
205
        Notification beforeDisposeNotification =
206
            new BaseNotification(MapControl3D.BEFORE_DISPOSE_PANEL_NOTIFICATION,
207
                null);
208
        
209
        observableHelper.notifyObservers(this,beforeDisposeNotification);
210
        
211
        this.cancellable.setCanceled(true);
212
        
213
        try {
214
            // It is necessary to wait to draw threads check cancellable object
215
            // before dispose MapControl3D
216
            Thread.sleep(100); 
217
        } catch (InterruptedException e) {
218
            LOG.warn("This thread has been interrupted when it was waitting until layers cancel drawing");
219
        }
205
        Thread disposeThread = new Thread(new Runnable() {
206
            
207
            public void run() {
208
                Notification beforeDisposeNotification =
209
                    new BaseNotification(
210
                        MapControl3D.BEFORE_DISPOSE_MAPCONTEX3D_NOTIFICATION, null);
220 211

  
221
        if (this.wwd != null) {
222
            this.wwd = null;
223
        }
212
                observableHelper.notifyObservers(DefaultMapControl3D.this,
213
                    beforeDisposeNotification);
224 214

  
225
        WorldWind.shutDown();
215
                while(WorldWind.getRetrievalService().hasActiveTasks()){
216
                    try {
217
                        Thread.sleep(100);
218
                    } catch (InterruptedException e) {
219
                        LOG.warn("This thread has been interrupted, dispose action can not be performed");
220
                        return;
221
                    }
222
                }
223

  
224
                disposeWwd();
225

  
226
                Notification afterDisposeNotification =
227
                    new BaseNotification(
228
                        MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION, null);
229

  
230
                observableHelper
231
                    .notifyObservers(DefaultMapControl3D.this, afterDisposeNotification);
232
            }
233
        }, "Dispose World Wind thread");
226 234
        
227
        this.cancellable.setCanceled(false);
228
        
229
        Notification afterDisposeNotification =
230
            new BaseNotification(MapControl3D.AFTER_DISPOSE_PANEL_NOTIFICATION,
231
                null);
232
        
233
        observableHelper.notifyObservers(this,afterDisposeNotification);
235
        disposeThread.start();
234 236
    }
235 237
    
236 238
    public Cancellable getCancellable(){
......
279 281
        }
280 282
        return this.wwd;
281 283
    }
284
    
285
    private void disposeWwd(){
286
        if (getWwd() != null) {
287
            this.wwd = null;
288
        }
289
    }
282 290

  
283 291
    public void hideAtmosphere() {
284 292
        hideLayer(SkyGradientLayer.class);

Also available in: Unified diff