X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2Fcolour%2FDateColourer.java;fp=src%2Ftim%2Fprune%2Fgui%2Fcolour%2FDateColourer.java;h=6dfeca63d424a81df43e973be75c112db2f0932a;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/gui/colour/DateColourer.java b/src/tim/prune/gui/colour/DateColourer.java new file mode 100644 index 0000000..6dfeca6 --- /dev/null +++ b/src/tim/prune/gui/colour/DateColourer.java @@ -0,0 +1,128 @@ +package tim.prune.gui.colour; + +import java.awt.Color; +import java.text.DateFormat; +import java.util.Calendar; +import java.util.HashMap; +import java.util.TimeZone; + +import tim.prune.config.Config; +import tim.prune.data.DataPoint; +import tim.prune.data.Timestamp; +import tim.prune.data.Track; +import tim.prune.data.TrackInfo; + +/** + * Point colourer giving a different colour to each date. + * Uses the currently selected timezone, so the results + * may be different when selecting a different timezone + */ +public class DateColourer extends DiscretePointColourer +{ + // Doesn't really matter what format is used here, as long as dates are different + private static final DateFormat DEFAULT_DATE_FORMAT = DateFormat.getDateInstance(); + // Selected timezone for deciding which date a timestamp falls on + private TimeZone _selectedTimezone = null; + + /** + * Constructor + * @param inStartColour start colour of scale + * @param inEndColour end colour of scale + * @param inWrapLength number of unique colours before wrap + */ + public DateColourer(Color inStartColour, Color inEndColour, int inWrapLength) + { + super(inStartColour, inEndColour, inWrapLength); + } + + /** + * Calculate the colours for each of the points in the given track + * @param inTrackInfo track info object + */ + @Override + public synchronized void calculateColours(TrackInfo inTrackInfo) + { + // Note, this method needs to be synchronized because otherwise the + // Calendar objects in the different threads get confused and the + // wrong colours are generated. + + // TODO: Move this timezone-selection into a helper for use by others? + // Select the current timezone + final String zoneId = Config.getConfigString(Config.KEY_TIMEZONE_ID); + if (zoneId == null || zoneId.equals("")) { + _selectedTimezone = TimeZone.getDefault(); + } + else { + _selectedTimezone = TimeZone.getTimeZone(zoneId); + } + // initialise the array to the right size + Track track = inTrackInfo == null ? null : inTrackInfo.getTrack(); + final int numPoints = track == null ? 0 : track.getNumPoints(); + init(numPoints); + // Make a hashmap of the already-used dates + HashMap usedDates = new HashMap(20); + // Also store the previous one, because they're probably consecutive + String prevDate = null; + int prevIndex = -1; + + // loop over track points + int dayIndex = -1; + for (int i=0; i