Revision 7570

View differences:

trunk/libraries/libJCRS/src/DEMO/ComandosListener.java
1
/*
2
 * Created on 17-jun-2003
3
 *
4
 * Copyright (c) 2003
5
 * Francisco Jos�Pearrubia Mart�ez
6
 * IVER Tecnolog�s de la Informacin S.A.
7
 * Salamanca 50
8
 * 46005 Valencia (        SPAIN )
9
 * +34 963163400
10
 * mailto:fran@iver.es
11
 * http://www.iver.es
12
 */
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
package DEMO;
54

  
55
import java.awt.Color;
56
import java.awt.Graphics2D;
57
import java.awt.HeadlessException;
58
import java.awt.Image;
59
import java.awt.event.ActionEvent;
60
import java.awt.event.ActionListener;
61
import java.awt.image.ImageObserver;
62
import java.io.File;
63
import java.io.FileNotFoundException;
64
import java.io.IOException;
65

  
66
import javax.swing.JDialog;
67

  
68
import org.cresques.cts.IProjection;
69
//import org.cresques.cts.ProjectionPool;
70
import org.geotools.data.DataSourceException;
71
import org.geotools.data.DataStore;
72
import org.geotools.data.FeatureSource;
73
import org.geotools.map.DefaultMapLayer;
74
import org.geotools.map.MapLayer;
75
import org.geotools.styling.Style;
76
import org.geotools.styling.StyleBuilder;
77

  
78
import com.hardcode.driverManager.Driver;
79
import com.hardcode.driverManager.DriverLoadException;
80
import com.iver.cit.gvsig.fmap.DriverException;
81
import com.iver.cit.gvsig.fmap.MapContext;
82
import com.iver.cit.gvsig.fmap.MapControl;
83
import com.iver.cit.gvsig.fmap.ViewPort;
84
import com.iver.cit.gvsig.fmap.core.IGeometry;
85
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
86
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
87
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
88
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
89
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
90
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
91
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
92
import com.iver.cit.gvsig.fmap.layers.CancelationException;
93
import com.iver.cit.gvsig.fmap.layers.FLayer;
94
import com.iver.cit.gvsig.fmap.layers.FLyrGT2_old;
95
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
96
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
97
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
98
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
99
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
100
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel;
101

  
102
import com.iver.cit.gvsig.gui.DataBaseOpenDialog;
103
import com.iver.cit.gvsig.gui.FOpenDialog;
104
import com.iver.cit.gvsig.gui.FPanelLocConfig;
105
import com.iver.cit.gvsig.gui.FileOpenDialog;
106
import com.iver.cit.gvsig.gui.Table;
107
import com.iver.cit.gvsig.gui.panels.ProjChooserPanel;
108
import com.iver.cit.gvsig.gui.styling.SymbolSelector;
109
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow;
110
import com.iver.cit.gvsig.project.ProjectTable;
111
import com.vividsolutions.jts.geom.LineString;
112
import com.vividsolutions.jts.geom.MultiLineString;
113
import com.vividsolutions.jts.geom.MultiPoint;
114
import com.vividsolutions.jts.geom.Point;
115

  
116

  
117

  
118
//import java.awt.Frame;
119

  
120
/**
121
 * @author Administrador
122
 *
123
 * To change the template for this generated type comment go to
124
 * Window>Preferences>Java>Code Generation>Code and Comments
125
 */
