ingo@2327: package de.intevation.flys.jfree; ingo@2327: ingo@2327: ingo@2327: import org.jfree.chart.axis.ValueAxis; aheinecke@5673: import org.jfree.chart.axis.LogarithmicAxis; ingo@2327: import org.jfree.data.Range; ingo@2327: ingo@2327: ingo@2327: /** ingo@2327: * @author Ingo Weinzierl ingo@2327: */ ingo@2327: public class DoubleBounds implements Bounds { ingo@2327: ingo@2327: protected double lower; ingo@2327: protected double upper; ingo@2327: ingo@2327: ingo@2330: /** ingo@2330: * Default constructor. A DoubleBounds has always set lower < ingo@2330: * upper! ingo@2330: */ ingo@2327: public DoubleBounds(double lower, double upper) { ingo@2330: this.lower = Math.min(lower, upper); ingo@2330: this.upper = Math.max(lower, upper); ingo@2327: } ingo@2327: ingo@2327: ingo@2327: @Override ingo@2327: public Number getLower() { ingo@2327: return Double.valueOf(lower); ingo@2327: } ingo@2327: ingo@2327: ingo@2327: @Override ingo@2327: public Number getUpper() { ingo@2327: return Double.valueOf(upper); ingo@2327: } ingo@2327: ingo@2327: ingo@2327: @Override ingo@2327: public void applyBounds(ValueAxis axis) { ingo@2327: axis.setRange(new Range(lower, upper)); ingo@2327: } ingo@2327: ingo@2327: ingo@3650: /** ingo@3650: * Set extended range to ValueAxis. ingo@3650: * @param percent how many percent to extend (in each direction, ingo@3650: * thus 10 percent on [0,100] -> [-10,110]. ingo@3650: */ ingo@2327: @Override ingo@2330: public void applyBounds(ValueAxis axis, int percent) { ingo@2330: double space = (upper - lower) / 100 * percent; aheinecke@5673: if (axis instanceof LogarithmicAxis) { aheinecke@5673: axis.setRange(new Range(Math.max(lower-space, 0.0001), aheinecke@5673: Math.max(upper+space, 0.0002))); aheinecke@5673: } else { aheinecke@5673: axis.setRange(new Range(lower-space, upper+space)); aheinecke@5673: } ingo@2330: } ingo@2330: ingo@2330: ingo@2330: @Override ingo@2327: public Bounds combine(Bounds bounds) { ingo@2327: if (bounds == null) { ingo@2327: return this; ingo@2327: } ingo@2327: ingo@2327: DoubleBounds other = (DoubleBounds) bounds; ingo@2327: ingo@2327: double otherLower = other.getLower().doubleValue(); ingo@2327: double otherUpper = other.getUpper().doubleValue(); ingo@2327: ingo@2327: return new DoubleBounds( ingo@2327: otherLower < lower ? otherLower : lower, ingo@2327: otherUpper > upper ? otherUpper : upper); ingo@2327: } ingo@2327: ingo@2327: ingo@2327: @Override ingo@2327: public String toString() { ingo@2327: return "DoubleBounds=[" + lower + " ; " + upper + "]"; ingo@2327: } ingo@2327: } ingo@2327: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :