--- old/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/common/DataPageToolkit.java 2019-10-22 09:27:13.309033379 -0400 +++ new/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/common/DataPageToolkit.java 2019-10-22 09:27:13.128030793 -0400 @@ -1,6 +1,7 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * + * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, Red Hat Inc. All rights reserved. + * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The contents of this file are subject to the terms of either the Universal Permissive License @@ -10,17 +11,17 @@ * * Redistribution and use in source and binary forms, with or without modification, are permitted * provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions * and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials provided with * the distribution. - * + * * 3. Neither the name of the copyright holder nor the names of its contributors may be used to * endorse or promote products derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR @@ -139,6 +140,7 @@ import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStore.SelectionStoreEntry; import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStoreActionToolkit; import org.openjdk.jmc.ui.charts.AWTChartToolkit.IColorProvider; +import org.openjdk.jmc.ui.charts.ChartFilterControlBar; import org.openjdk.jmc.ui.charts.IQuantitySeries; import org.openjdk.jmc.ui.charts.ISpanSeries; import org.openjdk.jmc.ui.charts.IXDataRenderer; @@ -155,6 +157,7 @@ import org.openjdk.jmc.ui.handlers.ActionToolkit; import org.openjdk.jmc.ui.handlers.MCContextMenuManager; import org.openjdk.jmc.ui.misc.ChartCanvas; +import org.openjdk.jmc.ui.misc.ChartTextCanvas; import org.openjdk.jmc.ui.misc.CompositeToolkit; import org.openjdk.jmc.ui.misc.DisplayToolkit; import org.openjdk.jmc.ui.misc.FilterEditor; @@ -312,6 +315,10 @@ setChart(canvas, chart, selectionListener, null); } + public static void setChart(ChartTextCanvas canvas, XYChart chart, Consumer selectionListener) { + setChart(canvas, chart, selectionListener, null); + } + public static void setChart( ChartCanvas canvas, XYChart chart, Consumer selectionListener, Consumer> selectRangeConsumer) { @@ -331,6 +338,37 @@ } }); + canvas.setSelectionListener(() -> { + selectionListener.accept(ItemRow.getRangeSelection(chart, JfrAttributes.LIFETIME)); + IQuantity start = chart.getSelectionStart(); + IQuantity end = chart.getSelectionEnd(); + if (selectRangeConsumer != null) { + selectRangeConsumer + .accept(start != null && end != null ? QuantityRange.createWithEnd(start, end) : null); + } + }); + canvas.setChart(chart); + } + + public static void setChart( + ChartTextCanvas canvas, XYChart chart, Consumer selectionListener, + Consumer> selectRangeConsumer) { + IMenuManager contextMenu = canvas.getContextMenu(); + contextMenu.removeAll(); + canvas.getContextMenu().add(new Action(Messages.CHART_ZOOM_TO_SELECTED_RANGE) { + @Override + public void run() { + IQuantity selectionStart = chart.getSelectionStart(); + IQuantity selectionEnd = chart.getSelectionEnd(); + if (selectionStart == null || selectionEnd == null) { + chart.clearVisibleRange(); + } else { + chart.setVisibleRange(selectionStart, selectionEnd); + } + canvas.redrawChartText(); + } + }); + canvas.setSelectionListener(() -> { selectionListener.accept(ItemRow.getRangeSelection(chart, JfrAttributes.LIFETIME)); IQuantity start = chart.getSelectionStart();