Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src-test / org / gvsig / georeferencing / gui / pointsTable / PointsTable.java @ 8020

History | View | Annotate | Download (4.79 KB)

1
package org.gvsig.georeferencing.gui.pointsTable;
2

    
3
import java.awt.Component;
4
import java.awt.GridLayout;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
7

    
8
import javax.swing.AbstractCellEditor;
9
import javax.swing.JCheckBox;
10
import javax.swing.JPanel;
11
import javax.swing.JScrollPane;
12
import javax.swing.JTable;
13
import javax.swing.SwingConstants;
14
import javax.swing.SwingUtilities;
15
import javax.swing.event.ListSelectionListener;
16
import javax.swing.table.DefaultTableModel;
17
import javax.swing.table.TableCellEditor;
18
import javax.swing.table.TableCellRenderer;
19
import javax.swing.table.TableModel;
20

    
21
/**
22
 * Clase que representa la tabla de puntos
23
 * @author Nacho Brodin (brodin_ign@gva.es)
24
 */
25
public class PointsTable extends JPanel {
26
        
27
        private JTable table = null;
28
        private JScrollPane jScrollPane = null;
29
        
30
        private TableModelPoint tabModel = null;
31
        private TableModel tabModel1 = null;
32
        final static String[]         columnNames = {"", "N?", "X", "Y", 
33
                                                                                "X'", "Y'", "Error X",  
34
                                                                                "Error Y",  "RMS"};
35

    
36
        
37
        public TableModelPoint getTableModel(){
38
                return tabModel;
39
        }
40
        
41
        public PointsTable() {
42
                super(new GridLayout(1,0));
43
                
44
                
45
                //table.setPreferredScrollableViewportSize(new Dimension(500, 70));
46
                        
47
                
48
                /*TableColumn column = null;
49
                for (int i = 0; i < table.getModel().getColumnCount(); i++) {
50
                        column = table.getColumnModel().getColumn(i);
51
                        if(i == 0){
52
                                column.setCellRenderer(new CheckColumnRenderer());
53
                                column.setCellEditor(new CheckColumnEditor());
54
                                column.setMaxWidth(19);
55
                                column.setMinWidth(19);
56
                        }
57
                        if(i == 1){
58
                                column.setMaxWidth(25);
59
                                column.setMinWidth(25);
60
                        }
61
                        if((i == 2) || (i == 3)){
62
                                column.setMinWidth(50);
63
                                column.setMaxWidth(140);
64
                        }
65
                        if((i == 4) || (i == 5)){
66
                                column.setMinWidth(80);
67
                                column.setMaxWidth(190);
68
                        }
69
                }*/
70

    
71
                add( getJScrollPane()); 
72
        }
73
        
74
        private JScrollPane getJScrollPane() {
75
                if (jScrollPane == null) {
76
                        jScrollPane = new JScrollPane();
77
                        jScrollPane.setBounds(6, 17, 469, 280);
78
                        jScrollPane.setViewportView(getTable());
79
                }
80
                return jScrollPane;
81
        }
82
        
83
        public JTable getTable() {
84
                if (table == null) {
85
                        table = new JTable();
86
                        table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
87
                        table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
88
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
89
                                        
90
                                }
91
                        });
92
                        //tabModel = new TableModelPoint();
93
                        tabModel1 = new DefaultTableModel(null, columnNames);
94
                        table = new JTable(tabModel1);
95
                }
96
                return table;
97
        }
98
                
99
        /**
100
         * TableModel del JTable que contiene los puntos con sus errores
101
         * @author Nacho Brodin (brodin_ign@gva.es)
102
         */
103
        public class TableModelPoint extends DefaultTableModel {
104
                
105
                public TableModelPoint(){
106
                        super(new Object[0][9], columnNames);
107
                }
108
                
109
                public int getColumnCount() {
110
                        return columnNames.length;
111
                }
112
                
113
                public String getColumnName(int col) {
114
                        return columnNames[col];
115
                }
116
                
117
                public Class getColumnClass(int c) {
118
                        if (c == 0)
119
                                return Boolean.class;
120
                        return String.class;
121
                }
122
                
123
                public void addNew() {
124
                        super.addRow(new Object[] {new Boolean(true), "", "", "", "", "", "", "", ""});
125
                }
126
                
127
                public void setValueAt(Object value, int row, int col) { 
128
                        super.setValueAt(value, row, col);
129
                }
130
                
131
                /**
132
                 * Devuelve true si la celda es editable. Solo son editables
133
                 * las celdas de los puntos.
134
                 */
135
                public boolean isCellEditable(int row, int col){
136
                        return false;
137
                }
138
        }
139
        
140
        class CheckColumnRenderer extends JCheckBox implements TableCellRenderer {
141
                final private static long serialVersionUID = -3370601314380922368L;
142
                
143
                public Component getTableCellRendererComponent(JTable table,
144
                                Object value,
145
                                boolean isSelected,
146
                                boolean hasFocus,
147
                                int row, int column) {
148
                        if (value == null) {
149
                                this.setSelected(false);
150
                        }
151
                        
152
                        Boolean ValueAsBoolean = (Boolean) value;
153
                        this.setSelected(ValueAsBoolean.booleanValue());
154
                        this.setHorizontalAlignment(SwingConstants.CENTER);
155
                        
156
                        return this;
157
                }
158
        }
159
        
160
        class CheckColumnEditor extends AbstractCellEditor implements TableCellEditor {
161
                final private static long serialVersionUID = -3370601314380922368L;
162
                public JCheckBox checkBox;
163
                
164
                public CheckColumnEditor() {
165
                        super();
166
                        checkBox = new JCheckBox();
167
                        checkBox.addActionListener(new ActionListener() {
168
                                public void actionPerformed(ActionEvent event) {
169
                                        //checkBox.setSelected(!checkBox.isSelected());
170
                                        fireEditingStopped();
171
                                }
172
                        });
173
                }
174
                
175
                public Component getTableCellEditorComponent(JTable table, Object obj,
176
                                boolean isSelected,
177
                                int row, int col) {
178
                        checkBox.setHorizontalAlignment(SwingUtilities.CENTER);
179
                        
180
                        Boolean lValueAsBoolean = (Boolean) obj;
181
                        checkBox.setSelected(lValueAsBoolean.booleanValue());
182
                        
183
                        return checkBox;
184
                }
185
                
186
                public Object getCellEditorValue() {
187
                        return new Boolean(checkBox.isSelected());
188
                }
189
        }
190
        
191
        
192
}