diff --git a/src/main/java/biz/nellemann/mdexpl/NetworkServiceCell.java b/src/main/java/biz/nellemann/mdexpl/NetworkServiceCell.java index 0295097..4b1ae7f 100644 --- a/src/main/java/biz/nellemann/mdexpl/NetworkServiceCell.java +++ b/src/main/java/biz/nellemann/mdexpl/NetworkServiceCell.java @@ -3,19 +3,26 @@ package biz.nellemann.mdexpl; import biz.nellemann.mdexpl.model.NetworkService; import com.gluonhq.charm.glisten.control.CharmListCell; import com.gluonhq.charm.glisten.control.ListTile; -import javafx.scene.image.ImageView; +import javafx.scene.Node; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; public class NetworkServiceCell extends CharmListCell { private final ListTile tile; - private final ImageView imageView; + //private final ImageView imageView; + private final Rectangle icon; public NetworkServiceCell() { this.tile = new ListTile(); - imageView = new ImageView(); - imageView.setFitHeight(15); - imageView.setFitWidth(25); - tile.setPrimaryGraphic(imageView); + //imageView = new ImageView(); + //imageView.setFitHeight(15); + //imageView.setFitWidth(25); + //tile.setPrimaryGraphic(imageView); + icon = new Rectangle(); + icon.setHeight(25); + icon.setWidth(25); + tile.setPrimaryGraphic(icon); tile.setOnMouseClicked(e -> { System.out.println("Selected -> " + itemProperty().get().getName() ); }); setText(null); } @@ -24,13 +31,10 @@ public class NetworkServiceCell extends CharmListCell { public void updateItem(NetworkService item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) { - tile.textProperty().setAll(item.getName() + " (" + item.getType() + ")", + tile.textProperty().setAll(item.getName(), "App: " + item.getApp(), "URL: " + item.getUrl() ); - //final Image image = Devices.getImage(item.getFlag()); - /*if (image != null) { - imageView.setImage(image); - }*/ + icon.setFill(item.getColor()); setGraphic(tile); } else { setGraphic(null); diff --git a/src/main/java/biz/nellemann/mdexpl/NetworkServiceListener.java b/src/main/java/biz/nellemann/mdexpl/NetworkServiceListener.java index bd7c76e..44a9751 100644 --- a/src/main/java/biz/nellemann/mdexpl/NetworkServiceListener.java +++ b/src/main/java/biz/nellemann/mdexpl/NetworkServiceListener.java @@ -3,6 +3,7 @@ package biz.nellemann.mdexpl; import biz.nellemann.mdexpl.model.NetworkService; import javafx.application.Platform; import javafx.collections.ObservableList; +import javafx.scene.paint.Color; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,14 +15,16 @@ public class NetworkServiceListener implements ServiceListener { private static final Logger log = LoggerFactory.getLogger(NetworkServiceListener.class); - private final String serviceType; + private final String service; private final ObservableList observableList; - public NetworkServiceListener(String type, ObservableList observableList) { - log.info("NetworkServiceListener() - type: {}", type); - this.serviceType = type; - this.observableList = observableList; + private final Color color; + public NetworkServiceListener(String service, ObservableList observableList, Color color) { + log.info("NetworkServiceListener() - type: {}", service); + this.service = service; + this.observableList = observableList; + this.color = color; } @Override @@ -34,7 +37,7 @@ public class NetworkServiceListener implements ServiceListener { if (serviceInfo != null) { String name = serviceInfo.getName(); log.info("serviceRemoved() - Service: " + name); - NetworkService oldNetworkService = new NetworkService(name, serviceType, serviceInfo.getApplication(), serviceInfo.getURLs()[0]); + NetworkService oldNetworkService = new NetworkService(name, service, serviceInfo.getApplication(), serviceInfo.getURLs()[0], color); Platform.runLater(() -> { observableList.remove(oldNetworkService); }); @@ -49,7 +52,7 @@ public class NetworkServiceListener implements ServiceListener { String name = serviceInfo.getName(); String app = serviceInfo.getApplication(); log.info("serviceResolved() - Service: {} - {} with url {}", app, name, url); - NetworkService newNetworkService = new NetworkService(name, serviceType, app, url); + NetworkService newNetworkService = new NetworkService(name, service, app, url, color); Platform.runLater(() -> { if(!observableList.contains(newNetworkService)) { observableList.add(newNetworkService); diff --git a/src/main/java/biz/nellemann/mdexpl/model/NetworkService.java b/src/main/java/biz/nellemann/mdexpl/model/NetworkService.java index f5f9b8b..465c2d5 100644 --- a/src/main/java/biz/nellemann/mdexpl/model/NetworkService.java +++ b/src/main/java/biz/nellemann/mdexpl/model/NetworkService.java @@ -1,17 +1,21 @@ package biz.nellemann.mdexpl.model; +import javafx.scene.paint.Color; + public class NetworkService { private String name; private String type; private String app; private String url; + private Color color; - public NetworkService(String name, String type, String app, String url) { + public NetworkService(String name, String type, String app, String url, Color color) { this.name = name; this.type = type; this.app = app; this.url = url; + this.color = color; } public String getName() { @@ -47,6 +51,15 @@ public class NetworkService { this.url = url; } + public Color getColor() { + return color; + } + + public void setColor(Color color) { + this.color = color; + } + + @Override public String toString() { return name + " (" + type + "), app=" + app + ", url=" + url; diff --git a/src/main/java/biz/nellemann/mdexpl/service/DiscoveryService.java b/src/main/java/biz/nellemann/mdexpl/service/DiscoveryService.java index cf3352e..7f6e8c2 100644 --- a/src/main/java/biz/nellemann/mdexpl/service/DiscoveryService.java +++ b/src/main/java/biz/nellemann/mdexpl/service/DiscoveryService.java @@ -3,6 +3,7 @@ package biz.nellemann.mdexpl.service; import biz.nellemann.mdexpl.NetworkServiceListener; import biz.nellemann.mdexpl.model.NetworkService; import javafx.collections.ObservableList; +import javafx.scene.paint.Color; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,7 +12,9 @@ import javax.inject.Singleton; import javax.jmdns.JmDNS; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Singleton @@ -23,12 +26,34 @@ public class DiscoveryService { private JmDNS jmdns; - // From: http://www.dns-sd.org/serviceTypes.html + some guesses - private final List services = Arrays.asList( + /*private final HashMap services = HashMap<>({ "http", "https", "upnp", "ssh", "sip", "rdp", "ntp", "rdp", "rtsp", "ntp", "smb", "nfs", "llrp", "ftp", "ep", "daap", "ipp", "ipps", "googlecast", "sonos", "airplay", "smartenergy", "skype", "bittorrent" - ); + );*/ + + // From: http://www.dns-sd.org/serviceTypes.html + some guesses + private final Map services = new HashMap<>() {{ + put("http", Color.BLUE); + put("https", Color.DARKBLUE); + + put("googlecast", Color.RED); + put("airplay", Color.SLATEGRAY); + put("sonos", Color.SANDYBROWN); + + put("ipp", Color.LIGHTGRAY); + put("ipps", Color.LIGHTGRAY); + + put("nfs", Color.CORAL); + put("smb", Color.CORAL); + put("cifs", Color.CORAL); + + put("smartenergy", Color.LIGHTGREEN); + + put("sip", Color.YELLOW); + put("skype", Color.YELLOW); + }}; + @PostConstruct public void initialize() { @@ -40,18 +65,14 @@ public class DiscoveryService { } } - public void register() { - - } public void setObservableList(ObservableList list) { this.observableList = list; - services.forEach(service -> { - String serviceType = String.format("_%s._%s.local.", service, "tcp"); - NetworkServiceListener networkServiceListener = new NetworkServiceListener(serviceType, observableList); - jmdns.addServiceListener(serviceType, networkServiceListener); + services.forEach((item, color) -> { + String service = String.format("_%s._%s.local.", item, "tcp"); + NetworkServiceListener networkServiceListener = new NetworkServiceListener(service, observableList, color); + jmdns.addServiceListener(service, networkServiceListener); }); } - } diff --git a/src/main/java/biz/nellemann/mdexpl/view/MainPresenter.java b/src/main/java/biz/nellemann/mdexpl/view/MainPresenter.java index 0969767..19fb28f 100644 --- a/src/main/java/biz/nellemann/mdexpl/view/MainPresenter.java +++ b/src/main/java/biz/nellemann/mdexpl/view/MainPresenter.java @@ -68,12 +68,6 @@ public class MainPresenter { } - @FXML - protected void onButtonRefresh() { - log.info("onButtonRefresh()"); - } - - public void onEventShowing(LifecycleEvent lifecycleEvent) { } diff --git a/src/main/resources/biz/nellemann/mdexpl/view/about.fxml b/src/main/resources/biz/nellemann/mdexpl/view/about.fxml index 23cd1ce..df8b47f 100644 --- a/src/main/resources/biz/nellemann/mdexpl/view/about.fxml +++ b/src/main/resources/biz/nellemann/mdexpl/view/about.fxml @@ -8,7 +8,7 @@ - +