X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.utils%2Fsrc%2Forg%2Fsimantics%2Futils%2Fformat%2FSwitchFormat.java;h=cdf3d751664c6acb3b37fe6830c2fa9f58a267ee;hb=29bf3f64e43ed153670dfeee6dd4b553d1543016;hp=28e28e6ebf55cfd8450398bd16a073cf94600a4e;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/format/SwitchFormat.java b/bundles/org.simantics.utils/src/org/simantics/utils/format/SwitchFormat.java index 28e28e6eb..cdf3d7516 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/format/SwitchFormat.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/format/SwitchFormat.java @@ -1,67 +1,67 @@ -/******************************************************************************* - * 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.utils.format; - -import java.text.FieldPosition; -import java.text.NumberFormat; -import java.text.ParsePosition; - -public class SwitchFormat extends NumberFormat { - - private static final long serialVersionUID = -205210065554444251L; - - double low; - double high; - NumberFormat lowFormat; - NumberFormat middleFormat; - NumberFormat highFormat; - - public SwitchFormat(double low, double high, NumberFormat lowFormat, NumberFormat middleFormat, NumberFormat highFormat) - { - this.low = low; - this.high = high; - this.lowFormat = lowFormat; - this.middleFormat = middleFormat; - this.highFormat = highFormat; - } - - @Override - public StringBuffer format(double number, StringBuffer toAppendTo, - FieldPosition pos) { - - NumberFormat f; - double x = Math.abs(number); - if (x==0.0) f = middleFormat; else - if (x<=low) f = lowFormat; else - if (x>=high) f = highFormat; else f = middleFormat; - - return f.format(number, toAppendTo, pos); - } - - @Override - public StringBuffer format(long number, StringBuffer toAppendTo, - FieldPosition pos) { - NumberFormat f; - double x = Math.abs(number); - if (x==0.0) f = middleFormat; else - if (x<=low) f = lowFormat; else - if (x>=high) f = highFormat; else f = middleFormat; - - return f.format(number, toAppendTo, pos); - } - - @Override - public Number parse(String source, ParsePosition parsePosition) { - return 0; - } - -} +/******************************************************************************* + * 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.utils.format; + +import java.text.FieldPosition; +import java.text.NumberFormat; +import java.text.ParsePosition; + +public class SwitchFormat extends NumberFormat { + + private static final long serialVersionUID = -205210065554444251L; + + double low; + double high; + NumberFormat lowFormat; + NumberFormat middleFormat; + NumberFormat highFormat; + + public SwitchFormat(double low, double high, NumberFormat lowFormat, NumberFormat middleFormat, NumberFormat highFormat) + { + this.low = low; + this.high = high; + this.lowFormat = lowFormat; + this.middleFormat = middleFormat; + this.highFormat = highFormat; + } + + @Override + public StringBuffer format(double number, StringBuffer toAppendTo, + FieldPosition pos) { + + NumberFormat f; + double x = Math.abs(number); + if (x==0.0) f = middleFormat; else + if (x<=low) f = lowFormat; else + if (x>=high) f = highFormat; else f = middleFormat; + + return f.format(number, toAppendTo, pos); + } + + @Override + public StringBuffer format(long number, StringBuffer toAppendTo, + FieldPosition pos) { + NumberFormat f; + double x = Math.abs(number); + if (x==0.0) f = middleFormat; else + if (x<=low) f = lowFormat; else + if (x>=high) f = highFormat; else f = middleFormat; + + return f.format(number, toAppendTo, pos); + } + + @Override + public Number parse(String source, ParsePosition parsePosition) { + return 0; + } + +}