Skip to content

Commit b1726ba

Browse files
committed
Merge remote-tracking branch 'origin/dev/1.9.4_add_jl_web_engine' into dev/1.9.5_jpms
# Conflicts: # pom.xml # src/main/java/io/github/makbn/jlmap/JLMapView.java # src/main/java/module-info.java
2 parents 3949cfd + b289602 commit b1726ba

File tree

14 files changed

+166
-140
lines changed

14 files changed

+166
-140
lines changed

pom.xml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<maven.compiler.target>17</maven.compiler.target>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<javafx.version>19.0.2.1</javafx.version>
18+
<lombok.version>1.18.34</lombok.version>
1819
</properties>
1920

2021
<developers>
@@ -36,7 +37,7 @@
3637
<build>
3738
<plugins>
3839
<plugin>
39-
<version>3.11.0</version>
40+
<version>3.13.0</version>
4041
<groupId>org.apache.maven.plugins</groupId>
4142
<artifactId>maven-compiler-plugin</artifactId>
4243
<configuration>
@@ -52,9 +53,10 @@
5253
<path>
5354
<groupId>org.projectlombok</groupId>
5455
<artifactId>lombok</artifactId>
55-
<version>1.18.28</version>
56+
<version>${lombok.version}</version>
5657
</path>
5758
</annotationProcessorPaths>
59+
<useModulePath>true</useModulePath>
5860
</configuration>
5961
</plugin>
6062
<plugin>
@@ -116,6 +118,8 @@
116118
</configuration>
117119
</plugin>
118120
</plugins>
121+
<sourceDirectory>src/main/java</sourceDirectory>
122+
<testSourceDirectory>src/test/java</testSourceDirectory>
119123
</build>
120124

121125
<dependencyManagement>
@@ -159,18 +163,13 @@
159163
<dependency>
160164
<groupId>org.projectlombok</groupId>
161165
<artifactId>lombok</artifactId>
162-
<version>1.18.28</version>
166+
<version>${lombok.version}</version>
163167
<scope>provided</scope>
164168
</dependency>
165169
<dependency>
166-
<groupId>org.apache.logging.log4j</groupId>
167-
<artifactId>log4j-api</artifactId>
168-
<version>2.20.0</version>
169-
</dependency>
170-
<dependency>
171-
<groupId>org.apache.logging.log4j</groupId>
172-
<artifactId>log4j-core</artifactId>
173-
<version>2.20.0</version>
170+
<groupId>org.slf4j</groupId>
171+
<artifactId>slf4j-api</artifactId>
172+
<version>2.0.16</version>
174173
</dependency>
175174
<dependency>
176175
<groupId>com.google.code.gson</groupId>

src/main/java/io/github/makbn/jlmap/JLMapCallbackHandler.java

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,38 @@
99
import io.github.makbn.jlmap.model.*;
1010
import lombok.AccessLevel;
1111
import lombok.experimental.FieldDefaults;
12-
import lombok.extern.log4j.Log4j2;
12+
import lombok.extern.slf4j.Slf4j;
1313

1414
import java.io.Serializable;
1515
import java.util.HashMap;
16+
import java.util.Optional;
1617

