Bonjour,

J'essaye d'utiliser le BufferedMapBean et de comparer ses performances avec celle d'un MapBean normal,

L'ajout des ShapeLayers et des pluginLayer fonctionne sans erreurs.


Cependant, Je dispose d'une classe FileLayer qui étend la classe OMGraphicHandlerLayer :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
public class FileLayer extends OMGraphicHandlerLayer implements ActionListener {..}
la classe FileLayer lit un fichier .txt et en extrait un tableau de points qu'elle doit dessiner.

L'implémentation suivante fonctionne parfaitement avec le MapBean :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
 
package vue.layers;
 
import java.awt.Color;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.regex.Pattern;
 
import javax.swing.JFrame;
 
 
import vue.TestWindow;
 
import com.bbn.openmap.event.ProjectionEvent;
import com.bbn.openmap.layer.OMGraphicHandlerLayer;
import com.bbn.openmap.omGraphics.OMColor;
import com.bbn.openmap.omGraphics.OMGraphic;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.OMPoly;
import com.bbn.openmap.proj.Cylindrical;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.util.Debug;
 
 
public class FileLayer  extends OMGraphicHandlerLayer implements ActionListener {
 
	private static final long serialVersionUID = 1L;
 
	//Flag for lineType: true is LINETYPE_STRAIGHT, false is LINETYPE_GREATCIRCLE.
	protected boolean boxy = true;
 
    //The equator, dateline and meridian lines, premade.
    protected OMGraphicList markerLines = null;
 
    //Vecteur contenant les tableaux de couleurs+coordonnéesXY de chaque poly 
    private Vector<Vector<Float>> vectPoly;
 
    //Vecteur contenant les couleurs
    private Vector<int[]> vectCoul;
 
    //permet de la retrouver quand on souhaite les afficher/supprimer sur le graphique
    public int indice;
 
    public int transparence; 
 
 
    private String titre;
    private String[] legende = new String[11];;
    private int nbLegende = 0;
 
 
 