126
public class ComandosListener implements ActionListener {
127
	private MapControl m_MapControl;
128
    private MapContext m_Mapa;
129
    private SingleView theView;
130
    
131
    private static final boolean WKB_ENABLED = true;
132
    
133
    class MyImageObserver implements ImageObserver {
134

  
135
    	private MapControl mapCtrl;
136
    	public MyImageObserver(MapControl mapCtrl)
137
    	{
138
    		this.mapCtrl = mapCtrl;
139
    	}
140
		public boolean imageUpdate(Image img,
141
                int infoflags,
142
                int x,
143
                int y,
144
                int width,
145
                int height) {
146
			if ((infoflags | ImageObserver.ALLBITS) != 0)
147
			{
148
				// TODO: A?ADIR ALGO AS? AL MAPCONTROL
149
				// if (mapCtrl.getStatus() == MapControl.ACTUALIZADO)
150
				{
151
					// System.out.println("Image " + infoflags);
152
					mapCtrl.drawGraphics();
153
				}
154
			}
155
			return true;
156
		}
157
    	
158
    }
159
    
160
    private MyImageObserver theImgObserver;
161
    
162
    PruebasGT2 pruebasGT2 = new PruebasGT2();
163

  
164
    public ComandosListener(MapControl mapa, SingleView Owner) {
165
        m_Mapa = mapa.getMapContext();
166
        theView = Owner;
167
        m_MapControl = mapa;
168
    }
169
    
170
    /**
171
     * Load the data from the specified dataStore and construct a {@linkPlain Context context} with
172
     * a default style.
173
     *
174
     * @param url The url of the shapefile to load.
175
     * @param name DOCUMENT ME!
176
     *
177
     * @throws IOException is a I/O error occured.
178
     * @throws DataSourceException if an error occured while reading the data source.
179
     * @throws FileNotFoundException DOCUMENT ME!
180
     */
181
    protected void loadLayer(DataStore store, String layerName)
182
        throws IOException, DataSourceException {
183
        final FeatureSource features = store.getFeatureSource(layerName);
184

  
185
        // Create the style
186
        final StyleBuilder builder = new StyleBuilder();
187
        final Style style;
188
        Class geometryClass = features.getSchema().getDefaultGeometry().getType();
189

  
190
        if (LineString.class.isAssignableFrom(geometryClass)
191
                || MultiLineString.class.isAssignableFrom(geometryClass)) {
192
            style = builder.createStyle(builder.createLineSymbolizer());
193
        } else if (Point.class.isAssignableFrom(geometryClass)
194
                || MultiPoint.class.isAssignableFrom(geometryClass)) {
195
            style = builder.createStyle(builder.createPointSymbolizer());
196
        } else {
197
            style = builder.createStyle(builder.createPolygonSymbolizer(Color.ORANGE, Color.BLACK, 1));
198
        }
199

  
200
        final MapLayer layer = new DefaultMapLayer(features, style);
201
        layer.setTitle(layerName);
202
        
203
        FLyrGT2_old lyrGT2 = new FLyrGT2_old(layer);
204
        try {
205
			m_Mapa.getLayers().addLayer(lyrGT2);
206
		} catch (CancelationException e) {
207
			// TODO Auto-generated catch block
208
			e.printStackTrace();
209
		}
210
        
211
    }
212
    
213
    
214
    /* (non-Javadoc)
215
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
216
     */
217
    public void actionPerformed(ActionEvent e) {
218
		// TODO LWS Esto debe venir de fuera (proyeccion del fichero, o de la vista)
219
    	IProjection proj = CRSFactory.getCRS(ProjChooserPanel.getCurProj().getAbrev());
220
		ViewPort vp = m_Mapa.getViewPort();
221

  
222
        if (e.getActionCommand() == "ZOOM_TODO") {
223
            try {
224
				vp.setExtent(m_Mapa.getFullExtent());
225
				m_MapControl.drawMap(false);
226
			} catch (DriverException e1) {
227
				// TODO Auto-generated catch block
228
				e1.printStackTrace();
229
			}
230
            m_MapControl.drawMap(false);
231
        }
232
        if (e.getActionCommand() == "ZOOM_PREVIO") {            
233
            vp.setPreviousExtent();
234
        }
235
        if (e.getActionCommand() == "SYMBOL_MANAGER") {            
236
            if (e.getActionCommand() == "SYMBOL_MANAGER") {            
237
                JDialog dialog = new JDialog();
238
                /* JSVGCanvas canvas = new JSVGCanvas();
239
                try {
240
                    canvas.setURI( new File("D:/java/eclipse30/eclipse/workspace/FMap 03/docs/fill1.svg").toURL().toString() );
241
                } catch (MalformedURLException e1) {
242
                    // TODO Auto-generated catch block
243
                    e1.printStackTrace();
244
                } */
245
                SymbolSelector canvas = new SymbolSelector();
246

  
247
                dialog.getContentPane().add( canvas );
248

  
249
                dialog.setSize( 600, 300 );
250
                dialog.show( true );
251
                
252
            }
253
            
254
        }
255

  
256
        if (e.getActionCommand().indexOf("GT2") != -1 && pruebasGT2 != null) {
257
        	pruebasGT2.setMapContext(m_Mapa);
258
        	pruebasGT2.actionPerformed(e);
259
        }
260
        
261
		if (e.getActionCommand() == "OPEN_LOCATOR") {
262
			//Set up the dialog that the button brings up.
263
			JDialog dialog = new JDialog();
264
			FPanelLocConfig m_panelLoc = new FPanelLocConfig(theView.getMapOverview());
265
			m_panelLoc.setPreferredSize(m_panelLoc.getSize());
266
			dialog.getContentPane().add(m_panelLoc);
267
			dialog.setModal(true);			
268
			dialog.pack();
269
			dialog.show();
270
		} 
271
        
272
		if (e.getActionCommand() == "PRUEBA") {
273
			int i;
274
			double valor;
275
			FThemeManagerWindow dlg = new FThemeManagerWindow();
276
			
277
			dlg.show(); 
278
		}
279

  
280
        if (e.getActionCommand() == "ZOOM_MAS") {
281
            m_MapControl.setTool("zoomIn"); // Por defecto
282
        }
283

  
284
        if (e.getActionCommand() == "ZOOM_MENOS") {
285
			m_MapControl.setTool("zoomout");
286
        }
287

  
288
        if (e.getActionCommand() == "PAN") {
289
			m_MapControl.setTool("pan");
290
        }
291

  
292
        if (e.getActionCommand() == "INFO") {
293
			m_MapControl.setTool("info");
294
        }
295
        if (e.getActionCommand() == "SELRECT") {
296
			m_MapControl.setTool("rectSelection");
297
        }
298
        
299
        if (e.getActionCommand() == "MEDICION") {
300
			m_MapControl.setTool("medicion");
301
        }
302
        if (e.getActionCommand() == "MEDIRAREA") {
303
			m_MapControl.setTool("area");
304
            
305
            // Prueba de graficos
306
			theImgObserver = new MyImageObserver(m_MapControl);
307
			
308
            GraphicLayer lyr =  m_MapControl.getMapContext().getGraphicsLayer();
309
            lyr.clearAllGraphics();
310
            lyr.clearSymbolsGraphics();
311
            FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
312
            File fIcon = new File("d:/sonic.gif");
313
            // File fIcon = new File("d:/7bart.gif");
314
            theSymbol.setSizeInPixels(true);
315
            
316
            theSymbol.setIconURI(fIcon.toURI());
317
            theSymbol.setSize(theSymbol.getIcon().getHeight(null));
318
            
319
            theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_IMAGEN);
320
            theSymbol.setImgObserver(theImgObserver);
321

  
322
            int idSymbol = lyr.addSymbol(theSymbol);
323
            IGeometry geom = ShapeFactory.createPoint2D(100,100);
324
            FGraphic theGraphic = new FGraphic(geom, idSymbol);
325
            lyr.addGraphic(theGraphic);
326
            FGraphicLabel theLabel = new FGraphicLabel(geom, idSymbol, "Hola colega");
327
            // lyr.addGraphic(theLabel);
328
            m_MapControl.drawGraphics();
329
        }
330
        
331
        if ((e.getActionCommand() == "ADD_LAYER") || (e.getActionCommand() == "ADD_MEMORY_LAYER")) {
332
        	JDialog dlg = new JDialog();
333
            dlg.setModal(true);
334
            FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class, RasterDriver.class});