1718
/**
1819
* @author Mehdi Akbarian Rastaghi (@makbn)
1920
*/
20-
@Log4j2
21+
@Slf4j
2122
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
2223
public class JLMapCallbackHandler implements Serializable {
23-
24-
transient JLMapView mapView;
24+
private static final String FUNCTION_MOVE = "move";
25+
private static final String FUNCTION_CLICK = "click";
26+
private static final String FUNCTION_ZOOM = "zoom";
27+
private static final String FUNCTION_MOVE_START = "movestart";
28+
private static final String FUNCTION_MOVE_END = "moveend";
29+
transient OnJLMapViewListener listener;
2530
transient HashMap<Class<? extends JLObject<?>>, HashMap<Integer, JLObject<?>>> jlObjects;
2631
transient Gson gson;
2732
HashMap<String, Class<? extends JLObject<?>>[]> classMap;
2833

29-
public JLMapCallbackHandler(JLMapView mapView) {
30-
this.mapView = mapView;
34+
public JLMapCallbackHandler(OnJLMapViewListener listener) {
35+
this.listener = listener;
3136
this.jlObjects = new HashMap<>();
3237
this.gson = new Gson();
3338
this.classMap = new HashMap<>();
3439
initClassMap();
3540
}
41+
3642
@SuppressWarnings("unchecked")
3743
private void initClassMap() {
38-
3944
classMap.put("marker", new Class[]{JLMarker.class});
4045
classMap.put("marker_circle", new Class[]{JLCircleMarker.class});
4146
classMap.put("polyline", new Class[]{JLPolyline.class, JLMultiPolyline.class});
@@ -50,7 +55,7 @@ private void initClassMap() {
5055
* @param param4 additional param
5156
* @param param5 additional param
5257
*/
53-
@SuppressWarnings("unchecked")
58+
@SuppressWarnings("all")
5459
public void functionCalled(String functionName, Object param1, Object param2,
5560
Object param3, Object param4, Object param5) {
5661
log.debug(String.format("function: %s \tparam1: %s \tparam2: %s " +
@@ -87,70 +92,69 @@ public void functionCalled(String functionName, Object param1, Object param2,
8792
return;
8893
}
8994
}
90-
} else if (param1.equals("main_map")
91-
&& mapView.getMapListener().isPresent()) {
95+
} else if (param1.equals("main_map") && getMapListener().isPresent()) {
9296
switch (functionName) {
93-
case "move" -> mapView.getMapListener()
97+
case FUNCTION_MOVE -> getMapListener()
9498
.get()
9599
.onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE,
96100
gson.fromJson(String.valueOf(param4), JLLatLng.class),
97101
gson.fromJson(String.valueOf(param5), JLBounds.class),
98102
Integer.parseInt(String.valueOf(param3))));
99-
case "movestart" -> mapView.getMapListener()
103+
case FUNCTION_MOVE_START -> getMapListener()
100104
.get()
101105
.onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE_START,
102106
gson.fromJson(String.valueOf(param4), JLLatLng.class),
103107
gson.fromJson(String.valueOf(param5), JLBounds.class),
104108
Integer.parseInt(String.valueOf(param3))));
105-
case "moveend" -> mapView.getMapListener()
109+
case FUNCTION_MOVE_END -> getMapListener()
106110
.get()
107111
.onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE_END,
108112
gson.fromJson(String.valueOf(param4), JLLatLng.class),
109113
gson.fromJson(String.valueOf(param5), JLBounds.class),
110114
Integer.parseInt(String.valueOf(param3))));
111-
case "click" -> mapView.getMapListener()
115+
case FUNCTION_CLICK -> getMapListener()
112116
.get()
113117
.onAction(new ClickEvent(gson.fromJson(String.valueOf(param3),
114118
JLLatLng.class)));
115119

116-
case "zoom" -> mapView.getMapListener()
120+
case FUNCTION_ZOOM -> getMapListener()
117121
.get()
118122
.onAction(new ZoomEvent(OnJLMapViewListener.Action.ZOOM,
119123
Integer.parseInt(String.valueOf(param3))));
120124
default -> log.error(functionName + " not implemented!");
121125
}
122126
}
123127
} catch (Exception e) {
124-
log.error(e);
128+
log.error(e.getMessage(), e);
125129
}
126130
}
127131

