root / trunk / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / slidertext / listeners / SliderTextListener.java @ 8026
History | View | Annotate | Download (2.89 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.gui.beans.slidertext.listeners; |
20 |
|
21 |
import java.awt.event.ActionEvent; |
22 |
import java.awt.event.ActionListener; |
23 |
import java.awt.event.FocusEvent; |
24 |
import java.awt.event.FocusListener; |
25 |
import java.awt.event.KeyEvent; |
26 |
import java.awt.event.KeyListener; |
27 |
|
28 |
import javax.swing.event.ChangeEvent; |
29 |
import javax.swing.event.ChangeListener; |
30 |
|
31 |
import org.gvsig.gui.beans.slidertext.SliderTextContainer; |
32 |
|
33 |
/**
|
34 |
*
|
35 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
36 |
*
|
37 |
*/
|
38 |
public class SliderTextListener implements ChangeListener, ActionListener, KeyListener, FocusListener{ |
39 |
|
40 |
private SliderTextContainer sliderTextContainer = null; |
41 |
private String lastText = ""; |
42 |
|
43 |
public SliderTextListener(SliderTextContainer panel){
|
44 |
this.sliderTextContainer = panel;
|
45 |
} |
46 |
|
47 |
private void initialize(){ |
48 |
|
49 |
} |
50 |
|
51 |
public void actionPerformed(ActionEvent e) { |
52 |
|
53 |
} |
54 |
|
55 |
public void stateChanged(ChangeEvent e) { |
56 |
//Modificamos la caja de texto con el valor de la posici?n del slider
|
57 |
sliderTextContainer.getText().setText(sliderTextContainer.getSlider().getValue()+"");
|
58 |
} |
59 |
|
60 |
public void keyPressed(KeyEvent e) { |
61 |
lastText = sliderTextContainer.getText().getText(); |
62 |
} |
63 |
|
64 |
public void keyReleased(KeyEvent e) { |
65 |
validateTextField(); |
66 |
|
67 |
//Asignamos la nueva posici?n de la barra cuando se modifica el texto
|
68 |
if(e.getKeyCode() == 10){ |
69 |
sliderTextContainer.getSlider().setValue(Double.valueOf(sliderTextContainer.getText().getText()).intValue());
|
70 |
} |
71 |
} |
72 |
|
73 |
public void keyTyped(KeyEvent e) { |
74 |
// TODO Auto-generated method stub
|
75 |
|
76 |
} |
77 |
|
78 |
public void focusGained(FocusEvent e) { |
79 |
// TODO Auto-generated method stub
|
80 |
|
81 |
} |
82 |
|
83 |
public void focusLost(FocusEvent e) { |
84 |
validateTextField(); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Comprobamos que los datos introducidos por el texto sean correctos sino
|
89 |
* borramos el ?ltimo caracter
|
90 |
*/
|
91 |
private void validateTextField(){ |
92 |
try{
|
93 |
Double.valueOf(sliderTextContainer.getText().getText());
|
94 |
}catch(NumberFormatException exc){ |
95 |
if(!sliderTextContainer.getText().getText().equals("")) |
96 |
sliderTextContainer.getText().setText(lastText); |
97 |
else
|
98 |
sliderTextContainer.getText().setText("0");
|
99 |
} |
100 |
} |
101 |
} |