2 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 package org
.lttng
.scope
.tmf2
.views
.ui
.timeline
.widgets
.timegraph
.toolbar
.nav
;
12 import java
.util
.List
;
13 import java
.util
.stream
.Collectors
;
15 import org
.lttng
.scope
.tmf2
.views
.ui
.timeline
.widgets
.timegraph
.TimeGraphWidget
;
17 import com
.google
.common
.collect
.ImmutableList
;
19 import javafx
.scene
.control
.Button
;
20 import javafx
.scene
.control
.MenuButton
;
21 import javafx
.scene
.control
.RadioMenuItem
;
22 import javafx
.scene
.control
.ToggleGroup
;
23 import javafx
.scene
.image
.ImageView
;
24 import javafx
.scene
.layout
.HBox
;
27 * Class encapsulating the fowards/backwards navigation buttons, with support
28 * for different "modes" of navigation.
30 * @author Alexandre Montplaisir
32 public class NavigationButtons
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 private static class BackButton
extends Button
{
40 private final TimeGraphWidget fViewer
;
42 public BackButton(TimeGraphWidget viewer
, NavigationMode initialNavMode
) {
44 setNavMode(initialNavMode
);
47 public void setNavMode(NavigationMode navMode
) {
48 setGraphic(new ImageView(navMode
.getBackIcon()));
50 navMode
.navigateBackwards(fViewer
);
55 private static class ForwardButton
extends Button
{
57 private final TimeGraphWidget fViewer
;
59 public ForwardButton(TimeGraphWidget viewer
, NavigationMode initialNavMode
) {
61 setNavMode(initialNavMode
);
64 public void setNavMode(NavigationMode navMode
) {
65 setGraphic(new ImageView(navMode
.getForwardIcon()));
67 navMode
.navigateForwards(fViewer
);
72 // ------------------------------------------------------------------------
73 // Pre-defined navigation modes
74 // ------------------------------------------------------------------------
76 private static final List
<NavigationMode
> NAVIGATION_MODES
= ImmutableList
.of(
77 new NavigationModeFollowStateChanges(),
78 new NavigationModeFollowEvents(),
79 new NavigationModeFollowArrows(),
80 new NavigationModeFollowBookmarks());
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
86 private final Button fBackButton
;
87 private final Button fForwardButton
;
88 private final MenuButton fMenuButton
;
91 * Constructor. This will prepare the buttons, which can then be retrieved
92 * with {@link #getBackButton()}, {@link #getForwardButton()} and
93 * {@link #getMenuButton()}.
96 * The viewer to which the buttons will belong
98 public NavigationButtons(TimeGraphWidget viewer
) {
99 List
<NavigationMode
> navModes
= NAVIGATION_MODES
;
100 NavigationMode initialMode
= navModes
.get(0);
102 BackButton backButton
= new BackButton(viewer
, initialMode
);
103 ForwardButton forwardButton
= new ForwardButton(viewer
, initialMode
);
104 MenuButton menuButton
= new MenuButton();
106 ToggleGroup tg
= new ToggleGroup();
107 List
<RadioMenuItem
> items
= NAVIGATION_MODES
.stream()
109 RadioMenuItem item
= new RadioMenuItem();
110 item
.setText(nm
.getModeName());
111 item
.setGraphic(new HBox(new ImageView(nm
.getBackIcon()), new ImageView(nm
.getForwardIcon())));
112 item
.setToggleGroup(tg
);
113 item
.setOnAction(e
-> {
114 backButton
.setNavMode(nm
);
115 forwardButton
.setNavMode(nm
);
117 item
.setDisable(!nm
.isEnabled());
120 .collect(Collectors
.toList());
122 items
.get(0).setSelected(true);
123 menuButton
.getItems().addAll(items
);
125 fBackButton
= backButton
;
126 fForwardButton
= forwardButton
;
127 fMenuButton
= menuButton
;
131 * Get the "back" button.
133 * @return The back button
135 public Button
getBackButton() {
140 * Get the "forward" button.
142 * @return The forward button
144 public Button
getForwardButton() {
145 return fForwardButton
;
149 * Get the drop-down menu button, which allows switching between the
150 * available navigation modes.
152 * @return The drop-down menu button
154 public MenuButton
getMenuButton() {