From c34ab48af76eab013df393cbe2e9fd26d8035179 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Wed, 13 May 2015 15:44:13 -0400 Subject: [PATCH] tmf: Fix calculation of sash weights in performAlign This ensures that the sash width is taken into account when calculating the sash weights when trying to align to a specific offset. There can still be some drifting by 1 pixel, but this is caused by integer trimming in the computations inside SashForm and SashLayout. Change-Id: I742dc99e90e3eb4c9f95b1bac3da286f3187af3e Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/47884 Reviewed-by: Hudson CI --- .../analysis/os/linux/ui/views/cpuusage/CpuUsageView.java | 7 +++---- .../eclipse/tracecompass/tmf/ui/views/TmfChartView.java | 7 +++---- .../tracecompass/tmf/ui/views/histogram/HistogramView.java | 7 +++---- .../tmf/ui/widgets/timegraph/TimeGraphCombo.java | 6 +++--- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java b/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java index 65b46c2c0d..37eea52600 100644 --- a/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java +++ b/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/cpuusage/CpuUsageView.java @@ -203,11 +203,10 @@ public class CpuUsageView extends TmfView implements ITmfTimeAligned { */ @Override public void performAlign(int offset, int width) { - int plotAreaOffset = fXYViewer.getPointAreaOffset(); - int sashOffset = Math.max(1, offset - plotAreaOffset); int total = fSashForm.getBounds().width; - int width1 = (int) (sashOffset / (float) total * 1000); - int width2 = (int) ((total - sashOffset) / (float) total * 1000); + int plotAreaOffset = fXYViewer.getPointAreaOffset(); + int width1 = Math.max(0, offset - plotAreaOffset - fSashForm.getSashWidth()); + int width2 = Math.max(0, total - width1 - fSashForm.getSashWidth()); fSashForm.setWeights(new int[] { width1, width2 }); fSashForm.layout(); diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/TmfChartView.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/TmfChartView.java index 1a019423cc..a90e83205a 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/TmfChartView.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/TmfChartView.java @@ -221,11 +221,10 @@ public abstract class TmfChartView extends TmfView implements ITmfTimeAligned { */ @Override public void performAlign(int offset, int width) { - int plotAreaOffset = fChartViewer.getPointAreaOffset(); - int sashOffset = Math.max(1, offset - plotAreaOffset); int total = fSashForm.getBounds().width; - int width1 = (int) (sashOffset / (float) total * 1000); - int width2 = (int) ((total - sashOffset) / (float) total * 1000); + int plotAreaOffset = fChartViewer.getPointAreaOffset(); + int width1 = Math.max(0, offset - plotAreaOffset - fSashForm.getSashWidth()); + int width2 = Math.max(0, total - width1 - fSashForm.getSashWidth()); fSashForm.setWeights(new int[] { width1, width2 }); fSashForm.layout(); diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramView.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramView.java index 799b2c5a1b..2bb75b8727 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramView.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramView.java @@ -441,11 +441,10 @@ public class HistogramView extends TmfView implements ITmfTimeAligned { */ @Override public void performAlign(int offset, int width) { - int plotAreaOffset = fTimeRangeHistogram.getPointAreaOffset(); - int sashOffset = Math.max(1, offset - plotAreaOffset); int total = fSashForm.getBounds().width; - int width1 = (int) (sashOffset / (float) total * 1000); - int width2 = (int) ((total - sashOffset) / (float) total * 1000); + int plotAreaOffset = fTimeRangeHistogram.getPointAreaOffset(); + int width1 = Math.max(0, offset - plotAreaOffset - fSashForm.getSashWidth()); + int width2 = Math.max(0, total - width1 - fSashForm.getSashWidth()); fSashForm.setWeights(new int[] { width1, width2 }); fSashForm.layout(); diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java index 220b0e16ca..4890cd3f2b 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphCombo.java @@ -1233,9 +1233,9 @@ public class TimeGraphCombo extends Composite { public void performAlign(int offset, int width) { int total = fSashForm.getBounds().width; int timeAxisOffset = Math.min(offset, total); - int sash1Width = (int) (timeAxisOffset / (float) total * 1000); - int sash2Width = (int) ((total - timeAxisOffset) / (float) total * 1000); - fSashForm.setWeights(new int[] { sash1Width, sash2Width }); + int width1 = Math.max(0, timeAxisOffset - fSashForm.getSashWidth()); + int width2 = total - timeAxisOffset; + fSashForm.setWeights(new int[] { width1, width2 }); fSashForm.layout(); Composite composite = fTimeGraphViewer.getTimeAlignedComposite(); -- 2.34.1