I was contemplating whether to manually draw the schedule, to use a JTable, or use JPanels in a GridbagLayout. I did think of JFreeChart, but I’m not sure if there’s a chart suitable, and I was hoping its Gantt chart was up to the job. It was.
The below sample shows it can render multiple “tasks” in the same row, so it satisfies my needs.
TaskSeriesCollection dataset = new TaskSeriesCollection();
TaskSeries unavailable = new TaskSeries("Unavailable");
Task room1 = new Task("Meeting Room 1",
new GregorianCalendar(2009, Month.DECEMBER, 1, 7, 00).getTime(),
new GregorianCalendar(2009, Month.DECEMBER, 1, 18, 00).getTime());
unavailable.add(room1);
room1.addSubtask(new Task("Meeting 1",
new GregorianCalendar(2009, Month.DECEMBER, 1, 9, 00).getTime(),
new GregorianCalendar(2009, Month.DECEMBER, 1, 16, 00).getTime()));
Task room2 = new Task("Meeting Room 2",
new GregorianCalendar(2009, Month.DECEMBER, 1, 7, 00).getTime(),
new GregorianCalendar(2009, Month.DECEMBER, 1, 18, 00).getTime());
unavailable.add(room2);
room2.addSubtask(new Task("Meeting 2",
new GregorianCalendar(2009, Month.DECEMBER, 1, 10, 00).getTime(),
new GregorianCalendar(2009, Month.DECEMBER, 1, 11, 00).getTime()));
room2.addSubtask(new Task("Meeting 3",
new GregorianCalendar(2009, Month.DECEMBER, 1, 14, 00).getTime(),
new GregorianCalendar(2009, Month.DECEMBER, 1, 15, 00).getTime()));
room2.addSubtask(new Task("Meeting 4",
new GregorianCalendar(2009, Month.DECEMBER, 1, 16, 00).getTime(),
new GregorianCalendar(2009, Month.DECEMBER, 1, 18, 00).getTime()));
dataset.add(unavailable);
JFrame frame = new JFrame("MeetNow!");
// title, domain axis, range axis, dataset, legend, tooltip, urls
JFreeChart chart = ChartFactory.createGanttChart("", "Room", "Time", dataset, false, true, false);
ChartPanel chartPanel = new ChartPanel(chart);
frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setBounds(50, 50, 800, 200);
frame.setVisible(true);
The result of the above code is like this.
Using a set of models I hooked up this UI to the query code. For some chart customization I added the meeting subject onto the bar and tooltip, changed the color and added some controls on the top.
See Part II for querying Exchange for the schedule, and Part I for setting up the Web Service.