de.jaret.util.ui.timebars.strategy
Class DefaultOverlapStrategy

java.lang.Object
  extended by de.jaret.util.ui.timebars.strategy.DefaultOverlapStrategy
All Implemented Interfaces:
IOverlapStrategy

public class DefaultOverlapStrategy
extends java.lang.Object
implements IOverlapStrategy

Default implementation of an overlap strategy that does a complete check on overlaps between intervals including transitive overlaps. This can be time consuming when dealing with a lot of intervals. Thanks go to Mathias Kurt for supplying an optimized algorithm for computing the overlapping quite fast.

Version:
$Id: $
Author:
kliem

Field Summary
protected  boolean _assumeSortedIntervals
          if set to false, intervals will be sorted before checking overlapping.
protected  TimeBarViewerDelegate _delegate
          the delegate the strategy works for.
protected  java.util.Map<TimeBarRow,java.util.Map<de.jaret.util.date.Interval,OverlapInfo>> _oiRowCache
          Cache for overlap infos.
 
Constructor Summary
DefaultOverlapStrategy(TimeBarViewerDelegate delegate)
          Construct a default strategy for a specific delegate.
 
Method Summary
 void clearCachedData()
          Clear all cached data.
 void dispose()
          Called when a strategy is no loner used.
 boolean getAssumeSortedIntervals()
          Retrieve the status of assumeSortedIntervals.
 int getMaxOverlapCount(TimeBarRow row)
          Retrieve tha maximal count of overlapping intervals in a row.
 OverlapInfo getOverlapInfo(TimeBarRow row, de.jaret.util.date.Interval interval)
          Retrieve the information about overlapping intervals and drawing position for a given interval.
 void setAssumeSortedIntervals(boolean assumeSortedIntervals)
          If set to false intervals will be sorted often ... defaults to true.
 java.util.Map<de.jaret.util.date.Interval,OverlapInfo> updateOICache(TimeBarRow row)
          Calculate the number of overlapping intervals and determine the positions to draw them on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_delegate

protected TimeBarViewerDelegate _delegate
the delegate the strategy works for.


_oiRowCache

protected java.util.Map<TimeBarRow,java.util.Map<de.jaret.util.date.Interval,OverlapInfo>> _oiRowCache
Cache for overlap infos.


_assumeSortedIntervals

protected boolean _assumeSortedIntervals
if set to false, intervals will be sorted before checking overlapping.

Constructor Detail

DefaultOverlapStrategy

public DefaultOverlapStrategy(TimeBarViewerDelegate delegate)
Construct a default strategy for a specific delegate.

Parameters:
delegate - the delegate the strategy works for
Method Detail

getOverlapInfo

public OverlapInfo getOverlapInfo(TimeBarRow row,
                                  de.jaret.util.date.Interval interval)
Retrieve the information about overlapping intervals and drawing position for a given interval.

Specified by:
getOverlapInfo in interface IOverlapStrategy
Parameters:
row - row of the interval
interval - interval
Returns:
the overlap information

getMaxOverlapCount

public int getMaxOverlapCount(TimeBarRow row)
Retrieve tha maximal count of overlapping intervals in a row.

Specified by:
getMaxOverlapCount in interface IOverlapStrategy
Parameters:
row - row to check
Returns:
count of maximum overlapping intervals in the row

updateOICache

public java.util.Map<de.jaret.util.date.Interval,OverlapInfo> updateOICache(TimeBarRow row)
Calculate the number of overlapping intervals and determine the positions to draw them on. May Assume sorted Intervals - check the strategy implementation! Assumes sorted intervals unless assumeSortedIntervals is set to false.

Specified by:
updateOICache in interface IOverlapStrategy
Parameters:
row - row to update the cache for
Returns:
a map containing overlap infos for every interval in the row

clearCachedData

public void clearCachedData()
Clear all cached data. This method is to be called on model changes that invalidate cleared data.

Specified by:
clearCachedData in interface IOverlapStrategy

dispose

public void dispose()
Called when a strategy is no loner used. May be useful to help garbage collecting or disconnect listeners. Simply helps the garbage collector.

Specified by:
dispose in interface IOverlapStrategy

getAssumeSortedIntervals

public boolean getAssumeSortedIntervals()
Retrieve the status of assumeSortedIntervals. If this is false, intervals will be sorted temporarily for overlapping.

Returns:
the status

setAssumeSortedIntervals

public void setAssumeSortedIntervals(boolean assumeSortedIntervals)
If set to false intervals will be sorted often ... defaults to true.

Parameters:
assumeSortedIntervals - the new status


Copyright © 2012. All Rights Reserved.