Skip to content

Commit 3c4dbf0

Browse files
authored
Add SwtKt (and demonstrate that SVG rasterization on mac is low-resolution) (#33)
2 parents 8463eea + 978b5ee commit 3c4dbf0

File tree

10 files changed

+185
-9
lines changed

10 files changed

+185
-9
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# DurianSwt releases
22

33
## [Unreleased]
4+
### Added
5+
- `com.diffplug.common.swt.SwtKt` which is required to instantiate `Point` or `Rectangle` in Kotlin starting with Eclipse 4.36 ([]() responding to [swt#1711](https://github.com/eclipse-platform/eclipse.platform.swt/pull/1711#issuecomment-2715777755))
46

57
## [5.2.0] - 2025-08-28
68
### Added

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ subprojects { subProject ->
2020

2121
ext.maven_name = subProject.name
2222
ext.javadoc_links = [
23-
"https://javadoc.io/doc/com.diffplug.durian/durian-collect/${VER_DURIAN}",
24-
"https://javadoc.io/doc/com.diffplug.durian/durian-concurrent/${VER_DURIAN}",
25-
"https://javadoc.io/doc/com.diffplug.durian/durian-rx/${VER_DURIAN_RX}",
2623
'https://docs.oracle.com/javase/8/docs/api/'
2724
].join(' ')
2825

durian-swt/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ p2deps {
1717
into 'testImplementation', {
1818
p2repo "https://download.eclipse.org/eclipse/updates/$VER_ECLIPSE_PLATFORM/"
1919
install 'org.eclipse.swt'
20+
install 'org.eclipse.swt.svg'
2021
}
2122
}
2223
dependencies {
@@ -61,6 +62,8 @@ test {
6162

6263
// only run the interactive tests
6364
tasks.register('interactiveTest', Test) {
65+
testClassesDirs = sourceSets.test.output.classesDirs
66+
classpath = sourceSets.test.runtimeClasspath
6467
systemProperty 'com.diffplug.test.autoclose.milliseconds', null
6568
useJUnit {
6669
includeCategories 'com.diffplug.common.swt.InteractiveTest'
@@ -69,3 +72,11 @@ tasks.register('interactiveTest', Test) {
6972
}
7073
}
7174
}
75+
76+
tasks.register('runIssue2228', JavaExec) {
77+
classpath = sourceSets.test.runtimeClasspath
78+
mainClass = 'com.diffplug.common.swt.Issue_2228'
79+
if (isMac) {
80+
jvmArgs = ['-XstartOnFirstThread']
81+
}
82+
}

durian-swt/src/main/java/com/diffplug/common/swt/Shells.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Shells private constructor(private val style: Int, private val coat: Coat)
3838
private var title: String? = null
3939
private var image: Image? = null
4040
private var alpha = SWT.DEFAULT
41-
private val size = Point(SWT.DEFAULT, SWT.DEFAULT)
41+
private val size = SwtKt.Point(SWT.DEFAULT, SWT.DEFAULT)
4242
private var positionIncludesTrim = true
4343
private var location: Map.Entry<Corner, Point>? = null
4444
private var dontOpen = false
@@ -86,7 +86,7 @@ class Shells private constructor(private val style: Int, private val coat: Coat)
8686
* Calls [.setLocation] and [.setSize] in one line.
8787
*/
8888
fun setRectangle(rect: Rectangle): Shells {
89-
return setLocation(Point(rect.x, rect.y)).setSize(Point(rect.width, rect.height))
89+
return setLocation(SwtKt.Point(rect.x, rect.y)).setSize(SwtKt.Point(rect.width, rect.height))
9090
}
9191

9292
/**
@@ -290,12 +290,12 @@ class Shells private constructor(private val style: Int, private val coat: Coat)
290290
}
291291
}
292292
val topLeft =
293-
location!!.key.topLeftRequiredFor(Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value)
294-
bounds = Rectangle(topLeft.x, topLeft.y, computedSize.x, computedSize.y)
293+
location!!.key.topLeftRequiredFor(SwtKt.Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value)
294+
bounds = SwtKt.Rectangle(topLeft.x, topLeft.y, computedSize.x, computedSize.y)
295295
} else {
296296
val computedSize = shell.computeSize(size.x, size.y, true)
297297
val topLeft =
298-
location!!.key.topLeftRequiredFor(Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value)
298+
location!!.key.topLeftRequiredFor(SwtKt.Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value)
299299
bounds = shell.computeTrim(topLeft.x, topLeft.y, computedSize.x, computedSize.y)
300300
}
301301
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.common.swt;
17+
18+
import org.eclipse.swt.graphics.Point;
19+
import org.eclipse.swt.graphics.Rectangle;
20+
21+
public class SwtKt {
22+
public static Point Point(int x, int y) {
23+
return new Point(x, y);
24+
}
25+
26+
public static Rectangle Rectangle(int x, int y, int width, int height) {
27+
return new Rectangle(x, y, width, height);
28+
}
29+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.common.swt;
17+
18+
import org.eclipse.jface.layout.GridLayoutFactory;
19+
import org.eclipse.jface.resource.ImageDescriptor;
20+
import org.eclipse.swt.SWT;
21+
import org.eclipse.swt.widgets.Composite;
22+
import org.eclipse.swt.widgets.Display;
23+
import org.eclipse.swt.widgets.Label;
24+
import org.eclipse.swt.widgets.Shell;
25+
import org.junit.Test;
26+
import org.junit.experimental.categories.Category;
27+
28+
@Category(InteractiveTest.class)
29+
public class Issue_2228 {
30+
@Test
31+
public void recreate() {
32+
// testCoat probably takes a title and a lambda that receives the parent Composite
33+
InteractiveTest.testCoat(
34+
"Show the difference between `.svg` and `@x2.png` rendering", Issue_2228::svg_and_png);
35+
}
36+
37+
private static void svg_and_png(Composite parent) {
38+
// two-column grid
39+
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);
40+
41+
// “.svg” label + image
42+
Label svgLabel = new Label(parent, SWT.NONE);
43+
svgLabel.setText(".svg");
44+
45+
Label svgImage = new Label(parent, SWT.NONE);
46+
ImageDescriptor svgDesc = ImageDescriptor.createFromFile(Issue_2228.class, "/issue_2228/strikethrough.svg");
47+
svgImage.setImage(svgDesc.createImage());
48+
49+
// “.png” label + image
50+
Label pngLabel = new Label(parent, SWT.NONE);
51+
pngLabel.setText(".png");
52+
53+
Label pngImage = new Label(parent, SWT.NONE);
54+
ImageDescriptor pngDesc = ImageDescriptor.createFromFile(Issue_2228.class, "/issue_2228/strikethrough.png");
55+
pngImage.setImage(pngDesc.createImage());
56+
}
57+
58+
public static void main(String[] args) {
59+
Display display = Display.getDefault();
60+
Shell shell = new Shell(display, SWT.SHELL_TRIM);
61+
svg_and_png(shell);
62+
shell.open();
63+
while (!shell.isDisposed()) {
64+
if (!display.readAndDispatch()) {
65+
display.sleep();
66+
}
67+
}
68+
display.dispose();
69+
}
70+
}
433 Bytes
Loading
Lines changed: 67 additions & 0 deletions
Loading
725 Bytes
Loading

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ VER_DURIAN=1.2.0
1616
VER_DURIAN_RX=5.0.1
1717
VER_DURIAN_DEBUG=1.1.0
1818
# SWT Dependencies from P2
19-
VER_ECLIPSE_PLATFORM=4.34
19+
VER_ECLIPSE_PLATFORM=4.37
2020
VER_ECLIPSE_PLATFORM_X86=4.7
2121

2222
# Testing

0 commit comments

Comments
 (0)