Revision 3040 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/Panels/TablePointsPanel.java

View differences:

TablePointsPanel.java
1 1
package com.iver.cit.gvsig.gui.Panels;
2 2

  
3
import java.awt.BorderLayout;
4
import java.awt.Dimension;
3 5
import java.awt.FlowLayout;
4 6
import java.awt.GridBagConstraints;
5 7
import java.awt.GridBagLayout;
8
import java.awt.GridLayout;
6 9
import java.awt.event.ActionEvent;
7 10
import java.awt.event.ActionListener;
11
import java.awt.event.MouseAdapter;
12
import java.awt.event.MouseEvent;
8 13

  
9 14
import javax.swing.JLabel;
10 15
import javax.swing.JPanel;
16
import javax.swing.JScrollPane;
17
import javax.swing.JTable;
18
import javax.swing.table.AbstractTableModel;
11 19

  
12 20
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog;
13
import javax.swing.JTable;
14 21
public class TablePointsPanel extends JPanel implements ActionListener{
15 22

  
16 23
	private GeoreferencingDialog parent = null;
......
20 27
	private TableControlerPanel tableControlerPanel = null;
21 28
	private JLabel jLabel = null;
22 29
	
23
	private JTable jTable = null;
30
	private int widthGeneralPanel = 380, heightGeneralPanel = 160;
31
	private int widthSupPanel = 370, heightSupPanel = 125;
32
	private int widthInfPanel = 375, heightInfPanel = 27;
33
	private int widthTable = 375, heightTable = 110;
34
	
35
	private PointTable table = null;
36
	
37
	
38
	
24 39
	/**
25 40
	 * This is the default constructor
26 41
	 */
......
40 55
        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
41 56
        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
42 57
        this.setLayout(new GridBagLayout());
43
        this.setPreferredSize(new java.awt.Dimension(380,160));
44
        this.setSize(new java.awt.Dimension(380,160));
58
        this.setPreferredSize(new java.awt.Dimension(widthGeneralPanel, heightGeneralPanel));
59
        this.setSize(new java.awt.Dimension(widthGeneralPanel, heightGeneralPanel));
45 60
        this.setLocation(new java.awt.Point(0,0));
46 61
        gridBagConstraints1.gridx = 0;
47 62
        gridBagConstraints1.gridy = 0;
......
64 79
	 */    
65 80
	private JPanel getPTable() {
66 81
		if (pTable == null) {
67
			FlowLayout flowLayout4 = new FlowLayout();
82
			BorderLayout borderLayout4 = new BorderLayout();
68 83
			pTable = new JPanel();
69
			pTable.setLayout(flowLayout4);
70
			pTable.setPreferredSize(new java.awt.Dimension(380,122));
71
			flowLayout4.setHgap(5);
72
			flowLayout4.setVgap(5);
73
			pTable.add(getJTable(), null);
84
			pTable.setLayout(borderLayout4);
85
			pTable.setSize(new java.awt.Dimension(widthSupPanel,heightSupPanel));
86
			pTable.setPreferredSize(new java.awt.Dimension(widthSupPanel,heightSupPanel));
87
			pTable.add(getJTable(), BorderLayout.CENTER);
74 88
		}
75 89
		return pTable;
76 90
	}
91
	
77 92
	/**
78 93
	 * This method initializes jPanel1	
79 94
	 * 	
......
82 97
	private JPanel getPPointSelection() {
83 98
		if (pPointSelection == null) {
84 99
			pPointSelection = new JPanel();
85
			pPointSelection.setPreferredSize(new java.awt.Dimension(375,27));
100
			pPointSelection.setPreferredSize(new java.awt.Dimension(widthInfPanel, heightInfPanel));
86 101
			if(this.tableControlerPanel == null){
87 102
				FlowLayout flowLayout1 = new FlowLayout();
88 103
				FlowLayout flowLayout = new FlowLayout();
......
95 110
				flowLayout1.setHgap(0);
96 111
				jLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
97 112
				flowLayout6.setAlignment(java.awt.FlowLayout.LEFT);
98
				flowLayout6.setHgap(0);
113
				flowLayout6.setHgap(3);
99 114
				flowLayout6.setVgap(1);
100 115
				pPointSelection.add(tableControlerPanel, null);
101 116
				pPointSelection.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
......
112 127
		return pPointSelection;
113 128
	}
114 129
	
115

  
116 130
	/* (non-Javadoc)
117 131
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
118 132
	 */
......
125 139
	 * 	
126 140
	 * @return javax.swing.JTable	
127 141
	 */    
128
	private JTable getJTable() {
129
		if (jTable == null) {
130
			jTable = new JTable();
131
			jTable.setPreferredSize(new java.awt.Dimension(375,120));
142
	public PointTable getJTable() {
143
		if (table == null) {
144
			table = new PointTable(null);
145
			table.setSize(new java.awt.Dimension(widthTable, heightTable));
146
			table.setPreferredSize(new java.awt.Dimension(widthTable, heightTable));
132 147
		}
133
		return jTable;
148
		return table;
134 149
	}
135
   }
150
	
151
	/**
152
	 * Asigna una tabla
153
	 * @param table
154
	 */
155
	public void setTable(PointTable table){
156
		this.table = table;
157
		table.setSize(new java.awt.Dimension(widthTable, heightTable));
158
		table.setPreferredSize(new java.awt.Dimension(widthTable, heightTable));
159
	}
160
	
161
	/**
162
	 * Calculo del nuevo tama?o a partir de un frame redimensionado
163
	 * @param w Ancho del frame
164
	 * @param h Alto del frame
165
	 */
166
	public void newFrameSize(int w, int h){
167
		int initWFrame = 385, initHFrame = 185;
168
		int initWGen = 380, initWSup = 370, initWInf = 375 , initWTable = 375;
169
		
170
		widthGeneralPanel = (int)((initWGen * w)/initWFrame);
171
		widthSupPanel = (int)((initWSup * w)/initWFrame);
172
		widthInfPanel = (int)((initWInf * w)/initWFrame);
173
		widthTable = (int)((initWTable * w)/initWFrame);
174
		
175
        this.resize(new java.awt.Dimension(widthGeneralPanel, heightGeneralPanel));
176
        getPTable().resize(new java.awt.Dimension(widthSupPanel,heightSupPanel));
177
		getPPointSelection().resize(new java.awt.Dimension(widthInfPanel, heightInfPanel));
178
		getJTable().resize(new java.awt.Dimension(widthTable, heightTable));
179
		
180
	}
181
	
182
	public class PointTable extends JPanel {
183
	   
184
		private JTable table = null;
185
		private JScrollPane scrollPane = null;
186
		private String[] columnNames = {"N?",
187
										"X",
188
                						"Y",
189
										"X'",
190
										"Y'",
191
                						"Error X", 
192
										"Error Y", 
193
										"RMS"};
194
		private Object[][] data = {
195
	            {"", "", "", "", "", "", "", ""}
196
		        }; 
197
		private TableModelPoint tabModel = null;
198
		
199
		public TableModelPoint getTableModel(){
200
			return tabModel;
201
		}
202
		
203
	    public PointTable(Object[][] d) {
204
	        super(new GridLayout(1,0));
205
	        /*if(d != null)
206
	        	this.data = d;
207
	        
208
	        table = new JTable(data, columnNames);*/
209
	        tabModel = new TableModelPoint();
210
	        table = new JTable(tabModel);
211
	        
212
	        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
213

  
214
	       
215
	        table.addMouseListener(new MouseAdapter() {
216
	           public void mouseClicked(MouseEvent e) {
217
	                    printDebugData(table);
218
	           }
219
	        });
220

  
221
	        scrollPane = new JScrollPane(table);
222
	        add(scrollPane);
223
	    }
224

  
225
	    private void printDebugData(JTable table) {
226
	        int numRows = table.getRowCount();
227
	        int numCols = table.getColumnCount();
228
	        javax.swing.table.TableModel model = table.getModel();
229

  
230
	        System.out.println("Value of data: ");
231
	        for (int i=0; i < numRows; i++) {
232
	            System.out.print("    row " + i + ":");
233
	            for (int j=0; j < numCols; j++) {
234
	                System.out.print("  " + model.getValueAt(i, j));
235
	            }
236
	            System.out.println();
237
	        }
238
	        System.out.println("--------------------------");
239
	    }
240
	    
241
	    class TableModelPoint extends AbstractTableModel {
242
	    	private String[] columnNames = {"N?",
243
											"X",
244
											"Y",
245
											"X'",
246
											"Y'",
247
											"Error X", 
248
											"Error Y", 
249
											"RMS"};
250
	    	private Object[][] data = {
251
	    			{"", "", "", "", "", "", "", ""}
252
	    			}; 
253
	    
254
	       
255
	        public int getColumnCount() {
256
	            return columnNames.length;
257
	        }
258

  
259
	        public int getRowCount() {
260
	            return data.length;
261
	        }
262

  
263
	        public String getColumnName(int col) {
264
	            return columnNames[col];
265
	        }
266

  
267
	        public Object getValueAt(int row, int col) {
268
	            return data[row][col];
269
	        }
270

  
271
	     
272
	        public Class getColumnClass(int c) {
273
	            return getValueAt(0, c).getClass();
274
	        }
275

  
276
	      
277
	        public boolean isCellEditable(int row, int col) {
278
	            if (col < 2) {
279
	                return false;
280
	            } else {
281
	                return true;
282
	            }
283
	        }
284

  
285
	        public void setValueAt(Object value, int row, int col) {
286
	        	data = new Object[row + 1][8];
287
	            data[row][col] = value;
288
	            fireTableCellUpdated(row, col);
289
	        }
290

  
291
	 
292
	    }
293
	}
294
}

Also available in: Unified diff