FlexGanttFX Developer Manual : 3.5 GraphicsBase

Introduction

The graphics view control is responsible for the rendering of activities and system layers, editing of activities, event notifications, hit detection, system layer management, and for context menu support.

Rendering

The graphics control uses the Canvas node and the direct drawing API of it (as opposed to the deferred rendering done via the Scenegraph). This is due to the large data volumes often displayed by Gantt charts. Directly rendering an activity into a bitmap is much faster than updating the scene graph, reapplying CSS styling, laying out nodes. The graphics control uses a pluggable renderer architecture where renderer instances can be mapped to activity types, very similar to the way Swing was doing it. The following code is an example of how to register a custom renderer for a given "Flight" activity and layout type. Please note that the graphics view is capable of displaying activities in three different layouts, hence the layout type must also be passed to the method. 


Renderer Registration
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 an GraphicsBase.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 type ActivityEvent 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 calling getActivityBoundsAt(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 calling setContextMenuCallback(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.  

Attachments:

graphics.png (image/png)