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
;
12 import org
.eclipse
.jdt
.annotation
.Nullable
;
13 import org
.lttng
.scope
.tmf2
.views
.ui
.timeline
.DebugOptions
;
15 import javafx
.animation
.FadeTransition
;
16 import javafx
.scene
.shape
.Rectangle
;
17 import javafx
.util
.Duration
;
19 class LoadingOverlay
extends Rectangle
{
21 private final DebugOptions fOpts
;
23 private @Nullable FadeTransition fCurrentFadeIn
;
24 private @Nullable FadeTransition fCurrentFadeOut
;
26 public LoadingOverlay(DebugOptions opts
) {
30 * Set the fill (color) by binding the property to the corresponding
31 * config option. That way if the use changes the configured value, this
32 * overlay will follow.
34 fillProperty().bind(fOpts
.loadingOverlayColor
);
37 * The opacity property on the other hand will change through normal
38 * operation of the overlay. We are just setting the initial value here,
41 setOpacity(fOpts
.loadingOverlayTransparentOpacity
.get());
44 * The overlay should not catch mouse events. Note we could use
45 * .setPickOnBounds(false) if we wanted to handle events but also allow
46 * them to go "through".
48 setMouseTransparent(true);
51 public synchronized void fadeIn() {
52 if (fCurrentFadeIn
!= null) {
53 /* We're already fading in, let it continue. */
56 if (fCurrentFadeOut
!= null) {
58 * Don't use stop() because that would revert to the initial opacity
61 fCurrentFadeOut
.pause();
62 fCurrentFadeOut
= null;
65 double fullOpacity
= fOpts
.loadingOverlayFullOpacity
.get();
66 double fullFadeInDuration
= fOpts
.loadingOverlayFadeInDuration
.get();
67 double startOpacity
= getOpacity();
69 /* Do a rule-of-three to determine the duration of fade-in we need. */
70 double neededDuration
= ((fullOpacity
- startOpacity
) / fullOpacity
) * fullFadeInDuration
;
71 FadeTransition fadeIn
= new FadeTransition(new Duration(neededDuration
), this);
72 fadeIn
.setFromValue(startOpacity
);
73 fadeIn
.setToValue(fullOpacity
);
75 fCurrentFadeIn
= fadeIn
;
78 public synchronized void fadeOut() {
79 if (fCurrentFadeOut
!= null) {
80 /* We're already fading out, let it continue. */
83 if (fCurrentFadeIn
!= null) {
84 fCurrentFadeIn
.pause();
85 fCurrentFadeIn
= null;
88 double fullOpacity
= fOpts
.loadingOverlayFullOpacity
.get();
89 double transparentOpacity
= fOpts
.loadingOverlayTransparentOpacity
.get();
90 double fullFadeOutDuration
= fOpts
.loadingOverlayFadeOutDuration
.get();
91 double startOpacity
= getOpacity();
93 /* Do a rule-of-three to determine the duration of fade-in we need. */
94 double neededDuration
= (startOpacity
/ fullOpacity
) * fullFadeOutDuration
;
95 FadeTransition fadeOut
= new FadeTransition(new Duration(neededDuration
), this);
96 fadeOut
.setFromValue(startOpacity
);
97 fadeOut
.setToValue(transparentOpacity
);
99 fCurrentFadeOut
= fadeOut
;