root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / IAU2000panel.java @ 8127
History | View | Annotate | Download (7.92 KB)
1 |
package org.gvsig.crs.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.FlowLayout; |
6 |
import java.awt.GridLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.KeyEvent; |
10 |
import java.awt.event.KeyListener; |
11 |
import java.sql.ResultSet; |
12 |
import java.sql.SQLException; |
13 |
|
14 |
import javax.swing.BorderFactory; |
15 |
import javax.swing.JButton; |
16 |
import javax.swing.JLabel; |
17 |
import javax.swing.JOptionPane; |
18 |
import javax.swing.JPanel; |
19 |
import javax.swing.JScrollPane; |
20 |
import javax.swing.JTable; |
21 |
import javax.swing.JTextField; |
22 |
import javax.swing.ListSelectionModel; |
23 |
import javax.swing.table.DefaultTableModel; |
24 |
import javax.swing.table.TableColumn; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.crs.CrsException; |
28 |
import org.gvsig.crs.CrsFactory; |
29 |
import org.gvsig.crs.EpsgConnection; |
30 |
import org.gvsig.crs.ICrs; |
31 |
import org.gvsig.crs.Query; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.cit.gvsig.gui.TableSorter; |
35 |
|
36 |
public class IAU2000panel extends JPanel implements KeyListener, ActionListener { |
37 |
|
38 |
/**
|
39 |
*
|
40 |
*/
|
41 |
private static final long serialVersionUID = 1L; |
42 |
public JPanel IAU2000panel = null; |
43 |
|
44 |
JLabel jLabel = null; |
45 |
JTextField crsTextFld = null; |
46 |
|
47 |
String cadWKT = ""; |
48 |
|
49 |
int transf = 0; |
50 |
boolean source_yn = false; |
51 |
int source_cod = 0; |
52 |
int method_code = 0; |
53 |
int datum_code = 0; |
54 |
int projection_conv_code = 0; |
55 |
public String crs_kind = null; |
56 |
|
57 |
boolean select = false; |
58 |
|
59 |
boolean inAnApplet = true; |
60 |
|
61 |
public EpsgConnection connect = null; |
62 |
|
63 |
private JButton searchButton = null; |
64 |
private JTextField searchTextField = null; |
65 |
public JTable jTable = null; |
66 |
private JScrollPane jScrollPane = null; |
67 |
public DefaultTableModel dtm = null; |
68 |
public DefaultTableModel dtm2 = null; |
69 |
public String key; |
70 |
public int selectedRowTable = -1; |
71 |
public int selectedRowTable2 = -1; |
72 |
|
73 |
private int codeCRS = -1; |
74 |
|
75 |
TransformationManualPanel manual = null;
|
76 |
|
77 |
public IAU2000panel() {
|
78 |
initialize(); |
79 |
} |
80 |
|
81 |
private void initialize(){ |
82 |
this.setLayout(new GridLayout(2,3)); |
83 |
this.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
84 |
|
85 |
this.add(getSearchButton(), null); |
86 |
this.add(getSearchTextField(), null); |
87 |
//this.add(getInfoCrs(), null);
|
88 |
this.add(getJScrollPane(), null); |
89 |
} |
90 |
|
91 |
public void connection(){ |
92 |
connect = new EpsgConnection();
|
93 |
connect.setConnectionIAU2000(); |
94 |
} |
95 |
|
96 |
private void searchButton() { |
97 |
searchTextField.setBackground(Color.white);
|
98 |
|
99 |
if (searchTextField.getText().equals("")) { |
100 |
searchTextField.setBackground(new Color(255,204,204)); |
101 |
JOptionPane.showMessageDialog(this, "Fill the name of CRS.", "Warning...", JOptionPane.WARNING_MESSAGE); |
102 |
} |
103 |
|
104 |
else {
|
105 |
//Eliminar filas en cada nueva bsqueda
|
106 |
int numRow = dtm.getRowCount();
|
107 |
while (numRow != 0) { |
108 |
numRow = numRow - 1;
|
109 |
dtm.removeRow(numRow); |
110 |
} |
111 |
|
112 |
ResultSet result = null; |
113 |
|
114 |
key = searchTextField.getText(); |
115 |
int code = Integer.parseInt(key); |
116 |
String sentence = "SELECT iau_code, iau_name " + |
117 |
"FROM IAU2000 " +
|
118 |
"WHERE iau_code = " + code;
|
119 |
|
120 |
result = Query.select(sentence,connect.getConnection());
|
121 |
|
122 |
Object[] data = new Object[2]; |
123 |
try {
|
124 |
while (result.next()){
|
125 |
data[0] = result.getString("iau_code"); |
126 |
data[1] = result.getString("iau_name"); |
127 |
dtm.addRow(data); |
128 |
} |
129 |
} catch (SQLException e1) { |
130 |
e1.printStackTrace(); |
131 |
} |
132 |
|
133 |
int numr = dtm.getRowCount();
|
134 |
|
135 |
if (numr == 0 ){ |
136 |
JOptionPane.showMessageDialog(this, "Not Results found.", "Warning...", |
137 |
JOptionPane.WARNING_MESSAGE);
|
138 |
} |
139 |
else{
|
140 |
this.getJTable().setRowSelectionInterval(0,0); |
141 |
} |
142 |
} |
143 |
} |
144 |
|
145 |
private JButton getSearchButton() { |
146 |
if (searchButton == null) { |
147 |
searchButton = new JButton(); |
148 |
searchButton.setPreferredSize(new Dimension(75,20)); |
149 |
searchButton.setText(PluginServices.getText(this,"Buscar")); |
150 |
searchButton.setMnemonic('S');
|
151 |
searchButton.addActionListener(this);
|
152 |
} |
153 |
return searchButton;
|
154 |
} |
155 |
|
156 |
private JTextField getSearchTextField() { |
157 |
if (searchTextField == null) { |
158 |
searchTextField = new JTextField(); |
159 |
searchTextField.setPreferredSize(new Dimension(300,20)); |
160 |
searchTextField.addKeyListener(this);
|
161 |
} |
162 |
return searchTextField;
|
163 |
} |
164 |
|
165 |
public JTable getJTable() { |
166 |
if (jTable == null) { |
167 |
String[] columnNames= {"Code of CRS","Cadena WKT"}; |
168 |
Object[][]data = {}; |
169 |
dtm = new DefaultTableModel(data, columnNames) |
170 |
{ |
171 |
public boolean isCellEditable(int row, int column) { |
172 |
return false; |
173 |
} |
174 |
}; |
175 |
TableSorter sorter = new TableSorter(dtm);
|
176 |
|
177 |
jTable = new JTable(sorter); |
178 |
sorter.setTableHeader(jTable.getTableHeader()); |
179 |
jTable.setCellSelectionEnabled(false);
|
180 |
jTable.setRowSelectionAllowed(true);
|
181 |
jTable.setColumnSelectionAllowed(false);
|
182 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
183 |
TableColumn column = null; |
184 |
for (int i = 0; i < 2; i++) { |
185 |
column = jTable.getColumnModel().getColumn(i); |
186 |
if (i == 0) { |
187 |
column.setPreferredWidth(80); //code column is shorter |
188 |
}else {
|
189 |
column.setPreferredWidth(400);
|
190 |
} |
191 |
|
192 |
} |
193 |
} |
194 |
return jTable;
|
195 |
|
196 |
} |
197 |
|
198 |
public void setCodeCRS(int code) { |
199 |
codeCRS = code; |
200 |
} |
201 |
|
202 |
public int getCodeCRS() { |
203 |
return codeCRS;
|
204 |
} |
205 |
|
206 |
private JScrollPane getJScrollPane() { |
207 |
if (jScrollPane == null) { |
208 |
jScrollPane = new JScrollPane(); |
209 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
210 |
jScrollPane.setBorder( |
211 |
BorderFactory.createCompoundBorder(
|
212 |
BorderFactory.createCompoundBorder(
|
213 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"IAU2000")), |
214 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
215 |
jScrollPane.getBorder())); |
216 |
jScrollPane.setViewportView(getJTable()); |
217 |
} |
218 |
return jScrollPane;
|
219 |
} |
220 |
|
221 |
public ICrs getProjection() {
|
222 |
try {
|
223 |
String txt = getWKT();
|
224 |
ICrs crs = new CrsFactory().getCRS(getCodeCRS(), txt);
|
225 |
return crs ;
|
226 |
} catch (CrsException e) {
|
227 |
e.printStackTrace(); |
228 |
} |
229 |
return null; |
230 |
} |
231 |
|
232 |
public void setWKT(String wk){ |
233 |
cadWKT = wk; |
234 |
} |
235 |
|
236 |
public String getWKT(){ |
237 |
return cadWKT;
|
238 |
} |
239 |
|
240 |
public void setProjection(IProjection crs) { |
241 |
//setCrs((ICrs) crs);
|
242 |
} |
243 |
|
244 |
public void loadViewCRS(int code){ |
245 |
connection(); |
246 |
String sentence = "SELECT iau_code, iau_name " + |
247 |
"FROM IAU2000 " +
|
248 |
"WHERE iau_code = " + code;
|
249 |
|
250 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
251 |
|
252 |
Object[] data = new Object[2]; |
253 |
try {
|
254 |
while (result.next()){
|
255 |
data[0] = result.getString("iau_code"); |
256 |
data[1] = result.getString("iau_name"); |
257 |
dtm.addRow(data); |
258 |
} |
259 |
} catch (SQLException e1) { |
260 |
e1.printStackTrace(); |
261 |
} |
262 |
} |
263 |
|
264 |
public void keyPressed(KeyEvent e) { |
265 |
if (e.getSource() == this.getSearchTextField()){ |
266 |
if (e.getKeyCode() == 10) { |
267 |
searchButton(); |
268 |
} |
269 |
|
270 |
if ((e.getKeyCode() >= 48 && e.getKeyCode() <= 57) || e.getKeyCode() >= 96 && e.getKeyCode() <= 105 || |
271 |
(e.getKeyCode() >= 0 && e.getKeyCode()<= 31) || e.getKeyCode() == 127){ |
272 |
} |
273 |
else {
|
274 |
JOptionPane.showMessageDialog(IAU2000panel.this,
|
275 |
"Only number format.",
|
276 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
277 |
String aux = searchTextField.getText();
|
278 |
if (aux.length() == 1 || aux.length() == 0){ |
279 |
searchTextField.setText("");
|
280 |
} |
281 |
else {
|
282 |
searchTextField.setText(aux.substring(0, aux.length()-1)); |
283 |
} |
284 |
} |
285 |
} |
286 |
|
287 |
} |
288 |
|
289 |
public void keyReleased(KeyEvent arg0) { |
290 |
// TODO Auto-generated method stub
|
291 |
|
292 |
} |
293 |
|
294 |
public void keyTyped(KeyEvent arg0) { |
295 |
// TODO Auto-generated method stub
|
296 |
|
297 |
} |
298 |
|
299 |
public void actionPerformed(ActionEvent e) { |
300 |
// TODO Auto-generated method stub
|
301 |
if (e.getSource() == this.getSearchButton()){ |
302 |
searchTextField.setBackground(Color.white);
|
303 |
if (searchTextField.getText().equals("")) { |
304 |
searchTextField.setBackground(new Color(255,204,204)); |
305 |
JOptionPane.showMessageDialog(IAU2000panel.this,
|
306 |
"Fill the key-word of the search.",
|
307 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
308 |
} |
309 |
else {
|
310 |
searchButton(); |
311 |
} |
312 |
} |
313 |
} |
314 |
|
315 |
} |