From 06866428b950ecb297c9b8e81ee170970d6ea2f5 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Tue, 19 Aug 2014 19:06:47 -0400 Subject: Fix SystemTap AbstractChartWithXaxis to handle swtchart 0.9 or lower. Change-Id: I10279e4b5d89e038c197471f6848487a20bb7a5e Reviewed-on: https://git.eclipse.org/r/31933 Tested-by: Hudson CI Reviewed-by: Jeff Johnston Tested-by: Jeff Johnston --- .../ui/charts/AbstractChartWithAxisBuilder.java | 61 +++++++++++++++++----- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'systemtap') diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/charts/AbstractChartWithAxisBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/charts/AbstractChartWithAxisBuilder.java index 1ccf3fa7cc..477bcb9151 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/charts/AbstractChartWithAxisBuilder.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/internal/systemtap/graphing/ui/charts/AbstractChartWithAxisBuilder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 IBM Corporation. + * Copyright (c) 2010, 2014 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Red Hat Inc - modified to handle SWTChart 0.9.0 vs 0.8.0 *******************************************************************************/ package org.eclipse.linuxtools.internal.systemtap.graphing.ui.charts; @@ -18,6 +19,7 @@ import org.eclipse.linuxtools.systemtap.graphing.core.adapters.IAdapter; import org.eclipse.linuxtools.systemtap.graphing.ui.charts.AbstractChartBuilder; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; @@ -105,27 +107,60 @@ public abstract class AbstractChartWithAxisBuilder extends AbstractChartBuilder @Override protected void createChart() { - super.createChart(); + super.createChart(); applyTitleBoundsListener(); chartMouseMoveListener = new ChartWithAxisMouseMoveListener(chart, chart.getPlotArea()); } /** - * After this method is called, the chart's title will (from then on) be centred with the plot area. + * After this method is called, the chart's title will (from then on) be centered with the plot area. * @since 3.0 */ protected void applyTitleBoundsListener() { - titleBoundsPaintListener = new PaintListener() { + ITitle title = chart.getTitle(); + // Underlying SWT Chart implementation changes from the title being a Control to just + // a PaintListener. In the Control class case, we can move it's location to + // center over a PieChart, but in the latter case, we need to alter the title + // with blanks in the PaintListener and have the title paint after it + // once the title has been altered. + if (title instanceof Control) { + titleBoundsPaintListener = new PaintListener() { - @Override - public void paintControl(PaintEvent e) { - Rectangle bounds = chart.getPlotArea().getBounds(); - Control title = (Control) chart.getTitle(); - Rectangle titleBounds = title.getBounds(); - title.setLocation(new Point(bounds.x + (bounds.width - titleBounds.width) / 2, title.getLocation().y)); - } - }; - chart.addPaintListener(titleBoundsPaintListener); + @Override + public void paintControl(PaintEvent e) { + Rectangle bounds = chart.getPlotArea().getBounds(); + Control title = (Control) chart.getTitle(); + Rectangle titleBounds = title.getBounds(); + title.setLocation(new Point(bounds.x + (bounds.width - titleBounds.width) / 2, title.getLocation().y)); + } + }; + chart.addPaintListener(titleBoundsPaintListener); + } else { + // move title paint listener to end + chart.removePaintListener((PaintListener)title); + titleBoundsPaintListener = new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + ITitle title = chart.getTitle(); + Font font = title.getFont(); + Font oldFont = e.gc.getFont(); + e.gc.setFont(font); + Control legend = (Control)chart.getLegend(); + Rectangle legendBounds = legend.getBounds(); + int adjustment = legendBounds.width - 15; + Point blankSize = e.gc.textExtent(" "); //$NON-NLS-1$ + int numBlanks = ((adjustment / blankSize.x) >> 1) << 1; + String text = title.getText().trim(); + for (int i = 0; i < numBlanks; ++i) + text += " "; //$NON-NLS-1$ + e.gc.setFont(oldFont); + title.setText(text); + } + }; + chart.addPaintListener(titleBoundsPaintListener); + chart.addPaintListener((PaintListener)title); + } } /** -- cgit v1.2.3