335
            DataBaseOpenDialog dbop = new DataBaseOpenDialog();
336
            // dbop.setClasses(new Class[]{DBDriver.class});
337
            
338
            FOpenDialog fopen = new FOpenDialog();
339
            fopen.addTab("Fichero", fileDlg);
340
            fopen.addTab("Base de datos", dbop);
341
            // fileDlg.setPreferredSize(fopen.getSize());
342
            dlg.setSize(fopen.getSize());
343
            dlg.getContentPane().add(fopen);
344
            dlg.pack();
345
            dlg.show();
346
            
347
  
348
            // TODO: Hacer lo de la capa WMS tambi?n.
349
    		if (fileDlg.getFiles() == null) return;
350
    		FLayer lyr = null;
351
    		File[] files = fileDlg.getFiles();
352
            String[] driverNames = fileDlg.getDriverNames();
353
            Driver[] drivers = new Driver[driverNames.length];
354
            for (int i = 0; i < drivers.length; i++) {
355
                try {
356
                    drivers[i] = LayerFactory.getDM().getDriver(driverNames[i]);
357
                } catch (DriverLoadException ex) {
358
                    System.err.println("No se pudo cargar el driver " + ex.getMessage());
359
                }
360
            }
361
            
362
			m_MapControl.getMapContext()
