[eclipse-linuxtools] Fix piechart title centering for swt-chart 0.9 and higher.
Jeff Johnston
jjohnstn at fedoraproject.org
Thu Jul 24 19:39:42 UTC 2014
commit d4f46548a734c97010515d0fb7a68576d9cf2171
Author: Jeff Johnston <jjohnstn at redhat.com>
Date: Thu Jul 24 15:07:29 2014 -0400
Fix piechart title centering for swt-chart 0.9 and higher.
eclipse-linuxtools.spec | 9 +++-
piechart.patch | 98 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+), 2 deletions(-)
---
diff --git a/eclipse-linuxtools.spec b/eclipse-linuxtools.spec
index b2f10a9..177de38 100644
--- a/eclipse-linuxtools.spec
+++ b/eclipse-linuxtools.spec
@@ -5,7 +5,7 @@
Name: %{?scl_prefix}eclipse-linuxtools
Version: 3.0.0
-Release: 3%{?dist}
+Release: 4%{?dist}
Summary: Linux specific Eclipse plugins
License: EPL
@@ -14,12 +14,13 @@ URL: http://eclipse.org/linuxtools/
Source0: http://git.eclipse.org/c/linuxtools/org.eclipse.linuxtools.git/snapshot/org.eclipse.linuxtools-%{version}.tar.bz2
Patch0: disable-libhover-lttng.patch
Patch1: rpm-menu.patch
+Patch2: piechart.patch
BuildRequires: tycho >= 0.20.0-6
BuildRequires: tycho-extras
BuildRequires: %{?scl_prefix}eclipse-cdt
BuildRequires: %{?scl_prefix}eclipse-jdt
-BuildRequires: %{?scl_prefix}swt-chart
+BuildRequires: %{?scl_prefix}swt-chart >= 0.9.0
BuildRequires: %{?scl_prefix}eclipse-remote
BuildRequires: eclipse-license
BuildRequires: maven-clean-plugin
@@ -140,6 +141,7 @@ All test bundles for the Linux Tools project.
%patch0
%patch1 -p1
+%patch2 -p1
%pom_remove_plugin org.jacoco:jacoco-maven-plugin
%pom_disable_module lttng
%pom_disable_module libhover
@@ -305,6 +307,9 @@ popd
%{_javadir}/linuxtools-tests
%changelog
+* Thu Jul 24 2014 Jeff Johnston <jjohnstn at redhat.com> 3.0.0-4
+- Fix piechart title centering for swt-chart 0.9 and higher.
+
* Thu Jul 24 2014 Sami Wagiaalla <swagiaal at redhat.com> 3.0.0-3
- Disable createrepo tests.
diff --git a/piechart.patch b/piechart.patch
new file mode 100644
index 0000000..ef74b1c
--- /dev/null
+++ b/piechart.patch
@@ -0,0 +1,98 @@
+diff -up ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java.fix ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java
+--- ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java.fix 2014-07-10 18:51:13.692736718 -0400
++++ ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChart.java 2014-07-11 16:48:18.143203309 -0400
+@@ -21,6 +21,7 @@ import org.swtchart.Chart;
+ import org.swtchart.IAxis;
+ import org.swtchart.IBarSeries;
+ import org.swtchart.ISeries;
++import org.swtchart.ITitle;
+
+ public class PieChart extends Chart {
+
+@@ -35,7 +36,12 @@ public class PieChart extends Chart {
+ axis.getTitle().setVisible(false);
+ }
+ getPlotArea().setVisible(false);
++ // Make the title draw after the pie-chart itself so we can modify the title
++ // to center over the pie-chart area
++ ITitle title = getTitle();
++ removePaintListener((PaintListener)title);
+ addPaintListener(pieChartPaintListener = new PieChartPaintListener(this));
++ addPaintListener((PaintListener)title);
+ IAxis xAxis = getAxisSet().getXAxis(0);
+ xAxis.enableCategory(true);
+ xAxis.setCategorySeries(new String[]{""}); //$NON-NLS-1$
+diff -up ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java.fix ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java
+--- ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java.fix 2014-07-10 13:14:44.350779682 -0400
++++ ./profiling/org.eclipse.linuxtools.dataviewers.piechart/src/org/eclipse/linuxtools/dataviewers/piechart/PieChartPaintListener.java 2014-07-11 15:04:25.881118928 -0400
+@@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Control;
+ import org.eclipse.swt.widgets.Display;
+ import org.swtchart.IBarSeries;
+ import org.swtchart.ISeries;
++import org.swtchart.ITitle;
+ import org.swtchart.Range;
+
+ public class PieChartPaintListener implements PaintListener {
+@@ -40,6 +41,8 @@ public class PieChartPaintListener imple
+ private int[][] pieSliceAngles;
+ private int pieWidth;
+
++ private String origTitleText;
++
+ /**
+ * Handles drawing and updating of a PieChart, with titles given to its legend and
+ * to each of its pies. Pies will be drawn in the given chart's plot area.
+@@ -70,7 +73,11 @@ public class PieChartPaintListener imple
+ return;
+ }
+ bounds = plotArea.getBounds();
+- setTitleBounds(bounds);
++ // Adjust the title so it centers in the plot area
++ if (origTitleText == null) {
++ origTitleText = chart.getTitle().getText();
++ }
++ adjustTitle(e);
+ int width = bounds.width / seriesValues.length;
+ int x = bounds.x;
+
+@@ -92,10 +99,24 @@ public class PieChartPaintListener imple
+ }
+ }
+
+- private void setTitleBounds(Rectangle bounds) {
+- Control title = (Control) chart.getTitle();
+- Rectangle titleBounds = title.getBounds();
+- title.setLocation(new Point(bounds.x + (bounds.width - titleBounds.width) / 2, title.getLocation().y));
++ // Adjust the title with trailing blanks so it centers in the plot area
++ // rather than for the entire chart view which looks odd when not
++ // centered above the pie-charts themselves.
++ private void adjustTitle(PaintEvent pe) {
++ ITitle title = chart.getTitle();
++ Font font = title.getFont();
++ Font oldFont = pe.gc.getFont();
++ pe.gc.setFont(font);
++ Control legend = (Control)chart.getLegend();
++ Rectangle legendBounds = legend.getBounds();
++ int adjustment = legendBounds.width - 15;
++ Point blankSize = pe.gc.textExtent(" "); //$NON-NLS-1$
++ int numBlanks = ((adjustment / blankSize.x) >> 1) << 1;
++ String text = origTitleText;
++ for (int i = 0; i < numBlanks; ++i)
++ text += " "; //$NON-NLS-1$
++ title.setText(text);
++ pe.gc.setFont(oldFont);
+ }
+
+ private void drawPieChart(PaintEvent e, int chartnum, Rectangle bounds) {
+diff -up ./profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF.fix ./profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF
+--- ./profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF.fix 2014-07-24 15:16:15.210891124 -0400
++++ ./profiling/org.eclipse.linuxtools.dataviewers.piechart/META-INF/MANIFEST.MF 2014-07-24 15:16:41.194324927 -0400
+@@ -6,7 +6,7 @@ Bundle-Version: 2.0.0.qualifier
+ Bundle-Vendor: %bundleProvider
+ Bundle-Localization: plugin
+ Require-Bundle: org.eclipse.ui,
+- org.swtchart
++ org.swtchart;bundle-version="0.9.0"
+ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+ Bundle-ActivationPolicy: lazy
+ Export-Package: org.eclipse.linuxtools.dataviewers.piechart
More information about the scm-commits
mailing list