    // Constructor
    public FileLayer (JFrame frame, String cheminResultat, String cheminCouleur, int pos, int indiceABS, int indiceORD, int trans) {
		// TODO Auto-generated constructor stub
 
 
    	// precalculate for boxy
        boxy = true;
        setName(cheminResultat);
 
        vectPoly = new Vector<Vector<Float>>();
        Vector<Float> vectTmp = new Vector<Float>();
 
		// Initialisation de vecteur de legende
        for(int i = 0 ; i < legende.length; i++){
        	legende[i] = "";
		}
 
 
        // Lecture du fichier et constructiondes du Vecteur contenant les coordonnées 
        // et la couleur sous forme de tableau pour chaque poly :
        // float [couleur, x, y, x, y, ... ,x, y]
 
    	// ouverture d'un flux en lecture sur le fichier des résultats
		BufferedReader in;
 
		try {
			in = new BufferedReader(
					new FileReader(cheminResultat));
 
			//double start = System.currentTimeMillis();
			//boucle : lecture des éléments graphiques un par un
			String line;
			while ((line = in.readLine()) != null) {				
				if(line.length()>1){
					if(!(line.substring(0,2).equals("# "))){
						// on n'est pas sur une ligne de commentaire
						if(line.substring(0,4).equals("#S A"))
						{
							// ligne de couleur
							if(vectTmp.size()!=0)
							{
								vectPoly.add(vectTmp);
							}
							vectTmp = new Vector<Float>();
					        vectTmp.add(Float.parseFloat(line.substring(4,8)));
						}
						else if(Pattern.compile("^#[aA][0-9].[0-9][ \t\n\f\r]*=.*").matcher(line).matches())
						{
							nbLegende = (int)(Double.parseDouble(line.substring(2, 5))*10);
							legende[nbLegende] = line.replaceAll("^#[aA][0-9].[0-9][ \t\n\f\r]*=", "");
						}
						else if(Pattern.compile("^#[tT]itre[ \t\n\f\r]*=.*").matcher(line).matches())
						{
							titre = line.replaceAll("^#[tT]itre[ \t\n\f\r]*=", "").trim();
						}
						else
						{
							// ligne de coodornnées
 
							StringTokenizer st = new StringTokenizer(line);
							String tab[] = new String[st.countTokens()];
 
 
							int taille = st.countTokens();
 
							for(int j = 0; j<taille; j++){
									tab[j] = st.nextToken();
							}
 
							vectTmp.add(Float.parseFloat(tab[indiceABS]));
							vectTmp.add(Float.parseFloat(tab[indiceORD]));
						}
					}
				}			
			}
 
			// pour enregistrer le dernier
			if(vectTmp.size()!=0){
				vectPoly.add(vectTmp);
			}
 
 
 
 
			// fermeture du flux de lecture
			in.close();
 
 
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
 
		 // Lecture du fichier de gestion des couleurs
		 // Vecteur <Float[R,G,B]; Float[R,G,B]; ... Float[R,G,B]>
		 vectCoul = new Vector<int[]>(); 
		 // si ce dernier n'existe pas, on prends une pallette de gris
		for(int i= 0; i < 101; i++){
			vectCoul.add(new int[]{i+50,i+50,i+50});
		}
 
    }
 
    /**
     * Implementing the ProjectionPainter interface.
     */
    public synchronized void renderDataForProjection(Projection proj,
                                                     java.awt.Graphics g) {
        if (proj == null) {
            Debug.error("FileLayer .renderDataForProjection: null projection!");
            return;
        } else if (!proj.equals(getProjection())) {
            setProjection(proj.makeClone());
            // Figure out which line type to use
            if (proj instanceof Cylindrical)
                boxy = true;
            else
                boxy = false;
            	setList(constructGraticuleLines());
        }
        paint(g);
    }
 
    /**
     * Invoked when the projection has changed or this Layer has been
     * added to the MapBean.
     * <p>
     * Perform some extra checks to see if reprojection of the
     * graphics is really necessary.
     * 
     * @param e ProjectionEvent
     *  
     */
    public void projectionChanged(ProjectionEvent e) {
 
        // extract the projection and check to see if it's really
        // different.
        // if it isn't then we don't need to do all the work again,
        // just
        // repaint.
        Projection proj = setProjection(e);
        if (proj == null) {
            repaint();
            return;
        }
 
        // Figure out which line type to use
        if (proj instanceof Cylindrical)
            boxy = true;
        else
            boxy = false;
 
        setList(null);
        doPrepare();
    }
 
    /**
     * Creates the OMGraphic list with graticule lines.
     */
    public synchronized OMGraphicList prepare() {
        return constructGraticuleLines();
    }
 
    /**
     * Create the graticule lines.
     * <p>
     * NOTES:
     * <ul>
     * <li>Currently graticule lines are hardcoded to 10 degree
     * intervals.
     * <li>No thought has been given to clipping based on the view
     * rectangle. For non-boxy projections performance may be degraded
     * at very large scales. (But we make up for this by running the
     * task in its own thread to support liveness).
     * </ul>
     * 
     * @return OMGraphicList new graphic list
     */
    public OMGraphicList constructGraticuleLines() {
 
        OMGraphicList newgraphics = new OMGraphicList(20);
        // Lets figure out which lines should be painted...
        Projection projection = getProjection();
 
        if (projection == null) {
            return newgraphics;
        }
 
        if (markerLines == null) {
            markerLines = constructMarkerLines();
        } else {
            synchronized (markerLines) {
                setLineTypeAndProject(markerLines,
                        boxy ? OMGraphic.LINETYPE_STRAIGHT
                                : OMGraphic.LINETYPE_RHUMB);
            }
        }
 
        newgraphics.add(markerLines);
 
        if (Debug.debugging("graticule")) {
            Debug.output("GraticuleLayer.constructGraticuleLines(): "
                    + "constructed " + newgraphics.size() + " graticule lines");
        }
 
        return newgraphics;
    }
 
    /** Constructs the Dateline and Prime Meridian lines. */
    protected OMGraphicList constructMarkerLines() {
 
        OMGraphicList lines = new OMGraphicList();
        OMPoly currentLine;
 
 
        // pour touts les fauchées
        for(int i = 0; i<vectPoly.size(); i++){
 
 
 
        	float[] llp = new float[vectPoly.elementAt(i).size()-1];
 
        	for(int j=1; j<vectPoly.elementAt(i).size();j++){
        		llp[j-1] = vectPoly.elementAt(i).elementAt(j);
        	}
 
            currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, !boxy ? OMGraphic.LINETYPE_STRAIGHT
                    : OMGraphic.LINETYPE_GREATCIRCLE);
 
 
            currentLine.setLinePaint(new Color(vectCoul.elementAt((int)(vectPoly.elementAt(i).elementAt(0)*100.0f))[0],vectCoul.elementAt((int)(vectPoly.elementAt(i).elementAt(0)*100.0f))[1],vectCoul.elementAt((int)(vectPoly.elementAt(i).elementAt(0)*100.0f))[2],transparence));
 
 
            }
 
 
            currentLine.setDoShapes(false);
            lines.addOMGraphic(currentLine);
 
        }
 
 
        if (Debug.debugging("graticule")) {
            Debug.output("GraticuleLayer.constructMarkerLines(): "
                    + "constructed " + lines.size() + " graticule lines");
        }
 
        lines.generate(getProjection());
 
 
        return lines;
    }
 
    /**
     * Take a graphic list, and set all the items on the list to the
     * line type specified, and project them into the current
     * projection.
     * 
     * @param list the list containing the lines to change.
     * @param lineType the line type to cahnge the lines to.
     */
    protected void setLineTypeAndProject(OMGraphicList list, int lineType) {
        int size = list.size();
        OMGraphic graphic;
        for (int i = 0; i < size; i++) {
            graphic = list.getOMGraphicAt(i);
            graphic.setLineType(lineType);
            graphic.generate(getProjection());
        }
    }
 
  public String[] getListeLegendes() 
  {
	  return legende;
  }
 
  public String getTitre() 
  {
	  return titre;
  }
 
  public void ResLogger(String Text) {
 
	  TestWindow.Logger(Text);
  }
}


J'ajoute le fileLayer à mon BufferedMapbean/MapBean de la manière suivante :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
 
public void AddFileLayer(String chemin) {
 
	ResltatLayerAdded = true;
 
	fileLayer= new FileLayer(chemin,"/",1,0,1,1);
 
        RenderPolicy rp = new BufferedImageRenderPolicy();
 
        fileLayer.setRenderPolicy(rp);
 
	mapBean.add(fileLayer);
 
	this.setVisible(true);
 
	}

Lors de l'ajout d'un tel layer releve une erreur de debug dans la console ( au moment où le layer essaye de s'afficher ) : |LayerWorker.construct(): null


[Problème]
J'aimerai bien savoir comment faire pour que je puisse utiliser mon FileLayer dans un BufferedMapBean .


Des commentaires sur les performances du BufferedMapBean comparées à celles du MapBean normal sont les bienvenues.


Merci