Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.fmap.mapcontext.swing / org.gvsig.fmap.mapcontext.swing.impl / src / main / java / org / gvsig / fmap / mapcontext / raster / swing / impl / operations / OperationListTableModel.java @ 43803

History | View | Annotate | Download (5.34 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontext.raster.swing.impl.operations;
24

    
25
import javax.swing.table.AbstractTableModel;
26

    
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

    
30
import org.gvsig.raster.lib.buffer.api.BufferLocator;
31
import org.gvsig.raster.lib.buffer.api.OperationManager;
32
import org.gvsig.raster.lib.buffer.api.operations.OperationList;
33
import org.gvsig.raster.lib.buffer.api.operations.OperationListEntry;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.i18n.I18nManager;
36

    
37

    
38

    
39
/**
40
 * @author fdiaz
41
 *
42
 */
43
public class OperationListTableModel extends AbstractTableModel {
44

    
45
    /**
46
     *
47
     */
48
    private static final long serialVersionUID = 5993288441174158255L;
49
    private static final Logger LOG = LoggerFactory.getLogger(OperationListTableModel.class);
50

    
51
    private static final int COLUMNS = 2;
52

    
53
    private static final int COLUMN_OPERATION = 0;
54
    private static final int COLUMN_IS_ACTIVE = 1;
55

    
56

    
57

    
58
    private OperationList operationList;
59

    
60
    /**
61
     *
62
     */
63
    public OperationListTableModel() {
64
        operationList = ((OperationManager)BufferLocator.getBufferManager()).createOperationList();
65
    }
66

    
67
    @Override
68
    public int getRowCount() {
69
        return operationList.size();
70
    }
71

    
72
    @Override
73
    public int getColumnCount() {
74
        return COLUMNS;
75
    }
76

    
77
    @Override
78
    public Object getValueAt(int rowIndex, int columnIndex) {
79
        OperationListEntry entry = operationList.get(rowIndex);
80
        switch (columnIndex) {
81
        case COLUMN_OPERATION:
82
            return entry.getOperation();
83
        case COLUMN_IS_ACTIVE:
84
            return entry.isActive();
85
        }
86
        return null;
87
    }
88

    
89
    @Override
90
    public String getColumnName(int column) {
91
        I18nManager i18nManager = ToolsLocator.getI18nManager();
92
        switch (column) {
93
        case COLUMN_OPERATION:
94
            return i18nManager.getTranslation("_operation");
95
        case COLUMN_IS_ACTIVE:
96
            return i18nManager.getTranslation("_active");
97
        }
98
        return null;
99
    }
100

    
101
    @Override
102
    public boolean isCellEditable(int rowIndex, int columnIndex) {
103
        if(columnIndex==COLUMN_IS_ACTIVE){
104
            return true;
105
        }
106
        return false;
107
    }
108

    
109
    @Override
110
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
111
        if (rowIndex < operationList.size()) {
112
            if (columnIndex < COLUMNS) {
113
                switch (columnIndex) {
114
                case COLUMN_IS_ACTIVE:
115
                    if (aValue == null) {
116
                        operationList.get(rowIndex).setActive(false);
117
                        break;
118
                    }
119
                    if (!(aValue instanceof Boolean)) {
120
                        throw new IllegalArgumentException("The object '" + aValue.toString() + "' must be a Boolean.");
121
                    }
122
                    operationList.get(rowIndex).setActive((Boolean) aValue);
123
                    this.fireTableDataChanged();
124
                    break;
125
                default:
126
                    super.setValueAt(aValue, rowIndex, columnIndex);
127
                    break;
128
                }
129
            }
130
            fireTableDataChanged();
131
        }
132
    }
133

    
134
    /**
135
     * @param rasterStoreBand
136
     */
137
    public void add(OperationListEntry operationListEntry) {
138
        operationList.add(operationListEntry);
139
        fireTableDataChanged();
140
    }
141

    
142
    /**
143
     * @param selectedRow
144
     */
145
    public void removeElementAt(int selectedRow) {
146
        operationList.remove(selectedRow);
147
        fireTableDataChanged();
148
    }
149

    
150
    public OperationListEntry getElementAt(int selectedRow) {
151
        return operationList.get(selectedRow);
152
    }
153

    
154
    /**
155
     * @param selectedRow
156
     */
157
    public void up(int selectedRow) {
158
        if(selectedRow>0){
159
            OperationListEntry operationListEntry = operationList.remove(selectedRow);
160
            operationList.add(selectedRow-1, operationListEntry);
161
            fireTableDataChanged();
162
        }
163
    }
164

    
165
    /**
166
     * @param selectedRow
167
     */
168
    public void down(int selectedRow) {
169
        if(selectedRow<operationList.size()){
170
            OperationListEntry operationListEntry = operationList.remove(selectedRow);
171
            operationList.add(selectedRow+1, operationListEntry);
172
            fireTableDataChanged();
173
        }
174
    }
175

    
176
    @Override
177
    public Class<?> getColumnClass(int col) {
178
        if (col == COLUMN_IS_ACTIVE) {
179
            return Boolean.class;
180
        }
181
        return super.getColumnClass(col);
182
    }
183

    
184
}