1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.jfreechart.chart.properties;
\r
14 import org.eclipse.jface.dialogs.IInputValidator;
\r
17 * Validator for validating that an input is double.
\r
19 * Can allow empty strings.
\r
21 * @author Teemu Lempinen
\r
24 public class DoubleValidator implements IInputValidator {
\r
29 * New double validator. Does not allow empty strings
\r
31 public DoubleValidator() {
\r
36 * New double validator.
\r
37 * @param allowEmpty Are empty strings allowed
\r
39 public DoubleValidator(boolean allowEmpty) {
\r
40 this.allowEmpty = allowEmpty;
\r
44 public String isValid(String newText) {
\r
45 if (allowEmpty && newText.trim().isEmpty())
\r
48 Double.parseDouble(newText);
\r
50 } catch (NumberFormatException e) {
\r
51 return e.getMessage();
\r