Statistics
| Revision:

root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / CrsRecentsPanel.java @ 12202

History | View | Annotate | Download (7.56 KB)

1
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ibez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

    
41
package org.gvsig.crs.gui.panels;
42

    
43
import java.awt.BorderLayout;
44
import java.awt.Dimension;
45
import java.awt.FlowLayout;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48

    
49

    
50
import javax.swing.Action;
51
import javax.swing.BorderFactory;
52
import javax.swing.JButton;
53
import javax.swing.JLabel;
54
import javax.swing.JPanel;
55
import javax.swing.JScrollPane;
56
import javax.swing.JTable;
57
import javax.swing.ListSelectionModel;
58

    
59
import javax.swing.table.DefaultTableModel;
60
import javax.swing.table.TableColumn;
61

    
62
import org.cresques.cts.IProjection;
63
import org.gvsig.crs.CrsException;
64
import org.gvsig.crs.CrsFactory;
65
import org.gvsig.crs.ICrs;
66
import org.gvsig.crs.persistence.CrsData;
67
import org.gvsig.crs.persistence.RecentCRSsPersistence;
68

    
69
import com.iver.andami.PluginServices;
70
import com.iver.cit.gvsig.gui.TableSorter;
71

    
72
/**
73
 * Clase que genera el panel de recientes
74
 * 
75
 * @author Jos Luis Gmez Martnez (jolugomar@gmail.com)
76
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
77
 * @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
78
 *
79
 */
80
public class CrsRecentsPanel extends JPanel implements ActionListener {
81

    
82
        /**
83
         * 
84
         */
85
        private static final long serialVersionUID = 1L;
86
        
87
        public JTable jTable = null;
88
        private JScrollPane jScrollPane = null;
89
        private JButton infoCrs=null;
90
        public DefaultTableModel dtm = null;
91
        public TableSorter sorter = null;
92
        private CrsData crsDataArray[] = null;
93
        
94
        public int selectedRowTable = -1;
95
        private String authority = null;
96
        private int codeCRS = -1;
97
        private ICrs crs = null;
98
        
99
        public CrsRecentsPanel() {
100
                super();
101
                initialize();
102
        }
103
        
104
        private void initialize(){
105
                this.setLayout(new BorderLayout());
106
                JPanel p=new JPanel(new FlowLayout(FlowLayout.LEFT,15,15));
107
                p.add(getJLabel());
108
                this.add(p, BorderLayout.NORTH);
109
                this.add(getJScrollPane(), BorderLayout.CENTER);
110
                JPanel pSouth=new JPanel(new FlowLayout(FlowLayout.RIGHT,5,5));
111
                pSouth.add(getInfoCrs());
112
                this.add(pSouth,BorderLayout.SOUTH);
113
        }
114
        
115
        private JLabel getJLabel(){
116
                JLabel label = new JLabel();
117
                label.setText(PluginServices.getText(this, "ultimos_crs_utilizados")+":");
118
                return label;
119
        }
120
        /**
121
         * Inicializa el panel que contiene la tabla con los crs
122
         * @return
123
         */
124
        private JScrollPane getJScrollPane() {
125
                if (jScrollPane == null) {
126
                        jScrollPane = new JScrollPane();
127
                        jScrollPane.setBorder(
128
                                    BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3,3,3,3),jScrollPane.getBorder()));
129
                        jScrollPane.setViewportView(getJTable());
130
                }
131
                return jScrollPane;
132
        }
133
        /**
134
         * Inicializa la tabla que contiene los crs
135
         * @return
136
         */
