Statistics
| Revision:

root / tags / v1_1_Build_1012 / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / options / TableOptions.java @ 12987

History | View | Annotate | Download (6.17 KB)

1 5791 nacho
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.georeferencing.gui.options;
20
21
import java.awt.Component;
22
import java.awt.Dimension;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
25
import java.awt.event.MouseAdapter;
26
import java.awt.event.MouseEvent;
27
28
import javax.swing.AbstractCellEditor;
29
import javax.swing.JCheckBox;
30
import javax.swing.JScrollPane;
31
import javax.swing.JTable;
32
import javax.swing.SwingConstants;
33
import javax.swing.SwingUtilities;
34
import javax.swing.table.DefaultTableModel;
35
import javax.swing.table.TableCellEditor;
36
import javax.swing.table.TableCellRenderer;
37
import javax.swing.table.TableColumn;
38
39
/**
40
 * Panel que contiene opciones de georreferenciaci?n a elegir por
41
 * el usuario.
42
 *
43
 * @author Nacho Brodin (brodin_ign@gva.es)
44
 *
45
 */
46
public class TableOptions extends JScrollPane{
47
48
        private JTable                                         table = null;
49
        private TableModelPoint                 tabModel = null;
50
        final static String[]                         columnNames = {"", ""};
51
52
        public TableModelPoint getTableModel(){
53
                return tabModel;
54
        }
55
56
    public TableOptions() {
57
        tabModel = new TableModelPoint();
58
        table = new JTable(tabModel);
59
                setSize(380, 160);
60
                table.setSize(380, 160);
61
        table.setPreferredScrollableViewportSize(new Dimension(380, 160));
62
63
        TableColumn column = null;
64
        for (int i = 0; i < table.getModel().getColumnCount(); i++) {
65
                column = table.getColumnModel().getColumn(i);
66
                if(i == 0){
67
                column.setCellRenderer(new CheckColumnRenderer());
68
                column.setCellEditor(new CheckColumnEditor());
69
                column.setMaxWidth(19);
70
                column.setMinWidth(19);
71
                }
72
        }
73
74
        add(table);
75
    }
76
77
    /**
78
     * Introduce una entrada de la tabla
79
     * @param active Valor para el checkBox
80
     * @param text Texto
81
     */
82
    public void setEntry(boolean active, String text){
83
            tabModel.setEntry(active, text);
84
    }
85
86
    /**
87
     * TableModel del JTable que contiene los puntos con sus errores
88
     * @author Nacho Brodin (brodin_ign@gva.es)
89
     */
90
    public class TableModelPoint extends DefaultTableModel {
91
92
        public TableModelPoint(){
93
                super(new Object[0][2], columnNames);
94
        }
95
96
        public int getColumnCount() {
97
            return columnNames.length;
98
        }
99
100
        public String getColumnName(int col) {
101
            return columnNames[col];
102
        }
103
104
        public Class getColumnClass(int c) {
105
                if (c == 0)
106
                        return Boolean.class;
107
                return String.class;
108
        }
109
110
        public void addNew() {
111
            super.addRow(new Object[] {new Boolean(true), ""});
112
        }
113
114
        public void setValueAt(Object value, int row, int col) {
115
                super.setValueAt(value, row, col);
116
        }
117
118
        /**
119
         * Introduce una entrada de la tabla
120
         * @param active Valor para el checkBox
121
         * @param text Texto
122
         */
123
        public void setEntry(boolean active, String text){
124
                super.addRow(new Object[] {new Boolean(active), text});
125
        }
126
127
        /**
128
         * Devuelve true si la celda es editable. Solo son editables
129
         * las celdas de los puntos.
130
         */
131
        public boolean isCellEditable(int row, int col){
132
                return false;
133
        }
134
    }
135
136
    /**
137
     *
138
     * @author Nacho Brodin (brodin_ign@gva.es)
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
    /**
161
     *
162
     * @author Nacho Brodin (brodin_ign@gva.es)
163
     */
164
    class CheckColumnEditor extends AbstractCellEditor implements TableCellEditor {
165
            final private static long serialVersionUID = -3370601314380922368L;
166
            public JCheckBox checkBox;
167
168
        public CheckColumnEditor() {
169
            super();
170
            checkBox = new JCheckBox();
171
            checkBox.addActionListener(new ActionListener() {
172
                    public void actionPerformed(ActionEvent event) {
173
                             //checkBox.setSelected(!checkBox.isSelected());
174
                        fireEditingStopped();
175
                    }
176
                });
177
        }
178
179
        public Component getTableCellEditorComponent(JTable table, Object obj,
180
                                                     boolean isSelected,
181
                                                     int row, int col) {
182
                checkBox.setHorizontalAlignment(SwingUtilities.CENTER);
183
184
            Boolean lValueAsBoolean = (Boolean) obj;
185
            checkBox.setSelected(lValueAsBoolean.booleanValue());
186
187
            return checkBox;
188
        }
189
190
        public Object getCellEditorValue() {
191
            return new Boolean(checkBox.isSelected());
192
        }
193
    }
194
}