Revision 11130 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/layerOperations/ComposedLayer.java

View differences:

ComposedLayer.java
2 2

  
3 3
import java.awt.Graphics2D;
4 4
import java.awt.image.BufferedImage;
5
import java.util.ArrayList;
6
import java.util.Iterator;
5 7

  
6 8
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
9
import com.hardcode.gdbms.engine.data.driver.DriverException;
10
import com.iver.cit.gvsig.fmap.MapContext;
7 11
import com.iver.cit.gvsig.fmap.ViewPort;
8 12
import com.iver.cit.gvsig.fmap.layers.FLayer;
13
import com.iver.cit.gvsig.fmap.layers.LayerDrawEvent;
9 14
import com.iver.utiles.swing.threads.Cancellable;
10 15

  
11 16
/**
12
 * Interface for the classes that make able 
17
 * Abstract class for the classes that make able 
13 18
 * a single draw for a layers group
14 19
 *  
15 20
 * @see  com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
16 21
 */
17
public interface ComposedLayer {
22
public abstract class ComposedLayer {
18 23

  
24
	ArrayList pendingLayersEvents= new ArrayList(); 
25
	MapContext mapContext = null; 
26
	
27
	public ComposedLayer(){
28
		
29
	}
30

  
31
	public void setMapContext(MapContext mapContext) {
32
		this.mapContext = mapContext;
33
	}
34
	
19 35
	/**
20 36
	 * Checks if the layer can be added to this group
21 37
	 * 
22 38
	 * @param layer
23 39
	 * @return layer can be added or not
24 40
	 */
25
	public boolean canAdd(FLayer layer);
41
	public abstract boolean canAdd(FLayer layer);
26 42
	
27 43
	/**
28
	 * Adds the layer to the draw group
44
	 * Adds the layer to the draw group. 
45
	 * You have to implements the doAdd(FLayer) method.
46
	 * 
47
	 * 
29 48
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer)
30 49
	 * 
31 50
	 * @param layer
32 51
	 * @throws Exception 
33 52
	 */
34
	public void add(FLayer layer) throws Exception;
53
	public final void add(FLayer layer) throws Exception {
54
		if (this.mapContext == null){
55
			this.mapContext =layer.getMapContext();
56
		}
57
        doAdd(layer);
58
    	pendingLayersEvents.add(layer);		
59
	}
35 60
	
36 61
	/**
37 62
	 * Draws all the group in one pass
38
	 * 
63
	 * You have to implements the doDraw method. 
39 64
	 *
40 65
	 * @see  com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
41 66
	 */
42
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
43
			Cancellable cancel,double scale) throws ReadDriverException;
67
    public final void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
68
			Cancellable cancel,double scale) throws ReadDriverException {
69
    	doDraw(image, g, viewPort, cancel, scale);
70
    	fireLayerDrawingEvents(g,viewPort);
71
		pendingLayersEvents.clear();    	
72
    }
73
    
74
	/**
75
	 * Fires the event LayerDrawEvent.LAYER_AFTER_DRAW for every
76
	 * layers of the group.
77
	 * 
78
	 *  
79
	 *  @see com.iver.cit.gvsig.fmap.layers.LayerDrawEvent
80
	 * 
81
	 */
82
	private void fireLayerDrawingEvents(Graphics2D g, ViewPort viewPort) {
83
		Iterator iter = pendingLayersEvents.iterator();
84
		LayerDrawEvent afterEvent;
85
		FLayer layer = null ;
86
		while (iter.hasNext()) {
87
			layer =(FLayer)iter.next();
88
			afterEvent = new LayerDrawEvent(layer, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
89
			System.out.println("+++ evento " + afterEvent.getLayer().getName());
90
			mapContext.fireLayerDrawingEvent(afterEvent);
91
		}
92
	}
93
	
44 94

  
95
	/**
96
	 * Adds the layer to the draw group.
97
	 * Specific implementation. 
98
	 * 
99
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#add(FLayer)
100
	 * 
101
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer)
102
	 * 
103
	 * @param layer
104
	 * @throws Exception 
105
	 */
106
	protected abstract void doAdd(FLayer layer) throws Exception ;
45 107
	
108
	/**
109
	 * Draws all the group in one pass.
110
	 * Specific implementation. 
111
	 *
112
	 * @see  com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
113
	 *
114
	 * @see  com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
115
	 */	
116
	protected abstract void doDraw(BufferedImage image, Graphics2D g, ViewPort viewPort,
117
			Cancellable cancel,double scale) throws ReadDriverException ;
118
    
119
	
46 120
}

Also available in: Unified diff