Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / regionalpha / panel / RegionAlphaUI.java @ 18362

History | View | Annotate | Download (4.04 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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.raster.regionalpha.panel;
20

    
21
import java.awt.BorderLayout;
22
import java.util.ArrayList;
23

    
24
import javax.swing.event.TableModelEvent;
25
import javax.swing.event.TableModelListener;
26

    
27
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
28
import org.gvsig.gui.beans.table.TableContainer;
29
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
30
import org.gvsig.raster.dataset.Params;
31
import org.gvsig.raster.grid.filter.RegistrableFilterListener;
32
import org.gvsig.raster.grid.roi.ROI;
33

    
34
import com.iver.cit.gvsig.fmap.layers.FLayer;
35
/**
36
 * 
37
 * @version 17/01/2008
38
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
39
 */
40
public class RegionAlphaUI extends RegistrableFilterListener implements TableModelListener {
41
        private TableContainer tableContainer = null;
42
        private FLayer layer = null;
43
        
44
        public RegionAlphaUI() {
45
                initialize();
46
        }
47
        
48
        private void initialize() {
49
                setLayout(new BorderLayout());
50
                add(getTableContainer(), BorderLayout.CENTER);
51
        }
52
        
53
        private TableContainer getTableContainer() {
54
                if (tableContainer == null) {
55
                        String[] columnNames = {" ", "Nombre", ""};
56
                        int[] columnWidths = {22, 334, 0};
57
                        tableContainer = new TableContainer(columnNames, columnWidths);
58
                        tableContainer.setModel("CheckBoxModel");
59
                        tableContainer.initialize();
60
                        tableContainer.setControlVisible(false);
61
                        tableContainer.setMoveRowsButtonsVisible(false);
62
                        tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMinWidth(22);
63
                        tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMaxWidth(22);
64
                        tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMinWidth(0);
65
                        tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMaxWidth(0);
66
                        tableContainer.getModel().addTableModelListener(this);
67
                }
68
                return tableContainer;
69
        }
70
        
71
        public void setLayer(FLayer layer) {
72
                this.layer = layer;
73
                if (layer == null)
74
                        return;
75
                ArrayList roisArray = ((FLyrRasterSE) layer).getRois();
76
                if (roisArray != null) {
77
                        for (int i = 0; i < roisArray.size(); i++) {
78
                                ROI roi = (ROI) roisArray.get(i);
79
        
80
                                Object row[] = {"", "", ""};
81
                                row[0] = new Boolean(false);
82
                                row[1] = roi.getName(); 
83
                                row[2] = new Integer(i);
84
                                try {
85
                                        getTableContainer().addRow(row);
86
                                } catch (NotInitializeException e) {
87
                                }
88
                        }
89
                }
90
        }
91
        
92
        private ArrayList getSelectedROIs() {
93
                if (layer == null)
94
                        return null;
95

    
96
                ArrayList roisArray = ((FLyrRasterSE) layer).getRois();
97
                ArrayList selected = new ArrayList();
98
                if (roisArray != null) {
99
                        for (int i = 0; i < roisArray.size(); i++) {
100
                                if (((Boolean) tableContainer.getModel().getValueAt(i, 0)).booleanValue()) {
101
                                        selected.add(roisArray.get(i));
102
                                }
103
                        }
104
                }
105
                return selected;
106
        }
107
        
108
        /**
109
         * Sobrecargamos el m?todo getParams para que siempre devuelva
110
         * algo.
111
         */
112
        public Params getParams() {
113
                params = new Params();
114
                params.setParam("rois",
115
                                getSelectedROIs(),
116
                                -1,
117
                                null);
118
                return params;
119
        }
120

    
121
        /*
122
         * (non-Javadoc)
123
         * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
124
         */
125
        public void tableChanged(TableModelEvent e) {
126
                callStateChanged();
127
        }
128
}