Revision 9240 trunk/libraries/libJCRS/src/org/gvsig/crs/gui/panels/InfoTransformationsRecentsPanel.java

View differences:

InfoTransformationsRecentsPanel.java
6 6
import java.awt.GridLayout;
7 7
import java.awt.event.ActionEvent;
8 8
import java.awt.event.ActionListener;
9
import java.sql.ResultSet;
10
import java.sql.SQLException;
9 11

  
12
import javax.swing.BorderFactory;
10 13
import javax.swing.JButton;
11 14
import javax.swing.JLabel;
12 15
import javax.swing.JPanel;
......
16 19
import javax.swing.table.DefaultTableModel;
17 20

  
18 21
import org.cresques.ui.DefaultDialogPanel;
22
import org.gvsig.crs.EpsgConnection;
19 23
import org.gvsig.crs.ICrs;
24
import org.gvsig.crs.Query;
20 25

  
21 26
import com.iver.andami.PluginServices;
22 27
import com.iver.andami.ui.mdiManager.IWindow;
......
35 40
	private JPanel jPanelbuttons;
36 41
	private JButton jButtonOk;
37 42
	public TableSorter sorter = null;
43
	String[] data = null;
38 44
	
39 45
	private ICrs proj;
40 46
		
41
	public InfoTransformationsRecentsPanel() {
47
	public InfoTransformationsRecentsPanel(String[] data) {
42 48
		super();
43 49
		// TODO Auto-generated constructor stub
50
		this.data = data;
44 51
		inicializate();
45 52
	}
46 53
	
47 54
	private void inicializate() {
48
		this.add(getJPanel(), null);		
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
		
49 61
	}
50 62

  
51
	private JPanel getJPanel() {
52
		if(panelLabels == null) {
53
			panelLabels = new JPanel();
54
			panelLabels.setLayout(new GridLayout(2,1));
55
			panelLabels.setLayout(new FlowLayout(FlowLayout.LEADING,5,10));
56
			panelLabels.setPreferredSize(new Dimension(525, 300));
57
			panelLabels.add(getJScrollPane1(), null);
58
			panelLabels.add(getJPanelButtons(), null);
59
		}
60
		return panelLabels;
61
	}
62
	
63 63
	private JPanel getJPanelButtons() {
64 64
		if(jPanelbuttons == null) {
65 65
			jPanelbuttons = new JPanel();
66 66
			jPanelbuttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
67
			jPanelbuttons.setPreferredSize(new Dimension(525,50));
67
			jPanelbuttons.setPreferredSize(new Dimension(400,50));
68 68
			jPanelbuttons.add(getJButtonOk(),null);
69 69
		}
70 70
		return jPanelbuttons;
......
85 85
	private JScrollPane getJScrollPane1() {
86 86
		if(jScrollPane1 == null) {
87 87
			jScrollPane1 = new JScrollPane();
88
			jScrollPane1.setPreferredSize(new Dimension(400,150));		
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()));
89 95
			jScrollPane1.setViewportView(getJTable());
90 96
		}
91 97
		return jScrollPane1;
......
95 101
		if(jTable == null) {
96 102
			String[] columnNames = {PluginServices.getText(this,"nombre")
97 103
					,PluginServices.getText(this,"valor")};
98
			Object[][]data;
99
			data = new Object[1][2];			
100
			dtm = new DefaultTableModel(data, columnNames)
104
			Object[][] datos = obtainData();
105
			dtm = new DefaultTableModel(datos, columnNames)
101 106
			 {
102 107
				public boolean isCellEditable(int row, int column) {
103 108
					return false;
104
				}
105
				/*
106
				 * metodo necesario para cuando utilizamos tablas ordenadas
107
				 * ya que sino al ordenar por algun campo no se queda con el orden
108
				 * actual al seleccionar una fila (non-Javadoc)
109
				 * @see javax.swing.table.TableModel#getColumnClass(int)
110
				 */
111
				/*public Class getColumnClass(int column)
112
				{
113
					return getValueAt(0, column).getClass();
114
				}*/
115
				};
109
				}		
110
			};
116 111
			sorter = new TableSorter(dtm);			
117 112

  
118 113
			jTable = new JTable(sorter);
......
125 120
		}
126 121
		return jTable;
127 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
	}
128 185

  
129 186
	public WindowInfo getWindowInfo() {
130 187
		WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);

Also available in: Unified diff