Merge pull request 'Show service properties' (#2) from properties into main
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

Reviewed-on: #2
This commit is contained in:
Mark Nellemann 2023-08-16 07:40:40 +00:00
commit 8b6d863c6d
11 changed files with 63 additions and 22 deletions

View file

@ -40,8 +40,8 @@ dependencies {
implementation 'org.slf4j:slf4j-api:2.0.7' // Logging API
runtimeOnly 'org.slf4j:slf4j-simple:2.0.7' // Logging API
implementation 'javax.inject:javax.inject:1'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'jakarta.inject:jakarta.inject-api:2.0.1'
implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1'
implementation 'org.jmdns:jmdns:3.5.8'
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
@ -77,7 +77,7 @@ jlink {
'--vendor', 'Nellemann Data',
'--description', 'List mDNS services on your local network.',
'--copyright', 'Mark Nellemann <mark.nellemann@gmail.com>',
'--app-version', version
'--app-version', project.findProperty('version')
]
// Requires: https://wixtoolset.org/ to create installer on Windows

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View file

@ -1 +1 @@
version = 0.0.2
version = 1.0.1

View file

@ -6,7 +6,6 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import java.awt.Taskbar;
import java.awt.Toolkit;

View file

@ -2,17 +2,17 @@ package biz.nellemann.mdexpl;
import biz.nellemann.mdexpl.model.NetworkService;
import biz.nellemann.mdexpl.service.DiscoveryService;
import jakarta.inject.Inject;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.stage.WindowEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.ResourceBundle;
public class MainPresenter {
@ -20,6 +20,7 @@ public class MainPresenter {
private static final Logger log = LoggerFactory.getLogger(MainPresenter.class);
@FXML
private BorderPane view;
@ -29,6 +30,9 @@ public class MainPresenter {
@FXML
private ListView<NetworkService> listView;
@FXML
public ListView<String> propertiesList;
@Inject
DiscoveryService discoveryService;

View file

@ -1,14 +1,16 @@
package biz.nellemann.mdexpl;
import biz.nellemann.mdexpl.model.NetworkService;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Rectangle;
import javafx.scene.input.Clipboard;
public class NetworkServiceCell extends ListCell<NetworkService> {
private final Rectangle icon;
@ -31,6 +33,14 @@ public class NetworkServiceCell extends ListCell<NetworkService> {
if(itemProperty().get() != null) {
clipboardContent.putString(itemProperty().get().getUrl());
clipboard.setContent(clipboardContent);
Node source = (Node) e.getSource();
Scene scene = source.getScene();
Object node = scene.lookup("#propertiesList");
if(node instanceof ListView listView) {
listView.setItems(FXCollections.observableArrayList(itemProperty().get().getProperties()));
}
};
});
setText(null);

View file

@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceInfo;
import javax.jmdns.ServiceListener;
import java.util.Iterator;
public class NetworkServiceListener implements ServiceListener {
@ -21,7 +22,7 @@ public class NetworkServiceListener implements ServiceListener {
private final Color color;
public NetworkServiceListener(String service, ObservableList<NetworkService> observableList, Color color) {
log.info("NetworkServiceListener() - type: {}", service);
log.debug("NetworkServiceListener() - type: {}", service);
this.service = service;
this.observableList = observableList;
this.color = color;
@ -38,15 +39,15 @@ public class NetworkServiceListener implements ServiceListener {
ServiceInfo serviceInfo = event.getInfo();
if (serviceInfo != null) {
String name = serviceInfo.getName();
String url = serviceInfo.getURLs()[0];
log.info("serviceRemoved() - Service: " + name);
NetworkService networkService = new NetworkService(name, service, serviceInfo.getSubtype(), serviceInfo.getApplication(), serviceInfo.getURLs()[0], color);
while (observableList.contains(networkService)) {
Platform.runLater(() -> {
observableList.remove(networkService);
Platform.runLater( () -> {
observableList.stream().filter(e -> (
e.getName().equals(name) && e.getUrl().equals(url)
)).forEach(observableList::remove);
});
}
}
}
@Override
public void serviceResolved(ServiceEvent event) {
@ -56,7 +57,15 @@ public class NetworkServiceListener implements ServiceListener {
String name = serviceInfo.getName();
String app = serviceInfo.getApplication();
log.info("serviceResolved() - Service: {} - {} with url {}", app, name, url);
NetworkService networkService = new NetworkService(name, service, serviceInfo.getSubtype(), app, url, color);
for (Iterator<String> it = serviceInfo.getPropertyNames().asIterator(); it.hasNext(); ) {
String key = it.next();
String value = serviceInfo.getPropertyString(key);
//log.info(" -> " + key + " = " + value);
networkService.addProperty(key, value);
}
Platform.runLater(() -> {
if(!observableList.contains(networkService)) {
observableList.add(networkService);

View file

@ -1,8 +1,11 @@
package biz.nellemann.mdexpl.model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import javafx.scene.paint.Color;
import java.util.Objects;
import java.util.*;
public class NetworkService {
@ -12,6 +15,8 @@ public class NetworkService {
private String app;
private String url;
private Color color;
private final ArrayList<String> propertiesList = new ArrayList<>();
public NetworkService(String name, String type, String subType, String app, String url, Color color) {
this.name = name;
@ -71,6 +76,14 @@ public class NetworkService {
this.color = color;
}
public void addProperty(String key, String value) {
propertiesList.add(key + ": " + value);
}
public ArrayList<?> getProperties() {
return propertiesList;
}
@Override
public String toString() {

View file

@ -2,12 +2,12 @@ package biz.nellemann.mdexpl.service;
import biz.nellemann.mdexpl.NetworkServiceListener;
import biz.nellemann.mdexpl.model.NetworkService;
import jakarta.inject.Singleton;
import javafx.collections.ObservableList;
import javafx.scene.paint.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Singleton;
import javax.jmdns.JmDNS;
import java.io.IOException;
import java.net.InetAddress;
@ -56,6 +56,9 @@ public class DiscoveryService {
put("homekit", Color.LIGHTGREEN);
put("homebridge", Color.LIGHTGREEN);
put("device-info", Color.DARKGREEN);
//put("rdlink", Color.DARKGREEN);
put("sip", Color.YELLOW);
put("skype", Color.YELLOW);

View file

@ -3,8 +3,8 @@ module biz.nellemann.mdexpl {
requires javafx.fxml;
requires javax.jmdns;
requires org.slf4j;
requires javax.inject;
requires java.annotation;
requires jakarta.inject;
requires jakarta.annotation;
requires java.desktop;
opens biz.nellemann.mdexpl to javafx.fxml;

View file

@ -3,10 +3,13 @@
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane fx:id="view" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="biz.nellemann.mdexpl.MainPresenter">
<BorderPane fx:id="view" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="biz.nellemann.mdexpl.MainPresenter">
<center>
<ListView fx:id="listView" BorderPane.alignment="CENTER" />
</center>
<right>
<ListView fx:id="propertiesList" />
</right>
</BorderPane>