Skip to content

Commit

Permalink
Added exit button for better development,
Browse files Browse the repository at this point in the history
Fixed autofocus flickering
  • Loading branch information
ByAlexius committed May 6, 2024
1 parent 8e5b114 commit 5d29588
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 33 deletions.
28 changes: 25 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,38 @@ plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.1.0'
id "com.diffplug.spotless" version "6.25.0"
id 'org.beryx.jlink' version '2.25.0'
}

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

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

sourceCompatibility = '21'
targetCompatibility = '21'
spotless {
java {
target('**/*.java')
removeUnusedImports();
}
}

jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = "JSaveExam"
}
}

jlinkZip {
group = 'distribution'
}

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

task preBuild {
println("Running Prebuild")
Expand All @@ -26,6 +46,8 @@ task addLicense(type: Exec) {

build.dependsOn preBuild
preBuild.dependsOn addLicense
preBuild.dependsOn spotlessApply
preBuild.dependsOn spotlessCheck

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/at/rziha/jsaveexam/JSaveExam.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package at.rziha.jsaveexam;

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

Expand Down Expand Up @@ -62,6 +63,7 @@ public JSaveExam(String url) {
SwingUtilities.invokeLater(() -> {
WebPageLoader webPageLoader = new WebPageLoader(finalUrl);
webPageLoader.setVisible(true);
addCloseButton(webPageLoader);
defaultGraphicsDefault.setFullScreenWindow(webPageLoader);
});

Expand All @@ -74,9 +76,25 @@ public JSaveExam(String url) {
blackedOutWindow.setLocationByPlatform(true);
blackedOutWindow.setLocation(bounds.x, bounds.y);
d.setFullScreenWindow(blackedOutWindow);

addCloseButton(blackedOutWindow);

blackedOutWindow.setVisible(true);
});
});
}
}

private static void addCloseButton(JFrame frame) {
JButton closeButton = new JButton("Close");
closeButton.addActionListener(e -> System.exit(0));
closeButton.setMargin(new Insets(5, 5, 5, 5));
closeButton.setBackground(new Color(220, 220, 220));
closeButton.setBorder(new RoundedBorder(5));

JPanel topBar = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
topBar.setBackground(new Color(220, 220, 220));
topBar.add(closeButton);
frame.add(topBar, BorderLayout.NORTH);
}
}
32 changes: 32 additions & 0 deletions src/main/java/at/rziha/jsaveexam/border/RoundedBorder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.border;

import javax.swing.border.AbstractBorder;
import java.awt.*;

public class RoundedBorder extends AbstractBorder {
private int radius;

public RoundedBorder(int radius) {
this.radius = radius;
}

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.setColor(c.getBackground());
g.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
}
}
32 changes: 16 additions & 16 deletions src/main/java/at/rziha/jsaveexam/webpage/BlackedOutWindow.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
/*
* 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 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() {
Expand All @@ -14,18 +24,8 @@ public BlackedOutWindow() {
setUndecorated(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);

getContentPane().setBackground(Color.BLACK);

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

}

@Override
public void windowLostFocus(WindowEvent e) {
requestFocus();
}
}));
getContentPane().setBackground(Color.BLACK);
}
}
16 changes: 2 additions & 14 deletions src/main/java/at/rziha/jsaveexam/webpage/WebPageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import javafx.scene.web.WebView;

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

public class WebPageLoader extends JFrame {

Expand All @@ -31,6 +29,8 @@ public WebPageLoader(String url) {
setUndecorated(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);

setAutoRequestFocus(true);

JFXPanel fxPanel = new JFXPanel();

Platform.runLater(() -> {
Expand All @@ -43,18 +43,6 @@ public WebPageLoader(String url) {

add(fxPanel);

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

}

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

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

0 comments on commit 5d29588

Please sign in to comment.