skip to main content
Programmer's documentation > Developing with the JViews Gantt SDK > Calendar view components > Calendar view beans
 
Calendar view beans
JViews Gantt features two high-level JavaBeans, the Monthly Calendar View JavaBean and Daily Calendar View JavaBean. Their API is based on the IlvMonthView and IlvDayView classes. These JavaBeans encapsulate the JViews Gantt library. Although the library can be used without the JavaBeans, you will find it easier to rely on them. Together with the IlvGanttModel interface, the two JavaBeans make up the main classes for handling calendar views in the JViews Gantt API.
Calendar View JavaBeans display activities from a Gantt data model overlaid on a monthly calendar or daily planner grid. Monthly and Daily Calendar Views provide an alternative view of the data contained in a Gantt data model and complement the displays provided by the Gantt chart bean and Schedule chart bean.
A basic sample Java™ application, is provided to illustrate the basic steps needed to incorporate either a Monthly Calendar View or a Daily Calendar View into the code of your application. The source code of this sample can be found in:
<installdir>/jviews-gantt/samples/calendarView/src/calendarView/CalendarViewExample.java
To incorporate either a Monthly Calendar View or a Daily Calendar View into the code of your application:
1. To instantiate a Monthly or Daily Calendar View and bind it to a Gantt data model, you need to import a minimum of the following packages:
import ilog.views.gantt.*;
import ilog.views.gantt.swing.calendarview.*;
2. Create a Gantt data model that implements the IlvGanttModel interface.
The data model should contain activities to be displayed by the Calendar View. Refer to Connecting to data for detailed information on how to instantiate different Gantt data model implementations and connect to your business data:
IlvGanttModel model = ...
3. Create the Monthly and Daily Calendar View JavaBean instances with the following lines of code:
IlvMonthView monthView = new IlvMonthView();
IlvDayView dayView = new IlvDayView();
4. Bind the Calendar View JavaBeans to the data model to allow them to display the activity information of the data model:
monthView.setGanttModel(model);
dayView.setGanttModel(model);
5. Customize the appearance and behavior of the chart using the IlvMonthView and IlvDayView classes API. For example:
Date startTime = model.getRootActivity().getStartTime();
monthView.setDate(startTime);
dayView.setDate(startTime);
final IlvMonthPanel monthPanel = monthView.getMonthPanel();
monthPanel().addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
    Point point = e.getPoint();
    Calendar calendar = monthPanel.getCellDate(point);
    if (calendar != null) {
      ganttChart.setVisibleTime(IlvTimeUtil.subtract(calendar.getTime(), ganttChart.getVisibleDuration().divide(2)));
    }
  }
}
The code example above creates an interaction; when the mouse is pressed inside a Monthly Calendar View day cell, the Gantt chart is scrolled to center on that date.
6. Add the Calendar View beans to the user interface
The Monthly and Daily Calendar View beans are standard Swing components that can be added to your application user interface in the same way as any other Swing component. For example, if your application uses a standard JFrame with a BorderLayout, you would add the chart to the center of the window like this:
JFrame appWindow = ...
appWindow.getContentPane().add(monthView, BorderLayout.CENTER);

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.