Revision 4244

View differences:

trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/pruebas/TransparencyByPixelPanel.java
11 11

  
12 12
public class TransparencyByPixelPanel extends Panel {
13 13

  
14
	private JPanel 					pBorder = null;
15
	private RGBInputPanel 			pWest = null;
16
	private JPanel 					pEast = null;
17
	private JPanel 					pCenter = null;
18
	private AddRemoveButtonsPanel 	pButtons = null;
19
	private AndOrSelectorPanel 		pOperation = null;
20
	private JList jList = null;
14
	private JPanel 							pBorder = null;
15
	private RGBInputPanel 					pWest = null;
16
	private JPanel 							pEast = null;
17
	private JPanel 							pCenter = null;
18
	private AddRemoveButtonsPanel 			pButtons = null;
19
	private AndOrSelectorPanel 				pOperation = null;
20
	private JList 							jList = null;
21
	private TransparencyByPixelListener 	listener = null;	
22
	
21 23
	/**
22 24
	 * This is the default constructor
23 25
	 */
24 26
	public TransparencyByPixelPanel() {
25 27
		super();
26 28
		initialize();
29
		listener = new TransparencyByPixelListener(this);
27 30
	}
28 31

  
29 32
	/**
......
51 54
			pBorder = new JPanel();
52 55
			pBorder.setLayout(new GridBagLayout());
53 56
			pBorder.setPreferredSize(new java.awt.Dimension(333,118));
54
			pBorder.add(getPWest(), gridBagConstraints2);
57
			pBorder.add(getPRGBInput(), gridBagConstraints2);
55 58
			pBorder.add(getPCenter(), new GridBagConstraints());
56
			pBorder.add(getPEast(), new GridBagConstraints());
59
			pBorder.add(getPList(), new GridBagConstraints());
57 60
		}
58 61
		return pBorder;
59 62
	}
......
63 66
	 * 	
64 67
	 * @return javax.swing.JPanel	
65 68
	 */
66
	private JPanel getPWest() {
69
	public JPanel getPRGBInput() {
67 70
		if (pWest == null) {
68 71
			FlowLayout flowLayout = new FlowLayout();
69 72
			flowLayout.setHgap(1);
......
80 83
	 * 	
81 84
	 * @return javax.swing.JPanel	
82 85
	 */
83
	private JPanel getPEast() {
86
	public JPanel getPList() {
84 87
		if (pEast == null) {
85 88
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
86 89
			gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
......
127 130
	 * 	
128 131
	 * @return javax.swing.JPanel	
129 132
	 */
130
	private JPanel getPButtons() {
133
	public JPanel getPButtons() {
131 134
		if (pButtons == null) {
132 135
			pButtons = new AddRemoveButtonsPanel();
133 136
			pButtons.setPreferredSize(new java.awt.Dimension(60,63));
......
140 143
	 * 	
141 144
	 * @return javax.swing.JPanel	
142 145
	 */
143
	private JPanel getPOperation() {
146
	public JPanel getPOperation() {
144 147
		if (pOperation == null) {
145 148
			pOperation = new AndOrSelectorPanel();
146 149
			pOperation.setPreferredSize(new java.awt.Dimension(60,50));
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/pruebas/PruebaFrame.java
1
package com.iver.cit.gvsig.rasterTools.saveRaster.pruebas;
2

  
3
import javax.swing.JFrame;
4

  
5
public class PruebaFrame extends JFrame{
6

  
7
	public PruebaFrame(){
8
		this.setSize(333,158);
9
		this.getContentPane().add(new TransparencyByPixelPanel());
10
		this.show();
11
	}
12
	/**
13
	 * @param args
14
	 */
15
	public static void main(String[] args) {
16
		PruebaFrame f = new PruebaFrame();
17
	}
18

  
19
}
0 20

  
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/pruebas/RGBInputPanel.java
1 1
package com.iver.cit.gvsig.rasterTools.saveRaster.pruebas;
2 2

  
3
import java.awt.FlowLayout;
3 4
import java.awt.GridBagConstraints;
4 5
import java.awt.GridBagLayout;
6
import java.awt.event.FocusEvent;
7
import java.awt.event.FocusListener;
8
import java.io.IOException;
5 9

  
6 10
import javax.swing.JLabel;
7 11
import javax.swing.JPanel;
8 12
import javax.swing.JTextField;
9
import java.awt.FlowLayout;
10 13

  
11
public class RGBInputPanel extends JPanel {
14
/**
15
 * Panel con los 3 campos para introducir listas de valores RGB. Este
16
 * gestiona los eventos de FocusListener para validar que los valores 
17
 * que se introducen son correctos. Si el TextField pierde el foco y
18
 * tiene un valor incorrecto resetea el contenido.
19
 * 
20
 * Los m?todos publicos getRangeXXX devuelven el intervalo de valores
21
 * en forma de array multidimensional de 2xN elementos. Cada pareja de 
22
 * valores es un rango de color en ese valor de pixel. Un rango de valores
23
 * podria ser por ejemplo {{1,3},{15,30},{200, 255}}
24
 *  
25
 * @author Nacho Brodin (brodin_ign@gva.es)
26
 *
27
 */
28
public class RGBInputPanel extends JPanel implements FocusListener{
12 29

  
13
	private JPanel pRed = null;
14
	private JPanel pGreen = null;
15
	private JPanel pBlue = null;
16
	private JLabel lRed = null;
17
	private JLabel lGreen = null;
18
	private JLabel lBlue = null;
19
	private JTextField tRed = null;
20
	private JTextField tGreen = null;
21
	private JTextField tBlue = null;
30
	private JPanel 			pRed = null;
31
	private JPanel			pGreen = null;
32
	private JPanel 			pBlue = null;
33
	private JLabel			lRed = null;
34
	private JLabel 			lGreen = null;
35
	private JLabel 			lBlue = null;
36
	private JTextField 		tRed = null;
37
	private JTextField 		tGreen = null;
38
	private JTextField 		tBlue = null;
39
	private int[][] 		rangeRed = null;
40
    private int[][] 		rangeGreen = null;
41
    private int[][] 		rangeBlue = null;
22 42

  
23 43
	/**
24 44
	 * This is the default constructor
......
49 69
		this.add(getPRed(), gridBagConstraints);
50 70
		this.add(getPGreen(), gridBagConstraints1);
51 71
		this.add(getPBlue(), gridBagConstraints2);
72
		this.getTBlue().addFocusListener(this);
73
		this.getTGreen().addFocusListener(this);
74
		this.getTRed().addFocusListener(this);
52 75
	}
53 76

  
54 77
	/**
......
119 142
	 * 	
120 143
	 * @return javax.swing.JTextField	
121 144
	 */
122
	private JTextField getTRed() {
145
	public JTextField getTRed() {
123 146
		if (tRed == null) {
124 147
			tRed = new JTextField();
125 148
			tRed.setPreferredSize(new java.awt.Dimension(60,19));
......
132 155
	 * 	
133 156
	 * @return javax.swing.JTextField	
134 157
	 */
135
	private JTextField getTGreen() {
158
	public JTextField getTGreen() {
136 159
		if (tGreen == null) {
137 160
			tGreen = new JTextField();
138 161
			tGreen.setPreferredSize(new java.awt.Dimension(60,19));
......
145 168
	 * 	
146 169
	 * @return javax.swing.JTextField	
147 170
	 */
148
	private JTextField getTBlue() {
171
	public JTextField getTBlue() {
149 172
		if (tBlue == null) {
150 173
			tBlue = new JTextField();
151 174
			tBlue.setPreferredSize(new java.awt.Dimension(60,19));
......
153 176
		return tBlue;
154 177
	}
155 178

  
179
	public void focusGained(FocusEvent e) {
180
		// TODO Auto-generated method stub
181
		
182
	}
183

  
184
	/**
185
     * Obtiene el rango de valores a partir de la cadena de
186
     * texto introducida por el usuario. Sirve para parsear 
187
     * el contenido de los campos de texto que contienen listas
188
     * de valores para RGB.
189
     * @param values
190
     */
191
    private int[][] getTransparencyValues(String values)
192
                                   throws IOException {
193
        int[][] rangeTransparency = null;
194

  
195
        for (int i = 0; i < values.length(); i++) {
196
            char c = values.charAt(i);
197

  
198
            //Control de caracter valido
199
            if ((c != ':') && (c != ',')) {
200
                try {
201
                    Integer.parseInt(String.valueOf(c));
202
                } catch (Exception exp) {
203
                    System.err.println("Caracteres incorrectos en la cadena:" +
204
                                       c);
205
                    throw new IOException("Caracteres incorrectos en la cadena.");
206
                }
207
            }
208

  
209
            //Control de comienzo por un simbolo
210
            if (values.startsWith(",") || values.startsWith(":") ||
211
                    values.endsWith(",") || values.endsWith(":")) {
212
                System.err.println("La cadena empieza o acaba con simbolos incorrectos");
213
                throw new IOException();
214
            }
215

  
216
            //Control de signos consecutivos
217
            if (i < (values.length() - 1)) {
218
                char cmas = values.charAt(i + 1);
219

  
220
                if (((c == ',') || (c == ':')) &&
221
                        ((cmas == ',') || (cmas == ':'))) {
222
                    System.err.println("Signos consecutivos");
223
                    throw new IOException();
224
                }
225
            }
226

  
227
            //Control de dos : seguidos con un n?mero en el medio
228
            if ((i < (values.length() - 3)) && (c == ':')) {
229
                int n = i + 1;
230

  
231
                while ((n < (values.length() - 1)) &&
232
                           (values.charAt(n) != ',') &&
233
                           (values.charAt(n) != ':'))
234
                    n++;
235

  
236
                char signoSgte = values.charAt(n);
237

  
238
                if (signoSgte == ':') {
239
                    System.err.println("Dos separadores de rango consecutivos");
240
                    throw new IOException();
241
                }
242
            }
243
        }
244

  
245
        //Obtenemos los valores de los intervalos
246
        if (!values.equals("")) {
247
            String[] t1 = null;
248
            t1 = values.split("\\,");
249
            rangeTransparency = new int[t1.length][2];
250

  
251
            for (int i = 0; i < t1.length; i++) {
252
                if (t1[i].indexOf(":") == -1) {
253
                    rangeTransparency[i][0] = rangeTransparency[i][1] = Integer.parseInt(t1[i]);
254
                } else {
255
                    String[] t2 = null;
256
                    t2 = t1[i].split("\\:");
257

  
258
                    if (Integer.parseInt(t2[1]) > Integer.parseInt(t2[0])) {
259
                        rangeTransparency[i][0] = Integer.parseInt(t2[0]);
260
                        rangeTransparency[i][1] = Integer.parseInt(t2[1]);
261
                    } else {
262
                        rangeTransparency[i][0] = Integer.parseInt(t2[1]);
263
                        rangeTransparency[i][1] = Integer.parseInt(t2[0]);
264
                    }
265
                }
266

  
267
                if ((rangeTransparency[i][0] < 0) ||
268
                        (rangeTransparency[i][0] > 255) ||
269
                        (rangeTransparency[i][1] < 0) ||
270
                        (rangeTransparency[i][1] > 255)) {
271
                    System.err.println("Valores fuera de rango (0-255)");
272
                    throw new IOException();
273
                }
274
            }
275

  
276
            return rangeTransparency;
277

  
278
            //for(int i=0;i<rangeTransparency.length;i++)
279
            //	System.out.println("("+rangeTransparency[i][0]+":"+rangeTransparency[i][1]+")");
280
        }
281

  
282
        return null;
283
    }
284
    
285
	public void focusLost(FocusEvent e) {
286
		if (!getTRed().getText().equals("")) {
287
            try {
288
                rangeRed = getTransparencyValues(getTRed().getText());
289
            } catch (IOException exc) {
290
                getTRed().setText("");
291
            }
292
        }
293

  
294
        if (!getTGreen().getText().equals("")) {
295
            try {
296
                rangeGreen = getTransparencyValues(getTGreen().getText());
297
            } catch (IOException exc) {
298
                getTGreen().setText("");
299
            }
300
        }
301

  
302
        if (!getTBlue().getText().equals("")) {
303
            try {
304
                rangeBlue = getTransparencyValues(getTBlue().getText());
305
            } catch (IOException exc) {
306
                getTBlue().setText("");
307
            }
308
        }
309
	}
310

  
311
	/**
312
	 * Obtiene la lista de valores del campo Blue.
313
	 * @return array multidimensional con los intervalos
314
	 */
315
	public int[][] getRangeBlue() {
316
		return rangeBlue;
317
	}
318

  
319
	/**
320
	 * Obtiene la lista de valores del campo Green.
321
	 * @return array multidimensional con los intervalos
322
	 */
323
	public int[][] getRangeGreen() {
324
		return rangeGreen;
325
	}
326

  
327
	/**
328
	 * Obtiene la lista de valores del campo Red.
329
	 * @return array multidimensional con los intervalos
330
	 */
331
	public int[][] getRangeRed() {
332
		return rangeRed;
333
	}
334

  
156 335
}
trunk/extensions/extRasterTools/src/com/iver/cit/gvsig/rasterTools/saveRaster/pruebas/TransparencyByPixelListener.java
1
package com.iver.cit.gvsig.rasterTools.saveRaster.pruebas;
2

  
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5
import java.awt.event.FocusEvent;
6
import java.awt.event.FocusListener;
7
import java.awt.event.KeyEvent;
8
import java.awt.event.KeyListener;
9
import java.awt.event.MouseEvent;
10
import java.awt.event.MouseListener;
11

  
12
import javax.swing.event.ChangeEvent;
13
import javax.swing.event.ChangeListener;
14

  
15

  
16
public class TransparencyByPixelListener implements ActionListener, ChangeListener, MouseListener, FocusListener,
17
KeyListener {
18

  
19
	private TransparencyByPixelPanel 	panel = null;
20
	private RGBInputPanel				rgbInputPanel = null;
21
	
22
	/**
23
	 * This is the default constructor
24
	 */
25
	public TransparencyByPixelListener(TransparencyByPixelPanel panel) {
26
		this.panel = panel;
27
		rgbInputPanel = ((RGBInputPanel)panel.getPRGBInput());
28
		/*rgbInputPanel.getTBlue().addFocusListener(this);
29
		rgbInputPanel.getTGreen().addFocusListener(this);
30
		rgbInputPanel.getTRed().addFocusListener(this);*/
31
	}
32

  
33
	//*******************************
34
	//ChangeListener
35
	
36
	public void focusGained(FocusEvent e) {
37
		// TODO Auto-generated method stub
38
		
39
	}
40

  
41
	public void focusLost(FocusEvent e) {
42
		// TODO Auto-generated method stub
43
	}
44
	
45
	public void stateChanged(ChangeEvent e) {
46
		// TODO Auto-generated method stub
47
		
48
	}
49
	
50
	//*******************************
51
	//MouseListener
52
	public void mouseClicked(MouseEvent e) {
53
		// TODO Auto-generated method stub
54
		
55
	}
56

  
57
	public void mouseEntered(MouseEvent e) {
58
		// TODO Auto-generated method stub
59
		
60
	}
61

  
62
	public void mouseExited(MouseEvent e) {
63
		// TODO Auto-generated method stub
64
		
65
	}
66

  
67
	public void mousePressed(MouseEvent e) {
68
		// TODO Auto-generated method stub
69
		
70
	}
71

  
72
	public void mouseReleased(MouseEvent e) {
73
		// TODO Auto-generated method stub
74
		
75
	}
76

  
77
	public void keyPressed(KeyEvent e) {
78
		// TODO Auto-generated method stub
79
		
80
	}
81

  
82
	public void keyReleased(KeyEvent e) {
83
		// TODO Auto-generated method stub
84
		
85
	}
86

  
87
	public void keyTyped(KeyEvent e) {
88
		// TODO Auto-generated method stub
89
		
90
	}
91

  
92
	//*******************************
93
	//ActionListener
94
	
95
	public void actionPerformed(ActionEvent e) {
96
		// TODO Auto-generated method stub
97
		
98
	}
99

  
100
}
0 101

  

Also available in: Unified diff