Skip to content

Commit

Permalink
fix(osgi): Remove split package to fix OSGI ClassLoading error
Browse files Browse the repository at this point in the history
Fixes #109
  • Loading branch information
bric3 committed Sep 8, 2022
1 parent ac672fb commit 3f64985
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.github.bric3.fireplace.flamegraph.FrameFontProvider;
import io.github.bric3.fireplace.flamegraph.FrameModel;
import io.github.bric3.fireplace.flamegraph.FrameTextsProvider;
import io.github.bric3.fireplace.flamegraph.ZoomAnimation;
import io.github.bric3.fireplace.flamegraph.animation.ZoomAnimation;
import io.github.bric3.fireplace.ui.BalloonToolTip;
import org.openjdk.jmc.common.util.FormatToolkit;
import org.openjdk.jmc.flightrecorder.stacktrace.tree.Node;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 Datadog, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Fireplace
*
Expand All @@ -9,98 +25,9 @@
*/
package io.github.bric3.fireplace.flamegraph;

import io.github.bric3.fireplace.flamegraph.FlamegraphView.FlamegraphCanvas;
import io.github.bric3.fireplace.flamegraph.FlamegraphView.ZoomAction;
import io.github.bric3.fireplace.flamegraph.FlamegraphView.ZoomableComponent;
import org.pushingpixels.radiance.animation.api.Timeline;
import org.pushingpixels.radiance.animation.api.ease.Sine;
import org.pushingpixels.radiance.animation.api.swing.EventDispatchThreadTimelineCallbackAdapter;

