Skip to content

Commit d71d639

Browse files
PanamaGL SWT support
1 parent 5605920 commit d71d639

27 files changed

Lines changed: 1883 additions & 5 deletions

File tree

jzy3d-core-swt/pom.xml

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
22
<modelVersion>4.0.0</modelVersion>
33

44
<parent>
@@ -18,5 +18,105 @@
1818
<version>${project.version}</version>
1919
</dependency>
2020

21+
<!-- The org.eclipse.platform::org.eclipse.swt artifact is only an empty
22+
hull for SWT (the jar does not contain any class-files). The actual class
23+
files are contained in platform-specific artifacts. The OS-specific artifact
24+
is selected by the profiles below. -->
25+
<dependency>
26+
<groupId>org.eclipse.platform</groupId>
27+
<artifactId>org.eclipse.swt</artifactId>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.eclipse.platform</groupId>
32+
<artifactId>org.eclipse.jface</artifactId>
33+
</dependency>
34+
2135
</dependencies>
36+
37+
<profiles>
38+
<!-- macOS requires -XstartOnFirstThread for SWT Display creation in tests. -->
39+
<profile>
40+
<id>mac-surefire</id>
41+
<activation>
42+
<os>
43+
<family>mac</family>
44+
</os>
45+
</activation>
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-surefire-plugin</artifactId>
51+
<configuration>
52+
<argLine>-XstartOnFirstThread</argLine>
53+
</configuration>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
</profile>
58+
59+
<profile>
60+
<id>MacOS x86_64</id>
61+
<activation>
62+
<os>
63+
<family>mac</family>
64+
<arch>x86_64</arch>
65+
</os>
66+
</activation>
67+
<dependencies>
68+
<dependency>
69+
<groupId>org.eclipse.platform</groupId>
70+
<artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
71+
</dependency>
72+
</dependencies>
73+
</profile>
74+
75+
<profile>
76+
<id>MacOS Aarch64</id>
77+
<activation>
78+
<os>
79+
<family>mac</family>
80+
<arch>aarch64</arch>
81+
</os>
82+
</activation>
83+
<dependencies>
84+
<dependency>
85+
<groupId>org.eclipse.platform</groupId>
86+
<artifactId>org.eclipse.swt.cocoa.macosx.aarch64</artifactId>
87+
</dependency>
88+
</dependencies>
89+
</profile>
90+
91+
<profile>
92+
<id>Windows</id>
93+
<activation>
94+
<os>
95+
<family>Windows</family>
96+
</os>
97+
</activation>
98+
<dependencies>
99+
<dependency>
100+
<groupId>org.eclipse.platform</groupId>
101+
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
102+
</dependency>
103+
</dependencies>
104+
</profile>
105+
106+
<profile>
107+
<id>Unix</id>
108+
<activation>
109+
<os>
110+
<family>unix</family>
111+
</os>
112+
</activation>
113+
<dependencies>
114+
<dependency>
115+
<groupId>org.eclipse.platform</groupId>
116+
<artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId>
117+
</dependency>
118+
</dependencies>
119+
</profile>
120+
</profiles>
121+
22122
</project>

jzy3d-native-jogl-swt/src/main/java/org/jzy3d/analysis/SWTAnalysisLauncher.java renamed to jzy3d-core-swt/src/main/java/org/jzy3d/analysis/SWTAnalysisLauncher.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
import org.eclipse.swt.widgets.Shell;
77
import org.jzy3d.bridge.swt.SWT_AWT_Bridge;
88
import org.jzy3d.chart.Chart;
9-
import org.jzy3d.chart.Settings;
109

