root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TranspByPixelListener.java @ 10940
History | View | Annotate | Download (4.93 KB)
1 | 10740 | nacho | /* 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 | 10940 | nacho | import org.gvsig.raster.util.TransparencyRange; |
31 | 10740 | nacho | |
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 | |||
40 | private TranspByPixelPanel panel = null; |
||
41 | private TranspByPixelRGBInputPanel rgbInputPanel = null; |
||
42 | private JList list = null; |
||
43 | private JButton addButton = null; |
||
44 | private JButton removeButton = null; |
||
45 | private JRadioButton andRb = null; |
||
46 | private JRadioButton orRb = null; |
||
47 | private ArrayList entries = new ArrayList(); |
||
48 | private JCheckBox cbActivar = null; |
||
49 | |||
50 | /**
|
||
51 | * This is the default constructor
|
||
52 | */
|
||
53 | public TranspByPixelListener(TranspByPixelPanel panel) {
|
||
54 | this.panel = panel;
|
||
55 | rgbInputPanel = ((TranspByPixelRGBInputPanel)panel.getPRGBInput()); |
||
56 | list = panel.getJList(); |
||
57 | |||
58 | addButton = ((TranspByPixelAddRemoveButtonsPanel)panel.getPButtons()).getBAdd(); |
||
59 | removeButton = ((TranspByPixelAddRemoveButtonsPanel)panel.getPButtons()).getBRemove(); |
||
60 | andRb = ((TranspByPixelAndOrSelectorPanel)panel.getPOperation()).getRbAnd(); |
||
61 | orRb = ((TranspByPixelAndOrSelectorPanel)panel.getPOperation()).getRbOr(); |
||
62 | cbActivar = panel.getActiveCheck(); |
||
63 | |||
64 | addButton.addActionListener(this);
|
||
65 | removeButton.addActionListener(this);
|
||
66 | andRb.addActionListener(this);
|
||
67 | orRb.addActionListener(this);
|
||
68 | cbActivar.addActionListener(this);
|
||
69 | } |
||
70 | |||
71 | //*******************************
|
||
72 | //ActionListener
|
||
73 | |||
74 | public void actionPerformed(ActionEvent e) { |
||
75 | |||
76 | //A?ade elementos a la lista
|
||
77 | if(e.getSource() == addButton){
|
||
78 | if(rgbInputPanel.isValidValue()){
|
||
79 | TransparencyRange entry = new TransparencyRange();
|
||
80 | entry.setRed(rgbInputPanel.getRangeRed()); |
||
81 | entry.setGreen(rgbInputPanel.getRangeGreen()); |
||
82 | entry.setBlue(rgbInputPanel.getRangeBlue()); |
||
83 | |||
84 | String textR = rgbInputPanel.getTRed().getText();
|
||
85 | if(textR.equals("")) |
||
86 | textR = "*";
|
||
87 | String textG = rgbInputPanel.getTGreen().getText();
|
||
88 | if(textG.equals("")) |
||
89 | textG = "*";
|
||
90 | String textB = rgbInputPanel.getTBlue().getText();
|
||
91 | if(textB.equals("")) |
||
92 | textB = "*";
|
||
93 | if(andRb.isSelected()){
|
||
94 | entry.setStrEntry(textR+" & "+textG+" & "+textB); |
||
95 | entry.setAnd(true);
|
||
96 | } |
||
97 | |||
98 | if(orRb.isSelected()){
|
||
99 | entry.setStrEntry(textR+" | "+textG+" | "+textB); |
||
100 | entry.setAnd(false);
|
||
101 | } |
||
102 | panel.getListModel().addElement(entry.getStrEntry()); |
||
103 | entries.add(entry); |
||
104 | |||
105 | //Limpiamos los textField
|
||
106 | rgbInputPanel.getTRed().setText("");
|
||
107 | rgbInputPanel.getTGreen().setText("");
|
||
108 | rgbInputPanel.getTBlue().setText("");
|
||
109 | } |
||
110 | } |
||
111 | |||
112 | //Elimina elementos de la lista
|
||
113 | if(e.getSource() == removeButton){
|
||
114 | if(list.getSelectedIndex() != -1){ |
||
115 | String rule = (String)panel.getListModel().get(list.getSelectedIndex()); |
||
116 | String[] s = rule.split(" & "); |
||
117 | if(s.length < 3){ |
||
118 | s = rule.split(" \\| ");
|
||
119 | andRb.setSelected(false);
|
||
120 | orRb.setSelected(true);
|
||
121 | }else{
|
||
122 | andRb.setSelected(true);
|
||
123 | orRb.setSelected(false);
|
||
124 | } |
||
125 | |||
126 | for(int i=0;i<s.length;i++){ |
||
127 | if(s[i].equals("*")) |
||
128 | s[i] = "";
|
||
129 | } |
||
130 | |||
131 | if(s.length == 3){ |
||
132 | rgbInputPanel.getTRed().setText(s[0].trim());
|
||
133 | rgbInputPanel.getTGreen().setText(s[1].trim());
|
||
134 | rgbInputPanel.getTBlue().setText(s[2].trim());
|
||
135 | |||
136 | for(int i=0;i<entries.size();i++){ |
||
137 | if( ((TransparencyRange)entries.get(i)).getStrEntry().equals(rule) )
|
||
138 | entries.remove(i); |
||
139 | } |
||
140 | panel.getListModel().remove(list.getSelectedIndex()); |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | if(e.getSource() == cbActivar)
|
||
146 | panel.setControlEnabled(cbActivar.isSelected()); |
||
147 | } |
||
148 | |||
149 | /**
|
||
150 | * Obtiene el array de entradas de valores a?adidos a la lista
|
||
151 | * @return ArrayList
|
||
152 | */
|
||
153 | public ArrayList getEntries(){ |
||
154 | return entries;
|
||
155 | } |
||
156 | |||
157 | /**
|
||
158 | * Asigna el array de entradas de valores a?adidos a la lista
|
||
159 | * @param list ArrayList
|
||
160 | */
|
||
161 | public void setEntries(ArrayList list){ |
||
162 | entries = list; |
||
163 | } |
||
164 | } |