128132
private boolean callListenerOnObject(
129133
String functionName, JLObject<JLObject<?>> jlObject, Object... params) {
130134
switch (functionName) {
131-
case "move" -> {
135+
case FUNCTION_MOVE -> {
132136
jlObject.getOnActionListener()
133137
.move(jlObject, OnJLObjectActionListener.Action.MOVE);
134138
return true;
135139
}
136-
case "movestart" -> {
140+
case FUNCTION_MOVE_START -> {
137141
jlObject.getOnActionListener()
138142
.move(jlObject, OnJLObjectActionListener.Action.MOVE_START);
139143
return true;
140144
}
141-
case "moveend" -> {
145+
case FUNCTION_MOVE_END -> {
142146
//update coordinate of the JLObject
143-
jlObject.update("moveend", gson.fromJson(String.valueOf(params[3]), JLLatLng.class));
147+
jlObject.update(FUNCTION_MOVE_END, gson.fromJson(String.valueOf(params[3]), JLLatLng.class));
144148
jlObject.getOnActionListener()
145149
.move(jlObject, OnJLObjectActionListener.Action.MOVE_END);
146150
return true;
147151
}
148-
case "click" -> {
152+
case FUNCTION_CLICK -> {
149153
jlObject.getOnActionListener()
150154
.click(jlObject, OnJLObjectActionListener.Action.CLICK);
151155
return true;
152156
}
153-
default -> log.error(functionName + " not implemented!");
157+
default -> log.error("{} not implemented!", functionName);
154158
}
155159
return false;
156160
}
@@ -171,7 +175,10 @@ public void remove(Class<? extends JLObject<?>> targetClass, int id) {
171175
if (!jlObjects.containsKey(targetClass))
172176
return;
173177
JLObject<?> object = jlObjects.get(targetClass).remove(id);
174-
if (object != null)
175-
log.error(targetClass.getSimpleName() + " id:" + object.getId() + " removed");
178+
if (object != null) log.error("{} id: {} removed", targetClass.getSimpleName(), object.getId());
179+
}
180+
181+
private Optional<OnJLMapViewListener> getMapListener() {
182+
return Optional.ofNullable(listener);
176183
}
177184
}

src/main/java/io/github/makbn/jlmap/JLMapController.java

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,82 @@
11
package io.github.makbn.jlmap;
22

3+
import io.github.makbn.jlmap.engine.JLWebEngine;
34
import io.github.makbn.jlmap.exception.JLMapNotReadyException;
45
import io.github.makbn.jlmap.layer.*;
56
import io.github.makbn.jlmap.model.JLLatLng;
6-
import io.github.makbn.jlmap.model.JLMapOption;
7-
import javafx.concurrent.Worker;
8-
import javafx.scene.layout.AnchorPane;
9-
import javafx.scene.web.WebView;
10-
import lombok.AccessLevel;
11-
import lombok.NonNull;
12-
import lombok.experimental.FieldDefaults;
137

148
import java.util.HashMap;
159

1610
/**
1711
* @author Mehdi Akbarian Rastaghi (@makbn)
1812
*/
19-
@FieldDefaults(makeFinal = true, level = AccessLevel.PROTECTED)
20-
abstract class JLMapController extends AnchorPane {
21-
JLMapOption mapOption;
13+
interface JLMapController {
2214

23-
JLMapController(@NonNull JLMapOption mapOption) {
24-
this.mapOption = mapOption;
25-
}
26-
27-
protected abstract WebView getWebView();
15+
JLWebEngine getJLEngine();
2816

29-
protected abstract void addControllerToDocument();
17+
void addControllerToDocument();
3018

31-
protected abstract HashMap<Class<? extends JLLayer>, JLLayer> getLayers();
19+
HashMap<Class<? extends JLLayer>, JLLayer> getLayers();
3220

3321
/**
3422
* handle all functions for add/remove layers from UI layer
23+
*
3524
* @return current instance of {{@link JLUiLayer}}
3625
*/
37-
public JLUiLayer getUiLayer(){
26+
default JLUiLayer getUiLayer() {
3827
checkMapState();
3928
return (JLUiLayer) getLayers().get(JLUiLayer.class);
4029
}
4130

4231
/**
4332
* handle all functions for add/remove layers from Vector layer
33+
*
4434
* @return current instance of {{@link JLVectorLayer}}
4535
*/
46-
public JLVectorLayer getVectorLayer(){
36+
default JLVectorLayer getVectorLayer() {
4737
checkMapState();
4838
return (JLVectorLayer) getLayers().get(JLVectorLayer.class);
4939
}
5040

51-
public JLControlLayer getControlLayer() {
41+
default JLControlLayer getControlLayer() {
5242
checkMapState();
5343
return (JLControlLayer) getLayers().get(JLControlLayer.class);
5444
}
5545

56-
public JLGeoJsonLayer getGeoJsonLayer() {
46+
default JLGeoJsonLayer getGeoJsonLayer() {
5747
checkMapState();
5848
return (JLGeoJsonLayer) getLayers().get(JLGeoJsonLayer.class);
5949
}
6050

6151
/**
6252
* Sets the view of the map (geographical center).
53+
*
6354
* @param latLng Represents a geographical point with a certain latitude
6455
* and longitude.
6556
*/
66-
public void setView(JLLatLng latLng){
57+
default void setView(JLLatLng latLng) {
6758
checkMapState();
68-
getWebView().getEngine()
59+
getJLEngine()
6960
.executeScript(String.format("jlmap.panTo([%f, %f]);",
7061
latLng.getLat(), latLng.getLng()));
7162
}
7263

7364
/**
7465
* Sets the view of the map (geographical center) with animation duration.
66+
*
7567
* @param duration Represents the duration of transition animation.
76-
* @param latLng Represents a geographical point with a certain latitude
77-
* and longitude.
68+
* @param latLng Represents a geographical point with a certain latitude
69+
* and longitude.
7870
*/
79-
public void setView(JLLatLng latLng, int duration){
71+
default void setView(JLLatLng latLng, int duration) {
8072
checkMapState();
81-
getWebView().getEngine()
73+
getJLEngine()
8274
.executeScript(String.format("setLatLng(%f, %f,%d);",
8375
latLng.getLat(), latLng.getLng(), duration));
8476
}
8577

8678
private void checkMapState() {
87-
if (getWebView() == null ||
88-
getWebView().getEngine()
89-
.getLoadWorker().getState() != Worker.State.SUCCEEDED) {
79+
if (getJLEngine() == null || getJLEngine().getStatus() != JLWebEngine.Status.SUCCEEDED) {
9080
throw JLMapNotReadyException.builder().build();
9181
}
9282
}

0 commit comments

Comments
 (0)