1110
public class SWTAnalysisLauncher extends AnalysisLauncher {
1211

1312
public static void openStaticSWT(IAnalysis demo) throws Exception {
14-
Settings.getInstance().setHardwareAccelerated(true);
1513
Chart chart = demo.getChart();
1614

1715
Display display = new Display();

jzy3d-native-jogl-swt/src/main/java/org/jzy3d/bridge/swt/FrameSWTBridge.java renamed to jzy3d-core-swt/src/main/java/org/jzy3d/bridge/swt/FrameSWTBridge.java

File renamed without changes.

jzy3d-native-jogl-swt/src/main/java/org/jzy3d/bridge/swt/SWT_AWT_Bridge.java renamed to jzy3d-core-swt/src/main/java/org/jzy3d/bridge/swt/SWT_AWT_Bridge.java

File renamed without changes.

jzy3d-native-jogl-swt/src/main/java/org/jzy3d/bridge/swt/SWT_AWT_ImageConverter.java renamed to jzy3d-core-swt/src/main/java/org/jzy3d/bridge/swt/SWT_AWT_ImageConverter.java

File renamed without changes.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package org.jzy3d.chart.controllers.keyboard.camera;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.events.KeyEvent;
5+
import org.eclipse.swt.events.KeyListener;
6+
import org.jzy3d.chart.Chart;
7+
import org.jzy3d.chart.controllers.RateLimiter;
8+
import org.jzy3d.chart.controllers.camera.AbstractCameraController;
9+
import org.jzy3d.maths.Coord2d;
10+
11+
/**
12+
* SWT camera key controller, mirroring {@code AWTCameraKeyController}.
13+
*
14+
* Arrow keys rotate; SHIFT + arrows zoom/shift.
15+
*/
16+
public class SWTCameraKeyController extends AbstractCameraController
17+
implements KeyListener, ICameraKeyController {
18+
19+
protected RateLimiter rateLimiter;
20+
21+
public SWTCameraKeyController() {}
22+
23+
public SWTCameraKeyController(Chart chart) {
24+
register(chart);
25+
}
26+
27+
@Override
28+
public void register(Chart chart) {
29+
super.register(chart);
30+
chart.getCanvas().addKeyController(this);
31+
}
32+
33+
@Override
34+
public void dispose() {
35+
getChart().getCanvas().removeKeyController(this);
36+
super.dispose();
37+
}
38+
39+
@Override
40+
public void keyPressed(KeyEvent e) {
41+
if (rateLimiter != null && !rateLimiter.rateLimitCheck()) {
42+
return;
43+
}
44+
45+
boolean shiftDown = (e.stateMask & SWT.SHIFT) != 0;
46+
47+
if (!shiftDown) {
48+
Coord2d move = new Coord2d();
49+
float offset = 0.1f;
50+
switch (e.keyCode) {
51+
case SWT.ARROW_DOWN:
52+
move.y = move.y + offset;
53+
rotate(move);
54+
break;
55+
case SWT.ARROW_UP:
56+
move.y = move.y - offset;
57+
rotate(move);
58+
break;
59+
case SWT.ARROW_LEFT:
60+
move.x = move.x - offset;
61+
rotate(move);
62+
break;
63+
case SWT.ARROW_RIGHT:
64+
move.x = move.x + offset;
65+
rotate(move);
66+
break;
67+
default:
68+
break;
69+
}
70+
} else {
71+
switch (e.keyCode) {
72+
case SWT.ARROW_DOWN:
73+
shift(0.1f);
74+
break;
75+
case SWT.ARROW_UP:
76+
shift(-0.1f);
77+
break;
78+
case SWT.ARROW_LEFT:
79+
zoomZ(0.9f);
80+
break;
81+
case SWT.ARROW_RIGHT:
82+
zoomZ(1.1f);
83+
break;
84+
default:
85+
break;
86+
}
87+
}
88+
}
89+
90+
@Override
91+
public void keyReleased(KeyEvent e) {}
92+
93+
public RateLimiter getRateLimiter() {
94+
return rateLimiter;
95+
}
96+
97+
public void setRateLimiter(RateLimiter rateLimiter) {
98+
this.rateLimiter = rateLimiter;
99+
}
100+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.jzy3d.chart.controllers.keyboard.screenshot;
2+
3+
import java.io.IOException;
4+
import org.eclipse.swt.events.KeyEvent;
5+
import org.eclipse.swt.events.KeyListener;
6+
import org.jzy3d.chart.Chart;
7+
8+
/**
9+
* Saves a screenshot in PNG format once the {@code S} key is pressed.
10+
*
11+
* SWT counterpart of {@code AWTScreenshotKeyController}.
12+
*/
13+
public class SWTScreenshotKeyController extends AbstractScreenshotKeyController
14+
implements KeyListener, IScreenshotKeyController {
15+
16+
public SWTScreenshotKeyController(Chart chart, String outputFile) {
17+
super(chart, outputFile);
18+
}
19+
20+
@Override
21+
public void keyPressed(KeyEvent e) {
22+
// SWT does not have keyTyped — match the AWT controller by triggering on the lowercase 's'
23+
// character so the behavior is identical.
24+
if (e.character == 's') {
25+
try {
26+
screenshot(chart, outputFile);
27+
fireDone(outputFile);
28+
} catch (IOException ex) {
29+
fireError(outputFile, ex);
30+
}
31+
}
32+
}
33+
34+
@Override
35+
public void keyReleased(KeyEvent e) {}
36+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.jzy3d.chart.controllers.mouse;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.events.MouseEvent;
5+
6+
/**
7+
* Utility helpers mirroring {@code AWTMouseUtilities} for SWT mouse events.
8+
*
9+
* SWT button numbering: {@code event.button} 1 = left, 2 = middle, 3 = right. While dragging,
10+
* SWT does not re-populate {@code event.button}; the held buttons are reported in
11+
* {@code event.stateMask} via the {@link SWT#BUTTON1}/{@link SWT#BUTTON3} bits.
12+
*/
13+
public class SWTMouseUtilities {
14+
15+
public static boolean isDoubleClick(MouseEvent e) {
16+
return e.count > 1;
17+
}
18+
19+
public static boolean isLeftDown(MouseEvent e) {
20+
return (e.stateMask & SWT.BUTTON1) != 0 || e.button == 1;
21+
}
22+
23+
public static boolean isRightDown(MouseEvent e) {
24+
return (e.stateMask & SWT.BUTTON3) != 0 || e.button == 3;
25+
}
26+
27+
public static boolean isRightClick(MouseEvent e) {
28+
return e.button == 3;
29+
}
30+
}

0 commit comments

Comments
 (0)