Initial commit - WIP

This commit is contained in:
Mark Nellemann 2023-08-07 15:39:39 +02:00
commit 48019f23bb
24 changed files with 1233 additions and 0 deletions

16
.editorconfig Normal file
View file

@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset=utf-8
end_of_line=lf
indent_size=4
indent_style=space
insert_final_newline=true
trim_trailing_whitespace=true
[*.{yml,yaml,gsp,htm,html,sh}]
indent_size=2

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
.idea
.vscode
.gradle
.project
.classpath
.settings
.DS_Store
bin/
build/

96
README.md Normal file
View file

@ -0,0 +1,96 @@
# mDNS Explorer
View all multicastDNS devices.
## Development
Java SDK version 17 (or later) is required.
## Native Images
The native images are built with GraalVM.
Download the Gluon version of GraalVM from https://github.com/gluonhq/graal/releases/tag/gluon-22.1.0.1-Final and extract it locally.
Point the GRAALVM_HOME environment variable to the folder:
```export GRAALVM_HOME="/path/to/gluon-22.1.0.1```
With all requirements setup and on a supported platform, the general idea is to run:
```shell
./gradlew clean build
./gradlew nativeBuild -Ptarget=android # or -Ptarget=ios
./gradlew nativeLink -Ptarget=android
./gradlew nativePackage -Ptarget=android
./gradlew nativeInstall -Ptarget=android
./gradlew nativeRun -Ptarget=android
```
or, in one go for Android:
```shell
./gradlew -Ptarget=android clean build nativeBuild nativeLink nativePackage nativeInstall nativeRun
```
or, in one go for iOS:
```shell
./gradlew -Ptarget=ios clean build nativeBuild nativeLink nativePackage nativeInstall nativeRun
```
### Linux
See https://docs.gluonhq.com/#prerequisites_linux
For nativeBuild on Linux, install the following dependencies.
```shell
sudo apt install libgtk-3-dev libavformat-dev libavutil-dev libavcodec-dev libasound2-dev libpango1.0-dev libxtst-dev build-essential
```
#### Building for Android (on Linux)
See https://docs.gluonhq.com/#prerequisites_android
Install Android Studio and use sdkmanager to install the following:
- Android SDK Platform 31
- NDK (Side by side)
Point the ANDROID_NDK variable to the installed NDK directory:
```
export ANDROID_NDK="/home/mark/Android/Sdk/ndk/25.2.9519653/"
```
Add the platform-tools to you PATH to use 'adb' command:
```
export PATH="$PATH:/home/mark/Android/Sdk/platform-tools/"
```
Run the 'adb devices' and 'adb usb' to verify your Android device is in development mode and allows connections.
### MacOS
See https://docs.gluonhq.com/#platforms_macos
Install the xcode command line tools and an iPhone emulator.
If you have problems with *xcrun* not being able to find *iphoneos*, try:
```shell
sudo xcode-select --switch /Applications/Xcode.app
```
Download and install homebrew, and install the following:
```shell
brew install maven
brew install --HEAD libusbmuxd
brew install --HEAD libimobiledevice
```
#### iOS (on MacOS)
See https://docs.gluonhq.com/#prerequisites_ios

119
build.gradle Normal file
View file

