Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / DEMO / ComandosListener.java @ 423

History | View | Annotate | Download (6.17 KB)

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
package com.iver.cit.gvsig.DEMO;
14

    
15
import java.awt.event.ActionEvent;
16
import java.awt.event.ActionListener;
17
import java.io.File;
18

    
19
import javax.swing.JDialog;
20

    
21
import org.cresques.cts.IProjection;
22
import org.cresques.cts.ProjectionPool;
23

    
24
import com.hardcode.driverManager.DriverLoadException;
25
import com.iver.cit.gvsig.fmap.FMap;
26
import com.iver.cit.gvsig.fmap.NewMapControl;
27
import com.iver.cit.gvsig.fmap.ViewPort;
28
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
29
import com.iver.cit.gvsig.fmap.layers.CancelationException;
30
import com.iver.cit.gvsig.fmap.layers.FLayer;
31
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
32
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
33
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
34
import com.iver.cit.gvsig.gui.FLegendManagerWindow;
35
import com.iver.cit.gvsig.gui.FOpenDialog;
36

    
37

    
38

    
39
//import java.awt.Frame;
40

    
41
/**
42
 * @author Administrador
43
 *
44
 * To change the template for this generated type comment go to
45
 * Window>Preferences>Java>Code Generation>Code and Comments
46
 */
47
public class ComandosListener implements ActionListener {
48
        private NewMapControl m_MapControl;
49
    private FMap m_Mapa;
50
    private SingleView theView;
51

    
52
    public ComandosListener(NewMapControl mapa, SingleView Owner) {
53
        m_Mapa = mapa.getMapContext();
54
        theView = Owner;
55
        m_MapControl = mapa;
56
    }
57

    
58
    /* (non-Javadoc)
59
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
60
     */
61
    public void actionPerformed(ActionEvent e) {
62
                // TODO LWS Esto debe venir de fuera (proyeccion del fichero, o de la vista)
63
                IProjection proj = ProjectionPool.get("ed50utm30");
64
                ViewPort vp = m_Mapa.getViewPort();
65

    
66
        if (e.getActionCommand() == "ZOOM_TODO") {
67
            try {
68
                                vp.setExtent(m_Mapa.getFullExtent());
69
                                m_MapControl.drawMap();
70
                        } catch (DriverIOException e1) {
71
                                // TODO Auto-generated catch block
72
                                e1.printStackTrace();
73
                        }
74
            m_MapControl.drawMap();
75
        }
76
        if (e.getActionCommand() == "ZOOM_PREVIO") {            
77
            vp.setExtentPrev();
78
        }
79
        
80
                /* if (e.getActionCommand() == "OPEN_LOCATOR") {
81
                        //Set up the dialog that the button brings up.
82
                        JDialog dialog = new JDialog();
83
                        FPanelLocConfig m_panelLoc = new FPanelLocConfig(m_Owner);
84
                        m_panelLoc.setPreferredSize(m_panelLoc.getSize());
85
                        dialog.getContentPane().add(m_panelLoc);
86
                        dialog.setModal(true);                        
87
                        dialog.pack();
88
                        dialog.show();
89
                } */
90
        
91
                if (e.getActionCommand() == "PRUEBA") {
92
                        int i;
93
                        double valor;
94
                        FLegendManagerWindow dlg = new FLegendManagerWindow();
95
                        
96
                        dlg.show(); 
97
                }
98

    
99
        if (e.getActionCommand() == "ZOOM_MAS") {
100
                m_MapControl.setTool("zoomrect");
101
        }
102

    
103
        if (e.getActionCommand() == "ZOOM_MENOS") {
104
                        m_MapControl.setTool("zoomout");
105
        }
106

    
107
        if (e.getActionCommand() == "PAN") {
108
                        m_MapControl.setTool("pan");
109
        }
110

    
111
        if (e.getActionCommand() == "INFO") {
112
                        m_MapControl.setTool("info");
113
        }
114
        if (e.getActionCommand() == "MEDICION") {
115
                        m_MapControl.setTool("medicion");
116
        }
117
        if (e.getActionCommand() == "MEDIRAREA") {
118
                        m_MapControl.setTool("area");
119
        }
120
        
121
        if ((e.getActionCommand() == "ADD_LAYER") || (e.getActionCommand() == "ADD_MEMORY_LAYER")) {
122
                JDialog dlg = new JDialog();
123
            FOpenDialog fopen = new FOpenDialog();
124
            dlg.setModal(true);
125
            fopen.setPreferredSize(fopen.getSize());
126
            dlg.setSize(fopen.getSize());
127
            dlg.getContentPane().add(fopen);
128
            dlg.pack();
129
            dlg.show();
130
            /* fopen.setTitle("Abrir una capa");
131
            fopen.setModal(true);
132
            fopen.pack();
133
            fopen.show(); */
134
                    FLyrVect lyr = null;
135
                    // IFLayer lyrLoc = null;
136
                    if (fopen.getFiles() == null) return; // Es posible que hayamos a?adido una
137
                                    // capa WMS, o WFS, etc.
138
                    File[] files = fopen.getFiles();
139
                    for  (int iFile=0; iFile < files.length; iFile++)
140
                    {
141
                            File fich = files[iFile];
142
                            String layerName = fich.getName();
143
                            String layerPath = fich.getAbsolutePath();
144
                            
145
                            try {
146
                                    lyr = (FLyrVect) LayerFactory.createLayer(fopen.getDriverName(), fich, proj);
147
                                    lyr.setLegend(LegendFactory.createSingleSymbolLegend());
148
                                    lyr.setVisible(true);
149
                                    lyr.setName(layerName);
150
                                    if (lyr != null )
151
                                    {
152
                                            try {
153
                                                    theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
154
                                            } catch (CancelationException ex) {
155
                                                    // TODO Auto-generated catch block
156
                                                    ex.printStackTrace();
157
                                            }
158
                                            // TODO: Poner una variable y dibujar solo cuando
159
                                            // todas las capas hayan sido cargadas.
160
                                            theView.getMapControl().drawMap();                                           
161
                                            theView.getTOC().refresh();
162
                                    }                    
163
                                    
164
                            } catch (DriverLoadException ex) {
165
                                    ex.printStackTrace();
166
                            } catch (DriverIOException ex) {
167
                                        // TODO Auto-generated catch block
168
                                        ex.printStackTrace();
169
                                }
170
                    } // for
171
            return;
172

    
173
        }
174

    
175
        /**
176

177
        String pathFich = fc.getDirectory() + fc.getFile();
178

179

180
        System.out.println(pathFich);
181
        FLyrVect lyr = new FLyrVect(fc.getFile(),pathFich);
182

183
        m_Mapa.AddLayer(lyr);
184
        m_Owner.jLeyenda.Refresh();
185

186
        }
187

188
        **/
189
        if (e.getActionCommand() == "EXPORT") {
190
            // Export jExport = new Export(m_MapControl);
191
        }
192

    
193
        if (e.getActionCommand() == "VIEW_TABLE") {
194
            /* FLyrVect lyrSelec = m_Owner.getTOC().getFirstLyrVectSelected();
195
            Table nuevaTabla = new Table();
196
            nuevaTabla.setModel(new FTable(lyrSelec.getRecordset()));
197
            JDialog myDialog = new JDialog(m_Owner, "Tabla de Atributos (" 
198
                              + nuevaTabla.getModel().getRecordsCount() + " registros)" );
199
            myDialog.setContentPane(nuevaTabla);
200

201
            // myViewer.addAttributeTableViewerListener(m_Owner);
202
            myDialog.pack();
203
            myDialog.show(); */
204
        }
205
    }
206
}