Skip to content

Commit b289602

Browse files
committed
replacing log4j with slf4j. adding JLWebEngine to make the code base ready for the next round of development. removing maven-assembly-plugin plugin. adding module-info descriptor file. code cleanup.
1 parent 5026f52 commit b289602

File tree

15 files changed

+204
-167
lines changed

15 files changed

+204
-167
lines changed

pom.xml

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
</developer>
1919
</developers>
2020

21+
<properties>
22+
<javafx.version>19.0.2.1</javafx.version>
23+
<lombok.version>1.18.34</lombok.version>
24+
</properties>
25+
2126
<licenses>
2227
<license>
2328
<name>GNU General Public License, Version 3.0</name>
@@ -29,42 +34,34 @@
2934
<build>
3035
<plugins>
3136
<plugin>
32-
<version>3.11.0</version>
37+
<version>3.13.0</version>
3338
<groupId>org.apache.maven.plugins</groupId>
3439
<artifactId>maven-compiler-plugin</artifactId>
3540
<configuration>
3641
<source>17</source>
3742
<target>17</target>
43+
<annotationProcessorPaths>
44+
<path>
45+
<groupId>org.projectlombok</groupId>
46+
<artifactId>lombok</artifactId>
47+
<version>${lombok.version}</version>
48+
</path>
49+
</annotationProcessorPaths>
50+
<useModulePath>true</useModulePath>
3851
</configuration>
3952
</plugin>
4053
<plugin>
4154
<groupId>org.openjfx</groupId>
4255
<artifactId>javafx-maven-plugin</artifactId>
4356
<version>0.0.8</version>
44-
</plugin>
45-
<plugin>
46-
<artifactId>maven-assembly-plugin</artifactId>
47-
<executions>
48-
<execution>
49-
<phase>package</phase>
50-
<goals>
51-
<goal>single</goal>
52-
</goals>
53-
</execution>
54-
</executions>
5557
<configuration>
56-
<archive>
57-
<manifest>
58-
<addClasspath>true</addClasspath>
59-
<mainClass>io.github.makbn.jlmap.Leaflet</mainClass>
60-
</manifest>
61-
</archive>
62-
<descriptorRefs>
63-
<descriptorRef>jar-with-dependencies</descriptorRef>
64-
</descriptorRefs>
58+
<!--for development purpose, this class can be found in the test directory-->
59+
<!--<mainClass>io.github.makbn.jlmap/io.github.makbn.jlmap.LeafletTestJFX</mainClass>-->
6560
</configuration>
6661
</plugin>
6762
</plugins>
63+
<sourceDirectory>src/main/java</sourceDirectory>
64+
<testSourceDirectory>src/test/java</testSourceDirectory>
6865
</build>
6966

7067
<dependencyManagement>
@@ -84,43 +81,38 @@
8481
<dependency>
8582
<groupId>org.openjfx</groupId>
8683
<artifactId>javafx-controls</artifactId>
87-
<version>19.0.2.1</version>
84+
<version>${javafx.version}</version>
8885
</dependency>
8986
<dependency>
9087
<groupId>org.openjfx</groupId>
9188
<artifactId>javafx-base</artifactId>
92-
<version>19.0.2.1</version>
89+
<version>${javafx.version}</version>
9390
</dependency>
9491
<dependency>
9592
<groupId>org.openjfx</groupId>
9693
<artifactId>javafx-swing</artifactId>
97-
<version>19.0.2.1</version>
94+
<version>${javafx.version}</version>
9895
</dependency>
9996
<dependency>
10097
<groupId>org.openjfx</groupId>
10198
<artifactId>javafx-web</artifactId>
102-
<version>19.0.2.1</version>
99+
<version>${javafx.version}</version>
103100
</dependency>
104101
<dependency>
105102
<groupId>org.openjfx</groupId>
106103
<artifactId>javafx-graphics</artifactId>
107-
<version>17</version>
104+
<version>${javafx.version}</version>
108105
</dependency>
109106
<dependency>
110107
<groupId>org.projectlombok</groupId>
111108
<artifactId>lombok</artifactId>
112-
<version>1.18.28</version>
109+
<version>${lombok.version}</version>
113110
<scope>provided</scope>
114111
</dependency>
115112
<dependency>
116-
<groupId>org.apache.logging.log4j</groupId>
117-
<artifactId>log4j-api</artifactId>
118-
<version>2.20.0</version>
119-
</dependency>
120-
<dependency>
121-
<groupId>org.apache.logging.log4j</groupId>
122-
<artifactId>log4j-core</artifactId>
123-
<version>2.20.0</version>
113+
<groupId>org.slf4j</groupId>
114+
<artifactId>slf4j-api</artifactId>
115+
<version>2.0.16</version>
124116
</dependency>
125117
<dependency>
126118
<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)