@ -0,0 +1,119 @@
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.14'
id "com.github.johnrengelman.shadow" version "8.1.1"
id 'com.gluonhq.gluonfx-gradle-plugin' version '1.0.19'
}
repositories {
mavenCentral()
mavenLocal()
maven {
url 'https://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
version = "0.0.1"
mainClassName = "biz.nellemann.mdexpl.App"
application.mainModule = "biz.nellemann.mdexpl"
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
modularity.inferModulePath = false
}
/* This is to be able to build with a JDK not bundled with JavaFX */
javafx {
version = '21+'
modules = [ 'javafx.controls', 'javafx.fxml' ]
// platform("linux-aarch64")
}
dependencies {
implementation 'com.gluonhq:charm-glisten:6.2.3'
implementation 'com.gluonhq:glisten-afterburner:2.1.0'
implementation 'org.slf4j:slf4j-api:2.0.7' // Logging API
runtimeOnly 'org.slf4j:slf4j-simple:2.0.7' // Logging API
implementation 'org.jmdns:jmdns:3.5.8'
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
testImplementation 'org.slf4j:slf4j-simple:2.0.7'
}
test {
useJUnitPlatform()
}
gluonfx {
verbose = true
target = project.hasProperty("target") ? project.getProperty("target") : 'host'
//target = 'ios' // Uncomment to enable iOS - see https://docs.gluonhq.com/#prerequisites_ios
//target = 'android' // Uncomment to enable Android - see https://docs.gluonhq.com/#prerequisites_android
attachConfig {
version = "4.0.18"
services 'storage', 'display', 'lifecycle', 'statusbar', 'cache'
}
reflectionList = [
"javafx.fxml.FXMLLoader",
"com.gluonhq.charm.glisten.mvc.View",
"com.gluonhq.charm.glisten.control.Icon",
"com.gluonhq.charm.glisten.control.DropdownButton",
"com.gluonhq.charm.glisten.control.BottomNavigation",
"com.gluonhq.charm.glisten.control.BottomNavigationButton",
"biz.nellemann.mdexpl.view.AboutPresenter",
"biz.nellemann.mdexpl.view.MainPresenter", "biz.nellemann.mdexpl.model.MainModel",
"biz.nellemann.mdexpl.service.DiscoveryService",
]
compilerArgs = [
'-Djava.awt.headless=true'
]
appIdentifier = 'biz.nellemann.mdexpl'
release {
// Android
appLabel = "mDNS Explorer"
//versionCode = "1"
//versionName = "1.0"
//providedKeyStorePath = ""
//providedKeyStorePassword = ""
//providedKeyAlias = ""
//providedKeyAliasPassword = ""
// iOS
//bundleName = ""
//bundleVersion = ""
//bundleShortVersion = ""
//providedSigningIdentity = ""
//providedProvisioningProfile = ""
//skipSigning = true // Will not run or deploy if not signed
}
}
shadowJar {
//archiveBaseName.set("vtd-poc-app")
//archiveClassifier.set('all')
archiveVersion.set("${System.env.BITBUCKET_BRANCH ?: 'dev' }")
}
tasks.build.dependsOn tasks.shadowJar
tasks.processResources {
filesMatching('**/configuration.properties') {
filter(ReplaceTokens, tokens: [copyright: '2023', version: System.env.BITBUCKET_BUILD_NUMBER ?: 'development' ])
}
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

244
gradlew vendored Executable file
View file

@ -0,0 +1,244 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

92
gradlew.bat vendored Normal file
View file

@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

10
settings.gradle Normal file
View file

@ -0,0 +1,10 @@
pluginManagement {
repositories {
mavenLocal()
maven {
url "https://nexus.gluonhq.com/nexus/content/repositories/releases"
}
gradlePluginPortal()
}
}
rootProject.name = "mDNS Explorer"

View file

@ -0,0 +1,41 @@
package biz.nellemann.mdexpl;
import biz.nellemann.mdexpl.view.AppViewManager;
import com.gluonhq.charm.glisten.application.AppManager;
import com.gluonhq.charm.glisten.visual.Swatch;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import java.util.Objects;
public class App extends Application {
private final AppManager appManager = AppManager.initialize(this::postInit);
@Override
public void init() {
AppViewManager.registerViewsAndDrawer();
}
@Override
public void start(Stage primaryStage) {
//System.setProperty(com.gluonhq.attach.util.Constants.ATTACH_DEBUG,"true");
appManager.start(primaryStage);
}
private void postInit(Scene scene) {
Swatch.GREEN.assignTo(scene);
//scene.getStylesheets().add(App.class.getResource("style.css").toExternalForm());
((Stage) scene.getWindow()).getIcons().add(new Image(Objects.requireNonNull(App.class.getResourceAsStream("/icon.png"))));
}
public static void main(String[] args) {
launch(args);
}
}

View file

@ -0,0 +1,44 @@
package biz.nellemann.mdexpl;
import biz.nellemann.mdexpl.model.Device;
import biz.nellemann.mdexpl.model.Devices;
import com.gluonhq.charm.glisten.control.CharmListCell;
import com.gluonhq.charm.glisten.control.ListTile;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class DeviceCell extends CharmListCell<Device> {
private final ListTile tile;
private final ImageView imageView;
public DeviceCell() {
this.tile = new ListTile();
imageView = new ImageView();
imageView.setFitHeight(15);
imageView.setFitWidth(25);
tile.setPrimaryGraphic(imageView);
setText(null);
}
@Override
public void updateItem(Device item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
tile.textProperty().setAll(item.getName() + " (" + item.getAbbr() + ")",
"Capital: " + item.getCapital() +
", Population (M): " + String.format("%.2f", item.getPopulation() / 1_000_000d),
"Area (km" + "\u00B2" + "): " + item.getArea() +
", Density (pop/km" + "\u00B2" + "): " + String.format("%.1f", item.getDensity())
);
final Image image = Devices.getImage(item.getFlag());
if (image != null) {
imageView.setImage(image);
}
setGraphic(tile);
} else {
setGraphic(null);
}
}
}

View file

@ -0,0 +1,52 @@
package biz.nellemann.mdexpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceInfo;
import javax.jmdns.ServiceListener;
import java.util.HashMap;
public class NetworkServiceListener implements ServiceListener {
private static final Logger log = LoggerFactory.getLogger(NetworkServiceListener.class);
private final HashMap<String, String> onlineList = new HashMap<>();
private final String serviceType;
public NetworkServiceListener(String type) {
log.info("NetworkServiceListener() - type: {}", type);
this.serviceType = type;
}
@Override
public void serviceAdded(ServiceEvent event) {
}
@Override
public void serviceRemoved(ServiceEvent event) {
ServiceInfo serviceInfo = event.getInfo();
if (serviceInfo != null) {
String name = serviceInfo.getName();
onlineList.remove(name);
log.info("serviceRemoved() - Removed service: " + name);
}
}
@Override
public void serviceResolved(ServiceEvent event) {
ServiceInfo serviceInfo = event.getInfo();
if (serviceInfo != null) {
String url = serviceInfo.getURLs()[0];
String name = serviceInfo.getName();
String app = serviceInfo.getApplication();
log.debug(serviceInfo.toString());
onlineList.put(name, url);
log.info("serviceResolved() - Found {}: {} with url {}", app, name, url);
}
}
}

View file

@ -0,0 +1,87 @@
package biz.nellemann.mdexpl.model;
public class Device {
private String name;
private String abbr;
private String capital;
private int population;
private int area; /* km^2 */
private String flag;
public Device(String name, String abbr, String capital, int population, int area, String flag) {
this.name = name;
this.abbr = abbr;
this.capital = capital;
this.population = population;
this.area = area;
this.flag = flag;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAbbr() {
return abbr;
}
public void setAbbr(String abbr) {
this.abbr = abbr;
}
public String getCapital() {
return capital;
}
public void setCapital(String capital) {
this.capital = capital;
}
public int getPopulation() {
return population;
}
public void setPopulation(int population) {
this.population = population;
}
public int getArea() {
return area;
}
public void setArea(int area) {
this.area = area;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
/**
* Population density
* @return population density (pop. per km^2)
*/
public double getDensity() {
if (area > 0) {
return (double) population / (double) area;
}
return 0;
}
@Override
public String toString() {
return name + " (" + abbr + "), capital=" + capital + ", population=" + population + ", area=" + area;
}
}

View file

@ -0,0 +1,65 @@
package biz.nellemann.mdexpl.model;
import com.gluonhq.attach.cache.Cache;
import com.gluonhq.attach.cache.CacheService;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.image.Image;
public class Devices {
private static final Cache<String, Image> CACHE;
static {
CACHE = CacheService.create()
.map(cache -> cache.<String, Image>getCache("images"))
.orElseThrow(() -> new RuntimeException("No CacheService available"));
}
private static final String URL_PATH = "https://upload.wikimedia.org/wikipedia/commons/thumb/";
public static ObservableList<Device> statesList = FXCollections.observableArrayList(
new Device("Alabama", "AL", "Montgomery", 4903185, 135767, URL_PATH + "5/5c/Flag_of_Alabama.svg/23px-Flag_of_Alabama.svg.png"),
new Device("Alaska", "AK", "Juneau", 731545, 1723337, URL_PATH + "e/e6/Flag_of_Alaska.svg/21px-Flag_of_Alaska.svg.png"),
new Device("Arizona", "AZ", "Phoenix", 7278717, 295233, URL_PATH + "9/9d/Flag_of_Arizona.svg/23px-Flag_of_Arizona.svg.png"),
new Device("Arkansas", "AR", "Little Rock", 3017804, 137733, URL_PATH + "9/9d/Flag_of_Arkansas.svg/23px-Flag_of_Arkansas.svg.png"),
new Device("California", "CA", "Sacramento", 39512223, 423968, URL_PATH + "0/01/Flag_of_California.svg/23px-Flag_of_California.svg.png"),
new Device("Colorado", "CO", "Denver", 5758736, 269602, URL_PATH + "4/46/Flag_of_Colorado.svg/23px-Flag_of_Colorado.svg.png"),
new Device("Connecticut", "CT", "Hartford", 3565287, 14356, URL_PATH + "9/96/Flag_of_Connecticut.svg/20px-Flag_of_Connecticut.svg.png"),
new Device("Delaware", "DE", "Dover", 973764, 6446, URL_PATH + "c/c6/Flag_of_Delaware.svg/23px-Flag_of_Delaware.svg.png"),
new Device("Florida", "FL", "Tallahassee", 21477737, 170312, URL_PATH + "f/f7/Flag_of_Florida.svg/23px-Flag_of_Florida.svg.png"),
new Device("Georgia", "GA", "Atlanta", 10617423, 153910, URL_PATH + "5/54/Flag_of_Georgia_%28U.S._state%29.svg/23px-Flag_of_Georgia_%28U.S._state%29.svg.png"),
new Device("Hawaii", "HI", "Honolulu", 1415872, 28314, URL_PATH + "e/ef/Flag_of_Hawaii.svg/23px-Flag_of_Hawaii.svg.png"),
new Device("Idaho", "ID", "Boise", 1787065, 216443, URL_PATH + "a/a4/Flag_of_Idaho.svg/19px-Flag_of_Idaho.svg.png"),
new Device("Illinois", "IL", "Springfield", 12671821, 149997, URL_PATH + "0/01/Flag_of_Illinois.svg/23px-Flag_of_Illinois.svg.png")
);
public static Image getUSFlag() {
return getImage(URL_PATH + "a/a4/Flag_of_the_United_States.svg/320px-Flag_of_the_United_States.svg.png");
}
/**
* This method will always return the required image.
* It will cache the image and return from cache if still there.
* @param image: A valid url to retrieve the image
* @return an Image
*/
public static Image getImage(String image) {
if (image == null || image.isEmpty()) {
return null;
}
Image cachedImage = CACHE.get(image);
if (cachedImage == null) {
cachedImage = new Image(image, true);
cachedImage.errorProperty().addListener((obs, ov, nv) -> {
if (nv) {
CACHE.remove(image);
}
});
CACHE.put(image, cachedImage);
}
return cachedImage;
}
}

View file

@ -0,0 +1,20 @@
package biz.nellemann.mdexpl.model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.inject.Singleton;
@Singleton
public class MainModel {
private static final Logger log = LoggerFactory.getLogger(MainModel.class);
@PostConstruct
public void initialize() {
log.info("initialize()");
}
}

View file

@ -0,0 +1,48 @@
package biz.nellemann.mdexpl.service;
import biz.nellemann.mdexpl.NetworkServiceListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.inject.Singleton;
import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Singleton
public class DiscoveryService {
private final static Logger log = LoggerFactory.getLogger(DiscoveryService.class);
// http://www.dns-sd.org/serviceTypes.html
private final List<String> services = Arrays.asList(
"http", "https", "upnp", "ssh", "sip", "rdp", "ntp", "rdp", "rtsp",
"ntp", "smb", "nfs", "llrp", "ftp", "ep", "daap", "ipp", "ipps",
"googlecast", "appletv", "appletv-itunes", "smartenergy", "skype", "bittorrent",
"sonos", "airplay"
);
@PostConstruct
public void initialize() {
log.info("initialize()");
try {
JmDNS jmdns = JmDNS.create(null, "mdnsExplorer");
services.forEach(service -> {
String serviceType = String.format("_%s._%s.local.", service, "tcp");
NetworkServiceListener networkServiceListener = new NetworkServiceListener(serviceType);
jmdns.addServiceListener(serviceType, networkServiceListener);
});
} catch (IOException e) {
log.error("initialize() - {}", e.getMessage());
}
}
}

View file

@ -0,0 +1,64 @@
package biz.nellemann.mdexpl.view;
import com.gluonhq.charm.glisten.application.AppManager;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.util.ResourceBundle;
public class AboutPresenter {
private static final Logger log = LoggerFactory.getLogger(AboutPresenter.class);
@FXML
private ResourceBundle resources;
@FXML
View about;
@FXML
Label labelInfoWebsite;
@FXML
Label labelVersion;
@Inject String appVersion;
@Inject String aboutWebsite;
@FXML
public void initialize() {
log.info("initialize()");
about.showingProperty().addListener((obs, oldValue, newValue) -> {
if (newValue) {
AppManager appManager = AppManager.getInstance();
AppBar appBar = appManager.getAppBar();
appBar.setNavIcon(MaterialDesignIcon.MENU.button(e ->
appManager.getDrawer().open()));
appBar.setTitleText("About");
appBar.getActionItems().add(MaterialDesignIcon.CLOSE.button(e -> {
appManager.goHome();
}));
}
});
labelVersion.setText(appVersion);
labelInfoWebsite.setText(aboutWebsite);
}
}

View file

@ -0,0 +1,52 @@
package biz.nellemann.mdexpl.view;
import biz.nellemann.mdexpl.App;
import com.gluonhq.charm.glisten.afterburner.AppView;
import com.gluonhq.charm.glisten.afterburner.AppViewRegistry;
import com.gluonhq.charm.glisten.afterburner.Utils;
import com.gluonhq.charm.glisten.application.AppManager;
import com.gluonhq.charm.glisten.control.Avatar;
import com.gluonhq.charm.glisten.control.NavigationDrawer;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.scene.image.Image;
import java.util.Locale;
import java.util.Objects;
import static com.gluonhq.charm.glisten.afterburner.AppView.Flag.*;
public class AppViewManager {
public static final AppViewRegistry REGISTRY = new AppViewRegistry();
// Shown in drawer
public static final AppView PRIMARY_VIEW = view("Explorer", MainPresenter.class, MaterialDesignIcon.HOME, SHOW_IN_DRAWER, HOME_VIEW, SKIP_VIEW_STACK);
public static final AppView ABOUT_VIEW = view("About", AboutPresenter.class, MaterialDesignIcon.HELP, SHOW_IN_DRAWER);
private static AppView view(String title, Class<?> presenterClass, MaterialDesignIcon menuIcon, AppView.Flag... flags ) {
return REGISTRY.createView(name(presenterClass), title, presenterClass, menuIcon, flags);
}
private static String name(Class<?> presenterClass) {
return presenterClass.getSimpleName().toUpperCase(Locale.ROOT).replace("PRESENTER", "");
}
public static void registerViewsAndDrawer() {
for (AppView view : REGISTRY.getViews()) {
view.registerView();
}
NavigationDrawer.Header header = new NavigationDrawer.Header("mDNS Explorer",
"Multicast DNS Explorer",
new Avatar(48, new Image(Objects.requireNonNull(App.class.getResourceAsStream("/icon.png"))))
);
Utils.buildDrawer(AppManager.getInstance().getDrawer(), header, REGISTRY.getViews());
//NavigationDrawer.Footer footer = new NavigationDrawer.Footer("Bla");
//AppManager.getInstance().getDrawer().setFooter(footer);
}
}

View file

@ -0,0 +1,82 @@
package biz.nellemann.mdexpl.view;
import biz.nellemann.mdexpl.model.MainModel;
import biz.nellemann.mdexpl.service.DiscoveryService;
import com.gluonhq.charm.glisten.application.AppManager;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.CharmListView;
import com.gluonhq.charm.glisten.control.Icon;
import com.gluonhq.charm.glisten.control.LifecycleEvent;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML;
import javafx.geometry.Orientation;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.ImageView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.util.ResourceBundle;
public class MainPresenter {
private static final Logger log = LoggerFactory.getLogger(MainPresenter.class);
@FXML
private View main;
@Inject
private MainModel model;
@Inject
private DiscoveryService discoveryService;
@FXML
private ResourceBundle resources;
@FXML
private CharmListView charmListView;
@FXML
public void initialize() {
log.info("initialize()");
main.showingProperty().addListener((obs, oldValue, newValue) -> {
if (newValue) {
AppManager appManager = AppManager.getInstance();
AppBar appBar = appManager.getAppBar();
appBar.setNavIcon(MaterialDesignIcon.MENU.button(e ->
appManager.getDrawer().open()));
appBar.setTitleText("mDNS Explorer");
//appBar.getActionItems().add(progressIndicator);
}
});
}
@FXML
protected void onButtonRefresh() {
log.info("onButtonRefresh()");
}
public void onEventShowing(LifecycleEvent lifecycleEvent) {
}
public void onEventHiding(LifecycleEvent lifecycleEvent) {
}
}

View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.Icon?>
<?import com.gluonhq.charm.glisten.mvc.View?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<View fx:id="about" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="biz.nellemann.mdexpl.view.AboutPresenter">
<VBox alignment="CENTER">
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="mDNS Explorer">
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
<font>
<Font size="36.0" />
</font>
</Label>
<Label fx:id="labelVersion" alignment="CENTER" layoutX="10.0" layoutY="234.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="version" textAlignment="CENTER">
<VBox.margin>
<Insets bottom="5.0" top="5.0" />
</VBox.margin>
</Label>
<HBox alignment="CENTER" spacing="5.0">
<children>
<Icon content="INFO" />
<Label fx:id="labelInfoWebsite" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" textAlignment="CENTER">
</Label>
</children>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</HBox>
</VBox>
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
</View>

View file

@ -0,0 +1,8 @@
###
# properties defined in configuration.properties per folder (component)
# can be directly injected into a presenter
appCopyright=@copyright@
appVersion=@version@
aboutWebsite=https://www.nellemann.biz

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.BottomNavigation?>
<?import com.gluonhq.charm.glisten.control.BottomNavigationButton?>
<?import com.gluonhq.charm.glisten.control.CharmListView?>
<?import com.gluonhq.charm.glisten.control.Icon?>
<?import com.gluonhq.charm.glisten.mvc.View?>
<?import javafx.scene.layout.BorderPane?>
<View fx:id="main" onHiding="#onEventHiding" onShowing="#onEventShowing" prefHeight="800.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="biz.nellemann.mdexpl.view.MainPresenter">
<bottom>
<BottomNavigation>
<BottomNavigationButton onAction="#onButtonRefresh" selected="true" text="Refresh">
<graphic>
<Icon content="REFRESH" />
</graphic>
</BottomNavigationButton>
</BottomNavigation>
</bottom>
<center>
<CharmListView fx:id="charmListView" BorderPane.alignment="CENTER" />
</center>
</View>

BIN
src/main/resources/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

View file

@ -0,0 +1,6 @@
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.showDateTime=false
org.slf4j.simpleLogger.showShortLogName=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS
org.slf4j.simpleLogger.levelInBrackets=true
org.slf4j.simpleLogger.defaultLogLevel=info