Skip to content

Commit

Permalink
Added First Window Managment
Browse files Browse the repository at this point in the history
  • Loading branch information
ByAlexius committed May 6, 2024
1 parent c622c09 commit 807da33
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 13 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions add_license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

license_text='/*
* Copyright (c) 2024, Alexander Rziha
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.
*/'

# Target directory
target_dir="src"

# Loop through all .java files in the target directory and its subdirectories
find "$target_dir" -type f -name "*.java" | while read file; do

# Check if file exists
if [ -f "$file" ]; then
# Check if license text already exists
if ! grep -qF "$license_text" "$file"; then
# Prepend license text
echo "$license_text" | cat - "$file" > temp_file && mv temp_file "$file"
echo "License comment added to $file"
else
echo "License comment already exists in $file (skipped)"
fi
fi
done

echo "Checked all Java files and added the license text"
39 changes: 31 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
plugins {
id 'java'
id 'com.teamdev.jxbrowser' version '1.0.2'
}

jxbrowser {
version '7.38.2'
id 'application'
id 'org.openjfx.javafxplugin' version '0.1.0'
}

group = 'at.rziha'
version = '1.0-SNAPSHOT'

javafx {
version = "22.0.1"
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.web', 'javafx.swing' ]
}

sourceCompatibility = '21'
targetCompatibility = '21'

task preBuild {
println("Running Prebuild")
}

task addLicense(type: Exec) {
workingDir "$projectDir"
commandLine 'sh', "./add_license.sh"
}

build.dependsOn preBuild
preBuild.dependsOn addLicense

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

application {
mainModule = "at.rziha.jsaveexam"
mainClass = "at.rziha.jsaveexam.JSaveExam"
}

repositories {
mavenCentral()
}
Expand All @@ -18,9 +44,6 @@ dependencies {
compileOnly 'org.projectlombok:lombok:1.18.32'
annotationProcessor 'org.projectlombok:lombok:1.18.32'

implementation jxbrowser.crossPlatform
implementation jxbrowser.swing

testCompileOnly 'org.projectlombok:lombok:1.18.32'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
}
77 changes: 76 additions & 1 deletion src/main/java/at/rziha/jsaveexam/JSaveExam.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,82 @@
/*
* Copyright (c) 2024, Alexander Rziha
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.
*/
package at.rziha.jsaveexam;

import at.rziha.jsaveexam.webpage.BlackedOutWindow;
import at.rziha.jsaveexam.webpage.WebPageLoader;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class JSaveExam {
public static void main(String[] args) {
if (args == null || args.length == 0) {
new JSaveExam(null);
return;
}

String url = null;

for (String arg : args) {
if (arg.startsWith("--url="))
{
url = arg.substring("--url=".length());
}
}

new JSaveExam(url);
}

private GraphicsDevice defaultGraphicsDefault = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

private List<GraphicsDevice> notMainDisplay = new ArrayList<>();

public JSaveExam(String url) {
if (url == null || url.isEmpty())
url = "https://html5test.co/";

int test = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length;

if (GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length > 1) {
for (GraphicsDevice graphicsDevice : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
if (graphicsDevice != defaultGraphicsDefault)
notMainDisplay.add(graphicsDevice);
}
}

String finalUrl = url;
SwingUtilities.invokeLater(() -> {
WebPageLoader webPageLoader = new WebPageLoader(finalUrl);
webPageLoader.setVisible(true);
defaultGraphicsDefault.setFullScreenWindow(webPageLoader);
});

if (!notMainDisplay.isEmpty())
{
notMainDisplay.forEach(d -> {
SwingUtilities.invokeLater(() -> {
BlackedOutWindow blackedOutWindow = new BlackedOutWindow();
Rectangle bounds = d.getDefaultConfiguration().getBounds();
blackedOutWindow.setLocationByPlatform(true);
blackedOutWindow.setLocation(bounds.x, bounds.y);
d.setFullScreenWindow(blackedOutWindow);
blackedOutWindow.setVisible(true);
});
});
}
}
}
}
4 changes: 0 additions & 4 deletions src/main/java/at/rziha/jsaveexam/SwingApp.java

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/at/rziha/jsaveexam/webpage/BlackedOutWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package at.rziha.jsaveexam.webpage;

import com.sun.webkit.WebPage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;

public class BlackedOutWindow extends JFrame {
public BlackedOutWindow() {
setTitle("Blacked Out");
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setUndecorated(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);

getContentPane().setBackground(Color.BLACK);

addWindowFocusListener((new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {

}

@Override
public void windowLostFocus(WindowEvent e) {
requestFocus();
}
}));
}
}
62 changes: 62 additions & 0 deletions src/main/java/at/rziha/jsaveexam/webpage/WebPageLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024, Alexander Rziha
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.
*/
package at.rziha.jsaveexam.webpage;

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebView;

import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;

public class WebPageLoader extends JFrame {

public WebPageLoader(String url) {
setTitle("Web Page");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setUndecorated(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);

JFXPanel fxPanel = new JFXPanel();

Platform.runLater(() -> {
WebView webView = new WebView();
webView.getEngine().load(url);

Scene scene = new Scene(webView);
fxPanel.setScene(scene);
});

add(fxPanel);

addWindowFocusListener((new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {

}

@Override
public void windowLostFocus(WindowEvent e) {
requestFocus();
}
}));

Platform.runLater(() -> {
pack();
});
}
}

0 comments on commit 807da33

Please sign in to comment.