X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fchart%2Fproperty%2FTimeInputValidator.java;h=d8d48ca2ca5fad9319a34a8521564e5576a814ef;hp=ff3c508c2e1c78167afd01cfa7debdf85b8f1b96;hb=47269fe0acb894f346810417d950a1ab59cdc0ea;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/TimeInputValidator.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/TimeInputValidator.java index ff3c508c2..d8d48ca2c 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/TimeInputValidator.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/chart/property/TimeInputValidator.java @@ -1,81 +1,84 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.chart.property; - -import java.text.DecimalFormat; -import java.text.Format; -import java.text.ParseException; - -import org.eclipse.jface.dialogs.IInputValidator; -import org.simantics.utils.format.TimeFormat; - -/** - * @author Toni Kalajainen - */ -public class TimeInputValidator implements IInputValidator { - - Format decimalFormat = new DecimalFormat("0"); - - Format timeFormat = new TimeFormat(100, 0); - - double minValue; - - public TimeInputValidator(double minValue) { - this.minValue = minValue; - } - - public Double parse(String text) { - if (text==null) return null; - text = text.trim(); - if (text.equals("")) return null; - - try { - return (Double) timeFormat.parseObject(text); - } catch (ParseException e) { - } - - try { - Number n = (Number) decimalFormat.parseObject(text); - if (n instanceof Double) return (Double) n; - return n.doubleValue(); - } catch (ParseException e) { - } - - return null; - } - - @Override - public String isValid(String text) { - if (text==null) return "Null"; - text = text.trim(); - if (text.equals("")) return null; - - try { - Double d = (Double) timeFormat.parseObject(text); - - if (d != null && d.doubleValue()