363
			   .beginAtomicEvent();
364

  
365
    		for  (int iFile=0; iFile < files.length; iFile++)
366
    		{
367
    			File fich = files[iFile];
368
    			String layerName = fich.getName();
369
    			String layerPath = fich.getAbsolutePath();
370
    			
371
    			try {
372
                    if (drivers[iFile] instanceof VectorialFileDriver){
373
                        lyr = LayerFactory.createLayer(layerName,
374
                                (VectorialFileDriver) drivers[iFile], fich, proj);
375
                    }else if (drivers[iFile] instanceof RasterDriver){
376
/*                          lyr = LayerFactory.createLayer(layerName,
377
                                driverNames[iFile], fich, proj);
378
*/                  }
379

  
380
    				lyr.setVisible(true);
381
    				lyr.setName(layerName);
382
    				if (lyr != null )
383
    				{
384
    					try {
385
    						theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
386
    					} catch (CancelationException ex) {
387
    						// TODO Auto-generated catch block
388
    						ex.printStackTrace();
389
    					}
390
    					// TODO: Poner una variable y dibujar solo cuando
391
    					// todas las capas hayan sido cargadas.
392
    					// theView.getMapControl().drawMap();	   				
393
    					// theView.getTOC().refresh();
394
    				}    		
395
    				
396
    			} catch (DriverException ex) {
397
    				ex.printStackTrace();
398
				}
399
    			
400
    		} // for
401
			m_MapControl.getMapContext()
402
			   .endAtomicEvent();
403
			theView.getTOC().refresh();
404

  
405
            return;
406

  
407
        }
408

  
409
        /**
410

  
411
        String pathFich = fc.getDirectory() + fc.getFile();
412

  
413

  
414
        System.out.println(pathFich);
415
        FLyrVect lyr = new FLyrVect(fc.getFile(),pathFich);
416

  
417
        m_Mapa.AddLayer(lyr);
418
        m_Owner.jLeyenda.Refresh();
419

  
420
        }
421

  
422
        **/
423
        if (e.getActionCommand() == "EXPORT") {
424
            // Export jExport = new Export(m_MapControl);
425
        }
426

  
427
        if (e.getActionCommand() == "VIEW_TABLE") {
428
    		FLayer[] actives = m_Mapa.getLayers().getActives();
429

  
430
    		 for (int i = 0; i < actives.length; i++) {
431
            	if (actives[i] instanceof AlphanumericData){
432
            		AlphanumericData co = (AlphanumericData)actives[i];
433
    			
434
					SelectableDataSource dataSource;
435
					try {
436
						dataSource = co.getRecordset();
437
						EditableAdapter ea = new EditableAdapter();
438
						ea.setOriginalDataSource(dataSource);
439
						ProjectTable projectTable =  ProjectTable.createTable(actives[i].getName(),
440
									ea);
441
							projectTable.setAssociatedTable(co);
442
						
443
						Table t = new Table();
444
						t.setModel(projectTable);
445
			            JDialog myDialog = new JDialog(theView, "Tabla de Atributos (" 
446
			            		  + t.getModel().getAssociatedTable().getRecordset().getRowCount() + " registros)" );
447
			            myDialog.setContentPane(t);
448
	
449
			            // myViewer.addAttributeTableViewerListener(m_Owner);
450
			            myDialog.pack();
451
			            myDialog.show(); 
452
					} catch (DriverException e1) {
453
						// TODO Auto-generated catch block
454
						e1.printStackTrace();
455
					} catch (HeadlessException ex) {
456
						// TODO Auto-generated catch block
457
						ex.printStackTrace();
458
					} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
459
                        // TODO Auto-generated catch block
460
                        e1.printStackTrace();
461
                    }
462

  
463
    			}
464
    			
465
    		}
