Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / DEMO / ComandosListener.java @ 458

History | View | Annotate | Download (6.51 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.hardcode.gdbms.engine.data.DBDriver;
26
import com.iver.cit.gvsig.fmap.FMap;
27
import com.iver.cit.gvsig.fmap.NewMapControl;
28
import com.iver.cit.gvsig.fmap.ViewPort;
29
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
30
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
31
import com.iver.cit.gvsig.fmap.layers.CancelationException;
32
import com.iver.cit.gvsig.fmap.layers.FLayer;
33
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
34
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
35
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
36
import com.iver.cit.gvsig.gui.DataBaseOpenDialog;
37
import com.iver.cit.gvsig.gui.FOpenDialog;
38
import com.iver.cit.gvsig.gui.FileOpenDialog;
39
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow;
40
import com.iver.mdiApp.App;
41

    
42

    
43

    
44
//import java.awt.Frame;
45

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

    
57
    public ComandosListener(NewMapControl mapa, SingleView Owner) {
58
        m_Mapa = mapa.getMapContext();
59
        theView = Owner;
60
        m_MapControl = mapa;
61
    }
62

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

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

    
104
        if (e.getActionCommand() == "ZOOM_MAS") {
105
                m_MapControl.setTool("zoomrect");
106
        }
107

    
108
        if (e.getActionCommand() == "ZOOM_MENOS") {
109
                        m_MapControl.setTool("zoomout");
110
        }
111

    
112
        if (e.getActionCommand() == "PAN") {
113
                        m_MapControl.setTool("pan");
114
        }
115

    
116
        if (e.getActionCommand() == "INFO") {
117
                        m_MapControl.setTool("info");
118
        }
119
        if (e.getActionCommand() == "MEDICION") {
120
                        m_MapControl.setTool("medicion");
121
        }
122
        if (e.getActionCommand() == "MEDIRAREA") {
123
                        m_MapControl.setTool("area");
124
        }
125
        
126
        if ((e.getActionCommand() == "ADD_LAYER") || (e.getActionCommand() == "ADD_MEMORY_LAYER")) {
127
                JDialog dlg = new JDialog();
128
            dlg.setModal(true);
129
            FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class});
130
            DataBaseOpenDialog dbop = new DataBaseOpenDialog();
131
            dbop.setClasses(new Class[]{DBDriver.class});
132
            
133
            FOpenDialog fopen = new FOpenDialog();
134
            fopen.addTab("Fichero", fileDlg);
135
            fopen.addTab("Base de datos", dbop);
136
            // fileDlg.setPreferredSize(fopen.getSize());
137
            dlg.setSize(fopen.getSize());
138
            dlg.getContentPane().add(fopen);
139
            dlg.pack();
140
            dlg.show();
141
            
142
  
143
            // TODO: Hacer lo de la capa WMS tambi?n.
144
                    if (fileDlg.getFiles() == null) return;
145
                    FLayer lyr = null;
146
                    File[] files = fileDlg.getFiles();
147
                    for  (int iFile=0; iFile < files.length; iFile++)
148
                    {
149
                            File fich = files[iFile];
150
                            String layerName = fich.getName();
151
                            String layerPath = fich.getAbsolutePath();
152
                            
153
                            try {
154
                                    lyr = (FLyrVect) LayerFactory.createLayer(fileDlg.getDriverName(), fich, proj);
155

    
156
                                    lyr.setVisible(true);
157
                                    lyr.setName(layerName);
158
                                    if (lyr != null )
159
                                    {
160
                                            try {
161
                                                    theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
162
                                            } catch (CancelationException ex) {
163
                                                    // TODO Auto-generated catch block
164
                                                    ex.printStackTrace();
165
                                            }
166
                                            // TODO: Poner una variable y dibujar solo cuando
167
                                            // todas las capas hayan sido cargadas.
168
                                            theView.getMapControl().drawMap();                                           
169
                                            theView.getTOC().refresh();
170
                                    }                    
171
                                    
172
                            } catch (DriverLoadException ex) {
173
                                    ex.printStackTrace();
174
                            } catch (DriverIOException ex) {
175
                                        // TODO Auto-generated catch block
176
                                        ex.printStackTrace();
177
                                }
178
                    } // for
179
            return;
180

    
181
        }
182

    
183
        /**
184

185
        String pathFich = fc.getDirectory() + fc.getFile();
186

187

188
        System.out.println(pathFich);
189
        FLyrVect lyr = new FLyrVect(fc.getFile(),pathFich);
190

191
        m_Mapa.AddLayer(lyr);
192
        m_Owner.jLeyenda.Refresh();
193

194
        }
195

196
        **/
197
        if (e.getActionCommand() == "EXPORT") {
198
            // Export jExport = new Export(m_MapControl);
199
        }
200

    
201
        if (e.getActionCommand() == "VIEW_TABLE") {
202
            /* FLyrVect lyrSelec = m_Owner.getTOC().getFirstLyrVectSelected();
203
            Table nuevaTabla = new Table();
204
            nuevaTabla.setModel(new FTable(lyrSelec.getRecordset()));
205
            JDialog myDialog = new JDialog(m_Owner, "Tabla de Atributos (" 
206
                              + nuevaTabla.getModel().getRecordsCount() + " registros)" );
207
            myDialog.setContentPane(nuevaTabla);
208

209
            // myViewer.addAttributeTableViewerListener(m_Owner);
210
            myDialog.pack();
211
            myDialog.show(); */
212
        }
213
    }
214
}