svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / TransparencyByPixelListener.java @ 4377
History | View | Annotate | Download (3.58 KB)
1 |
package org.cresques.ui.raster; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.util.ArrayList; |
6 |
|
7 |
import javax.swing.JButton; |
8 |
import javax.swing.JList; |
9 |
import javax.swing.JRadioButton; |
10 |
|
11 |
import org.cresques.io.raster.TransparencyRange; |
12 |
|
13 |
|
14 |
public class TransparencyByPixelListener implements ActionListener { |
15 |
|
16 |
private TransparencyByPixelPanel panel = null; |
17 |
private RGBInputPanel rgbInputPanel = null; |
18 |
private JList list = null; |
19 |
private JButton addButton = null; |
20 |
private JButton removeButton = null; |
21 |
private JRadioButton andRb = null; |
22 |
private JRadioButton orRb = null; |
23 |
private ArrayList entries = new ArrayList(); |
24 |
|
25 |
/**
|
26 |
* This is the default constructor
|
27 |
*/
|
28 |
public TransparencyByPixelListener(TransparencyByPixelPanel panel) {
|
29 |
this.panel = panel;
|
30 |
rgbInputPanel = ((RGBInputPanel)panel.getPRGBInput()); |
31 |
list = panel.getJList(); |
32 |
|
33 |
addButton = ((AddRemoveButtonsPanel)panel.getPButtons()).getBAdd(); |
34 |
removeButton = ((AddRemoveButtonsPanel)panel.getPButtons()).getBRemove(); |
35 |
andRb = ((AndOrSelectorPanel)panel.getPOperation()).getRbAnd(); |
36 |
orRb = ((AndOrSelectorPanel)panel.getPOperation()).getRbOr(); |
37 |
|
38 |
addButton.addActionListener(this);
|
39 |
removeButton.addActionListener(this);
|
40 |
andRb.addActionListener(this);
|
41 |
orRb.addActionListener(this);
|
42 |
} |
43 |
|
44 |
//*******************************
|
45 |
//ActionListener
|
46 |
|
47 |
public void actionPerformed(ActionEvent e) { |
48 |
|
49 |
//A?ade elementos a la lista
|
50 |
if(e.getSource() == addButton){
|
51 |
if(rgbInputPanel.isValidValue()){
|
52 |
TransparencyRange entry = new TransparencyRange();
|
53 |
entry.setRed(rgbInputPanel.getRangeRed()); |
54 |
entry.setGreen(rgbInputPanel.getRangeGreen()); |
55 |
entry.setBlue(rgbInputPanel.getRangeBlue()); |
56 |
|
57 |
if(andRb.isSelected()){
|
58 |
entry.setStrEntry("("+rgbInputPanel.getTRed().getText()+") & ("+rgbInputPanel.getTGreen().getText()+") & ("+rgbInputPanel.getTBlue().getText()+")"); |
59 |
entry.setAnd(true);
|
60 |
} |
61 |
|
62 |
if(orRb.isSelected()){
|
63 |
entry.setStrEntry("("+rgbInputPanel.getTRed().getText()+") | ("+rgbInputPanel.getTGreen().getText()+") | ("+rgbInputPanel.getTBlue().getText()+")"); |
64 |
entry.setAnd(false);
|
65 |
} |
66 |
panel.getListModel().addElement(entry.getStrEntry()); |
67 |
entries.add(entry); |
68 |
|
69 |
//Limpiamos los textField
|
70 |
rgbInputPanel.getTRed().setText("");
|
71 |
rgbInputPanel.getTGreen().setText("");
|
72 |
rgbInputPanel.getTBlue().setText("");
|
73 |
} |
74 |
} |
75 |
|
76 |
//Elimina elementos de la lista
|
77 |
if(e.getSource() == removeButton){
|
78 |
if(list.getSelectedIndex() != -1){ |
79 |
String rule = (String)panel.getListModel().get(list.getSelectedIndex()); |
80 |
String[] s = rule.split(" & "); |
81 |
if(s.length < 3){ |
82 |
s = rule.split(" \\| ");
|
83 |
andRb.setSelected(false);
|
84 |
orRb.setSelected(true);
|
85 |
}else{
|
86 |
andRb.setSelected(true);
|
87 |
orRb.setSelected(false);
|
88 |
} |
89 |
|
90 |
if(s.length == 3){ |
91 |
rgbInputPanel.getTRed().setText(s[0].substring(1,s[0].lastIndexOf(")") )); |
92 |
rgbInputPanel.getTGreen().setText(s[1].substring(1,s[1].lastIndexOf(")") )); |
93 |
rgbInputPanel.getTBlue().setText(s[2].substring(1,s[2].lastIndexOf(")") )); |
94 |
|
95 |
for(int i=0;i<entries.size();i++){ |
96 |
if( ((TransparencyRange)entries.get(i)).getStrEntry().equals(rule) )
|
97 |
entries.remove(i); |
98 |
} |
99 |
panel.getListModel().remove(list.getSelectedIndex()); |
100 |
} |
101 |
} |
102 |
} |
103 |
} |
104 |
|
105 |
/**
|
106 |
* Obtiene el array de entradas de valores a?adidos a la lista
|
107 |
* @return ArrayList
|
108 |
*/
|
109 |
public ArrayList getEntries(){ |
110 |
return entries;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Asigna el array de entradas de valores a?adidos a la lista
|
115 |
* @param list ArrayList
|
116 |
*/
|
117 |
public void setEntries(ArrayList list){ |
118 |
entries = list; |
119 |
} |
120 |
} |