svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / InfoTransformationsRecentsPanel.java @ 9240
History | View | Annotate | Download (5.99 KB)
1 |
package org.gvsig.crs.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.FlowLayout; |
5 |
import java.awt.Font; |
6 |
import java.awt.GridLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.sql.ResultSet; |
10 |
import java.sql.SQLException; |
11 |
|
12 |
import javax.swing.BorderFactory; |
13 |
import javax.swing.JButton; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JPanel; |
16 |
import javax.swing.JScrollPane; |
17 |
import javax.swing.JTable; |
18 |
import javax.swing.ListSelectionModel; |
19 |
import javax.swing.table.DefaultTableModel; |
20 |
|
21 |
import org.cresques.ui.DefaultDialogPanel; |
22 |
import org.gvsig.crs.EpsgConnection; |
23 |
import org.gvsig.crs.ICrs; |
24 |
import org.gvsig.crs.Query; |
25 |
|
26 |
import com.iver.andami.PluginServices; |
27 |
import com.iver.andami.ui.mdiManager.IWindow; |
28 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
29 |
import com.iver.cit.gvsig.gui.TableSorter; |
30 |
|
31 |
public class InfoTransformationsRecentsPanel extends JPanel implements IWindow, ActionListener{ |
32 |
|
33 |
private static final long serialVersionUID = 1L; |
34 |
|
35 |
private JPanel panelLabels; |
36 |
|
37 |
private JTable jTable; |
38 |
public DefaultTableModel dtm = null; |
39 |
private JScrollPane jScrollPane1 = null; |
40 |
private JPanel jPanelbuttons; |
41 |
private JButton jButtonOk; |
42 |
public TableSorter sorter = null; |
43 |
String[] data = null; |
44 |
|
45 |
private ICrs proj;
|
46 |
|
47 |
public InfoTransformationsRecentsPanel(String[] data) { |
48 |
super();
|
49 |
// TODO Auto-generated constructor stub
|
50 |
this.data = data;
|
51 |
inicializate(); |
52 |
} |
53 |
|
54 |
private void inicializate() { |
55 |
setLayout(new GridLayout(2,1)); |
56 |
setLayout(new FlowLayout(FlowLayout.LEADING,5,10)); |
57 |
setPreferredSize(new Dimension(400, 200)); |
58 |
add(getJScrollPane1(), null);
|
59 |
add(getJPanelButtons(), null);
|
60 |
|
61 |
} |
62 |
|
63 |
private JPanel getJPanelButtons() { |
64 |
if(jPanelbuttons == null) { |
65 |
jPanelbuttons = new JPanel(); |
66 |
jPanelbuttons.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
67 |
jPanelbuttons.setPreferredSize(new Dimension(400,50)); |
68 |
jPanelbuttons.add(getJButtonOk(),null);
|
69 |
} |
70 |
return jPanelbuttons;
|
71 |
} |
72 |
|
73 |
private JButton getJButtonOk() { |
74 |
if(jButtonOk == null) { |
75 |
jButtonOk = new JButton(); |
76 |
jButtonOk.setText(PluginServices.getText(this,"ok")); |
77 |
jButtonOk.setPreferredSize(new Dimension(100,25)); |
78 |
jButtonOk.setMnemonic('O');
|
79 |
jButtonOk.setToolTipText("Accept");
|
80 |
jButtonOk.addActionListener(this);
|
81 |
} |
82 |
return jButtonOk;
|
83 |
} |
84 |
|
85 |
private JScrollPane getJScrollPane1() { |
86 |
if(jScrollPane1 == null) { |
87 |
jScrollPane1 = new JScrollPane(); |
88 |
jScrollPane1.setPreferredSize(new Dimension(400,150)); |
89 |
jScrollPane1.setBorder( |
90 |
BorderFactory.createCompoundBorder(
|
91 |
BorderFactory.createCompoundBorder(
|
92 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"info_transformations")), |
93 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
94 |
jScrollPane1.getBorder())); |
95 |
jScrollPane1.setViewportView(getJTable()); |
96 |
} |
97 |
return jScrollPane1;
|
98 |
} |
99 |
|
100 |
private JTable getJTable() { |
101 |
if(jTable == null) { |
102 |
String[] columnNames = {PluginServices.getText(this,"nombre") |
103 |
,PluginServices.getText(this,"valor")}; |
104 |
Object[][] datos = obtainData(); |
105 |
dtm = new DefaultTableModel(datos, columnNames) |
106 |
{ |
107 |
public boolean isCellEditable(int row, int column) { |
108 |
return false; |
109 |
} |
110 |
}; |
111 |
sorter = new TableSorter(dtm);
|
112 |
|
113 |
jTable = new JTable(sorter); |
114 |
|
115 |
jTable.setCellSelectionEnabled(false);
|
116 |
jTable.setRowSelectionAllowed(true);
|
117 |
jTable.setColumnSelectionAllowed(false);
|
118 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
119 |
|
120 |
} |
121 |
return jTable;
|
122 |
} |
123 |
|
124 |
private String[][] obtainData(){ |
125 |
String[][] valid = null; |
126 |
if (data[0].equals("EPSG")){ |
127 |
valid = new String[6][2]; |
128 |
valid[0][0] = PluginServices.getText(this,"source_crs"); |
129 |
valid[0][1] = data[2]; |
130 |
valid[1][0] = PluginServices.getText(this,"target_crs"); |
131 |
valid[1][1] = data[3]; |
132 |
EpsgConnection conn = new EpsgConnection();
|
133 |
conn.setConnectionEPSG(); |
134 |
String sentence = "SELECT coord_op_code, area_of_use_code " + |
135 |
"FROM epsg_coordoperation " +
|
136 |
"WHERE coord_op_name LIKE '" + data[1]+ "'" ; |
137 |
ResultSet result = Query.select(sentence,conn.getConnection()); |
138 |
try {
|
139 |
result.next(); |
140 |
valid[2][0] = PluginServices.getText(this,"transformation_code"); |
141 |
valid[2][1] = result.getString("coord_op_code"); |
142 |
sentence = "SELECT area_of_use FROM epsg_area " +
|
143 |
"WHERE area_code = "+ Integer.parseInt(result.getString("area_of_use_code")); |
144 |
|
145 |
} catch (SQLException e) { |
146 |
// TODO Auto-generated catch block
|
147 |
e.printStackTrace(); |
148 |
} |
149 |
valid[3][0] = PluginServices.getText(this,"transformation_name"); |
150 |
valid[3][1] = data[1]; |
151 |
valid[4][0] = PluginServices.getText(this,"details"); |
152 |
result = Query.select(sentence, conn.getConnection());
|
153 |
try {
|
154 |
result.next(); |
155 |
valid[4][1] = result.getString("area_of_use"); |
156 |
} catch (SQLException e) { |
157 |
// TODO Auto-generated catch block
|
158 |
e.printStackTrace(); |
159 |
} |
160 |
} |
161 |
else if (data[0].equals("USR")){ |
162 |
valid = new String[3][2]; |
163 |
valid[0][0] = PluginServices.getText(this,"source_crs"); |
164 |
valid[0][1] = data[2]; |
165 |
valid[1][0] = PluginServices.getText(this,"target_crs"); |
166 |
valid[1][1] = data[3]; |
167 |
valid[2][0] = PluginServices.getText(this,"details"); |
168 |
valid[2][1] = data[4]; |
169 |
} else {
|
170 |
valid = new String[4][2]; |
171 |
String[] partes = data[4].split("\\("); |
172 |
String nadFile = partes[0]; |
173 |
String codigoNad = partes[1].substring(0,partes[1].length()-1); |
174 |
valid[0][0] = PluginServices.getText(this,"source_crs"); |
175 |
valid[0][1] = data[2]; |
176 |
valid[1][0] =PluginServices.getText(this,"target_crs"); |
177 |
valid[1][1] = data[3]; |
178 |
valid[2][0] = PluginServices.getText(this,"nadgrids_file"); |
179 |
valid[2][1] = nadFile; |
180 |
valid[3][0] = PluginServices.getText(this,"calculated_in"); |
181 |
valid[3][1] = codigoNad; |
182 |
} |
183 |
return valid;
|
184 |
} |
185 |
|
186 |
public WindowInfo getWindowInfo() {
|
187 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
188 |
m_viewinfo.setTitle("Info");//PluginServices.getText(this,proj.getCrsWkt().getName())); |
189 |
return m_viewinfo;
|
190 |
} |
191 |
|
192 |
public void actionPerformed(ActionEvent e) { |
193 |
if (e.getSource() == getJButtonOk()){
|
194 |
PluginServices.getMDIManager().closeWindow(this);
|
195 |
} |
196 |
} |
197 |
|
198 |
} |