Introduction
Rendering
GanttChart ganttChart = new GanttChart(); GraphicsBase<?> graphics = ganttChart.getGraphics(); graphics.setActivityRenderer( Flight.class, // the type of activities that will be rendered GanttLayout.class, // the type of layout where the renderer will be used new FlightRenderer(graphics)); // the actual renderer instance
System Layers
Activities are not the only thing that need to be displayed. There are also the current time ("now"), grid lines, inner lines, agenda / chart lines, and so on. All of these things are rendered by so-called system layers. The graphics control manages two lists of these layers. One list for background layers and one list for foreground layers.
Background layers are drawn "behind" activities, foreground layers are drawn "in front of" activities. Each one of these lists are already pre-populated but can be changed by the application. For more information on the available system layers, please refer to their individual documentation.
System layers can be turned on and off directly via the API of the graphics control. There is a boolean property for each layer. The value of these properties can be set by calling the methods that follow the pattern setShowXYZLayer. System layers that are controlled like this will appear and disappear with a fade in / fade out animation, while calling SystemLayer.setVisible(boolean) directly will be without any animation.
Editing
Two different callbacks are used to control the editing behaviour of activities. The first maps a mouse event / mouse location to anGraphicsBase.EditMode
and can be registered by calling setEditModeCallback(Class, Class, Callback)
. The
second callback is used to determine whether a given editing mode / operation can be applied to an
activity at all. This callback is registered by calling setActivityEditingCallback(Class,
Callback)
. Most applications will only need to work with the second callback and keep the
defaults for the edit mode locations (for example: right edge used to change end time, left edge
used to change start time).Events
Events of typeActivityEvent
are sent whenever the user performs a change inside the graphics view. Applications that want to
receive these events can either call any one of the setOnActivityXYZEvent()
methods or
by adding an event handler directly via addEventHandler(ActionEvent.ACTIVITY_XYZ, ...)
.
Events are fired while the change is being performed and once it has been completed. For this the
ActivityEvent
class lists event types with the two different endings CHANGING and
CHANGED.Hitpoint Detection
The graphics view provides support for finding out information about a given position. Activities can be found by callinggetActivityBoundsAt(double, double)
or getActivityRefAt(double,
double)
. The time at an x-coordinate can be looked up by calling
getTimeAt(double)
. The opposite direction is also available: a location can be found
for a given time by calling getLocation(Instant)
.Context Menu
Context menus can be set on any control in JavaFX but due to the complexitiy of the graphics view it does make sense to provide additional built-in support. By callingsetContextMenuCallback(Callback)
a context menu specific
callback can be registered with the graphics control. This callback will be invoked when the user
triggers the context menu. A callback parameter object (see
GraphicsBase.ContextMenuParameter
) will be passed to the callback already populated
with the most important values that might be relevant for building a context menu.