466
        	
467
        }
468
    }
469
}
0 470

  
trunk/libraries/libJCRS/src/org/gvsig/crs/CrsFactory.java
45 45
	public ICrs getCRS(int epsg_code, String code, String params) throws CrsException {
46 46
		if (data.containsKey(code))
47 47
			return (Crs) data.get(code);
48
		
48
		System.out.println(params);
49 49
		Crs crs = new Crs(epsg_code, code,params);
50 50
		
51 51
		// LWS Esta l?nea sobra, cuando el cuadro de di?logo est?
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/dialog/CSSelectionDialog.java
1
/*
2
 * Created on 26-ene-2005
3
 */
4
package org.gvsig.crs.gui.dialog;
5

  
6
import java.awt.FlowLayout;
7
import java.awt.GridLayout;
8

  
9
import org.cresques.cts.IProjection;
10
import org.gvsig.crs.gui.CRSSelectionDialogPanel;
11

  
12

  
13
/**
14
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
15
 */
16
public class CSSelectionDialog
17
	extends CRSSelectionDialogPanel{
18
	
19
	private static final long serialVersionUID = 1L;
20
	/**
21
	 * 
22
	 */
23
	public CSSelectionDialog() {
24
		super();
25
		this.init();
26
	}
27
	/**
28
	 * This method initializes this
29
	 * 
30
	 * @return void
31
	 */
32
	private void init() {
33
		this.setBounds(0, 0, 600, 400);
34
		this.setLayout(new GridLayout(0,1));
35
		this.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
36
		
37
	}
38
	
39
	
40
	/*public IProjection getProjection() {
41
		return (IProjection) getProjPanel().getProjection();
42
	}
43
	
44
	public void setProjection(IProjection proj) {
45
		lastProj = proj;
46
		getProjPanel().setProjection(proj);
47
	}
48
	
49
	public String getProjectionAbrev(){
50
		return  (String) getProjPanel().getProjection().getAbrev();
51
	}*/	
52
}
0 53

  
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/dialog/TRSelectionDialog.java
1
/*
2
 * Created on 26-ene-2005
3
 */
4
package org.gvsig.crs.gui.dialog;
5

  
6
import java.awt.FlowLayout;
7
import java.awt.GridLayout;
8

  
9
import org.cresques.cts.IProjection;
10
import org.gvsig.crs.gui.TransformationSelectionDialogPanel;
11

  
12
import com.iver.andami.PluginServices;
13
import com.iver.andami.ui.mdiManager.IWindow;
14
import com.iver.andami.ui.mdiManager.WindowInfo;
15

  
16
/**
17
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
18
 */
19
public class TRSelectionDialog
20
	extends TransformationSelectionDialogPanel implements IWindow {
21
	/**
22
	 * 
23
	 */
24
	private static final long serialVersionUID = 1L;
25
	private boolean okPressed = false;
26
	private IProjection lastProj = null;
27

  
28
	/**
29
	 * 
30
	 */
31
	public TRSelectionDialog() {
32
		super();
33
		this.init();
34
	}
35
	/**
36
	 * This method initializes this
37
	 * 
38
	 * @return void
39
	 */
40
	private void init() {		
41
		this.setBounds(0, 0, 600, 500);
42
		this.setLayout(new GridLayout(0,1));
43
		this.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
44
		//PluginServices.getMDIManager().addWindow(this);
45
				
46
	}
47
	
48
	public boolean isOkPressed() { return okPressed; }
49
	
50
	/**
51
	 * @return
52
	 */
53
	public IProjection getProjection() {
54
		return (IProjection) getProjPanel().getProjection();
55
	}
56
	/**
57
	 * @param proj
58
	 */
59
	public void setProjection(IProjection proj) {
60
		lastProj = proj;
61
		getProjPanel().setProjection(proj);
62
	}
63
	
64
	public String getProjectionName(){
65
		return (String) getProjPanel().getProjection().getCrsWkt().getName();				
66
	}
67
	public WindowInfo getWindowInfo() {
68
		WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
69
   		m_viewinfo.setTitle(PluginServices.getText(this, "selecciona_sistema_de_referencia"));
70
		return m_viewinfo;
71
	}
72
}
0 73

  
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/panels/ProjChooserPanel.java
1
/*
2
 * Created on 30-ene-2005
3
 */
4
package org.gvsig.crs.gui.panels;
5

  
6
import java.awt.FlowLayout;
7
import java.awt.GridLayout;
8
import java.awt.event.ActionListener;
9
import java.sql.Connection;
10
import java.sql.DriverManager;
11
import java.sql.SQLException;
12

  
13
import javax.swing.JLabel;
14
import javax.swing.JPanel;
15

  
16
import org.cresques.cts.IProjection;
17
import org.gvsig.crs.EpsgConnection;
18
import org.gvsig.crs.ICrs;
19
import org.gvsig.gui.beans.swing.JButton;
20

  
21
import com.iver.andami.PluginServices;
22
import com.iver.cit.gvsig.gui.FOpenDialog;
23
import com.iver.cit.gvsig.gui.View;
24
import com.iver.cit.gvsig.gui.dialogs.CSSelectionDialog;
25

  
26
/**
27
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
28
 */
29
public class ProjChooserPanel extends JPanel {
30
    
31
	private static final long serialVersionUID = 1L;
32
	
33
	private static IProjection curProj = null; //(IProjection) new CRSFactory().getCRS("EPSG:23030");
34
	private JLabel jLblProj = null;
35
	private JLabel jLblProjName = null;
36
	private JButton jBtnChangeProj = null;
37
	private static boolean okPressed = false;
38
	private String abrev;
39
	
40
	public EpsgConnection connect = null;
41

  
42
	private ActionListener actionListener = null;
43
	
44
	public ProjChooserPanel(IProjection proj) {
45
		super();
46
		setCurProj(proj);
47
		initialize();
48
	}
49
	
50
	public ProjChooserPanel(){
51
		  connect = new EpsgConnection();
52
		  connect.setConnection();
53
		 }
54

  
55
	/**
56
	 * This method initializes this
57
	 *
58
	 * @return void
59
	 */
60
	private void initialize() {
61
        this.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 0));
62
        setPreferredSize(new java.awt.Dimension(330,35));
63
        this.setSize(new java.awt.Dimension(330,23));
64
        this.add(getJLblProjName(), null);
65
        this.add(getJLblProj(), null);
66
        this.add(getJBtnChangeProj(), null);
67
        //cambiar cuando la parte de JLuis se ensamble
68
        if(!((ICrs)curProj).getAbrev().equals("EPSG:23030"))
69
        	jLblProj.setText(((ICrs)curProj).getCrsWkt().getName());
70
        else
71
        	jLblProj.setText("EPSG:23030");
72
		initBtnChangeProj();
73
	}
