ItEr15S12RFComportamentoGraficoPlanificadorItEr14S13: Adding zoom level with semesters and months.
This commit is contained in:
parent
1095fca972
commit
6f1099836b
5 changed files with 115 additions and 15 deletions
|
|
@ -27,8 +27,8 @@ import org.zkoss.zul.Label;
|
|||
public class TimeTracker extends HtmlMacroComponent {
|
||||
|
||||
private static Interval getTestInterval() {
|
||||
return new Interval(TimeTrackerState.year(2008), TimeTrackerState
|
||||
.year(2019));
|
||||
return new Interval(TimeTrackerState.year(2009), TimeTrackerState
|
||||
.year(2012));
|
||||
}
|
||||
|
||||
private AbstractComponent fakeRow;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,109 @@
|
|||
package org.zkoss.ganttz.util.zoom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.Months;
|
||||
import org.joda.time.ReadablePeriod;
|
||||
import org.zkoss.ganttz.util.Interval;
|
||||
import org.zkoss.util.Locales;
|
||||
|
||||
/**
|
||||
* Zoom level with semesters in the first level and months in the second level
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class DetailThreeTimeTrackerState extends TimeTrackerState {
|
||||
|
||||
public static final DetailThreeTimeTrackerState INSTANCE = new DetailThreeTimeTrackerState();
|
||||
|
||||
private static final int FIRST_LEVEL_SIZE = 300;
|
||||
protected static final int SECOND_LEVEL_SIZE = 50;
|
||||
|
||||
private static LocalDate asLocalDate(Date date) {
|
||||
return new LocalDate(date);
|
||||
}
|
||||
|
||||
public interface IDetailItemCreator {
|
||||
DetailItem create(DateTime dateTime);
|
||||
}
|
||||
|
||||
public static Collection<DetailItem> createDetails(Interval interval,
|
||||
ReadablePeriod period, IDetailItemCreator detailItemCreator) {
|
||||
DateTime current = asLocalDate(interval.getStart())
|
||||
.toDateTimeAtStartOfDay();
|
||||
DateTime end = asLocalDate(interval.getFinish())
|
||||
.toDateTimeAtStartOfDay();
|
||||
List<DetailItem> result = new ArrayList<DetailItem>();
|
||||
while (current.isBefore(end)) {
|
||||
result.add(detailItemCreator.create(current));
|
||||
current = current.plus(period);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DetailThreeTimeTrackerState() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<DetailItem> createDetailsForFirstLevel(
|
||||
Interval interval) {
|
||||
return createDetails(getRealIntervalFor(interval), Months.months(6),
|
||||
new IDetailItemCreator() {
|
||||
|
||||
@Override
|
||||
public DetailItem create(DateTime dateTime) {
|
||||
return new DetailItem(FIRST_LEVEL_SIZE,
|
||||
getYearWithSemesterString(dateTime));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getYearWithSemesterString(DateTime dateTime) {
|
||||
return dateTime.getYear() + ","
|
||||
+ (dateTime.getMonthOfYear() < 6 ? "H1" : "H2");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<DetailItem> createDetailsForSecondLevel(
|
||||
Interval interval) {
|
||||
return createDetails(getRealIntervalFor(interval), Months.months(1),
|
||||
new IDetailItemCreator() {
|
||||
|
||||
@Override
|
||||
public DetailItem create(DateTime dateTime) {
|
||||
return new DetailItem(SECOND_LEVEL_SIZE,
|
||||
getMonthString(dateTime));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public LocalDate round(LocalDate date, boolean down) {
|
||||
if (date.getMonthOfYear() == 1 && date.getDayOfMonth() == 1)
|
||||
return date;
|
||||
if (date.getMonthOfYear() == 7 && date.getDayOfMonth() == 1)
|
||||
return date;
|
||||
date = date.withDayOfMonth(1);
|
||||
if (date.getMonthOfYear() < 7) {
|
||||
return down ? date.withMonthOfYear(1) : date.withMonthOfYear(7);
|
||||
} else {
|
||||
return down ? date.withMonthOfYear(7) : date.plusYears(1)
|
||||
.withMonthOfYear(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interval getRealIntervalFor(Interval testInterval) {
|
||||
LocalDate start = round(asLocalDate(testInterval.getStart()), true);
|
||||
LocalDate finish = round(asLocalDate(testInterval.getFinish()), false);
|
||||
return new Interval(start.toDateTimeAtStartOfDay().toDate(), finish
|
||||
.toDateTimeAtStartOfDay().toDate());
|
||||
}
|
||||
|
||||
private String getMonthString(DateTime dateTime) {
|
||||
return dateTime.toString("MMM", Locales.getCurrent());
|
||||
}
|
||||
}
|
||||
|
|
@ -14,9 +14,7 @@ import java.util.Vector;
|
|||
import org.zkoss.ganttz.util.Interval;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francisco Javier Moran Rúa
|
||||
*
|
||||
*/
|
||||
public class DetailTwoTimeTrackerState extends TimeTrackerState {
|
||||
|
||||
|
|
@ -96,7 +94,6 @@ public class DetailTwoTimeTrackerState extends TimeTrackerState {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param date
|
||||
* @param year
|
||||
* @return a number from 1(quarter until to 1st April) to 4(quarter until
|
||||
|
|
|
|||
|
|
@ -5,17 +5,14 @@
|
|||
|
||||
package org.zkoss.ganttz.util.zoom;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francisco Javier Moran Rúa
|
||||
*
|
||||
*/
|
||||
public enum ZoomLevel {
|
||||
|
||||
DETAIL_ONE(DetailOneTimeTrackerState.INSTANCE), DETAIL_TWO(
|
||||
DetailTwoTimeTrackerState.INSTANCE), DETAIL_THREE(
|
||||
DetailTwoTimeTrackerState.INSTANCE), DETAIL_FOUR(
|
||||
DetailThreeTimeTrackerState.INSTANCE), DETAIL_FOUR(
|
||||
DetailTwoTimeTrackerState.INSTANCE);
|
||||
|
||||
private final TimeTrackerState state;
|
||||
|
|
@ -27,7 +24,6 @@ public enum ZoomLevel {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return if there is no next, returns <code>this</code>. Otherwise returns
|
||||
* the next one.
|
||||
*/
|
||||
|
|
@ -40,7 +36,6 @@ public enum ZoomLevel {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return if there is no previous, returns <code>this</code>. Otherwise
|
||||
* returns the previous one.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class DataForPlanner {
|
|||
private DependencyRegistry getModelWith(int tasksToCreate) {
|
||||
DependencyRegistry dependencyRegistry = new DependencyRegistry();
|
||||
Date now = new Date();
|
||||
Date end = threeMonthsLater(now);
|
||||
Date end = twoMonthsLater(now);
|
||||
TaskBean first = null;
|
||||
TaskBean second = null;
|
||||
for (int i = 0; i < tasksToCreate; i++) {
|
||||
|
|
@ -55,11 +55,10 @@ public class DataForPlanner {
|
|||
return dependencyRegistry;
|
||||
}
|
||||
|
||||
private static Date threeMonthsLater(Date now) {
|
||||
private static Date twoMonthsLater(Date now) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(now);
|
||||
calendar.add(Calendar.MONTH, 3);
|
||||
calendar.add(Calendar.MONTH, 2);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue