Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / preferences / panels / PreferenceLoadLayer.java @ 17491

History | View | Annotate | Download (7.34 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.gui.preferences.panels;
20

    
21
import java.awt.Component;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.io.File;
28
import java.util.ArrayList;
29

    
30
import javax.swing.BorderFactory;
31
import javax.swing.ButtonGroup;
32
import javax.swing.JComboBox;
33
import javax.swing.JLabel;
34
import javax.swing.JList;
35
import javax.swing.JRadioButton;
36
import javax.swing.ListCellRenderer;
37

    
38
import org.gvsig.fmap.raster.util.Configuration;
39
import org.gvsig.raster.datastruct.ColorTable;
40
import org.gvsig.raster.datastruct.serializer.ColorTableLibraryPersistence;
41
import org.gvsig.raster.gui.preferences.combocolortable.PaintItem;
42
import org.gvsig.raster.gui.preferences.combocolortable.PreferenceColorTableIconPainter;
43
import org.gvsig.raster.util.PanelBase;
44

    
45
public class PreferenceLoadLayer extends PanelBase implements ActionListener {
46
        JComboBox      comboBoxColorTable    = null;
47
        JRadioButton   radioButtonRealce     = null;
48
        JRadioButton   radioButtonColorTable = null;
49

    
50
        private String palettesPath = System.getProperty("user.home") +
51
                File.separator +
52
                "gvSIG" + // PluginServices.getArguments()[0] +
53
                File.separator + "colortable";
54

    
55
        public PreferenceLoadLayer() {
56
                initialize();
57
                translate();
58
        }
59

    
60
        private void translate() {
61

    
62
        }
63
        private void initialize() {
64
                GridBagConstraints gridBagConstraints;
65
                ButtonGroup buttonGroup;
66
                JLabel jLabel9;
67
                buttonGroup = new ButtonGroup();
68
                jLabel9 = new JLabel();
69
                radioButtonRealce = new JRadioButton();
70
                radioButtonColorTable = new JRadioButton();
71

    
72
                getPanel().setLayout(new GridBagLayout());
73

    
74
                getPanel().setBorder(BorderFactory.createTitledBorder("Carga de capas"));
75
                jLabel9.setText("Al cargar una imagen no RGB, aplicarle:");
76
                jLabel9.setToolTipText("Al cargar una imagen No RGB");
77
                gridBagConstraints = new GridBagConstraints();
78
                gridBagConstraints.gridx = 0;
79
                gridBagConstraints.gridy = 0;
80
                gridBagConstraints.gridwidth = 2;
81
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
82
                gridBagConstraints.anchor = GridBagConstraints.WEST;
83
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
84
                getPanel().add(jLabel9, gridBagConstraints);
85

    
86
                buttonGroup.add(radioButtonRealce);
87
                radioButtonRealce.addActionListener(this);
88
                radioButtonRealce.setSelected(true);
89
                radioButtonRealce.setActionCommand("realce");
90
                radioButtonRealce.setText("Realce");
91
                radioButtonRealce.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
92
                radioButtonRealce.setMargin(new Insets(0, 0, 0, 0));
93
                gridBagConstraints = new GridBagConstraints();
94
                gridBagConstraints.gridx = 0;
95
                gridBagConstraints.gridy = 1;
96
                gridBagConstraints.gridwidth = 2;
97
                gridBagConstraints.anchor = GridBagConstraints.WEST;
98
                gridBagConstraints.insets = new Insets(2, 5, 2, 5);
99
                getPanel().add(radioButtonRealce, gridBagConstraints);
100

    
101
                buttonGroup.add(radioButtonColorTable);
102
                radioButtonColorTable.addActionListener(this);
103
                radioButtonColorTable.setText("Tabla de color");
104
                radioButtonRealce.setActionCommand("colortable");
105
                radioButtonColorTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
106
                radioButtonColorTable.setMargin(new Insets(0, 0, 0, 0));
107
                gridBagConstraints = new GridBagConstraints();
108
                gridBagConstraints.gridx = 0;
109
                gridBagConstraints.gridy = 2;
110
                gridBagConstraints.anchor = GridBagConstraints.WEST;
111
                gridBagConstraints.insets = new Insets(2, 5, 5, 2);
112
                getPanel().add(radioButtonColorTable, gridBagConstraints);
113

    
114
                gridBagConstraints = new GridBagConstraints();
115
                gridBagConstraints.gridx = 1;
116
                gridBagConstraints.gridy = 2;
117
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
118
                gridBagConstraints.weightx = 1.0;
119
                gridBagConstraints.insets = new Insets(2, 2, 5, 5);
120
                getPanel().add(getComboBoxColorTable(), gridBagConstraints);
121
        }
122

    
123
        public JComboBox getComboBoxColorTable() {
124
                if (comboBoxColorTable == null) {
125
                        comboBoxColorTable = new JComboBox();
126

    
127
                        ArrayList fileList = ColorTableLibraryPersistence.getPaletteFileList(palettesPath);
128

    
129
                        for (int i = 0; i < fileList.size(); i++) {
130
                                ArrayList paletteItems = new ArrayList();
131
                                String paletteName = ColorTableLibraryPersistence.loadPalette(palettesPath, (String) fileList.get(i), paletteItems);
132

    
133
                                if (paletteItems.size() <= 0)
134
                                        continue;
135

    
136
                                ColorTable colorTable = new ColorTable();
137
                                colorTable.setName(paletteName);
138
                                colorTable.createPaletteFromColorItems(paletteItems, true);
139
                                colorTable.setInterpolated(true);
140

    
141
                                ArrayList array = new ArrayList();
142
                                array.add(paletteName);
143
                                array.add(new PreferenceColorTableIconPainter(colorTable));
144

    
145
                                comboBoxColorTable.addItem(array);
146
                        }
147

    
148
                        comboBoxColorTable.setRenderer(new ListCellRenderer() {
149
                                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
150
                                        ArrayList array = (ArrayList) value;
151

    
152
                                        PaintItem paintItem = new PaintItem((String) array.get(0), (PreferenceColorTableIconPainter) array.get(1), isSelected);
153
                                        return paintItem;
154
                                }
155
                        });
156
                }
157
                return comboBoxColorTable;
158
        }
159

    
160
        private void setColorTableEnabled(boolean enabled) {
161
                getComboBoxColorTable().setEnabled(enabled);
162
        }
163

    
164
        public void initializeDefaults() {
165
                radioButtonRealce.setSelected(true);
166
                setColorTableEnabled(false);
167
        }
168

    
169
        public void initializeValues() {
170
                String colorTable = Configuration.getValue("loadlayer_usecolortable", (String) null);
171
                boolean finded = false;
172
                if (colorTable != null) {
173
                        radioButtonColorTable.setSelected(true);
174
                        setColorTableEnabled(true);
175

    
176
                        for (int i=0; i<getComboBoxColorTable().getItemCount(); i++) {
177
                                if (((String) ((ArrayList) getComboBoxColorTable().getItemAt(i)).get(0)).equals(colorTable)) {
178
                                        getComboBoxColorTable().setSelectedIndex(i);
179
                                        finded = true;
180
                                        break;
181
                                }
182
                        }
183
                }
184

    
185
                if (finded == false) {
186
                        radioButtonRealce.setSelected(true);
187
                        setColorTableEnabled(false);
188
                        Configuration.setValue("loadlayer_usecolortable", (String) null);
189
                }
190
        }
191

    
192
        public void storeValues() {
193
                if (radioButtonColorTable.isSelected())
194
                        Configuration.setValue("loadlayer_usecolortable", (String) ((ArrayList) getComboBoxColorTable().getSelectedItem()).get(0));
195
                else
196
                        Configuration.setValue("loadlayer_usecolortable", null);
197
        }
198

    
199
        public void actionPerformed(ActionEvent e) {
200
                if (radioButtonColorTable.isSelected()) {
201
                        setColorTableEnabled(true);
202
                } else {
203
                        setColorTableEnabled(false);
204
                }
205
        }
206
}