List of usage examples for org.jfree.data.gantt Task addSubtask
public void addSubtask(Task subtask)
From source file:org.ietr.preesm.mapper.ui.GanttPlotter.java
/** * Creates a dataset from a MapperDAGVertex. This dataset is used to prepare * display of a Gantt chart with one line per populated SLAM component. * //w w w . j a v a 2 s . c om * @return The dataset. */ private static IntervalCategoryDataset createDataset(GanttData ganttData) { TaskSeries series = new TaskSeries("Scheduled"); // Creating the component lines (operator or communicator) List<GanttComponent> components = ganttData.getComponents(); for (GanttComponent cmp : components) { Task currentJFreeCmp = new Task(cmp.getId(), new SimpleTimePeriod(0, 1)); series.add(currentJFreeCmp); // Setting the series length to the maximum end time of a task long finalCost = cmp.getEndTime(); series.get(cmp.getId()).setDuration(new SimpleTimePeriod(0, finalCost)); for (GanttTask ganttTask : cmp.getTasks()) { String taskName = ganttTask.getId(); long start = ganttTask.getStartTime(); long end = start + ganttTask.getDuration(); Task currentJFreeTask = new Task(taskName, new SimpleTimePeriod(start, end)); currentJFreeCmp.addSubtask(currentJFreeTask); } } TaskSeriesCollection collection = new TaskSeriesCollection(); collection.add(series); return collection; }
From source file:org.jfree.data.gantt.TaskTest.java
/** * Check the getSubTaskCount() method.// w w w . j a v a 2 s .c o m */ @Test public void testGetSubTaskCount() { Task t1 = new Task("T", new Date(100), new Date(200)); assertEquals(0, t1.getSubtaskCount()); t1.addSubtask(new Task("S1", new Date(100), new Date(110))); assertEquals(1, t1.getSubtaskCount()); Task s2 = new Task("S2", new Date(111), new Date(120)); t1.addSubtask(s2); assertEquals(2, t1.getSubtaskCount()); t1.addSubtask(new Task("S3", new Date(121), new Date(130))); assertEquals(3, t1.getSubtaskCount()); t1.removeSubtask(s2); assertEquals(2, t1.getSubtaskCount()); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Creates a task for the project availability. * @param set//from w ww.ja va 2 s. co m * Set of the project availability * @return The created task. */ private Task createProjectTask(final Set<Availability> set) { if (set.size() > 0) { final Task mainTask = new Task(AvailabilityGraph.PROJECT_WORKER.getLogin(), actualStart.getTime(), actualEnd.getTime()); for (Availability projectAvailability : set) { mainTask.addSubtask(new Task(AvailabilityGraph.PROJECT_WORKER.getLogin(), projectAvailability.getStartTime(), projectAvailability.getEndTime())); } return mainTask; } else { return new Task(AvailabilityGraph.PROJECT_WORKER.getLogin(), new Date(0), new Date(0)); } }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Creates a task for the employees./* w w w . j ava 2 s . co m*/ * @param worker * The specific employee. * @param workerAvailabilaties * Set of the employee availabilities. * @return The created task. */ private Task createWorkerTask(final Worker worker, final Set<Availability> workerAvailabilaties) { if (workerAvailabilaties.size() > 0) { final Task mainTask = new Task(worker.getVorname() + " " + worker.getName(), actualStart.getTime(), actualEnd.getTime()); for (Availability workerAvailability : workerAvailabilaties) { mainTask.addSubtask(new Task(worker.getVorname() + " " + worker.getName(), workerAvailability.getStartTime(), workerAvailability.getEndTime())); } return mainTask; } else { return new Task(worker.getVorname() + " " + worker.getName(), new Date(0), new Date(0)); } }
From source file:org.jfree.chart.demo.GanttDemo2.java
/** * Creates a sample dataset for a Gantt chart, using sub-tasks. In general, you won't * hard-code the dataset in this way - it's done here so that the demo is self-contained. * * @return The dataset./* w w w . jav a 2 s .com*/ */ private IntervalCategoryDataset createSampleDataset() { final TaskSeries s1 = new TaskSeries("Scheduled"); final Task t1 = new Task("Write Proposal", date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001)); t1.setPercentComplete(1.00); s1.add(t1); final Task t2 = new Task("Obtain Approval", date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001)); t2.setPercentComplete(1.00); s1.add(t2); // here is a task split into two subtasks... final Task t3 = new Task("Requirements Analysis", date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001)); final Task st31 = new Task("Requirements 1", date(10, Calendar.APRIL, 2001), date(25, Calendar.APRIL, 2001)); st31.setPercentComplete(1.0); final Task st32 = new Task("Requirements 2", date(1, Calendar.MAY, 2001), date(5, Calendar.MAY, 2001)); st32.setPercentComplete(1.0); t3.addSubtask(st31); t3.addSubtask(st32); s1.add(t3); // and another... final Task t4 = new Task("Design Phase", date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001)); final Task st41 = new Task("Design 1", date(6, Calendar.MAY, 2001), date(10, Calendar.MAY, 2001)); st41.setPercentComplete(1.0); final Task st42 = new Task("Design 2", date(15, Calendar.MAY, 2001), date(20, Calendar.MAY, 2001)); st42.setPercentComplete(1.0); final Task st43 = new Task("Design 3", date(23, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001)); st43.setPercentComplete(0.50); t4.addSubtask(st41); t4.addSubtask(st42); t4.addSubtask(st43); s1.add(t4); final Task t5 = new Task("Design Signoff", date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001)); s1.add(t5); final Task t6 = new Task("Alpha Implementation", date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001)); t6.setPercentComplete(0.60); s1.add(t6); final Task t7 = new Task("Design Review", date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001)); t7.setPercentComplete(0.0); s1.add(t7); final Task t8 = new Task("Revised Design Signoff", date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001)); t8.setPercentComplete(0.0); s1.add(t8); final Task t9 = new Task("Beta Implementation", date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001)); t9.setPercentComplete(0.0); s1.add(t9); final Task t10 = new Task("Testing", date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001)); t10.setPercentComplete(0.0); s1.add(t10); final Task t11 = new Task("Final Implementation", date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001)); t11.setPercentComplete(0.0); s1.add(t11); final Task t12 = new Task("Signoff", date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001)); t12.setPercentComplete(0.0); s1.add(t12); final TaskSeriesCollection collection = new TaskSeriesCollection(); collection.add(s1); return collection; }
From source file:org.jfree.data.gantt.TaskSeriesCollectionTest.java
/** * Creates a sample collection for testing purposes. * * @return A sample collection.//w ww . j av a 2 s. co m */ private TaskSeriesCollection createCollection2() { TaskSeriesCollection result = new TaskSeriesCollection(); TaskSeries s1 = new TaskSeries("S1"); Task t1 = new Task("Task 1", new Date(10), new Date(20)); t1.addSubtask(new Task("Task 1A", new Date(10), new Date(15))); t1.addSubtask(new Task("Task 1B", new Date(16), new Date(20))); t1.setPercentComplete(0.10); s1.add(t1); Task t2 = new Task("Task 2", new Date(30), new Date(40)); t2.addSubtask(new Task("Task 2A", new Date(30), new Date(35))); t2.addSubtask(new Task("Task 2B", new Date(36), new Date(40))); t2.setPercentComplete(0.20); s1.add(t2); result.add(s1); TaskSeries s2 = new TaskSeries("S2"); Task t3 = new Task("Task 3", new Date(50), new Date(60)); t3.addSubtask(new Task("Task 3A", new Date(50), new Date(55))); t3.addSubtask(new Task("Task 3B", new Date(56), new Date(60))); t3.setPercentComplete(0.30); s2.add(t3); result.add(s2); return result; }
From source file:org.jfree.data.gantt.TaskSeriesCollectionTest.java
/** * Creates a sample collection for testing purposes. * * @return A sample collection./*from w w w . java 2s. c o m*/ */ private TaskSeriesCollection createCollection3() { // define subtasks Task sub1 = new Task("Sub1", new Date(11), new Date(111)); Task sub2 = new Task("Sub2", new Date(22), new Date(222)); Task sub3 = new Task("Sub3", new Date(33), new Date(333)); Task sub4 = new Task("Sub4", new Date(44), new Date(444)); Task sub5 = new Task("Sub5", new Date(55), new Date(555)); Task sub6 = new Task("Sub6", new Date(66), new Date(666)); sub1.setPercentComplete(0.111); sub2.setPercentComplete(0.222); sub3.setPercentComplete(0.333); sub4.setPercentComplete(0.444); sub5.setPercentComplete(0.555); sub6.setPercentComplete(0.666); TaskSeries seriesA = new TaskSeries("Series A"); Task taskA1 = new Task("Task 1", new SimpleTimePeriod(new Date(100), new Date(200))); taskA1.setPercentComplete(0.1); taskA1.addSubtask(sub1); Task taskA2 = new Task("Task 2", new SimpleTimePeriod(new Date(220), new Date(350))); taskA2.setPercentComplete(0.2); taskA2.addSubtask(sub2); taskA2.addSubtask(sub3); seriesA.add(taskA1); seriesA.add(taskA2); TaskSeries seriesB = new TaskSeries("Series B"); // note that we don't define taskB1 Task taskB2 = new Task("Task 2", new SimpleTimePeriod(new Date(2220), new Date(3350))); taskB2.setPercentComplete(0.3); taskB2.addSubtask(sub4); taskB2.addSubtask(sub5); taskB2.addSubtask(sub6); seriesB.add(taskB2); TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(seriesA); tsc.add(seriesB); return tsc; }
From source file:com.opendoorlogistics.components.gantt.GanttChartComponent.java
@Override public void execute(final ComponentExecutionApi api, int mode, Object configuration, ODLDatastore<? extends ODLTable> ioDs, ODLDatastoreAlterable<? extends ODLTableAlterable> outputDs) { // Get items and sort by resource then date final StringConventions sc = api.getApi().stringConventions(); List<GanttItem> items = GanttItem.beanMapping.getTableMapping(0).readObjectsFromTable(ioDs.getTableAt(0)); // Rounding doubles to longs can create small errors where a start time is 1 millisecond after an end. // Set all start times to be <= end time for (GanttItem item : items) { if (item.getStart() == null || item.getEnd() == null) { throw new RuntimeException("Found Gannt item with null start or end time."); }//from w w w. ja v a2 s. com if (item.getStart().getValue() > item.getEnd().getValue()) { item.setStart(item.getEnd()); } } Collections.sort(items, new Comparator<GanttItem>() { @Override public int compare(GanttItem o1, GanttItem o2) { int diff = sc.compareStandardised(o1.getResourceId(), o2.getResourceId()); if (diff == 0) { diff = o1.getStart().compareTo(o2.getStart()); } if (diff == 0) { diff = o1.getEnd().compareTo(o2.getEnd()); } if (diff == 0) { diff = sc.compareStandardised(o1.getActivityId(), o2.getActivityId()); } if (diff == 0) { diff = Colours.compare(o1.getColor(), o2.getColor()); } return diff; } }); // Filter any zero duration items Iterator<GanttItem> it = items.iterator(); while (it.hasNext()) { GanttItem item = it.next(); if (item.getStart().compareTo(item.getEnd()) == 0) { it.remove(); } } // Get average colour for each activity type Map<String, CalculateAverageColour> calcColourMap = api.getApi().stringConventions() .createStandardisedMap(); for (GanttItem item : items) { CalculateAverageColour calc = calcColourMap.get(item.getActivityId()); if (calc == null) { calc = new CalculateAverageColour(); calcColourMap.put(item.getActivityId(), calc); } calc.add(item.getColor()); } // Put into colour map Map<String, Color> colourMap = api.getApi().stringConventions().createStandardisedMap(); for (Map.Entry<String, CalculateAverageColour> entry : calcColourMap.entrySet()) { colourMap.put(entry.getKey(), entry.getValue().getAverage()); } // Split items by resource ArrayList<ArrayList<GanttItem>> splitByResource = new ArrayList<>(); ArrayList<GanttItem> current = null; for (GanttItem item : items) { if (current == null || sc.compareStandardised(current.get(0).getResourceId(), item.getResourceId()) != 0) { current = new ArrayList<>(); splitByResource.add(current); } current.add(item); } // put into jfreechart's task data structure TaskSeries ts = new TaskSeries("Resources"); for (ArrayList<GanttItem> resource : splitByResource) { // get earliest and latest time (last time may not be in the last item) ODLTime earliest = resource.get(0).getStart(); ODLTime latest = null; for (GanttItem item : resource) { if (latest == null || latest.compareTo(item.getEnd()) < 0) { latest = item.getEnd(); } } Task task = new Task(resource.get(0).getResourceId(), new Date(earliest.getTotalMilliseconds()), new Date(latest.getTotalMilliseconds())); // add all items as subtasks for (GanttItem item : resource) { task.addSubtask(new MySubtask(item, new Date(item.getStart().getTotalMilliseconds()), new Date(item.getEnd().getTotalMilliseconds()))); } ts.add(task); } TaskSeriesCollection collection = new TaskSeriesCollection(); collection.add(ts); // Create the plot CategoryAxis categoryAxis = new CategoryAxis(null); DateAxis dateAxis = new DateAxis("Time"); CategoryItemRenderer renderer = new MyRenderer(collection, colourMap); final CategoryPlot plot = new CategoryPlot(collection, categoryAxis, dateAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.getDomainAxis().setLabel(null); ((DateAxis) plot.getRangeAxis()).setDateFormatOverride(new DateFormat() { @Override public Date parse(String source, ParsePosition pos) { // TODO Auto-generated method stub return null; } @Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { toAppendTo.append(new ODLTime(date.getTime()).toString()); return toAppendTo; } }); // Create the chart and apply the standard theme without shadows to it api.submitControlLauncher(new ControlLauncherCallback() { @Override public void launchControls(ComponentControlLauncherApi launcherApi) { JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); StandardChartTheme theme = new StandardChartTheme("standard theme", false); theme.setBarPainter(new StandardBarPainter()); theme.apply(chart); class MyPanel extends ChartPanel implements Disposable { public MyPanel(JFreeChart chart) { super(chart); } @Override public void dispose() { // TODO Auto-generated method stub } } MyPanel chartPanel = new MyPanel(chart); launcherApi.registerPanel("Resource Gantt", null, chartPanel, true); } }); }
From source file:org.jfree.data.gantt.TaskTest.java
/** * Confirm that the equals method can distinguish all the required fields. *//*from w ww . j a v a 2 s .co m*/ @Test public void testEquals() { Task t1 = new Task("T", new Date(1), new Date(2)); Task t2 = new Task("T", new Date(1), new Date(2)); assertTrue(t1.equals(t2)); assertTrue(t2.equals(t1)); t1.setDescription("X"); assertFalse(t1.equals(t2)); t2.setDescription("X"); assertTrue(t1.equals(t2)); t1.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertFalse(t1.equals(t2)); t2.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertTrue(t1.equals(t2)); t1.setPercentComplete(0.5); assertFalse(t1.equals(t2)); t2.setPercentComplete(0.5); assertTrue(t1.equals(t2)); t1.addSubtask(new Task("T", new Date(22), new Date(33))); assertFalse(t1.equals(t2)); t2.addSubtask(new Task("T", new Date(22), new Date(33))); assertTrue(t1.equals(t2)); }
From source file:netmason.support.graphics.GanttDisplay.java
/** * Creates a sample dataset for a Gantt chart, using sub-tasks. In general, * you won't hard-code the dataset in this way - it's done here so that the * demo is self-contained.// w w w . j ava 2s . c o m * * @return The dataset. */ private IntervalCategoryDataset createSampleDataset() { final Task t1 = new Task("Write Proposal", date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001)); t1.setPercentComplete(1.00); s1.add(t1); final Task t2 = new Task("Obtain Approval", date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001)); t2.setPercentComplete(1.00); s1.add(t2); // here is a task split into two subtasks... final Task t3 = new Task("Requirements Analysis", date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001)); final Task st31 = new Task("Requirements 1", date(10, Calendar.APRIL, 2001), date(25, Calendar.APRIL, 2001)); st31.setPercentComplete(1.0); final Task st32 = new Task("Requirements 2", date(1, Calendar.MAY, 2001), date(5, Calendar.MAY, 2001)); st32.setPercentComplete(1.0); t3.addSubtask(st31); t3.addSubtask(st32); s1.add(t3); // and another... final Task t4 = new Task("Design Phase", date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001)); final Task st41 = new Task("Design 1", date(6, Calendar.MAY, 2001), date(10, Calendar.MAY, 2001)); st41.setPercentComplete(1.0); final Task st42 = new Task("Design 2", date(15, Calendar.MAY, 2001), date(20, Calendar.MAY, 2001)); st42.setPercentComplete(1.0); final Task st43 = new Task("Design 3", date(23, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001)); st43.setPercentComplete(0.50); t4.addSubtask(st41); t4.addSubtask(st42); t4.addSubtask(st43); s1.add(t4); final Task t5 = new Task("Design Signoff", date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001)); s1.add(t5); final Task t6 = new Task("Alpha Implementation", date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001)); t6.setPercentComplete(0.60); s1.add(t6); final Task t7 = new Task("Design Review", date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001)); t7.setPercentComplete(0.0); s1.add(t7); final Task t8 = new Task("Revised Design Signoff", date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001)); t8.setPercentComplete(0.0); s1.add(t8); final Task t9 = new Task("Beta Implementation", date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001)); t9.setPercentComplete(0.0); s1.add(t9); final Task t10 = new Task("Testing", date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001)); t10.setPercentComplete(0.0); s1.add(t10); final Task t11 = new Task("Final Implementation", date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001)); t11.setPercentComplete(0.0); s1.add(t11); final Task t12 = new Task("Signoff", date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001)); t12.setPercentComplete(0.0); s1.add(t12); final TaskSeriesCollection collection = new TaskSeriesCollection(); collection.add(s1); return collection; }