Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2021-03-17 15:23:26 +0000
committerLars Vogel2021-03-24 11:25:52 +0000
commite534a45caef77d7c4d52cb1473501c0bc2252ea6 (patch)
tree6fc515b555466ddf88fa714be08751ed0307ea09
parentd922d8e3b14033d43a40f14255f6c94a0cf2c3c0 (diff)
downloadeclipse.platform.team-e534a45caef77d7c4d52cb1473501c0bc2252ea6.tar.gz
eclipse.platform.team-e534a45caef77d7c4d52cb1473501c0bc2252ea6.tar.xz
eclipse.platform.team-e534a45caef77d7c4d52cb1473501c0bc2252ea6.zip
Bug 571954 - Replace obsolete BufferedCanvas with standard SWT BufferingI20210329-1800I20210329-0200I20210328-1800I20210327-1800
SWT offers a standard way of handling double buffering hence we can replace the custom implementation with a default SWT canvas. Windows requires the double-buffering flag for that the other platforms do that automatically. Change-Id: I799d32c3cf40fbfaac94ab0e5506c8e777fe1ae7 Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java76
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedCanvas.java94
2 files changed, 47 insertions, 123 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 45bdb295a..f650d9cc3 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -46,7 +46,6 @@ import org.eclipse.compare.ISharedDocumentAdapter;
import org.eclipse.compare.IStreamContentAccessor;
import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.SharedDocumentAdapter;
-import org.eclipse.compare.internal.BufferedCanvas;
import org.eclipse.compare.internal.ChangeCompareFilterPropertyAction;
import org.eclipse.compare.internal.ChangePropertyAction;
import org.eclipse.compare.internal.CompareContentViewerSwitchingPane;
@@ -431,9 +430,9 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
// SWT widgets
- private BufferedCanvas fAncestorCanvas;
- private BufferedCanvas fLeftCanvas;
- private BufferedCanvas fRightCanvas;
+ private Canvas fAncestorCanvas;
+ private Canvas fLeftCanvas;
+ private Canvas fRightCanvas;
private Canvas fScrollCanvas;
private ScrollBar fVScrollBar;
private Canvas fBirdsEyeCanvas;
@@ -2036,12 +2035,15 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
// 1st row
if (fMarginWidth > 0) {
- fAncestorCanvas= new BufferedCanvas(composite, SWT.NONE) {
+ fAncestorCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
+ fAncestorCanvas.addPaintListener(new PaintListener() {
+
@Override
- public void doPaint(GC gc) {
- paintSides(gc, fAncestor, fAncestorCanvas, false);
+ public void paintControl(PaintEvent e) {
+ paintSides(e.gc, fAncestor, fAncestorCanvas, false);
+
}
- };
+ });
fAncestorCanvas.addMouseListener(
new MouseAdapter() {
@Override
@@ -2069,12 +2071,15 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
// 2nd row
if (fMarginWidth > 0) {
- fLeftCanvas= new BufferedCanvas(composite, SWT.NONE) {
+ fLeftCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
+ fLeftCanvas.addPaintListener(new PaintListener() {
+
@Override
- public void doPaint(GC gc) {
- paintSides(gc, fLeft, fLeftCanvas, false);
+ public void paintControl(PaintEvent e) {
+ paintSides(e.gc, fLeft, fLeftCanvas, false);
+
}
- };
+ });
fLeftCanvas.addMouseListener(
new MouseAdapter() {
@Override
@@ -2129,12 +2134,15 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
hsynchViewport(fRight.getSourceViewer(), fAncestor.getSourceViewer(), fLeft.getSourceViewer());
if (fMarginWidth > 0) {
- fRightCanvas= new BufferedCanvas(composite, SWT.NONE) {
+ fRightCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
+ fRightCanvas.addPaintListener(new PaintListener() {
+
@Override
- public void doPaint(GC gc) {
- paintSides(gc, fRight, fRightCanvas, fSynchronizedScrolling);
+ public void paintControl(PaintEvent e) {
+ paintSides(e.gc, fRight, fRightCanvas, fSynchronizedScrolling);
+
}
- };
+ });
fRightCanvas.addMouseListener(
new MouseAdapter() {
@Override
@@ -2159,13 +2167,17 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
);
- fBirdsEyeCanvas= new BufferedCanvas(composite, SWT.NONE) {
+ fBirdsEyeCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
+ fBirdsEyeCanvas.addPaintListener(new PaintListener() {
+
@Override
- public void doPaint(GC gc) {
+ public void paintControl(PaintEvent e) {
updateVScrollBar(); // Update scroll bar here as initially viewport height is wrong
- paintBirdsEyeView(this, gc);
+ paintBirdsEyeView((Canvas) e.widget, e.gc);
+
}
- };
+ });
+
fBirdsEyeCanvas.addMouseListener(
new MouseAdapter() {
@Override
@@ -2441,12 +2453,18 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
@Override
protected final Control createCenterControl(Composite parent) {
if (fSynchronizedScrolling) {
- final Canvas canvas= new BufferedCanvas(parent, SWT.NONE) {
+
+
+ final Canvas canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED);
+
+ canvas.addPaintListener(new PaintListener() {
+
@Override
- public void doPaint(GC gc) {
- paintCenter(this, gc);
+ public void paintControl(PaintEvent e) {
+ paintCenter((Canvas) e.widget, e.gc);
+
}
- };
+ });
new HoverResizer(canvas, HORIZONTAL);
Cursor normalCursor= canvas.getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
@@ -5136,17 +5154,17 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
fInScrolling= false;
if (isThreeWay() && fAncestorCanvas != null)
- fAncestorCanvas.repaint();
+ fAncestorCanvas.redraw();
if (fLeftCanvas != null)
- fLeftCanvas.repaint();
+ fLeftCanvas.redraw();
Control center= getCenterControl();
- if (center instanceof BufferedCanvas)
- ((BufferedCanvas) center).repaint();
+ if (center instanceof Canvas)
+ ((Canvas) center).redraw();
if (fRightCanvas != null)
- fRightCanvas.repaint();
+ fRightCanvas.redraw();
}
/*
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedCanvas.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedCanvas.java
deleted file mode 100644
index 4b9fb26cd..000000000
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedCanvas.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.internal;
-
-import org.eclipse.jface.util.Util;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-
-/**
- * A Canvas which reduces flicker by drawing in an off screen buffer.
- */
-public abstract class BufferedCanvas extends Canvas {
-
- /** The drawable for double buffering */
- Image fBuffer;
-
- public BufferedCanvas(Composite parent, int flags) {
- super(parent, flags | SWT.NO_BACKGROUND);
-
- addPaintListener(
- event -> doubleBufferPaint(event.gc)
- );
-
- addDisposeListener(
- e -> {
- if (fBuffer != null) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
- );
- }
-
- public void repaint() {
- if (!isDisposed()) {
- GC gc= new GC(this);
- doubleBufferPaint(gc);
- gc.dispose();
- if (Util.isGtk()) {
- redraw();
- }
- }
- }
-
- /*
- * Double buffer drawing.
- */
- void doubleBufferPaint(GC dest) {
-
- Point size= getSize();
-
- if (size.x <= 1 || size.y <= 1) // we test for <= 1 because on X11 controls have initial size 1,1
- return;
-
- if (fBuffer != null) {
- Rectangle r= fBuffer.getBounds();
- if (r.width != size.x || r.height != size.y) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
- if (fBuffer == null)
- fBuffer= new Image(getDisplay(), size.x, size.y);
-
- GC gc= new GC(fBuffer);
- try {
- gc.setBackground(getBackground());
- gc.fillRectangle(0, 0, size.x, size.y);
- doPaint(gc);
- } finally {
- gc.dispose();
- }
-
- dest.drawImage(fBuffer, 0, 0);
- }
-
- abstract public void doPaint(GC gc);
-}

Back to the top