@@ -4799,7 +4799,7 @@ public void setBackground (Color color) {
47994799 storeAndApplyOperationForExistingHandle (new SetBackgroundOperation (color ));
48004800}
48014801
4802- private class SetBackgroundOperation extends Operation {
4802+ private class SetBackgroundOperation extends ReplaceableOperation {
48034803 private final Color color ;
48044804
48054805 SetBackgroundOperation (Color color ) {
@@ -5113,7 +5113,7 @@ public void setFont (Font font) {
51135113 storeAndApplyOperationForExistingHandle (new SetFontOperation (font ));
51145114}
51155115
5116- private class SetFontOperation extends Operation {
5116+ private class SetFontOperation extends ReplaceableOperation {
51175117 private final Font font ;
51185118
51195119 SetFontOperation (Font font ) {
@@ -5148,7 +5148,7 @@ public void setForeground (Color color) {
51485148 storeAndApplyOperationForExistingHandle (new SetForegroundOperation (color ));
51495149}
51505150
5151- private class SetForegroundOperation extends Operation {
5151+ private class SetForegroundOperation extends ReplaceableOperation {
51525152 private final Color color ;
51535153
51545154 SetForegroundOperation (Color color ) {
@@ -5302,7 +5302,7 @@ public void setLineAttributes (LineAttributes attributes) {
53025302 storeAndApplyOperationForExistingHandle (new SetLineAttributesOperation (attributes ));
53035303}
53045304
5305- private class SetLineAttributesOperation extends Operation {
5305+ private class SetLineAttributesOperation extends ReplaceableOperation {
53065306 private final LineAttributes attributes ;
53075307
53085308 SetLineAttributesOperation (LineAttributes attributes ) {
@@ -5432,7 +5432,7 @@ public void setLineCap(int cap) {
54325432 storeAndApplyOperationForExistingHandle (new SetLineCapOperation (cap ));
54335433}
54345434
5435- private class SetLineCapOperation extends Operation {
5435+ private class SetLineCapOperation extends ReplaceableOperation {
54365436 private final int cap ;
54375437
54385438 SetLineCapOperation (int cap ) {
@@ -5477,7 +5477,7 @@ public void setLineDash(int[] dashes) {
54775477 storeAndApplyOperationForExistingHandle (new SetLineDashOperation (dashes ));
54785478}
54795479
5480- private class SetLineDashOperation extends Operation {
5480+ private class SetLineDashOperation extends ReplaceableOperation {
54815481 private final int [] dashes ;
54825482
54835483 SetLineDashOperation (int [] dashes ) {
@@ -5529,7 +5529,7 @@ public void setLineJoin(int join) {
55295529 storeAndApplyOperationForExistingHandle (new SetLineJoinOperation (join ));
55305530}
55315531
5532- private class SetLineJoinOperation extends Operation {
5532+ private class SetLineJoinOperation extends ReplaceableOperation {
55335533 private final int join ;
55345534
55355535 SetLineJoinOperation (int join ) {
@@ -5572,7 +5572,7 @@ public void setLineStyle(int lineStyle) {
55725572 storeAndApplyOperationForExistingHandle (new SetLineStyleOperation (lineStyle ));
55735573}
55745574
5575- private class SetLineStyleOperation extends Operation {
5575+ private class SetLineStyleOperation extends ReplaceableOperation {
55765576 private final int lineStyle ;
55775577
55785578 SetLineStyleOperation (int lineStyle ) {
@@ -5626,7 +5626,7 @@ public void setLineWidth(int lineWidth) {
56265626 storeAndApplyOperationForExistingHandle (new SetLineWidthOperation (lineWidth ));
56275627}
56285628
5629- private class SetLineWidthOperation extends Operation {
5629+ private class SetLineWidthOperation extends ReplaceableOperation {
56305630 private final int width ;
56315631
56325632 SetLineWidthOperation (int width ) {
@@ -6042,10 +6042,23 @@ int getZoom() {
60426042}
60436043
60446044private void storeAndApplyOperationForExistingHandle (Operation operation ) {
6045+ removePreviousOperationIfSupercededBy (operation );
60456046 operations .add (operation );
60466047 operation .apply ();
60476048}
60486049
6050+ private void removePreviousOperationIfSupercededBy (Operation operation ) {
6051+ if (operations .isEmpty ()) {
6052+ return ;
6053+ }
6054+ int lastIndex = operations .size () - 1 ;
6055+ Operation lastOperation = operations .get (lastIndex );
6056+ if (lastOperation .canBeReplacedBy (operation )) {
6057+ lastOperation .disposeAll ();
6058+ operations .remove (lastIndex );
6059+ }
6060+ }
6061+
60496062private void createGcHandle (Drawable drawable , GCData newData ) {
60506063 long newHandle = drawable .internal_new_GC (newData );
60516064 if (newHandle == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
@@ -6085,6 +6098,17 @@ void disposeAll() {
60856098 }
60866099 disposables .clear ();
60876100 }
6101+
6102+ boolean canBeReplacedBy (Operation operation ) {
6103+ return false ;
6104+ }
6105+ }
6106+
6107+ private abstract class ReplaceableOperation extends Operation {
6108+ @ Override
6109+ boolean canBeReplacedBy (Operation operation ) {
6110+ return operation .getClass ().equals (this .getClass ());
6111+ }
60886112}
60896113}
60906114
0 commit comments