diff --git a/org.mwc.cmap.core/src/org/mwc/cmap/core/ui_support/swt/SWTCanvasAdapter.java b/org.mwc.cmap.core/src/org/mwc/cmap/core/ui_support/swt/SWTCanvasAdapter.java index 59dd6c701d..52281dd544 100644 --- a/org.mwc.cmap.core/src/org/mwc/cmap/core/ui_support/swt/SWTCanvasAdapter.java +++ b/org.mwc.cmap.core/src/org/mwc/cmap/core/ui_support/swt/SWTCanvasAdapter.java @@ -278,6 +278,10 @@ static synchronized public java.awt.BasicStroke getStrokeFor(final int style) { return _myLineStyles.get(new Integer(style)); } + private GC buffer; + + private Image bufferImage; + /** * remember the background color - SWT has trouble remembering it */ @@ -293,6 +297,10 @@ static synchronized public java.awt.BasicStroke getStrokeFor(final int style) { */ private GC _theDest = null; + private GC _destBuffered = null; + + private boolean bufferEnabled = false; + /** * the list of registered painters for this canvas. */ @@ -793,6 +801,7 @@ public void emptyShape(final Shape shape) { @Override public final void endDraw(final Object theVal) { + flushBuffer(); // _theDest = null; // and forget the line width @@ -889,6 +898,20 @@ public void fillShape(final Shape shape) { } } + public void flushBuffer() { + if (bufferEnabled) { + _theDest.dispose(); + _theDest = _destBuffered; + this.drawImage(bufferImage, 0, 1, getSize().width, getSize().height); + + buffer = null; + + bufferImage.dispose(); + + bufferEnabled = false; + } + } + /** * get the current background colour */ @@ -1076,6 +1099,24 @@ public final boolean hasEditor() { return true; } + public void initializeBuffer() { + final String operSys = System.getProperty("os.name").toLowerCase(); + final boolean isMacOs = operSys.contains("mac"); + if (_theDest != null && !bufferEnabled && !isMacOs) { + final Color foregroundColor = _theDest.getForeground(); + + bufferEnabled = true; + final ImageData imageData = new ImageData(getSize().width, getSize().height, 24, new PaletteData(0, 0, 0)); + bufferImage = new Image(_theDest.getDevice(), imageData); + buffer = new GC(bufferImage); + _destBuffered = _theDest; + _theDest = buffer; + setBackgroundColor(_backgroundColor); + + _theDest.setForeground(foregroundColor); + } + } + @Override public final void removePainter(final CanvasType.PaintListener listener) { _thePainters.removeElement(listener); diff --git a/org.mwc.debrief.core/src/org/mwc/debrief/core/actions/DragFeature.java b/org.mwc.debrief.core/src/org/mwc/debrief/core/actions/DragFeature.java index d720db7120..bfefe96356 100644 --- a/org.mwc.debrief.core/src/org/mwc/debrief/core/actions/DragFeature.java +++ b/org.mwc.debrief.core/src/org/mwc/debrief/core/actions/DragFeature.java @@ -24,7 +24,6 @@ import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IViewPart; @@ -439,11 +438,6 @@ private void drawHere(final GC graphics, final WorldVector newVector) { final SWTCanvasAdapter ca = new SWTCanvasAdapter(_myCanvas.getProjection()) { private static final long serialVersionUID = 1L; - @Override - public void drawImage(final Image image, final int x, final int y, final int width, - final int height) { - } - @Override public void drawText(final Font theFont, final String theStr, final int x, final int y) { } @@ -472,6 +466,7 @@ protected void switchAntiAliasOn(final boolean val) { graphics.setBackground(fc); graphics.setLineWidth(2); ca.startDraw(graphics); + ca.initializeBuffer(); // see if it's a painter that also wants to know the error score @@ -486,6 +481,8 @@ protected void switchAntiAliasOn(final boolean val) { if (errorProvider != null) { final CoreTMASegment coreSeg = (CoreTMASegment) segment; coreSeg.paint(ca, errorProvider); + ca.flushBuffer(); + coreSeg.writeMessage(ca); painted = true; } } diff --git a/org.mwc.debrief.legacy/src/Debrief/Wrappers/Track/CoreTMASegment.java b/org.mwc.debrief.legacy/src/Debrief/Wrappers/Track/CoreTMASegment.java index 8aaaa2320e..9e85d5aaf6 100644 --- a/org.mwc.debrief.legacy/src/Debrief/Wrappers/Track/CoreTMASegment.java +++ b/org.mwc.debrief.legacy/src/Debrief/Wrappers/Track/CoreTMASegment.java @@ -73,6 +73,11 @@ abstract public class CoreTMASegment extends TrackSegment implements CanBePlotte */ protected String _dragMsg; + /** + * Position of the Draw + */ + protected WorldLocation _dragPosition; + /** * base constructor - sorts out the obvious * @@ -160,7 +165,7 @@ public void paint(final CanvasType dest, final ITimeVariableProvider errorProvid // ok, is this our first location? if (tmaLastLoc == null) { tmaLastLoc = new WorldLocation(getTrackStart()); - firstEnd = new WorldLocation(tmaLastLoc); + _dragPosition = firstEnd = new WorldLocation(tmaLastLoc); } else { // calculate a new vector final long timeDelta = thisTime - tmaLastDTG; @@ -204,7 +209,7 @@ public void paint(final CanvasType dest, final ITimeVariableProvider errorProvid // ok, plot the 1/2 way message if (_dragMsg != null) { - writeMessage(dest, firstEnd); + // writeMessage(dest, firstEnd); } } @@ -295,6 +300,12 @@ public void setSpeed(final WorldSpeed speed) { */ abstract public void stretch(double rngDegs, final WorldLocation origin); + public void writeMessage(final CanvasType dest) { + if (_dragMsg != null && _dragPosition != null) { + writeMessage(dest, _dragPosition); + } + } + private void writeMessage(final CanvasType dest, final WorldLocation firstEnd) { final Point pt = dest.toScreen(firstEnd);