Revision 473

View differences:

2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.api/src/main/java/org/gvsig/view3d/swing/api/MapControl3D.java
39 39
@SuppressWarnings("deprecation")
40 40
public interface MapControl3D extends Component, Disposable, Observable{
41 41
    
42
    static final String BEFORE_DISPOSE_PANEL_NOTIFICATION =
42
    static final String BEFORE_DISPOSE_MAPCONTEX3D_NOTIFICATION =
43 43
        "MapControl3D.beforeDisposePanel";
44
    static final String AFTER_DISPOSE_PANEL_NOTIFICATION =
44
    static final String AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION =
45 45
        "MapControl3D.afterDisposePanel";
46 46
    
47 47
    /**
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/DefaultView3DSwingManager.java
111 111

  
112 112
            Notification n = (Notification) notification;
113 113
            if (n.getType().equalsIgnoreCase(
114
                MapControl3D.AFTER_DISPOSE_PANEL_NOTIFICATION)) {
114
                MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION)) {
115 115

  
116 116
                MapControl3D mapControl3D = (MapControl3D) observable;
117 117
                MapContext mapContext = mapControl3D.getMapContext();
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/GvSIGLayerDataRaster.java
28 28
import gov.nasa.worldwind.avlist.AVKey;
29 29
import gov.nasa.worldwind.avlist.AVList;
30 30
import gov.nasa.worldwind.data.BufferedImageRaster;
31
import gov.nasa.worldwind.data.ByteBufferRaster;
32 31
import gov.nasa.worldwind.data.DataRaster;
33 32
import gov.nasa.worldwind.geom.Sector;
34
import gov.nasa.worldwind.util.BufferWrapper;
35 33

  
36 34
import java.awt.Dimension;
37 35
import java.awt.Graphics2D;
......
39 37
import java.awt.geom.AffineTransform;
40 38
import java.awt.geom.Point2D;
41 39
import java.awt.image.BufferedImage;
42
import java.awt.image.DataBufferByte;
43
import java.awt.image.WritableRaster;
44
import java.nio.ByteBuffer;
45 40

  
46 41
import org.cresques.cts.ICoordTrans;
47 42
import org.cresques.cts.IProjection;
......
162 157
                new Object[] { degrees[0], degrees[1], degrees[2], degrees[3] });
163 158
            return;
164 159
        } catch (ReadException e) {
165
            LOG.warn("Can't get full envelope of {}", layer.getInfoString());
160
            LOG.warn("Can't get full envelope of {}", layer.getName());
166 161
        }
167 162

  
168 163
        int canvasWidth = canvas.getWidth();
......
204 199
        viewPort.refreshExtent();
205 200

  
206 201
        try {
207

  
208 202
            layer.draw(image, (Graphics2D) image.getGraphics(), viewPort,
209 203
                mapControl3D.getCancellable(), getScale(viewPort));
210 204

  
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
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);
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/DefaultView3DPanel.java
46 46
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
47 47
 *
48 48
 */
49
public class DefaultView3DPanel extends JPanel implements View3DPanel, ComponentListener {
50

  
49
public class DefaultView3DPanel extends JPanel implements View3DPanel {
50
    
51 51
    private static final long serialVersionUID = -87105248886531868L;
52 52
    
53 53
    private ObservableHelper observableHelper;
......
68 68

  
69 69
        this.add(mapControl3D.asJComponent(), BorderLayout.CENTER);
70 70
        
71
        this.addComponentListener(this);
71
        this.addComponentListener(new ComponentListener() {
72
            
73
            public void componentShown(ComponentEvent e) {
74
            }
75
            
76
            public void componentResized(ComponentEvent e) {
77
            }
78
            
79
            public void componentMoved(ComponentEvent e) {
80
            }
81
            
82
            public void componentHidden(ComponentEvent e) {
83
                getMapControl3D().dispose();
84
            }
85
        });
72 86
    }
73 87

  
74 88
    public JComponent asJComponent() {
......
85 99
            WindowManager.MODE.WINDOW);
86 100
    }
87 101
    
88
    @Override
89
    public boolean requestFocusInWindow() {
90
        return super.requestFocusInWindow();
91
    }
92

  
93 102
    public void addObserver(Observer o) {
94 103
        if(observableHelper != null){
95 104
            observableHelper.addObserver(o);
......
108 117
            observableHelper.deleteObservers();
109 118
        }
110 119
    }
111

  
112
    public void componentResized(ComponentEvent e) {
113
    }
114

  
115
    public void componentMoved(ComponentEvent e) {
116
    }
117

  
118
    public void componentShown(ComponentEvent e) {
119
    }
120

  
121
    public void componentHidden(ComponentEvent e) {
122
        getMapControl3D().dispose();
123
    }
124 120
}
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.app/org.gvsig.view3d.app.common/src/main/java/org/gvsig/view3d/app/mainplugin/View3DExtension.java
32 32
import org.gvsig.app.project.documents.view.gui.IView;
33 33
import org.gvsig.fmap.mapcontext.MapContext;
34 34
import org.gvsig.fmap.mapcontext.layers.FLayers;
35
import org.gvsig.tools.observer.Notification;
36
import org.gvsig.tools.observer.Observable;
37
import org.gvsig.tools.observer.Observer;
35 38
import org.gvsig.view3d.swing.api.MapControl3D;
36 39
import org.gvsig.view3d.swing.api.View3DPanel;
37 40
import org.gvsig.view3d.swing.api.View3DSwingLocator;
......
42 45
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
43 46
 *
44 47
 */
45
public class View3DExtension extends Extension {
48
public class View3DExtension extends Extension implements Observer{
46 49

  
47 50
    public void initialize() {
48 51
        registerIcons();
......
69 72
                View3DPanel view3DPanel =
70 73
                    manager.createView3DPanel(view.getMapControl()
71 74
                        .getMapContext(), type);
75
                view3DPanel.getMapControl3D().addObserver(this);
72 76
                view3DPanel.show();
73 77
            }
74 78
        }
......
142 146
        return true;
143 147
    }
144 148

  
149
    public void update(Observable observable, Object notification) {
150
        if (observable instanceof MapControl3D
151
            && notification instanceof Notification) {
152

  
153
            Notification n = (Notification) notification;
154
            if (n.getType().equalsIgnoreCase(
155
                MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION)) {
156
                ApplicationManager appManager = ApplicationLocator.getManager();
157
                appManager.refreshMenusAndToolBars();
158
            }
159
        }
160
        
161
    }
162

  
145 163
}

Also available in: Unified diff