/**
* A zoom action that incorporates animation using <a href="https://github.com/kirill-grouchnikov/radiance/blob/sunshine/docs/animation/animation.md">Radiance Animation</a>
* Zoom animation support (Deprecated, change instead to {@link io.github.bric3.fireplace.flamegraph.animation.ZoomAnimation})
*/
public class ZoomAnimation implements ZoomAction {

private static final long ZOOM_ANIMATION_DURATION = 400L;

/**
* A key for a system property that can be used to disable zoom animations. Used to set the
* initial state of the `animateZoomTransitions` flag.
*/
private static final String ZOOM_ANIMATION_DISABLED_KEY = "fireplace.zoom.animation.disabled";

/**
* A flag controlling whether zoom transitions are animated. Defaults to true unless a
* system property is set to disable it (`-Dfireplace.zoom.animation.disabled=true`).
*/
private boolean animateZoomTransitions = !Boolean.getBoolean(ZOOM_ANIMATION_DISABLED_KEY);

public <T> void install(final FlamegraphView<T> flameGraph) {
flameGraph.overrideZoomAction(this);
}

/**
* Returns the flag that controls whether zoom transitions are animated. The default
* value is {@code true} unless the System property {@code fireplace.zoom.animation.disabled}
* is set to {@code true} (this provides a way to switch off the feature if required).
*
* @return A boolean.
*/
public boolean isAnimateZoomTransitions() {
return animateZoomTransitions;
}

/**
* Sets the flag that controls whether zoom transitions are animated.
*
* @param animateZoomTransitions the new flag value.
*/
public void setAnimateZoomTransitions(boolean animateZoomTransitions) {
this.animateZoomTransitions = animateZoomTransitions;
}

@Override
public boolean zoom(ZoomableComponent zoomableComponent, ZoomTarget zoomTarget) {
System.getLogger(FlamegraphCanvas.class.getName()).log(System.Logger.Level.DEBUG, () -> "zoom to " + zoomTarget);
if (!isAnimateZoomTransitions()) {
return false;
}
int startW = zoomableComponent.getWidth();
int startH = zoomableComponent.getHeight();
double deltaW = zoomTarget.width - startW;
double deltaH = zoomTarget.height - startH;

int startX = zoomableComponent.getLocation().x;
int startY = zoomableComponent.getLocation().y;
double deltaX = zoomTarget.x - startX;
double deltaY = zoomTarget.y - startY;


Timeline.builder()
.setDuration(ZOOM_ANIMATION_DURATION)
.setEase(new Sine())
.addCallback(new EventDispatchThreadTimelineCallbackAdapter() {
@Override
public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) {
if (newState.equals(Timeline.TimelineState.DONE)) {
// throw in a final update to the target position, because the last pulse
// might not have reached exactly timelinePosition = 1.0...
zoomableComponent.zoom(zoomTarget);
}
}

@Override
public void onTimelinePulse(float durationFraction, float timelinePosition) {
zoomableComponent.zoom(new ZoomTarget(
startX + (int) (timelinePosition * deltaX),
startY + (int) (timelinePosition * deltaY),
(int) (startW + timelinePosition * deltaW),
(int) (startH + timelinePosition * deltaH)
));
}
})
.build()
.playSkipping(3L);
return true;
}
@Deprecated
public class ZoomAnimation extends io.github.bric3.fireplace.flamegraph.animation.ZoomAnimation {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Fireplace
*
* Copyright (c) 2021, Today - Brice Dutheil
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package io.github.bric3.fireplace.flamegraph.animation;

import io.github.bric3.fireplace.flamegraph.FlamegraphView;
import io.github.bric3.fireplace.flamegraph.FlamegraphView.ZoomAction;
import io.github.bric3.fireplace.flamegraph.FlamegraphView.ZoomableComponent;
import io.github.bric3.fireplace.flamegraph.ZoomTarget;
import org.pushingpixels.radiance.animation.api.Timeline;
import org.pushingpixels.radiance.animation.api.ease.Sine;
import org.pushingpixels.radiance.animation.api.swing.EventDispatchThreadTimelineCallbackAdapter;

/**
* A zoom action that incorporates animation using <a href="https://github.com/kirill-grouchnikov/radiance/blob/sunshine/docs/animation/animation.md">Radiance Animation</a>
*/
public class ZoomAnimation implements ZoomAction {

private static final long ZOOM_ANIMATION_DURATION = 400L;

/**
* A key for a system property that can be used to disable zoom animations. Used to set the
* initial state of the `animateZoomTransitions` flag.
*/
private static final String ZOOM_ANIMATION_DISABLED_KEY = "fireplace.zoom.animation.disabled";

/**
* A flag controlling whether zoom transitions are animated. Defaults to true unless a
* system property is set to disable it (`-Dfireplace.zoom.animation.disabled=true`).
*/
private boolean animateZoomTransitions = !Boolean.getBoolean(ZOOM_ANIMATION_DISABLED_KEY);

public <T> void install(final FlamegraphView<T> flameGraph) {
flameGraph.overrideZoomAction(this);
}

/**
* Returns the flag that controls whether zoom transitions are animated. The default
* value is {@code true} unless the System property {@code fireplace.zoom.animation.disabled}
* is set to {@code true} (this provides a way to switch off the feature if required).
*
* @return A boolean.
*/
public boolean isAnimateZoomTransitions() {
return animateZoomTransitions;
}

/**
* Sets the flag that controls whether zoom transitions are animated.
*
* @param animateZoomTransitions the new flag value.
*/
public void setAnimateZoomTransitions(boolean animateZoomTransitions) {
this.animateZoomTransitions = animateZoomTransitions;
}

@Override
public boolean zoom(ZoomableComponent zoomableComponent, ZoomTarget zoomTarget) {
System.getLogger(zoomableComponent.getClass().getName()).log(System.Logger.Level.DEBUG, () -> "zoom to " + zoomTarget);
if (!isAnimateZoomTransitions()) {
return false;
}
int startW = zoomableComponent.getWidth();
int startH = zoomableComponent.getHeight();
double deltaW = zoomTarget.width - startW;
double deltaH = zoomTarget.height - startH;

int startX = zoomableComponent.getLocation().x;
int startY = zoomableComponent.getLocation().y;
double deltaX = zoomTarget.x - startX;
double deltaY = zoomTarget.y - startY;


Timeline.builder()
.setDuration(ZOOM_ANIMATION_DURATION)
.setEase(new Sine())
.addCallback(new EventDispatchThreadTimelineCallbackAdapter() {
@Override
public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) {
if (newState.equals(Timeline.TimelineState.DONE)) {
// throw in a final update to the target position, because the last pulse
// might not have reached exactly timelinePosition = 1.0...
zoomableComponent.zoom(zoomTarget);
}
}

@Override
public void onTimelinePulse(float durationFraction, float timelinePosition) {
zoomableComponent.zoom(new ZoomTarget(
startX + (int) (timelinePosition * deltaX),
startY + (int) (timelinePosition * deltaY),
(int) (startW + timelinePosition * deltaW),
(int) (startH + timelinePosition * deltaH)
));
}
})
.build()
.playSkipping(3L);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import io.github.bric3.fireplace.core.ui.Colors;
import io.github.bric3.fireplace.core.ui.Colors.Palette;
import io.github.bric3.fireplace.flamegraph.*;
import io.github.bric3.fireplace.flamegraph.animation.ZoomAnimation;
import io.github.bric3.fireplace.swt_awt.EmbeddingComposite;
import io.github.bric3.fireplace.swt_awt.SWTKeyLogger;
import io.github.bric3.fireplace.swt_awt.SWT_AWTBridge;
import org.eclipse.jface.window.DefaultToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
Expand Down

0 comments on commit 3f64985

Please sign in to comment.