List of usage examples for org.joda.time DateTime getYear
public int getYear()
From source file:net.tourbook.device.sporttracks.FitLogSAXHandler.java
License:Open Source License
private void finalizeTour() { boolean isComputeDrivingTime = true; // create data object for each tour final TourData tourData = new TourData(); /*/*from w w w.j a va2 s. c o m*/ * set tour start date/time */ // DateTime tourDateTime = _currentActivity.trackTourDateTime; // final long trackStartTime = _currentActivity.trackTourStartTime; // if (trackStartTime != Long.MIN_VALUE && trackStartTime < 0) { // // // this case occured, e.g. year was 0002 // tourDateTime = _currentActivity.tourStartTime; // // } else if (tourDateTime == null) { // // // this case can occure when a tour do not have a track // tourDateTime = _currentActivity.tourStartTime; // } final DateTime tourStartTime = _currentActivity.tourStartTime; tourData.setStartHour((short) tourStartTime.getHourOfDay()); tourData.setStartMinute((short) tourStartTime.getMinuteOfHour()); tourData.setStartSecond((short) tourStartTime.getSecondOfMinute()); tourData.setStartYear((short) tourStartTime.getYear()); tourData.setStartMonth((short) tourStartTime.getMonthOfYear()); tourData.setStartDay((short) tourStartTime.getDayOfMonth()); tourData.setWeek(tourStartTime); tourData.setTourTitle(_currentActivity.name); tourData.setTourDescription(_currentActivity.notes); tourData.setTourStartPlace(_currentActivity.location); tourData.setCalories(_currentActivity.calories); /* * weather */ tourData.setWeather(_currentActivity.weatherText); tourData.setWeatherClouds(_weatherId.get(_currentActivity.weatherConditions)); final float weatherTemperature = _currentActivity.weatherTemperature; if (weatherTemperature != Float.MIN_VALUE) { tourData.setTemperatureScale(TourbookDevice.TEMPERATURE_SCALE); tourData.setAvgTemperature((int) (weatherTemperature * TourbookDevice.TEMPERATURE_SCALE)); } tourData.importRawDataFile = _importFilePath; tourData.setTourImportFilePath(_importFilePath); tourData.setDeviceTimeInterval((short) -1); if (_currentActivity.timeSlices.size() == 0) { // tour do not contain a track tourData.setTourDistance(_currentActivity.distance); tourData.setTourRecordingTime(_currentActivity.duration); tourData.setTourDrivingTime(_currentActivity.duration); isComputeDrivingTime = false; tourData.setTourAltUp(_currentActivity.elevationUp); tourData.setTourAltDown(_currentActivity.elevationDown); } else { tourData.createTimeSeries(_currentActivity.timeSlices, false); } // after all data are added, the tour id can be created because it depends on the tour distance final Long tourId = tourData .createTourId(_device.createUniqueId(tourData, Util.UNIQUE_ID_SUFFIX_SPORT_TRACKS_FITLOG)); // check if the tour is already imported if (_tourDataMap.containsKey(tourId) == false) { if (isComputeDrivingTime) { tourData.computeTourDrivingTime(); } tourData.computeAltitudeUpDown(); tourData.computeComputedValues(); if (tourData.pulseSerie == null) { tourData.setAvgPulse(_currentActivity.avgPulse); tourData.setMaxPulse(_currentActivity.maxPulse); } if (tourData.cadenceSerie == null) { tourData.setAvgCadence(_currentActivity.avgCadence); } tourData.setDeviceId(_device.deviceId); tourData.setDeviceName(_device.visibleName); finalizeTour10SetTourType(tourData); finalizeTour20SetTags(tourData); finalizeTour30CreateMarkers(tourData); // add new tour to other tours _tourDataMap.put(tourId, tourData); } // cleanup _currentActivity.timeSlices.clear(); _currentActivity.laps.clear(); _currentActivity.equipmentName.clear(); _isImported = true; }
From source file:net.tourbook.export.gpx.DialogExportTour.java
License:Open Source License
/** * Set filename with the first tour date/time, when tour is merged "<#default>" is displayed *//*from ww w .ja v a2s . c o m*/ private void setFileName() { // search for the first tour TourData minTourData = null; final long minTourMillis = 0; for (final TourData tourData : _tourDataList) { final DateTime checkingTourDate = TourManager.getTourDateTime(tourData); if (minTourData == null) { minTourData = tourData; } else { final long tourMillis = checkingTourDate.getMillis(); if (tourMillis < minTourMillis) { minTourData = tourData; } } } if (_isMultipleTourAndMultipleFile) { // use default file name for each exported tour _comboFile.setText(Messages.dialog_export_label_DefaultFileName); } else if ((_tourDataList.size() == 1) && (_tourStartIndex != -1) && (_tourEndIndex != -1)) { // display the start date/time final DateTime dtTour = new DateTime(minTourData.getStartYear(), minTourData.getStartMonth(), minTourData.getStartDay(), minTourData.getStartHour(), minTourData.getStartMinute(), minTourData.getStartSecond(), 0); // adjust start time final int startTime = minTourData.timeSerie[_tourStartIndex]; final DateTime tourTime = dtTour.plusSeconds(startTime); _comboFile.setText(UI.format_yyyymmdd_hhmmss(tourTime.getYear(), tourTime.getMonthOfYear(), tourTime.getDayOfMonth(), tourTime.getHourOfDay(), tourTime.getMinuteOfHour(), tourTime.getSecondOfMinute())); } else { // display the tour date/time _comboFile.setText(UI.format_yyyymmdd_hhmmss(minTourData)); } }
From source file:net.tourbook.printing.DialogPrintTour.java
License:Open Source License
/** * Overwrite filename with the first tour date/time when the tour is not merged *///from w w w . j a v a 2 s .com private void setFileName() { // search for the first tour TourData minTourData = null; final long minTourMillis = 0; for (final TourData tourData : _tourDataList) { final DateTime checkingTourDate = TourManager.getTourDateTime(tourData); if (minTourData == null) { minTourData = tourData; } else { final long tourMillis = checkingTourDate.getMillis(); if (tourMillis < minTourMillis) { minTourData = tourData; } } } if ((_tourDataList.size() == 1) && (_tourStartIndex != -1) && (_tourEndIndex != -1)) { // display the start date/time final DateTime dtTour = new DateTime(minTourData.getStartYear(), minTourData.getStartMonth(), minTourData.getStartDay(), minTourData.getStartHour(), minTourData.getStartMinute(), minTourData.getStartSecond(), 0); final int startTime = minTourData.timeSerie[_tourStartIndex]; final DateTime tourTime = dtTour.plusSeconds(startTime); _comboFile.setText(UI.format_yyyymmdd_hhmmss(tourTime.getYear(), tourTime.getMonthOfYear(), tourTime.getDayOfMonth(), tourTime.getHourOfDay(), tourTime.getMinuteOfHour(), tourTime.getSecondOfMinute())); } else { // display the tour date/time _comboFile.setText(UI.format_yyyymmdd_hhmmss(minTourData)); } }
From source file:net.tourbook.tour.DialogExtractTour.java
License:Open Source License
/** * Create a new tour with the extracted time slices *///from w ww . j a v a2s.c o m private boolean extractTour() { /* * get data series */ final int[] tourAltitudeSerie = _tourDataSource.altitudeSerie; final int[] tourCadenceSerie = _tourDataSource.cadenceSerie; final int[] tourDistanceSerie = _tourDataSource.distanceSerie; final double[] tourLatitudeSerie = _tourDataSource.latitudeSerie; final double[] tourLongitudeSerie = _tourDataSource.longitudeSerie; final int[] tourPulseSerie = _tourDataSource.pulseSerie; final int[] tourTemperatureSerie = _tourDataSource.temperatureSerie; final int[] tourTimeSerie = _tourDataSource.timeSerie; final boolean isTourAltitude = (tourAltitudeSerie != null) && (tourAltitudeSerie.length > 0); final boolean isTourCadence = (tourCadenceSerie != null) && (tourCadenceSerie.length > 0); final boolean isTourDistance = (tourDistanceSerie != null) && (tourDistanceSerie.length > 0); final boolean isTourLat = (tourLatitudeSerie != null) && (tourLatitudeSerie.length > 0); final boolean isTourLon = (tourLongitudeSerie != null) && (tourLongitudeSerie.length > 0); final boolean isTourPulse = (tourPulseSerie != null) && (tourPulseSerie.length > 0); final boolean isTourTemperature = (tourTemperatureSerie != null) && (tourTemperatureSerie.length > 0); final boolean isTourTime = (tourTimeSerie != null) && (tourTimeSerie.length > 0); /* * get speed/power data when data are created by the device */ int[] tourPowerSerie = null; int[] tourSpeedSerie = null; final boolean isTourPower = _tourDataSource.isPowerSerieFromDevice(); final boolean isTourSpeed = _tourDataSource.isSpeedSerieFromDevice(); if (isTourPower) { tourPowerSerie = _tourDataSource.getPowerSerie(); } if (isTourSpeed) { tourSpeedSerie = _tourDataSource.getSpeedSerie(); } int dataSerieLength = -1; if (isTourAltitude) { dataSerieLength = tourAltitudeSerie.length; } else if (isTourCadence) { dataSerieLength = tourCadenceSerie.length; } else if (isTourDistance) { dataSerieLength = tourDistanceSerie.length; } else if (isTourLat) { dataSerieLength = tourLatitudeSerie.length; } else if (isTourLon) { dataSerieLength = tourLongitudeSerie.length; } else if (isTourPower) { dataSerieLength = tourPowerSerie.length; } else if (isTourPulse) { dataSerieLength = tourPulseSerie.length; } else if (isTourSpeed) { dataSerieLength = tourSpeedSerie.length; } else if (isTourTemperature) { dataSerieLength = tourTemperatureSerie.length; } else if (isTourTime) { dataSerieLength = tourTimeSerie.length; } if (dataSerieLength == -1) { StatusUtil.showStatus(Messages.NT001_DialogExtractTour_InvalidTourData); return false; } if (_isSplitTour) { // _extractEndIndex contains -1, set end index to the last time slice _extractEndIndex = dataSerieLength - 1; } final int extractSerieLength = _extractEndIndex - _extractStartIndex + 1; final int[] extractAltitudeSerie = new int[extractSerieLength]; final int[] extractCadenceSerie = new int[extractSerieLength]; final int[] extractDistanceSerie = new int[extractSerieLength]; final double[] extractLatitudeSerie = new double[extractSerieLength]; final double[] extractLongitudeSerie = new double[extractSerieLength]; final int[] extractPowerSerie = new int[extractSerieLength]; final int[] extractPulseSerie = new int[extractSerieLength]; final int[] extractSpeedSerie = new int[extractSerieLength]; final int[] extractTemperatureSerie = new int[extractSerieLength]; final int[] extractTimeSerie = new int[extractSerieLength]; final HashSet<TourMarker> extractedTourMarker = new HashSet<TourMarker>(); final ArrayList<TourWayPoint> extractedWayPoints = new ArrayList<TourWayPoint>(); /* * get start date/time */ DateTime extractedTourStart = null; final boolean isOriginalTime = _chkKeepOriginalDateTime.getSelection(); if (isOriginalTime) { extractedTourStart = _extractedTourStartTime; } else { extractedTourStart = new DateTime(_dtTourDate.getYear(), _dtTourDate.getMonth() + 1, _dtTourDate.getDay(), _dtTourTime.getHours(), _dtTourTime.getMinutes(), _dtTourTime.getSeconds(), 0); } int relTourStartTime = 0; int extractedRecordingTime = 0; if (isTourTime) { relTourStartTime = tourTimeSerie[_extractStartIndex]; extractedRecordingTime = tourTimeSerie[_extractEndIndex] - relTourStartTime; } // get distance int extractedDistance = 0; int relTourStartDistance = 0; if (isTourDistance) { relTourStartDistance = tourDistanceSerie[_extractStartIndex]; extractedDistance = tourDistanceSerie[_extractEndIndex] - relTourStartDistance; } /* * copy existing data series */ int extractedSerieIndex = 0; for (int sourceSerieIndex = _extractStartIndex; sourceSerieIndex <= _extractEndIndex; sourceSerieIndex++) { if (isTourTime) { extractTimeSerie[extractedSerieIndex] = tourTimeSerie[sourceSerieIndex] - relTourStartTime; } if (isTourAltitude) { extractAltitudeSerie[extractedSerieIndex] = tourAltitudeSerie[sourceSerieIndex]; } if (isTourCadence) { extractCadenceSerie[extractedSerieIndex] = tourCadenceSerie[sourceSerieIndex]; } if (isTourDistance) { extractDistanceSerie[extractedSerieIndex] = tourDistanceSerie[sourceSerieIndex] - relTourStartDistance; } if (isTourPulse) { extractPulseSerie[extractedSerieIndex] = tourPulseSerie[sourceSerieIndex]; } if (isTourLat) { extractLatitudeSerie[extractedSerieIndex] = tourLatitudeSerie[sourceSerieIndex]; } if (isTourLon) { extractLongitudeSerie[extractedSerieIndex] = tourLongitudeSerie[sourceSerieIndex]; } if (isTourTemperature) { extractTemperatureSerie[extractedSerieIndex] = tourTemperatureSerie[sourceSerieIndex]; } if (isTourPower) { extractPowerSerie[extractedSerieIndex] = tourPowerSerie[sourceSerieIndex]; } if (isTourSpeed) { extractSpeedSerie[extractedSerieIndex] = tourSpeedSerie[sourceSerieIndex]; } extractedSerieIndex++; } /* * get tour markers, way points */ final Set<TourMarker> tourMarkers = _tourDataSource.getTourMarkers(); if (_chkIncludeMarkerWaypoints.getSelection()) { for (final TourMarker tourMarker : tourMarkers) { final int markerSerieIndex = tourMarker.getSerieIndex(); // skip marker which are not within the extracted time slices if (markerSerieIndex < _extractStartIndex || markerSerieIndex > _extractEndIndex) { continue; } final int extractedMarkerIndex = markerSerieIndex - _extractStartIndex; final TourMarker extractedMarker = tourMarker.clone(_tourDataTarget); // adjust marker position, position is relativ to the tour start extractedMarker.setSerieIndex(extractedMarkerIndex); if (isTourTime) { tourMarker.setTime(extractTimeSerie[extractedMarkerIndex]); } if (isTourDistance) { tourMarker.setDistance(extractDistanceSerie[extractedMarkerIndex]); } extractedTourMarker.add(extractedMarker); } /* * copy all way points, they can be independant of the tour */ for (final TourWayPoint wayPoint : _tourDataSource.getTourWayPoints()) { extractedWayPoints.add((TourWayPoint) wayPoint.clone()); } } // get description String extractedDescription = UI.EMPTY_STRING; if (_chkIncludeDescription.getSelection()) { extractedDescription = _tourDataSource.getTourDescription(); } /* * get calories */ int extractedCalories = 0; if (_extractStartIndex == 0 && _extractEndIndex == (dataSerieLength - 1)) { // tour is copied, the calories can also be copied extractedCalories = _tourDataSource.getCalories(); } else { // TODO calories should be set when they are computed } /* * set target tour data */ _tourDataTarget.setStartYear((short) extractedTourStart.getYear()); _tourDataTarget.setStartMonth((short) extractedTourStart.getMonthOfYear()); _tourDataTarget.setStartDay((short) extractedTourStart.getDayOfMonth()); _tourDataTarget.setStartHour((short) extractedTourStart.getHourOfDay()); _tourDataTarget.setStartMinute((short) extractedTourStart.getMinuteOfHour()); _tourDataTarget.setStartSecond((short) extractedTourStart.getSecondOfMinute()); _tourDataTarget.setWeek(extractedTourStart); // tour id must be created after the tour date/time is set _tourDataTarget.createTourId(); _tourDataTarget.setTourTitle(_txtTourTitle.getText()); _tourDataTarget.setTourDescription(extractedDescription.toString()); _tourDataTarget.setTourMarkers(extractedTourMarker); _tourDataTarget.setWayPoints(extractedWayPoints); _tourDataTarget.setDeviceName(_isSplitTour ? Messages.Dialog_SplitTour_Label_DeviceName : Messages.Dialog_ExtractTour_Label_DeviceName); _tourDataTarget.setIsDistanceFromSensor(_tourDataSource.isDistanceSensorPresent()); _tourDataTarget.setDeviceTimeInterval(_tourDataSource.getDeviceTimeInterval()); _tourDataTarget.setTourRecordingTime(extractedRecordingTime); _tourDataTarget.setTourDistance(extractedDistance); _tourDataTarget.setWeather(_tourDataSource.getWeather()); _tourDataTarget.setWeatherClouds(_tourDataSource.getWeatherClouds()); _tourDataTarget.setWeatherWindDir(_tourDataSource.getWeatherWindDir()); _tourDataTarget.setWeatherWindSpeed(_tourDataSource.getWeatherWindSpeed()); _tourDataTarget.setRestPulse(_tourDataSource.getRestPulse()); _tourDataTarget.setCalories(extractedCalories); _tourDataTarget.setDpTolerance(_tourDataSource.getDpTolerance()); if (isTourAltitude) { _tourDataTarget.altitudeSerie = extractAltitudeSerie; } if (isTourDistance) { _tourDataTarget.distanceSerie = extractDistanceSerie; } if (isTourCadence) { _tourDataTarget.cadenceSerie = extractCadenceSerie; } if (isTourLat) { _tourDataTarget.latitudeSerie = extractLatitudeSerie; } if (isTourLon) { _tourDataTarget.longitudeSerie = extractLongitudeSerie; } if (isTourPower) { _tourDataTarget.setPowerSerie(extractPowerSerie); } if (isTourPulse) { _tourDataTarget.pulseSerie = extractPulseSerie; } if (isTourSpeed) { _tourDataTarget.setSpeedSerie(extractSpeedSerie); } if (isTourTemperature) { _tourDataTarget.temperatureSerie = extractTemperatureSerie; } if (isTourTime) { _tourDataTarget.timeSerie = extractTimeSerie; } _tourDataTarget.setTemperatureScale(_tourDataSource.getTemperatureScale()); _tourDataTarget.computeAltitudeUpDown(); _tourDataTarget.computeTourDrivingTime(); _tourDataTarget.computeComputedValues(); // set person which is required to save a tour _tourDataTarget.setTourPerson(getSelectedPerson()); /* * check size of the fields */ if (_tourDataTarget.isValidForSave() == false) { return false; } TourManager.saveModifiedTour(_tourDataTarget); // check if time slices should be removed if (getStateSplitMethod().equals(STATE_EXTRACT_METHOD_REMOVE)) { TourManager.removeTimeSlices(_tourDataSource, _extractStartIndex, _extractEndIndex, true); _tourDataEditor.updateUI(_tourDataSource, true); TourManager.fireEvent(TourEventId.TOUR_CHANGED, new TourEvent(_tourDataSource)); } return true; }
From source file:net.tourbook.tour.DialogJoinTours.java
License:Open Source License
/** * Join the tours and create a new tour/*from w w w .ja va 2 s. c o m*/ */ private boolean joinTours() { final boolean isOriginalTime = getStateJoinMethod().equals(STATE_JOIN_METHOD_ORIGINAL); /** * number of slices, time series are already checked in ActionJoinTours */ int joinedSliceCounter = 0; for (final TourData tourData : _selectedTours) { final int[] tourTimeSerie = tourData.timeSerie; final int[] tourDistanceSerie = tourData.distanceSerie; final double[] tourLatitudeSerie = tourData.latitudeSerie; final boolean isTourTime = (tourTimeSerie != null) && (tourTimeSerie.length > 0); final boolean isTourDistance = (tourDistanceSerie != null) && (tourDistanceSerie.length > 0); final boolean isTourLat = (tourLatitudeSerie != null) && (tourLatitudeSerie.length > 0); if (isTourTime) { joinedSliceCounter += tourTimeSerie.length; } else if (isTourDistance) { joinedSliceCounter += tourDistanceSerie.length; } else if (isTourLat) { joinedSliceCounter += tourLatitudeSerie.length; } } boolean isJoinAltitude = false; boolean isJoinDistance = false; boolean isJoinCadence = false; boolean isJoinLat = false; boolean isJoinLon = false; boolean isJoinPower = false; boolean isJoinPulse = false; boolean isJoinSpeed = false; // boolean isJoinTemperature = false; boolean isJoinTime = false; final int[] joinedAltitudeSerie = new int[joinedSliceCounter]; final int[] joinedCadenceSerie = new int[joinedSliceCounter]; final int[] joinedDistanceSerie = new int[joinedSliceCounter]; final double[] joinedLatitudeSerie = new double[joinedSliceCounter]; final double[] joinedLongitudeSerie = new double[joinedSliceCounter]; final int[] joinedPowerSerie = new int[joinedSliceCounter]; final int[] joinedPulseSerie = new int[joinedSliceCounter]; final int[] joinedSpeedSerie = new int[joinedSliceCounter]; final int[] joinedTemperatureSerie = new int[joinedSliceCounter]; final int[] joinedTimeSerie = new int[joinedSliceCounter]; final StringBuilder joinedDescription = new StringBuilder(); final HashSet<TourMarker> joinedTourMarker = new HashSet<TourMarker>(); final ArrayList<TourWayPoint> joinedWayPoints = new ArrayList<TourWayPoint>(); int joinedSerieIndex = 0; int joinedTourStartIndex = 0; int joinedTourStartDistance = 0; int joinedRecordingTime = 0; int joinedDrivingTime = 0; int joinedDistance = 0; int joinedCalories = 0; boolean isJoinedDistanceFromSensor = false; short joinedDeviceTimeInterval = -1; String joinedWeatherClouds = UI.EMPTY_STRING; String joinedWeather = UI.EMPTY_STRING; int joinedWeatherWindDir = 0; int joinedWeatherWindSpeed = 0; int joinedRestPulse = 0; int joinedTemperatureScale = 1; int relTourTime = 0; long relTourTimeOffset = 0; long absFirstTourStartTimeSec = 0; long absJoinedTourStartTimeSec = 0; DateTime joinedTourStart = null; boolean isFirstTour = true; /* * copy tour data series into joined data series */ for (final TourData tourTourData : _selectedTours) { final int[] tourAltitudeSerie = tourTourData.altitudeSerie; final int[] tourCadenceSerie = tourTourData.cadenceSerie; final int[] tourDistanceSerie = tourTourData.distanceSerie; final double[] tourLatitudeSerie = tourTourData.latitudeSerie; final double[] tourLongitudeSerie = tourTourData.longitudeSerie; final int[] tourPulseSerie = tourTourData.pulseSerie; final int[] tourTemperatureSerie = tourTourData.temperatureSerie; final int[] tourTimeSerie = tourTourData.timeSerie; final boolean isTourAltitude = (tourAltitudeSerie != null) && (tourAltitudeSerie.length > 0); final boolean isTourCadence = (tourCadenceSerie != null) && (tourCadenceSerie.length > 0); final boolean isTourDistance = (tourDistanceSerie != null) && (tourDistanceSerie.length > 0); final boolean isTourLat = (tourLatitudeSerie != null) && (tourLatitudeSerie.length > 0); final boolean isTourLon = (tourLongitudeSerie != null) && (tourLongitudeSerie.length > 0); final boolean isTourPulse = (tourPulseSerie != null) && (tourPulseSerie.length > 0); final boolean isTourTemperature = (tourTemperatureSerie != null) && (tourTemperatureSerie.length > 0); final boolean isTourTime = (tourTimeSerie != null) && (tourTimeSerie.length > 0); /* * get speed/power data when it's from the device */ int[] tourPowerSerie = null; int[] tourSpeedSerie = null; final boolean isTourPower = tourTourData.isPowerSerieFromDevice(); final boolean isTourSpeed = tourTourData.isSpeedSerieFromDevice(); if (isTourPower) { tourPowerSerie = tourTourData.getPowerSerie(); } if (isTourSpeed) { tourSpeedSerie = tourTourData.getSpeedSerie(); } /* * set tour time */ final DateTime tourStartTime = new DateTime(tourTourData.getStartYear(), tourTourData.getStartMonth(), tourTourData.getStartDay(), tourTourData.getStartHour(), tourTourData.getStartMinute(), tourTourData.getStartSecond(), 0); if (isFirstTour) { // get start date/time if (isOriginalTime) { joinedTourStart = tourStartTime; } else { joinedTourStart = new DateTime(_dtTourDate.getYear(), _dtTourDate.getMonth() + 1, _dtTourDate.getDay(), _dtTourTime.getHours(), _dtTourTime.getMinutes(), _dtTourTime.getSeconds(), 0); } // tour start in absolute seconds absJoinedTourStartTimeSec = joinedTourStart.getMillis() / 1000; absFirstTourStartTimeSec = absJoinedTourStartTimeSec; } else { // get relative time offset if (isOriginalTime) { final DateTime tourStart = tourStartTime; final long absTourStartTimeSec = tourStart.getMillis() / 1000; // keep original time relTourTimeOffset = absTourStartTimeSec - absFirstTourStartTimeSec; } else { /* * remove time gaps between tours, add relative time from the last tour and add * 1 second for the start of the next tour */ relTourTimeOffset += relTourTime + 1; } } /* * get number of slices */ int tourSliceCounter = 0; if (isTourTime) { tourSliceCounter = tourTimeSerie.length; } else if (isTourDistance) { tourSliceCounter = tourDistanceSerie.length; } else if (isTourLat) { tourSliceCounter = tourLatitudeSerie.length; } int relTourDistance = 0; /* * copy data series */ for (int tourSerieIndex = 0; tourSerieIndex < tourSliceCounter; tourSerieIndex++) { if (isTourTime) { relTourTime = tourTimeSerie[tourSerieIndex]; joinedTimeSerie[joinedSerieIndex] = (int) (relTourTimeOffset + relTourTime); isJoinTime = true; } if (isTourAltitude) { joinedAltitudeSerie[joinedSerieIndex] = tourAltitudeSerie[tourSerieIndex]; isJoinAltitude = true; } if (isTourCadence) { joinedCadenceSerie[joinedSerieIndex] = tourCadenceSerie[tourSerieIndex]; isJoinCadence = true; } if (isTourDistance) { relTourDistance = tourDistanceSerie[tourSerieIndex]; joinedDistanceSerie[joinedSerieIndex] = joinedTourStartDistance + relTourDistance; isJoinDistance = true; } if (isTourPulse) { joinedPulseSerie[joinedSerieIndex] = tourPulseSerie[tourSerieIndex]; isJoinPulse = true; } if (isTourLat) { joinedLatitudeSerie[joinedSerieIndex] = tourLatitudeSerie[tourSerieIndex]; isJoinLat = true; } if (isTourLon) { joinedLongitudeSerie[joinedSerieIndex] = tourLongitudeSerie[tourSerieIndex]; isJoinLon = true; } if (isTourTemperature) { joinedTemperatureSerie[joinedSerieIndex] = tourTemperatureSerie[tourSerieIndex]; } else { // set temperature to temporarily value joinedTemperatureSerie[joinedSerieIndex] = Integer.MIN_VALUE; } if (isTourPower) { joinedPowerSerie[joinedSerieIndex] = tourPowerSerie[tourSerieIndex]; isJoinPower = true; } if (isTourSpeed) { joinedSpeedSerie[joinedSerieIndex] = tourSpeedSerie[tourSerieIndex]; isJoinSpeed = true; } joinedSerieIndex++; } final Set<TourMarker> tourMarkers = tourTourData.getTourMarkers(); if (_chkIncludeMarkerWaypoints.getSelection()) { /* * copy tour markers */ for (final TourMarker tourMarker : tourMarkers) { final TourMarker clonedMarker = tourMarker.clone(_joinedTourData); int joinMarkerIndex = joinedTourStartIndex + clonedMarker.getSerieIndex(); if (joinMarkerIndex >= joinedSliceCounter) { joinMarkerIndex = joinedSliceCounter - 1; } // adjust marker position, position is relativ to the tour start clonedMarker.setSerieIndex(joinMarkerIndex); if (isJoinTime) { clonedMarker.setTime(joinedTimeSerie[joinMarkerIndex]); } if (isJoinDistance) { clonedMarker.setDistance(joinedDistanceSerie[joinMarkerIndex]); } joinedTourMarker.add(clonedMarker); } /* * copy way points */ for (final TourWayPoint wayPoint : tourTourData.getTourWayPoints()) { joinedWayPoints.add((TourWayPoint) wayPoint.clone()); } } if (_chkCreateTourMarker.getSelection()) { /* * create a tour marker */ // first find a free marker position in the tour int tourMarkerIndex = -1; for (int tourSerieIndex = 0; tourSerieIndex < tourSliceCounter; tourSerieIndex++) { boolean isIndexAvailable = true; // check if a marker occupies the current index for (final TourMarker tourMarker : tourMarkers) { if (tourMarker.getSerieIndex() == tourSerieIndex) { isIndexAvailable = false; break; } } if (isIndexAvailable) { // free index was found tourMarkerIndex = tourSerieIndex; break; } } if (tourMarkerIndex != -1) { // create tour marker label final String stateTourMarker = getStateTourMarker(); final long tourStartTimeMS = tourStartTime.getMillis(); String markerLabel = UI.EMPTY_STRING; if (stateTourMarker.equals(STATE_MARKER_TYPE_SMALL)) { markerLabel = _dtFormatterShort.print(tourStartTimeMS); } else if (stateTourMarker.equals(STATE_MARKER_TYPE_MEDIUM)) { markerLabel = _dtFormatterMedium.print(tourStartTimeMS); } else if (stateTourMarker.equals(STATE_MARKER_TYPE_LARGE)) { markerLabel = _dtFormatterFull.print(tourStartTimeMS); } final int joinMarkerIndex = joinedTourStartIndex + tourMarkerIndex; final TourMarker tourMarker = new TourMarker(_joinedTourData, ChartLabel.MARKER_TYPE_CUSTOM); tourMarker.setSerieIndex(joinMarkerIndex); tourMarker.setLabel(markerLabel); tourMarker.setVisualPosition(ChartLabel.VISUAL_VERTICAL_ABOVE_GRAPH); if (isJoinTime) { tourMarker.setTime(joinedTimeSerie[joinMarkerIndex]); } if (isJoinDistance) { tourMarker.setDistance(joinedDistanceSerie[joinMarkerIndex]); } joinedTourMarker.add(tourMarker); } } /* * create description */ if (_chkIncludeDescription.getSelection()) { final String tourDescription = tourTourData.getTourDescription(); if (joinedDescription.length() > 0) { // set space between two tours joinedDescription.append(UI.NEW_LINE2); } joinedDescription.append(Messages.Dialog_JoinTours_Label_Tour); joinedDescription.append(TourManager.getTourTitleDetailed(tourTourData)); if (tourDescription.length() > 0) { joinedDescription.append(UI.NEW_LINE); joinedDescription.append(tourDescription); } } /* * other tour values */ if (isFirstTour) { isJoinedDistanceFromSensor = tourTourData.isDistanceSensorPresent(); joinedDeviceTimeInterval = tourTourData.getDeviceTimeInterval(); joinedWeather = tourTourData.getWeather(); joinedWeatherClouds = tourTourData.getWeatherClouds(); joinedWeatherWindDir = tourTourData.getWeatherWindDir(); joinedWeatherWindSpeed = tourTourData.getWeatherWindSpeed(); joinedRestPulse = tourTourData.getRestPulse(); joinedTemperatureScale = tourTourData.getTemperatureScale(); } else { if (isJoinedDistanceFromSensor && tourTourData.isDistanceSensorPresent()) { // keep TRUE state } else { isJoinedDistanceFromSensor = false; } if (joinedDeviceTimeInterval == tourTourData.getDeviceTimeInterval()) { // keep value } else { joinedDeviceTimeInterval = -1; } } /* * summarize other fields */ tourTourData.computeTourDrivingTime(); joinedRecordingTime += tourTourData.getTourRecordingTime(); joinedDrivingTime += tourTourData.getTourDrivingTime(); joinedDistance += tourTourData.getTourDistance(); joinedCalories += tourTourData.getCalories(); /* * init next tour */ isFirstTour = false; joinedTourStartIndex = joinedSerieIndex; joinedTourStartDistance += relTourDistance; } /* * setup tour data */ _joinedTourData.setStartHour((short) joinedTourStart.getHourOfDay()); _joinedTourData.setStartMinute((short) joinedTourStart.getMinuteOfHour()); _joinedTourData.setStartSecond((short) joinedTourStart.getSecondOfMinute()); _joinedTourData.setStartYear((short) joinedTourStart.getYear()); _joinedTourData.setStartMonth((short) joinedTourStart.getMonthOfYear()); _joinedTourData.setStartDay((short) joinedTourStart.getDayOfMonth()); _joinedTourData.setWeek(joinedTourStart); // tour id must be created after the tour date/time is set _joinedTourData.createTourId(); _joinedTourData.setTourTitle(_txtTourTitle.getText()); _joinedTourData.setTourDescription(joinedDescription.toString()); _joinedTourData.setTourMarkers(joinedTourMarker); _joinedTourData.setWayPoints(joinedWayPoints); _joinedTourData.setDeviceName(Messages.Dialog_JoinTours_Label_DeviceName); _joinedTourData.setIsDistanceFromSensor(isJoinedDistanceFromSensor); _joinedTourData.setDeviceTimeInterval(joinedDeviceTimeInterval); _joinedTourData.setCalories(joinedCalories); _joinedTourData.setRestPulse(joinedRestPulse); _joinedTourData.setWeather(joinedWeather); _joinedTourData.setWeatherClouds(joinedWeatherClouds); _joinedTourData.setWeatherWindDir(joinedWeatherWindDir); _joinedTourData.setWeatherWindSpeed(joinedWeatherWindSpeed); _joinedTourData.setTourRecordingTime(joinedRecordingTime); _joinedTourData.setTourDrivingTime(joinedDrivingTime); _joinedTourData.setTourDistance(joinedDistance); // !! tour type and tour tags are already set !! if (isJoinAltitude) { _joinedTourData.altitudeSerie = joinedAltitudeSerie; } if (isJoinDistance) { _joinedTourData.distanceSerie = joinedDistanceSerie; } if (isJoinCadence) { _joinedTourData.cadenceSerie = joinedCadenceSerie; } if (isJoinLat) { _joinedTourData.latitudeSerie = joinedLatitudeSerie; } if (isJoinLon) { _joinedTourData.longitudeSerie = joinedLongitudeSerie; } if (isJoinPower) { _joinedTourData.setPowerSerie(joinedPowerSerie); } if (isJoinPulse) { _joinedTourData.pulseSerie = joinedPulseSerie; } if (isJoinSpeed) { _joinedTourData.setSpeedSerie(joinedSpeedSerie); } _joinedTourData.temperatureSerie = joinedTemperatureSerie; _joinedTourData.setTemperatureScale(joinedTemperatureScale); if (isJoinTime) { _joinedTourData.timeSerie = joinedTimeSerie; } _joinedTourData.computeAltitudeUpDown(); _joinedTourData.computeComputedValues(); // set person which is required to save a tour _joinedTourData.setTourPerson(getSelectedPerson()); /* * check size of the fields */ if (_joinedTourData.isValidForSave() == false) { return false; } /* * TourData.computeComputedValues() creates speed data serie which must be removed that * cleanupDataSeries() works correctly */ _joinedTourData.setSpeedSerie(null); _joinedTourData.cleanupDataSeries(); _joinedTourData = TourManager.saveModifiedTour(_joinedTourData); return true; }
From source file:net.tourbook.ui.views.calendar.CalendarGraph.java
License:Open Source License
private void drawCalendar(GC gc) { final int dayLabelXOffset = 1; final int XX = getSize().x; final int YY = getSize().y; // System.out.println(_graphClean ? "clean!" : "NOT clean!"); // System.out.println(_highlightChanged ? "HL changed!" : "HL NOT changed"); // System.out.println("-----------"); _fontHeight = gc.getFontMetrics().getHeight(); if (_graphClean && _image != null) { final GC oldGc = gc; _highlight = new Image(getDisplay(), XX, YY); gc = new GC(_highlight); gc.drawImage(_image, 0, 0);/* w w w . j a v a 2s . c o m*/ drawSelection(gc); if (_highlightChanged) { drawHighLight(gc); _highlightChanged = false; } gc.dispose(); oldGc.drawImage(_highlight, 0, 0); _highlight.dispose(); return; } if (_scrollDebug) { System.out.println("Drawing year: " + _dt.getYear() + " week: " + _dt.getWeekOfWeekyear()); //$NON-NLS-1$ //$NON-NLS-2$ } if (_image != null && !_image.isDisposed()) { _image.dispose(); } DateTime date = new DateTime(_dt); _image = new Image(getDisplay(), XX, YY); // update month/year dropdown box // look at the 1st day of the week after the first day displayed because if we go to // a specific month we ensure that the first day of the month is displayed in // the first line, meaning the first day in calendar normally contains a day // of the *previous* month if (_calendarYearMonthContributor.getSelectedYear() != date.plusDays(7).getYear()) { _calendarYearMonthContributor.selectYear(date.getYear()); } if (_calendarYearMonthContributor.getSelectedMonth() != date.plusDays(7).getMonthOfYear()) { _calendarYearMonthContributor.selectMonth(date.getMonthOfYear()); } final GC oldGc = gc; gc = new GC(_image); _refTextExtent = gc.stringExtent(_refText); final boolean oldLayout = _tinyLayout; _tinyLayout = (_refTextExtent.x > XX / 9); // getNumOfWeeks needs the _tinuLayout set if (oldLayout != _tinyLayout) { // the layout style changed, try to restore weeks and make selection visible if (_tinyLayout) { _dt_normal = _dt; _dt = _dt_tiny; } else { _dt_tiny = _dt; _dt = _dt_normal; } scrollBarUpdate(); if (_selectedItem.id > 0) { switch (_selectedItem.type) { case DAY: gotoDate(new DateTime(0).plusDays(_selectedItem.id.intValue())); return; case TOUR: gotoTourId(_selectedItem.id); return; } } } final int numCols = 9; // one col left and right of the week + 7 week days final int numRows = getNumOfWeeks(); // number of weeks per month displayed (make sure _tinyLayout is already defined!) final Color alternate = _colorCache.getColor(0xf0f0f0); _tourFocus = new ArrayList<ObjectLocation>(); _dayFocus = new ArrayList<ObjectLocation>(); CalendarTourData[] data; final Font normalFont = gc.getFont(); final FontData fd[] = normalFont.getFontData(); fd[0].setStyle(SWT.BOLD); final Font boldFont = new Font(_display, fd[0]); final Rectangle area = getClientArea(); gc.setBackground(_white); gc.setForeground(_black); gc.fillRectangle(area); final float dY = (float) YY / (float) numRows; float dX = (float) XX / (float) numCols; // keep the summary column at a minimal width and hide it completely if height goes blow usable value final int minSummaryWidth = _refTextExtent.x; final int minSummaryHeigth = (_refTextExtent.y * 2) / 3; int summaryWidth = 0; if (dY > minSummaryHeigth) { if (dX < minSummaryWidth) { summaryWidth = minSummaryWidth; } else { summaryWidth = (int) dX; } } final int minInfoWidth = _refTextExtent.x / 2; final int minInfoHeigth = (_refTextExtent.y / 3); int infoWidth = 0; if (dY > minInfoHeigth) { if (dX < minInfoWidth) { infoWidth = minInfoWidth; } else { infoWidth = (int) dX; } } dX = (float) (XX - summaryWidth - infoWidth) / (numCols - 2); _calendarAllDaysRectangle = new Rectangle(infoWidth, 0, (int) (7 * dX), YY); // _calendarFirstWeekRectangle = new Rectangle(infoWidth, 0, (int) (7 * dX), (int) dY); // _calendarLastWeekRectangle = new Rectangle( infoWidth, (int) ((getNumOfWeeks() - 1) * dY), (int) (7 * dX), (int) dY); // first draw the horizontal lines gc.setBackground(_white); gc.setForeground(_gray); for (int i = 0; i <= numRows; i++) { gc.drawLine(0, (int) (i * dY), XX, (int) (i * dY)); } // final Rectangle selectedRec = null; // final CalendarTourData selectedTour = null; // final boolean doSelection = false; final long todayDayId = (new Day(new DateTime())).dayId; gc.setFont(boldFont); // a rough guess about the max size of the label final Point[] headerSizes = { gc.stringExtent("22. May 99"), //$NON-NLS-1$ gc.stringExtent("22. May"), //$NON-NLS-1$ gc.stringExtent("22") }; //$NON-NLS-1$ gc.setFont(normalFont); final String[] headerFormats = { "dd. MMM yy", "dd. MMM", "dd" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String headerFormat = UI.EMPTY_STRING; // Find a format for the day header which fits into the rectangle available; int g = 0; while (g < headerSizes.length && headerSizes[g].x > (dX - dayLabelXOffset)) { g++; } g = Math.min(g, headerSizes.length - 1); // if the cell is smaller than the shortest format (no index 'g' was found) we use the shortest format and relay on clipping // if (headerSizes[g].y < dY) { // headerFormat = headerFormats[g]; // } headerFormat = headerFormats[g]; final int dayLabelWidht = headerSizes[g].x; int dayLabelHeight = headerSizes[g].y; // _tinyLayout = (refTextExtent.x > dX || refTextExtent.y > dY - dayLabelHeight) ? true : false; DateTime weekDate; long dayId = (new Day(date)).dayId; // we use simple ids // Weeks for (int i = 0; i < numRows; i++) { final int Y1 = (int) (i * dY); final int Y2 = (int) ((i + 1) * dY); // Days per week Rectangle dayRec = null; weekDate = date; // save the first day of this week as a pointer to this week if (infoWidth > 0) { final Rectangle infoRec = new Rectangle(0, Y1, infoWidth, (Y2 - Y1)); drawWeekInfo(gc, date, infoRec); } for (int j = 0; j < 7; j++) { final int X1 = infoWidth + (int) (j * dX); final int X2 = infoWidth + (int) ((j + 1) * dX); // final Rectangle dayRec = new Rectangle(X1, Y1, (X2 - X1), (Y2 - Y1)); dayRec = new Rectangle(X1, Y1, (X2 - X1), (Y2 - Y1)); final Day day = new Day(dayId); _dayFocus.add(new ObjectLocation(dayRec, dayId, day)); dayId = day.dayId + 1; final int weekDay = date.getDayOfWeek(); gc.setBackground(_white); // Day background rectangle if ((date.getMonthOfYear() % 2) == 1) { gc.setBackground(alternate); gc.fillRectangle(dayRec.x, dayRec.y + 1, dayRec.width, dayRec.height - 1); } data = _dataProvider.getCalendarDayData(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); // Day header box if (!_tinyLayout) { gc.setForeground(_gray); gc.fillGradientRectangle(X1, Y1, dayRec.width + 1, dayLabelHeight, true); // no clue why I've to add 1 to the width, looks like a bug on Linux and does not hurt as we overwrite with the vertial line at the end anyway // Day header label gc.setFont(boldFont); if (day.dayId == todayDayId) { gc.setForeground(_blue); } else if (weekDay == DateTimeConstants.SATURDAY || weekDay == DateTimeConstants.SUNDAY) { gc.setForeground(_red); } else { gc.setForeground(_darkGray); } gc.setClipping(X1, Y1, dayRec.width, dayLabelHeight); // this clipping should only kick in if shortest label format is still longer than the cell width gc.drawText(date.toString(headerFormat), X2 - dayLabelWidht - dayLabelXOffset, Y1, true); gc.setFont(normalFont); gc.setClipping(_nullRec); } else { dayLabelHeight = 0; } drawDayTours(gc, data, new Rectangle(dayRec.x, dayRec.y + dayLabelHeight, dayRec.width, dayRec.height - dayLabelHeight)); if (_tinyLayout && _showDayNumberInTinyView) { if (day.dayId == todayDayId) { gc.setForeground(_blue); } else if (weekDay == DateTimeConstants.SATURDAY || weekDay == DateTimeConstants.SUNDAY) { gc.setForeground(_red); } else { gc.setForeground(_darkGray); } gc.setAlpha(0x50); gc.setFont(boldFont); gc.setClipping(dayRec); gc.drawText(date.toString(headerFormat), X2 - dayLabelWidht - dayLabelXOffset, Y1, true); gc.setFont(normalFont); gc.setClipping(_nullRec); gc.setAlpha(0xFF); } date = date.plusDays(1); } if (summaryWidth > 0) { final int X1 = infoWidth + (int) (7 * dX); final int X2 = X1 + summaryWidth; final Rectangle weekRec = new Rectangle(X1, Y1, (X2 - X1), (Y2 - Y1)); final CalendarTourData weekSummary = _dataProvider.getCalendarWeekSummaryData(weekDate.getYear(), weekDate.getWeekOfWeekyear()); if (weekSummary.numTours > 0) { drawWeekSummary(gc, weekSummary, weekRec); } } } gc.setFont(normalFont); // and finally the vertical lines gc.setForeground(_display.getSystemColor(SWT.COLOR_GRAY)); for (int i = 0; i <= 7; i++) { gc.drawLine(infoWidth + (int) (i * dX), 0, infoWidth + (int) (i * dX), YY); } // draw the selection on top of our calendar graph image so we can reuse that image _highlight = new Image(getDisplay(), XX, YY); gc = new GC(_highlight); gc.drawImage(_image, 0, 0); drawSelection(gc); oldGc.drawImage(_highlight, 0, 0); _highlight.dispose(); boldFont.dispose(); oldGc.dispose(); gc.dispose(); _graphClean = true; }
From source file:net.tourbook.ui.views.calendar.CalendarYearMonthContributionItem.java
License:Open Source License
private void fillYearComboBox() { final int thisYear = (new DateTime()).getYear(); _cboYearValues = new ArrayList<Integer>(); _cboYearKeys = new HashMap<Integer, Integer>(); // for (int i = thisYear, j = 0; j < 21; i--, j++) { // changed to be consistent with the statistic charts final DateTime firstTourDateTime = CalendarTourDataProvider.getInstance().getFirstDateTime(); final int firstYear = firstTourDateTime.getYear(); final int years = Math.max(thisYear - firstYear, 1); for (int i = thisYear - years, j = 0; j <= years; i++, j++) { _cboYear.add(UI.EMPTY_STRING + i); _cboYearValues.add(i);// w w w .j a v a 2 s . c om _cboYearKeys.put(i, j); } _cboYear.select(years - 1); }
From source file:net.tourbook.ui.views.tourCatalog.YearStatisticView.java
License:Open Source License
/** * show statistic for several years// w ww . j a v a2s . c o m * * @param isShowLatestYear * shows the latest year and the years before */ private void updateYearChart(final boolean isShowLatestYear) { if (_currentRefItem == null) { return; } _pageBook.showPage(_pageChart); final Object[] yearItems = _currentRefItem.getFetchedChildrenAsArray(); // get the last year when it's forced if (isShowLatestYear && yearItems != null && yearItems.length > 0) { final Object item = yearItems[yearItems.length - 1]; if (item instanceof TVICatalogYearItem) { _lastYear = ((TVICatalogYearItem) item).year; } } _allTours.clear(); _DOYValues.clear(); _tourSpeed.clear(); final int firstYear = getFirstYear(); // loop: all years for (final Object yearItemObj : yearItems) { if (yearItemObj instanceof TVICatalogYearItem) { final TVICatalogYearItem yearItem = (TVICatalogYearItem) yearItemObj; // check if the year can be displayed final int yearItemYear = yearItem.year; if (yearItemYear >= firstYear && yearItemYear <= _lastYear) { // loop: all tours final Object[] tourItems = yearItem.getFetchedChildrenAsArray(); for (final Object tourItemObj : tourItems) { if (tourItemObj instanceof TVICatalogComparedTour) { final TVICatalogComparedTour tourItem = (TVICatalogComparedTour) tourItemObj; final DateTime dt = new DateTime(tourItem.getTourDate()); _DOYValues.add(getYearDOYs(dt.getYear()) + dt.getDayOfYear() - 1); _tourSpeed.add((int) (tourItem.getTourSpeed() * 10 / UI.UNIT_VALUE_DISTANCE)); _allTours.add(tourItem); } } } } } final ChartDataModel chartModel = new ChartDataModel(ChartDataModel.CHART_TYPE_BAR); final ChartDataXSerie xData = new ChartDataXSerie(ArrayListToArray.toInt(_DOYValues)); xData.setAxisUnit(ChartDataXSerie.AXIS_UNIT_DAY); xData.setChartSegments(createChartSegments()); chartModel.setXData(xData); // set the bar low/high data final ChartDataYSerie yData = new ChartDataYSerie(ChartDataModel.CHART_TYPE_BAR, ArrayListToArray.toInt(_tourSpeed)); yData.setValueDivisor(10); TourManager.setGraphColor(_prefStore, yData, GraphColorProvider.PREF_GRAPH_SPEED); /* * set/restore min/max values */ final TVICatalogRefTourItem refItem = _currentRefItem; final int minValue = yData.getVisibleMinValue(); final int maxValue = yData.getVisibleMaxValue(); final int dataMinValue = minValue - (minValue / 10); final int dataMaxValue = maxValue + (maxValue / 20); if (_isSynchMaxValue) { if (refItem.yearMapMinValue == Integer.MIN_VALUE) { // min/max values have not yet been saved /* * set the min value 10% below the computed so that the lowest value is not at the * bottom */ yData.setVisibleMinValue(dataMinValue); yData.setVisibleMaxValue(dataMaxValue); refItem.yearMapMinValue = dataMinValue; refItem.yearMapMaxValue = dataMaxValue; } else { /* * restore min/max values, but make sure min/max values for the current graph are * visible and not outside of the chart */ refItem.yearMapMinValue = Math.min(refItem.yearMapMinValue, dataMinValue); refItem.yearMapMaxValue = Math.max(refItem.yearMapMaxValue, dataMaxValue); yData.setVisibleMinValue(refItem.yearMapMinValue); yData.setVisibleMaxValue(refItem.yearMapMaxValue); } } else { yData.setVisibleMinValue(dataMinValue); yData.setVisibleMaxValue(dataMaxValue); } yData.setYTitle(Messages.tourCatalog_view_label_year_chart_title); yData.setUnitLabel(UI.UNIT_LABEL_SPEED); chartModel.addYData(yData); // set tool tip info chartModel.setCustomData(ChartDataModel.BAR_TOOLTIP_INFO_PROVIDER, new IChartInfoProvider() { @Override public ChartToolTipInfo getToolTipInfo(final int serieIndex, final int valueIndex) { return createToolTipInfo(valueIndex); } }); // set grid size _yearChart.setGridDistance(_prefStore.getInt(ITourbookPreferences.GRAPH_GRID_HORIZONTAL_DISTANCE), _prefStore.getInt(ITourbookPreferences.GRAPH_GRID_VERTICAL_DISTANCE)); // show the data in the chart _yearChart.updateChart(chartModel, false, true); /* * update start year combo box */ _cboLastYear.removeAll(); _comboYears.clear(); for (int year = firstYear - 1; year <= _lastYear + _numberOfYears; year++) { _cboLastYear.add(Integer.toString(year)); _comboYears.add(year); } _cboLastYear.select(_numberOfYears - 0); }
From source file:nl.mpcjanssen.simpletask.AddTask.java
License:Open Source License
private void insertDate(final int dateType) { Dialog d = Util.createDeferDialog(this, dateType, false, new Util.InputDialogListener() { @Override// w ww . j ava2s. c o m public void onClick(String selected) { if (selected.equals("pick")) { /* Note on some Android versions the OnDateSetListener can fire twice * https://code.google.com/p/android/issues/detail?id=34860 * With the current implementation which replaces the dates this is not an * issue. The date is just replaced twice */ final DateTime today = new DateTime(); DatePickerDialog dialog = new DatePickerDialog(AddTask.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { month++; DateTime date = ISODateTimeFormat.date() .parseDateTime(year + "-" + month + "-" + day); insertDateAtSelection(dateType, date); } }, today.getYear(), today.getMonthOfYear() - 1, today.getDayOfMonth()); dialog.show(); } else { insertDateAtSelection(dateType, Util.addInterval(new DateTime(), selected)); } } }); d.show(); }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
License:GNU General Public License
private void deferTasks(List<Task> tasks, final int dateType) { final List<Task> tasksToDefer = tasks; Dialog d = Util.createDeferDialog(this, dateType, true, new Util.InputDialogListener() { @Override/*from w w w. j ava 2 s . c o m*/ public void onClick(String selected) { if (selected != null && selected.equals("pick")) { final DateTime today = new DateTime(); DatePickerDialog dialog = new DatePickerDialog(Simpletask.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { month++; DateTime date = ISODateTimeFormat.date() .parseDateTime(year + "-" + month + "-" + day); deferTasks(date, tasksToDefer, dateType); } }, today.getYear(), today.getMonthOfYear() - 1, today.getDayOfMonth()); dialog.show(); } else { deferTasks(selected, tasksToDefer, dateType); } } }); d.show(); }