74

  
75
	private void initBtnChangeProj() {
76
		getJBtnChangeProj().addActionListener(new java.awt.event.ActionListener() {
77
			public void actionPerformed(java.awt.event.ActionEvent e) {
78
				okPressed = false;
79
				CSSelectionDialog csSelect = new CSSelectionDialog();
80
				csSelect.setProjection(curProj);
81
				
82
				csSelect.setLayout(new GridLayout(0,1));
83

  
84
		        PluginServices.getMDIManager().addWindow(csSelect);
85
		        if(View.m_MapControl == null)
86
		        	abrev = curProj.getAbrev();
87
		        else
88
		        	abrev = View.m_MapControl.getProjection().getAbrev();
89

  
90
		        if (csSelect.isOkPressed()) {
91
		        	curProj = csSelect.getProjection();
92
		        	if(View.m_MapControl == null)
93
		        		abrev = csSelect.getProjectionAbrev();
94
		        	else 
95
		        		abrev = View.m_MapControl.getProjection().getAbrev();
96
		        	jLblProj.setText(curProj.getAbrev());
97
		        	FOpenDialog.setLastProjection(curProj);
98
		        	okPressed = true;
99
		        	if (actionListener != null) {
100
		        		actionListener.actionPerformed(e);
101
		        	}
102
		        }else
103
		        	
104
		        	jLblProj.setText(abrev);
105
			}
106
		});
107
	}