137
        public JTable getJTable() {
138
                if (jTable == null) {
139
                        String[] columnNames= {PluginServices.getText(this,"fuente"),
140
                                        PluginServices.getText(this,"codigo"),
141
                                        PluginServices.getText(this,"nombre")};
142
                        Object[][]data = {};                        
143
                        dtm = new DefaultTableModel(data, columnNames)
144
                         {
145
                                private static final long serialVersionUID = 1L;
146
                                public boolean isCellEditable(int row, int column) {
147
                                        return false;
148
                                }
149
                                /*
150
                                 * metodo necesario para cuando utilizamos tablas ordenadas
151
                                 * ya que sino al ordenar por algun campo no se queda con el orden
152
                                 * actual al seleccionar una fila (non-Javadoc)
153
                                 * @see javax.swing.table.TableModel#getColumnClass(int)
154
                                 */
155
                                public Class getColumnClass(int column)
156
                                {
157
                                        return getValueAt(0, column).getClass();
158
                                }
159
                                };
160
                        sorter = new TableSorter(dtm);                        
161

    
162
                        jTable = new JTable(sorter);
163
                        sorter.setTableHeader(jTable.getTableHeader());
164
                        jTable.setCellSelectionEnabled(false);
165
                        jTable.setRowSelectionAllowed(true);
166
                        jTable.setColumnSelectionAllowed(false);
167
                        jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
168
                        TableColumn column = null;
169
                        for (int i = 0; i < 3; i++) {
170
                            column = jTable.getColumnModel().getColumn(i);
171
                            if (i == 0) {
172
                                column.setPreferredWidth(60); //code column is shorter                                     
173
                            }else if (i == 2) {
174
                                    column.setPreferredWidth(275);
175
                            }
176
                            else {                            
177
                                column.setPreferredWidth(160);
178
                            }
179
                        }        
180
                }
181
                return jTable;                
182
        }
183
        
184
        /**
185
         * Inicializa el botn que obtiene la informacin del CRS
186
         * @return
187
         */
188
        public JButton getInfoCrs() {
189
                if(infoCrs == null) {
190
                        infoCrs = new JButton();
191
                        infoCrs.setPreferredSize(new Dimension(85,20));
192
                        infoCrs.setText(PluginServices.getText(this,"infocrs"));
193
                        infoCrs.setMnemonic('I');
194
                        infoCrs.setEnabled(false);
195
                        infoCrs.setToolTipText(PluginServices.getText(this,"more_info"));
196
                        infoCrs.addActionListener(this);
197
                }
198
                return infoCrs;
199
        }
200
        public ICrs getProjection() {                
201
                return crs;
202
        }
203
        
204
        public void setCodeCRS(int code) {
205
                codeCRS = code;
206
        }
207
        
208
        public int getCodeCRS() {
209
                return codeCRS;
210
        }
211
        
212
        public void setProjection(IProjection crs) {
213
                //setCrs((ICrs) crs);
214
        }
215
        
216
        /**
217
         * Carga en la tabla los CRSs leidos del sistema de persistencia.
218
         */
219
        public void loadRecents(){
220
                RecentCRSsPersistence persistence = new RecentCRSsPersistence();
221
                crsDataArray = persistence.getArrayOfCrsData();
222
                
223
                for (int iRow = crsDataArray.length-1;iRow>=0;iRow--){
224
                        Object row[] ={crsDataArray[iRow].getAuthority(),Integer.toString(crsDataArray[iRow].getCode()),crsDataArray[iRow].getName()};
225
                        dtm.addRow(row);
226
                }
227
                
228
                /*
229
                /*Seleccionar el primer registro.
230
                 */
231
                int numr = dtm.getRowCount();
232
                if (numr != 0 )
233
                        this.getJTable().setRowSelectionInterval(0,0);
234
        }
235

    
236
        public ICrs getCrs() {
237
                return crs;
238
        }
239
        
240
        public void initCrs(){
241
                
242
                selectedRowTable = getJTable().getSelectedRow();                                                                
243
            Integer.parseInt((String)sorter.getValueAt(selectedRowTable,1));
244
                setAuthority((String)sorter.getValueAt(selectedRowTable,0)+":"+(String)sorter.getValueAt(selectedRowTable,1));
245
            
246
                codeCRS = Integer.parseInt((String)sorter.getValueAt(selectedRowTable,1));
247
                try {
248
                        crs = new CrsFactory().getCRS(getAuthority());
249
                } catch (CrsException e) {
250
                        e.printStackTrace();
251
                }
252
        }
253
        
254
        public String getAuthority() {
255
                return authority;
256
        }
257
        
258
        public void setAuthority(String aut) {
259
                this.authority = aut;
260
        }
261

    
262
        public void actionPerformed(ActionEvent e) {
263
                /*Si el objeto que genera el evento es el JButton 'InfoCrs'
264
                se muestra la informacin ralicionada con el Crs seleccionado en la tabla*/
265
                if (e.getSource() == this.getInfoCrs()) {
266
                        String[] aut = getAuthority().split(":");                        
267
                        InfoCRSPanel info = new InfoCRSPanel(aut[0], getCodeCRS());
268
                        PluginServices.getMDIManager().addWindow(info);
269
                }
270
                
271
        }
272

    
273
}