private boolean setMinMax(double min, double max) { if (model != null) { if (min > max) { throw new IllegalArgumentException("min should be less than max"); } else if (min == max) { // Avoid setting values at this point return false; } double previousBoundsMin = model.getCustomMin(); double previousBoundsMax = model.getCustomMax(); // Custom bounds if (model.getCustomMin() == model.getPreviousMin()) { model.setCustomMin(min); } else if (model.getCustomMin() < min) { model.setCustomMin(min); } if (model.getCustomMax() == model.getPreviousMax()) { model.setCustomMax(max); } else if (model.getCustomMax() > max) { model.setCustomMax(max); } model.setPreviousMin(min); model.setPreviousMax(max); if (model.hasValidBounds()) { fireTimelineModelEvent( new TimelineModelEvent( TimelineModelEvent.EventType.MIN_MAX, model, new double[] {min, max})); if (model.getCustomMax() != max || model.getCustomMin() != min) { fireTimelineModelEvent( new TimelineModelEvent( TimelineModelEvent.EventType.CUSTOM_BOUNDS, model, new double[] {min, max})); } } if ((Double.isInfinite(previousBoundsMax) || Double.isInfinite(previousBoundsMin)) && model.hasValidBounds()) { fireTimelineModelEvent( new TimelineModelEvent(TimelineModelEvent.EventType.VALID_BOUNDS, model, true)); } else if (!Double.isInfinite(previousBoundsMax) && !Double.isInfinite(previousBoundsMin) && !model.hasValidBounds()) { fireTimelineModelEvent( new TimelineModelEvent(TimelineModelEvent.EventType.VALID_BOUNDS, model, false)); } return true; } return false; }
@Override public void setCustomBounds(double min, double max) { if (model != null) { if (model.getCustomMin() != min || model.getCustomMax() != max) { if (min >= max) { throw new IllegalArgumentException("min should be less than max"); } if (min < model.getMin() || max > model.getMax()) { throw new IllegalArgumentException("Min and max should be in the bounds"); } // Interval if (model.getIntervalStart() < min || model.getIntervalEnd() > max) { dynamicController.setVisibleInterval(min, max); } // Custom bounds double[] val = new double[] {min, max}; model.setCustomMin(min); model.setCustomMax(max); fireTimelineModelEvent( new TimelineModelEvent(TimelineModelEvent.EventType.CUSTOM_BOUNDS, model, val)); } } }