108

  
109
	public JLabel getJLblProjName() {
110
		if (jLblProjName == null) {
111
	        jLblProjName = new JLabel("Proyeccion actual");
112
			jLblProjName.setText(PluginServices.getText(this,"__proyeccion_actual")); //$NON-NLS-1$
113
		}
114
		return jLblProjName;
115
	}
116

  
117
	public JLabel getJLblProj() {
118
		if (jLblProj == null) {
119
	        jLblProj = new JLabel();
120
			jLblProj.setText(curProj.getAbrev());
121
		}
122
		return jLblProj;
123
	}
124
	public void addBtnChangeProjActionListener(java.awt.event.ActionListener al) {
125
		jBtnChangeProj.addActionListener(al);
126
	}
127

  
128
	/**
129
	 * This method initializes jButton
130
	 *
131
	 * @return javax.swing.JButton
132
	 */
133
	public JButton getJBtnChangeProj() {
134
		if (jBtnChangeProj == null) {
135
			jBtnChangeProj = new JButton();
136
			jBtnChangeProj.setText("..."); //$NON-NLS-1$
137
		}
138
		return jBtnChangeProj;
139
	}
140
	/**
141
	 * @return Returns the curProj.
142
	 */
143
	public static IProjection getCurProj() {
144
		return curProj;
145
	}
146
	/**
147
	 * @param curProj The curProj to set.
148
	 */
149
	public void setCurProj(IProjection curProj) {
150
		this.curProj = curProj;
151
	}
152
	/**
153
	 * @return Returns the okPressed.
154
	 */
155
	public static boolean isOkPressed() {
156
		return okPressed;
157
	}
158
	/**
159
	 * @param actionListener The actionListener to set.
160
	 */
161
	public void addActionListener(ActionListener actionListener) {
162
		this.actionListener = actionListener;
163
	}
164
}  //  @jve:decl-index=0:visual-constraint="10,10"
0 165

  
trunk/libraries/libJCRS/src/org/gvsig/crs/gui/panels/ProjChooserPanelTransformation.java
1
package org.gvsig.crs.gui.panels;
2

  
3
import java.awt.FlowLayout;
4
import java.awt.GridLayout;
5
import java.awt.event.ActionListener;
6
import java.awt.event.ComponentEvent;
7
import java.awt.event.ComponentListener;
8
import java.awt.event.WindowEvent;
9
import java.awt.event.WindowListener;
10

  
11
import javax.swing.JFrame;
12
import javax.swing.JLabel;
13
import javax.swing.JPanel;
14

  
15
import org.cresques.cts.IProjection;
16
import org.gvsig.crs.EpsgConnection;
17
import org.gvsig.crs.ICrs;
18
import org.gvsig.gui.beans.swing.JButton;
19

  
20
import com.iver.andami.PluginServices;
21
import com.iver.cit.gvsig.gui.FOpenDialog;
22
import com.iver.cit.gvsig.gui.dialogs.TRSelectionDialog;
23

  
24
/**
25
 * @author Jos? Luis G?mez y Miguel Garc?a
26
 */
27
public class ProjChooserPanelTransformation extends JPanel {
28
    
29
	private static final long serialVersionUID = 1L;
30
	
31
	private static IProjection curProj = null; //(IProjection) new CRSFactory().getCRS("EPSG:23030");
32
	private JLabel jLblProj = null;
33
	private JLabel jLblProjName = null;
34
	private JButton jBtnChangeProj = null;
35
	private boolean okPressed = false;
36
	private String abrev;
37
	
38
	public EpsgConnection connect = null;
39

  
40
	private ActionListener actionListener = null;
41
	
42
	/**
43
	 *
44
	 */
45
	public ProjChooserPanelTransformation(IProjection proj) {
46
		super();
47
		setCurProj(proj);
48
		initialize();
49
	}
50
	
51
	public ProjChooserPanelTransformation(){
52
		  connect = new EpsgConnection();
53
		  connect.setConnection();
54
	}
55

  
56
	/**
57
	 * This method initializes this
58
	 *
59
	 * @return void
60
	 */
61
	private void initialize() {
62
        this.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 0));
