svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TranspByPixelListener.java @ 12091
History | View | Annotate | Download (6.17 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.rastertools.properties.panels; |
20 |
|
21 |
import java.awt.event.ActionEvent; |
22 |
import java.awt.event.ActionListener; |
23 |
import java.util.ArrayList; |
24 |
|
25 |
import javax.swing.JButton; |
26 |
import javax.swing.JCheckBox; |
27 |
import javax.swing.JList; |
28 |
import javax.swing.JRadioButton; |
29 |
|
30 |
import org.gvsig.raster.util.TransparencyRange; |
31 |
|
32 |
/**
|
33 |
* Maneja los eventos para el panel de transparencia por pixel.
|
34 |
*
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
36 |
*
|
37 |
*/
|
38 |
public class TranspByPixelListener implements ActionListener { |
39 |
private ArrayList entries = new ArrayList(); |
40 |
private JButton addButton = null; |
41 |
private JButton removeButton = null; |
42 |
private JCheckBox cbActivar = null; |
43 |
private JList list = null; |
44 |
private JRadioButton andRb = null; |
45 |
private JRadioButton orRb = null; |
46 |
private TranspByPixelPanel panel = null; |
47 |
private TranspByPixelRGBInputPanel rgbInputPanel = null; |
48 |
|
49 |
/**
|
50 |
* This is the default constructor
|
51 |
*/
|
52 |
public TranspByPixelListener(TranspByPixelPanel panel) {
|
53 |
this.panel = panel;
|
54 |
rgbInputPanel = ((TranspByPixelRGBInputPanel) panel.getPRGBInput()); |
55 |
list = panel.getJList(); |
56 |
|
57 |
addButton = ((TranspByPixelAddRemoveButtonsPanel) panel.getPButtons()).getBAdd(); |
58 |
removeButton = ((TranspByPixelAddRemoveButtonsPanel) panel.getPButtons()).getBRemove(); |
59 |
andRb = ((TranspByPixelAndOrSelectorPanel) panel.getPOperation()).getRbAnd(); |
60 |
orRb = ((TranspByPixelAndOrSelectorPanel) panel.getPOperation()).getRbOr(); |
61 |
cbActivar = panel.getActiveCheck(); |
62 |
|
63 |
addButton.addActionListener(this);
|
64 |
removeButton.addActionListener(this);
|
65 |
andRb.addActionListener(this);
|
66 |
orRb.addActionListener(this);
|
67 |
cbActivar.addActionListener(this);
|
68 |
} |
69 |
|
70 |
//*******************************
|
71 |
//ActionListener
|
72 |
|
73 |
public void actionPerformed(ActionEvent e) { |
74 |
|
75 |
// A?ade elementos a la lista
|
76 |
if (e.getSource() == addButton) {
|
77 |
if (rgbInputPanel.isValidValue()) {
|
78 |
TransparencyRange entry = new TransparencyRange();
|
79 |
entry.setRed(rgbInputPanel.getRangeRed()); |
80 |
entry.setGreen(rgbInputPanel.getRangeGreen()); |
81 |
entry.setBlue(rgbInputPanel.getRangeBlue()); |
82 |
if (rgbInputPanel.getTAlpha().isChecked())
|
83 |
entry.setAlpha(rgbInputPanel.getTAlpha().getValue()); |
84 |
else
|
85 |
entry.setAlpha(0);
|
86 |
|
87 |
String textR = rgbInputPanel.getTRed().getValue() + ""; |
88 |
if (!rgbInputPanel.getTRed().isChecked())
|
89 |
textR = "*";
|
90 |
String textG = rgbInputPanel.getTGreen().getValue() + ""; |
91 |
if (!rgbInputPanel.getTGreen().isChecked())
|
92 |
textG = "*";
|
93 |
String textB = rgbInputPanel.getTBlue().getValue() + ""; |
94 |
if (!rgbInputPanel.getTBlue().isChecked())
|
95 |
textB = "*";
|
96 |
|
97 |
if (andRb.isSelected()) {
|
98 |
entry.setStrEntry(textR + " & " + textG + " & " + textB); |
99 |
entry.setAnd(true);
|
100 |
} |
101 |
|
102 |
if (orRb.isSelected()) {
|
103 |
entry.setStrEntry(textR + " | " + textG + " | " + textB); |
104 |
entry.setAnd(false);
|
105 |
} |
106 |
|
107 |
panel.getListModel().addElement(entry.getStrEntry()); |
108 |
entries.add(entry); |
109 |
|
110 |
// Limpiamos los textField
|
111 |
rgbInputPanel.getTRed().setValue(0);
|
112 |
rgbInputPanel.getTGreen().setValue(0);
|
113 |
rgbInputPanel.getTBlue().setValue(0);
|
114 |
rgbInputPanel.getTAlpha().setValue(0);
|
115 |
rgbInputPanel.getTRed().setChecked(true);
|
116 |
rgbInputPanel.getTGreen().setChecked(true);
|
117 |
rgbInputPanel.getTBlue().setChecked(true);
|
118 |
rgbInputPanel.getTAlpha().setChecked(false);
|
119 |
} |
120 |
} |
121 |
|
122 |
// Elimina elementos de la lista
|
123 |
if (e.getSource() == removeButton) {
|
124 |
if (list.getSelectedIndex() != -1) { |
125 |
String rule = (String) panel.getListModel().get(list.getSelectedIndex()); |
126 |
String[] s = rule.split(" & "); |
127 |
if (s.length < 3) { |
128 |
s = rule.split(" \\| ");
|
129 |
andRb.setSelected(false);
|
130 |
orRb.setSelected(true);
|
131 |
} else {
|
132 |
andRb.setSelected(true);
|
133 |
orRb.setSelected(false);
|
134 |
} |
135 |
|
136 |
for (int i = 0; i < s.length; i++) { |
137 |
if (s[i].equals("*")) |
138 |
s[i] = "";
|
139 |
} |
140 |
|
141 |
if (s.length == 3) { |
142 |
if (s[0].trim().equals("")) { |
143 |
rgbInputPanel.getTRed().setValue(0);
|
144 |
rgbInputPanel.getTRed().setChecked(false);
|
145 |
} else {
|
146 |
rgbInputPanel.getTRed().setValue(Integer.parseInt(s[0].trim())); |
147 |
rgbInputPanel.getTRed().setChecked(true);
|
148 |
} |
149 |
|
150 |
if (s[1].trim().equals("")) { |
151 |
rgbInputPanel.getTGreen().setValue(0);
|
152 |
rgbInputPanel.getTGreen().setChecked(false);
|
153 |
} else {
|
154 |
rgbInputPanel.getTGreen().setValue(Integer.parseInt(s[1].trim())); |
155 |
rgbInputPanel.getTGreen().setChecked(true);
|
156 |
} |
157 |
|
158 |
if (s[2].trim().equals("")) { |
159 |
rgbInputPanel.getTBlue().setValue(0);
|
160 |
rgbInputPanel.getTBlue().setChecked(false);
|
161 |
} else {
|
162 |
rgbInputPanel.getTBlue().setValue(Integer.parseInt(s[2].trim())); |
163 |
rgbInputPanel.getTBlue().setChecked(true);
|
164 |
} |
165 |
int alpha = ((TransparencyRange) entries.get(list.getSelectedIndex())).getAlpha();
|
166 |
rgbInputPanel.getTAlpha().setValue(alpha); |
167 |
rgbInputPanel.getTAlpha().setChecked(alpha!=0);
|
168 |
|
169 |
entries.remove(list.getSelectedIndex()); |
170 |
panel.getListModel().remove(list.getSelectedIndex()); |
171 |
} |
172 |
} |
173 |
} |
174 |
|
175 |
if (e.getSource() == cbActivar)
|
176 |
panel.setControlEnabled(cbActivar.isSelected()); |
177 |
} |
178 |
|
179 |
/**
|
180 |
* Obtiene el array de entradas de valores a?adidos a la lista
|
181 |
* @return ArrayList
|
182 |
*/
|
183 |
public ArrayList getEntries() { |
184 |
return entries;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* Asigna el array de entradas de valores a?adidos a la lista
|
189 |
* @param list ArrayList
|
190 |
*/
|
191 |
public void setEntries(ArrayList list) { |
192 |
entries = list; |
193 |
} |
194 |
} |