Import "views" plugins
[deliverable/tracecompass.git] / tmf / org.lttng.scope.tmf2.views.ui / src / org / lttng / scope / tmf2 / views / ui / timeline / widgets / timegraph / LoadingOverlay.java
CommitLineData
c879c4db
AM
1/*
2 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
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
8 */
9
10package org.lttng.scope.tmf2.views.ui.timeline.widgets.timegraph;
11
12import org.eclipse.jdt.annotation.Nullable;
13import org.lttng.scope.tmf2.views.ui.timeline.DebugOptions;
14
15import javafx.animation.FadeTransition;
16import javafx.scene.shape.Rectangle;
17import javafx.util.Duration;
18
19class LoadingOverlay extends Rectangle {
20
21 private final DebugOptions fOpts;
22
23 private @Nullable FadeTransition fCurrentFadeIn;
24 private @Nullable FadeTransition fCurrentFadeOut;
25
26 public LoadingOverlay(DebugOptions opts) {
27 fOpts = opts;
28
29 /*
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.
33 */
34 fillProperty().bind(fOpts.loadingOverlayColor);
35
36 /*
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,
39 * no permanent bind.
40 */
41 setOpacity(fOpts.loadingOverlayTransparentOpacity.get());
42
43 /*
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".
47 */
48 setMouseTransparent(true);
49 }
50
51 public synchronized void fadeIn() {
52 if (fCurrentFadeIn != null) {
53 /* We're already fading in, let it continue. */
54 return;
55 }
56 if (fCurrentFadeOut != null) {
57 /*
58 * Don't use stop() because that would revert to the initial opacity
59 * right away.
60 */
61 fCurrentFadeOut.pause();
62 fCurrentFadeOut = null;
63 }
64
65 double fullOpacity = fOpts.loadingOverlayFullOpacity.get();
66 double fullFadeInDuration = fOpts.loadingOverlayFadeInDuration.get();
67 double startOpacity = getOpacity();
68
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);
74 fadeIn.play();
75 fCurrentFadeIn = fadeIn;
76 }
77
78 public synchronized void fadeOut() {
79 if (fCurrentFadeOut != null) {
80 /* We're already fading out, let it continue. */
81 return;
82 }
83 if (fCurrentFadeIn != null) {
84 fCurrentFadeIn.pause();
85 fCurrentFadeIn = null;
86 }
87
88 double fullOpacity = fOpts.loadingOverlayFullOpacity.get();
89 double transparentOpacity = fOpts.loadingOverlayTransparentOpacity.get();
90 double fullFadeOutDuration = fOpts.loadingOverlayFadeOutDuration.get();
91 double startOpacity = getOpacity();
92
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);
98 fadeOut.play();
99 fCurrentFadeOut = fadeOut;
100 }
101
102}
This page took 0.026446 seconds and 5 git commands to generate.