Revision 2997

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/documentfilters/PositiveDoubleDocumentFilter.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.tools.swing.api.documentfilters;
7

  
8
import javax.swing.JTextField;
9
import org.apache.commons.lang3.StringUtils;
10

  
11
/**
12
 *
13
 * @author fdiaz
14
 */
15
public class PositiveDoubleDocumentFilter extends DoubleDocumentFilter {
16
    
17
    public PositiveDoubleDocumentFilter(JTextField text) {
18
        super(text);
19
    }
20
    
21
    public static boolean isValid(JTextField text) {
22
        String s = text.getText();
23
        if( StringUtils.isEmpty(s) ) {
24
            return true;
25
        }
26
        try {
27
            double n = Double.parseDouble(s);
28
            return n >= 0;
29
        } catch (Exception ex) {
30
            return false;
31
        }
32
        
33
    }
34
    
35
}

Also available in: Unified diff