63
        setPreferredSize(new java.awt.Dimension(330,35));
64
        this.setSize(new java.awt.Dimension(330,23));
65
        this.add(getJLblProjName(), null);
66
        this.add(getJLblProj(), null);
67
        this.add(getJBtnChangeProj(), null);
68
        //cambiar cuando la parte de JLuis se ensamble
69
        if(!((ICrs)curProj).getAbrev().equals("EPSG:23030"))
70
        	jLblProj.setText(((ICrs)curProj).getCrsWkt().getName());
71
        else
72
        	jLblProj.setText("EPSG:23030");
73
		initBtnChangeProj();
74
	}
75

  
76
	private void initBtnChangeProj() {
77
		getJBtnChangeProj().addActionListener(new java.awt.event.ActionListener() {
78
			public void actionPerformed(java.awt.event.ActionEvent e) {
79
				okPressed = false;
80
				TRSelectionDialog csSelect = new TRSelectionDialog();
81
				csSelect.setProjection(curProj);
82
		        
83
				csSelect.setLayout(new GridLayout(0,1));
84
				
85
				PluginServices.getMDIManager().addWindow(csSelect);
86
		        abrev = curProj.getAbrev();
87

  
88
		        if (csSelect.getProjection() != curProj) {
89
		        	curProj = csSelect.getProjection();
90
		        	abrev = csSelect.getProjectionName();
91
		        	jLblProj.setText(abrev);
92
		        	FOpenDialog.setLastProjection(curProj);
93
		        	okPressed = true;
94
		        	if (actionListener != null) {
95
		        		actionListener.actionPerformed(e);
96
		        	}
97
		        }else
98
		        	jLblProj.setText(abrev);	
99
			}
100
		});
101
	}
102

  
103
	public JLabel getJLblProjName() {
104
		if (jLblProjName == null) {
105
	        jLblProjName = new JLabel("Proyeccion actual");
106
			jLblProjName.setText(PluginServices.getText(this,"__proyeccion_actual")); //$NON-NLS-1$
107
		}
108
		return jLblProjName;
109
	}
110

  
111
	public JLabel getJLblProj() {
112
		if (jLblProj == null) {
113
	        jLblProj = new JLabel();
114
			jLblProj.setText(curProj.getAbrev());
115
		}
116
		return jLblProj;
117
	}
118
	public void addBtnChangeProjActionListener(java.awt.event.ActionListener al) {
119
		jBtnChangeProj.addActionListener(al);
120
	}
121

  
122
	/**
123
	 * This method initializes jButton
124
	 *
125
	 * @return javax.swing.JButton
126
	 */
127
	public JButton getJBtnChangeProj() {
128
		if (jBtnChangeProj == null) {
129
			jBtnChangeProj = new JButton();
130
			jBtnChangeProj.setText("..."); //$NON-NLS-1$
131
		}
132
		return jBtnChangeProj;
133
	}
134
	/**
135
	 * @return Returns the curProj.
136
	 */
137
	public static IProjection getCurProj() {
138
		return curProj;
139
	}
140
	/**
141
	 * @param curProj The curProj to set.
142
	 */
143
	public void setCurProj(IProjection curProj) {
144
		this.curProj = curProj;
145
	}
146
	/**
147
	 * @return Returns the okPressed.
148
	 */
149
	public boolean isOkPressed() {
150
		return okPressed;
151
	}
152
	/**
153
	 * @param actionListener The actionListener to set.
154
	 */
155
	public void addActionListener(ActionListener actionListener) {
156
		this.actionListener = actionListener;
157
	}
158

  
159
}  //  @jve:decl-index=0:visual-constraint="10,10"
160

  
0 161

  

Also available in: Unified diff