Skip to content

Commit c46b509

Browse files
committed
First release
Added first version of Java Web Viewer. Check Readme.md for details on how to use a pre-compiled jar has been included for convenance alongside the source in this repo
1 parent 633ef9d commit c46b509

74 files changed

Lines changed: 967 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Launch - FullScreen.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
java --module-path lib --add-modules javafx.controls,javafx.web -jar viewer.jar "index.htm" "Java WebApp" 1200 760 true

Launch.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
java --module-path lib --add-modules javafx.controls,javafx.web -jar viewer.jar "index.htm" "Java WebApp" 1200 760

LocalViewer.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import javafx.application.Application;
2+
import javafx.geometry.Rectangle2D;
3+
import javafx.scene.Scene;
4+
import javafx.scene.web.WebView;
5+
import javafx.stage.Screen;
6+
import javafx.stage.Stage;
7+
import java.nio.file.Path;
8+
import java.nio.file.Paths;
9+
import java.util.List;
10+
11+
public class LocalViewer extends Application {
12+
public static void main(String[] args) { launch(args); }
13+
14+
@Override
15+
public void start(Stage stage) {
16+
WebView webView = new WebView();
17+
List<String> params = getParameters().getRaw();
18+
19+
// FIXED URL HANDLING - handles bare filenames, full paths, and web URLs
20+
String url = params.isEmpty() ? Paths.get("index.htm").toUri().toString() : params.get(0);
21+
22+
// Convert bare filenames/paths to proper file:// URLs
23+
if (!url.startsWith("http") && !url.startsWith("file://")) {
24+
try {
25+
Path path = Paths.get(url);
26+
url = path.toAbsolutePath().toUri().toString();
27+
} catch (Exception e) {
28+
// Fallback to relative path
29+
url = Paths.get(url).toUri().toString();
30+
}
31+
}
32+
33+
String title = params.size() > 1 ? params.get(1) : "Local HTML Viewer";
34+
double width = params.size() > 2 && !params.get(2).equalsIgnoreCase("auto") ?
35+
Double.parseDouble(params.get(2)) : 1200;
36+
double height = params.size() > 3 && !params.get(3).equalsIgnoreCase("auto") ?
37+
Double.parseDouble(params.get(3)) : 800;
38+
39+
webView.getEngine().load(url);
40+
Scene scene = new Scene(webView, width, height);
41+
stage.setScene(scene);
42+
stage.setTitle(title);
43+
44+
// Window positioning & behavior (skip if fullscreen/maximized)
45+
boolean fullscreen = params.size() > 4 && params.get(4).equalsIgnoreCase("true");
46+
boolean maximized = params.size() > 5 && params.get(5).equalsIgnoreCase("true");
47+
boolean resizable = params.size() > 6 ? !params.get(6).equalsIgnoreCase("false") : true;
48+
boolean alwaysOnTop = params.size() > 7 && params.get(7).equalsIgnoreCase("true");
49+
double x = params.size() > 8 && !params.get(8).equalsIgnoreCase("center") ? Double.parseDouble(params.get(8)) : -1;
50+
double y = params.size() > 9 && !params.get(9).equalsIgnoreCase("center") ? Double.parseDouble(params.get(9)) : -1;
51+
52+
stage.setResizable(resizable);
53+
stage.setAlwaysOnTop(alwaysOnTop);
54+
55+
if (fullscreen) {
56+
stage.setFullScreen(true);
57+
} else if (maximized) {
58+
stage.setMaximized(true);
59+
} else {
60+
stage.setWidth(width);
61+
stage.setHeight(height);
62+
if (x >= 0 && y >= 0) {
63+
stage.setX(x);
64+
stage.setY(y);
65+
} else {
66+
centerWindow(stage);
67+
}
68+
}
69+
70+
stage.show();
71+
}
72+
73+
private void centerWindow(Stage stage) {
74+
Screen screen = Screen.getPrimary();
75+
Rectangle2D bounds = screen.getVisualBounds();
76+
stage.setX((bounds.getWidth() - stage.getWidth()) / 2);
77+
stage.setY((bounds.getHeight() - stage.getHeight()) / 2);
78+
}
79+
}

README.md

Lines changed: 68 additions & 2 deletions
20.5 KB
Binary file not shown.
20.5 KB
Binary file not shown.
20 KB
Binary file not shown.
20.1 KB
Binary file not shown.
20 KB
Binary file not shown.
23.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)