Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1011 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / layerOperations / ComposedLayer.java @ 12904

History | View | Annotate | Download (4.3 KB)

1
package com.iver.cit.gvsig.fmap.layers.layerOperations;
2

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

    
9
import javax.print.attribute.PrintRequestAttributeSet;
10

    
11
import com.iver.cit.gvsig.fmap.DriverException;
12
import com.iver.cit.gvsig.fmap.MapContext;
13
import com.iver.cit.gvsig.fmap.ViewPort;
14
import com.iver.cit.gvsig.fmap.layers.FLayer;
15
import com.iver.cit.gvsig.fmap.layers.LayerDrawEvent;
16
import com.iver.utiles.swing.threads.Cancellable;
17

    
18
/**
19
 * Abstract class for the classes that make able
20
 * a single draw for a layers group
21
 *
22
 * @see  com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
23
 */
24
public abstract class ComposedLayer {
25

    
26
        ArrayList pendingLayersEvents= new ArrayList();
27
        MapContext mapContext = null;
28

    
29
        public ComposedLayer(){
30

    
31
        }
32

    
33
        public void setMapContext(MapContext mapContext) {
34
                this.mapContext = mapContext;
35
        }
36

    
37
        /**
38
         * Checks if the layer can be added to this group
39
         *
40
         * @param layer
41
         * @return layer can be added or not
42
         */
43
        public abstract boolean canAdd(FLayer layer);
44

    
45
        /**
46
         * Adds the layer to the draw group.
47
         * You have to implements the doAdd(FLayer) method.
48
         *
49
         *
50
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer)
51
         *
52
         * @param layer
53
         * @throws Exception
54
         */
55
        public final void add(FLayer layer) throws Exception {
56
                if (this.mapContext == null){
57
                        this.mapContext =layer.getMapContext();
58
                }
59
        doAdd(layer);
60
            pendingLayersEvents.add(layer);
61
        }
62

    
63
        /**
64
         * Draws all the group in one pass
65
         * You have to implements the doDraw method.
66
         *
67
         * @see  com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
68
         */
69
    public final void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
70
                        Cancellable cancel,double scale) throws DriverException {
71
            doDraw(image, g, viewPort, cancel, scale);
72
            fireLayerDrawingEvents(g,viewPort);
73
                pendingLayersEvents.clear();
74
    }
75

    
76
        /**
77
         * Prints all the group in one pass
78
         * You have to implements the doDraw method.
79
         *
80
         * @see  com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
81
         */
82
    public final void print(Graphics2D g, ViewPort viewPort,
83
                        Cancellable cancel,double scale,PrintRequestAttributeSet properties) throws DriverException {
84
            doPrint(g, viewPort, cancel, scale,properties);
85
                pendingLayersEvents.clear();
86
    }
87

    
88
        /**
89
         * Fires the event LayerDrawEvent.LAYER_AFTER_DRAW for every
90
         * layers of the group.
91
         *
92
         *
93
         *  @see com.iver.cit.gvsig.fmap.layers.LayerDrawEvent
94
         *
95
         */
96
        private void fireLayerDrawingEvents(Graphics2D g, ViewPort viewPort) {
97
                Iterator iter = pendingLayersEvents.iterator();
98
                LayerDrawEvent afterEvent;
99
                FLayer layer = null ;
100
                while (iter.hasNext()) {
101
                        layer =(FLayer)iter.next();
102
                        afterEvent = new LayerDrawEvent(layer, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
103
                        System.out.println("+++ evento " + afterEvent.getLayer().getName());
104
                        mapContext.fireLayerDrawingEvent(afterEvent);
105
                }
106
        }
107

    
108

    
109

    
110
        /**
111
         * Adds the layer to the draw group.
112
         * Specific implementation.
113
         *
114
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#add(FLayer)
115
         *
116
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#canAdd(FLayer)
117
         *
118
         * @param layer
119
         * @throws Exception
120
         */
121
        protected abstract void doAdd(FLayer layer) throws Exception ;
122

    
123
        /**
124
         * Draws all the group in one pass.
125
         * Specific implementation.
126
         *
127
         * @see  com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
128
         *
129
         * @see  com.iver.cit.gvsig.fmap.layers.FLayer#draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
130
         */
131
        protected abstract void doDraw(BufferedImage image, Graphics2D g, ViewPort viewPort,
132
                        Cancellable cancel,double scale) throws DriverException ;
133

    
134
        /**
135
         * Prints all the group in one pass.
136
         * Specific implementation.
137
         *
138
         * @see  com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer#print(Graphics2D, ViewPort, Cancellable, double)
139
         *
140
         * @see  com.iver.cit.gvsig.fmap.layers.FLayer#print(Graphics2D, ViewPort, Cancellable, double)
141
         */
142
        protected abstract void doPrint(Graphics2D g, ViewPort viewPort,
143
                        Cancellable cancel,double scale,PrintRequestAttributeSet properties) throws DriverException ;
144

    
145

    
146
}