Show service properties #2

Merged
nellemann merged 2 commits from properties into main 2023-08-16 07:40:41 +00:00
11 changed files with 62 additions and 21 deletions
Showing only changes of commit 603701c296 - Show all commits

View file

@ -40,8 +40,8 @@ dependencies {
implementation 'org.slf4j:slf4j-api:2.0.7' // Logging API implementation 'org.slf4j:slf4j-api:2.0.7' // Logging API
runtimeOnly 'org.slf4j:slf4j-simple:2.0.7' // Logging API runtimeOnly 'org.slf4j:slf4j-simple:2.0.7' // Logging API
implementation 'javax.inject:javax.inject:1' implementation 'jakarta.inject:jakarta.inject-api:2.0.1'
implementation 'javax.annotation:javax.annotation-api:1.3.2' implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1'
implementation 'org.jmdns:jmdns:3.5.8' implementation 'org.jmdns:jmdns:3.5.8'
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0' testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'

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 = 0.1.1

View file

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

View file

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

View file

@ -1,14 +1,16 @@
package biz.nellemann.mdexpl; package biz.nellemann.mdexpl;
import biz.nellemann.mdexpl.model.NetworkService; 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.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.ClipboardContent; import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.input.Clipboard; import javafx.scene.input.Clipboard;
public class NetworkServiceCell extends ListCell<NetworkService> { public class NetworkServiceCell extends ListCell<NetworkService> {
private final Rectangle icon; private final Rectangle icon;
@ -31,6 +33,14 @@ public class NetworkServiceCell extends ListCell<NetworkService> {
if(itemProperty().get() != null) { if(itemProperty().get() != null) {
clipboardContent.putString(itemProperty().get().getUrl()); clipboardContent.putString(itemProperty().get().getUrl());
clipboard.setContent(clipboardContent); 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); setText(null);

View file

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

View file

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

View file

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

View file

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

View file

@ -3,10 +3,13 @@
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.BorderPane?> <?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> <center>
<ListView fx:id="listView" BorderPane.alignment="CENTER" /> <ListView fx:id="listView" BorderPane.alignment="CENTER" />
</center> </center>
<right>
<ListView fx:id="propertiesList" />
</right>
</BorderPane> </BorderPane>