|
30 | 30 | import org.eclipse.swt.graphics.GC; |
31 | 31 | import org.eclipse.swt.graphics.Image; |
32 | 32 | import org.eclipse.swt.graphics.ImageData; |
33 | | -import org.eclipse.swt.graphics.ImageDataProvider; |
34 | 33 | import org.eclipse.swt.graphics.Point; |
35 | 34 | import org.eclipse.swt.graphics.Rectangle; |
36 | 35 | import org.eclipse.swt.layout.FillLayout; |
@@ -62,38 +61,6 @@ public class ClipboardExample { |
62 | 61 | Label status; |
63 | 62 | static final int HSIZE = 100, VSIZE = 60; |
64 | 63 |
|
65 | | -static final class AutoScaleImageDataProvider implements ImageDataProvider { |
66 | | - ImageData imageData; |
67 | | - int currentZoom; |
68 | | - public AutoScaleImageDataProvider (ImageData data) { |
69 | | - this.imageData = data; |
70 | | - this.currentZoom = getDeviceZoom (); |
71 | | - } |
72 | | - |
73 | | - @Override |
74 | | - public ImageData getImageData (int zoom) { |
75 | | - return autoScaleImageData(imageData, zoom, currentZoom); |
76 | | - } |
77 | | - |
78 | | - static ImageData autoScaleImageData (ImageData imageData, int targetZoom, int currentZoom) { |
79 | | - if (imageData == null || targetZoom == currentZoom) return imageData; |
80 | | - float scaleFactor = ((float) targetZoom)/((float) currentZoom); |
81 | | - return imageData.scaledTo (Math.round (imageData.width * scaleFactor), Math.round (imageData.height * scaleFactor)); |
82 | | - } |
83 | | - |
84 | | - static int getDeviceZoom () { |
85 | | - int zoom = 100; |
86 | | - String value = System.getProperty ("org.eclipse.swt.internal.deviceZoom"); |
87 | | - if (value != null) { |
88 | | - try { |
89 | | - zoom = Integer.parseInt(value); |
90 | | - } catch (NumberFormatException e) { |
91 | | - e.printStackTrace(); |
92 | | - } |
93 | | - } |
94 | | - return zoom; |
95 | | - } |
96 | | -} |
97 | 64 |
|
98 | 65 | public static void main( String[] args) { |
99 | 66 | Display display = new Display(); |
@@ -477,7 +444,7 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){ |
477 | 444 | if (copyImage[0] != null) { |
478 | 445 | status.setText(""); |
479 | 446 | // Fetch ImageData at current zoom and save in the clip-board. |
480 | | - clipboard.setContents(new Object[] {copyImage[0].getImageDataAtCurrentZoom()}, new Transfer[] {ImageTransfer.getInstance()}); |
| 447 | + clipboard.setContents(new Object[] {copyImage[0].getImageData()}, new Transfer[] {ImageTransfer.getInstance()}); |
481 | 448 | } else { |
482 | 449 | status.setText("No image to copy"); |
483 | 450 | } |
@@ -541,7 +508,7 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){ |
541 | 508 | } |
542 | 509 | status.setText(""); |
543 | 510 | // Consume the ImageData at current zoom as-is. |
544 | | - pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData)); |
| 511 | + pasteImage[0] = new Image(e.display, imageData); |
545 | 512 | pasteVBar.setEnabled(true); |
546 | 513 | pasteHBar.setEnabled(true); |
547 | 514 | pasteOrigin.x = 0; pasteOrigin.y = 0; |
|
0 commit comments