Chapter 6 : Controllers

Camera control

Camera mouse controller

The CameraMouseController let you control the Camera eye position as follow:

  • Rotate: Left click and drag mouse.
  • Scale: Roll mouse wheel.
  • Z Shift: Right click and drag mouse.
  • Animate: Double click will start the thread controller that rotates the view.

To add a mouse controller, simply call:


You can still concurrently edit the viewpoint by yourself by calling:

chart.getView().setViewpoint(float azimuth, float elevation);

See the Layout chapter for more information about viewpoint value range.

Camera threaded controller

You can add default threaded controllers that enable a continuous cube spin, and that are started or stopped by a mouse double-click. You can also make your own thread controller as follow:

CameraThreadController thread = new CameraThreadController();

Camera keyboard controller

Similar to the mouse controller, you can enable a keyboard controller to perform the following view changes:

  • Rotate: Arrows
  • Scale: Shift + arrows left & right
  • Z Shift: Shift + arrows up & down

To add a keyboard controller, simply call:


Note that the key controllers can only receive key events if the canvas is focused. You need to make a first click on the chart, or to programmatically force the focus to your chart panel to have the key controller enabled.

If you wish to implement your own controller see the Component Injection chapter.

Interaction with drawables

One may also interact with drawables (for example making a selection in a scatter), by using dedicated drawable selectors. There might be one mouse selector implementation per kind of Selectable object. This kind of mouse controllers have the following role:

  • Processing selection according to a selection window.
  • Drawing a selection rectangle.

Once a selector is built, one can still control the camera with mouse by using a DualModeMouseSelector that let you toggle between selection and rotation behavior by holding the C key:

ScatterMouseSelector selector = new ScatterMouseSelector(scatter);
DualModeMouseSelector mouse = new DualModeMouseSelector(chart, selector);

One may also use a MousePickingController that let you enable a different strategy for processing mouse selection. See the chapter “Interactive objects” for more details.